Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp270709pxu; Tue, 5 Jan 2021 10:23:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxq+XStDilih2LE3Shh9ezwillcfOd2bOPylXsg3jmZpyxMtWv3h/VQM3PdxNhZ+Z1bHWhi X-Received: by 2002:a17:906:3781:: with SMTP id n1mr392559ejc.296.1609871021252; Tue, 05 Jan 2021 10:23:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609871021; cv=none; d=google.com; s=arc-20160816; b=iVK2BWTUl26Xg3ssruB7jrNyB2nl+LB15UgyVidFZc4SudDeaSwgD3anuaPAqCqPXF n+XBzj+UnNT4ADi/i8hLQ/m3bn8RRHe58cyxrUCzPIhkhLzZd+pY8w1tg24OOrHux4gd qTxWjcJKhrfnvl3h0e3VlhSKJMD027Ci8ScZx3ZiE89+UzRo6g2pr7sexPU4Wk/j6M0E UylyHN/CPHmz9RO/gKNKrRMr/7mPSqS+Pnnes4qpEBYcpXi5XC+YjnOVzCH1ASABfXUp x3xR/Myx2Iw/TZK+6mocYJruUTm5CU4rbP2k+jyuvc0GeriKrgMzGVp3YK/B4MnkyL33 cZXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Gy+J0cbfxixn5TvjNXCvxPFrrX7MZbhWawuwobGMaqc=; b=jahrY1yQUZL4duDGij11GPLRBxOAcps7U4AtkoWwRBRDS3E/wGBudcL9UbnRyMKTn/ fz+sFb8la1ZcquB/Oty6AAk3Yz6qlVJCOo2LE0bRXWreA2hFvx/B6d8VTwb6G0DN5pnS Cs5ExlVQLFoo4gG37HRcRYxXd6DJ1BzokESnK5E2dSsRp5WBiL93OOT8ZMA+zypIXlau kDvQj90zttT31MtagunHdbRoA1uAaN3LLIBF1j7ZtDaQn9PbkMEL1KimTMOMyJXhN2Bb A0xF6IXo3Ced5lBtY2gfTErRJPJDijb71HdK3ydkh9BseATPZOogFzoR6ojFCAWAb1fz Tdxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e19si187126edy.553.2021.01.05.10.23.17; Tue, 05 Jan 2021 10:23:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727989AbhAESVM (ORCPT + 99 others); Tue, 5 Jan 2021 13:21:12 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:61280 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726049AbhAESVM (ORCPT ); Tue, 5 Jan 2021 13:21:12 -0500 Received: from 89-77-60-66.dynamic.chello.pl (89.77.60.66) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.537) id 71a2e7a3474a6b66; Tue, 5 Jan 2021 19:20:30 +0100 From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Srinivas Pandruvada Subject: [PATCH] cpufreq: intel_pstate: Use HWP capabilities in intel_cpufreq_adjust_perf() Date: Tue, 05 Jan 2021 19:20:29 +0100 Message-ID: <1784464.uM0JrOW1fs@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki If turbo P-states cannot be used, either due to the configuration of the processor, or because intel_pstate is not allowed to used them, the maximum available P-state with HWP enabled corresponds to the HWP_CAP.GUARANTEED value which is not static. It can be adjusted by an out-of-band agent or during an Intel Speed Select performance level change, so long as it remains less than or equal to HWP_CAP.MAX. However, if turbo P-states cannot be used, intel_cpufreq_adjust_perf() always uses pstate.max_pstate (set during the initialization of the driver only) as the maximum available P-state, so it may miss a change of the HWP_CAP.GUARANTEED value. Prevent that from happening by modifyig intel_cpufreq_adjust_perf() to always read the "guaranteed" and "maximum turbo" performance levels from the cached HWP_CAP value. Signed-off-by: Rafael J. Wysocki --- drivers/cpufreq/intel_pstate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) Index: linux-pm/drivers/cpufreq/intel_pstate.c =================================================================== --- linux-pm.orig/drivers/cpufreq/intel_pstate.c +++ linux-pm/drivers/cpufreq/intel_pstate.c @@ -2653,12 +2653,13 @@ static void intel_cpufreq_adjust_perf(un unsigned long capacity) { struct cpudata *cpu = all_cpu_data[cpunum]; + u64 hwp_cap = READ_ONCE(cpu->hwp_cap_cached); int old_pstate = cpu->pstate.current_pstate; int cap_pstate, min_pstate, max_pstate, target_pstate; update_turbo_state(); - cap_pstate = global.turbo_disabled ? cpu->pstate.max_pstate : - cpu->pstate.turbo_pstate; + cap_pstate = global.turbo_disabled ? HWP_GUARANTEED_PERF(hwp_cap) : + HWP_HIGHEST_PERF(hwp_cap); /* Optimization: Avoid unnecessary divisions. */