Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp1863529imb; Sun, 3 Mar 2019 09:05:49 -0800 (PST) X-Google-Smtp-Source: APXvYqy9moKJ4s0HSdkfQNHS6xLm85/liRVpDpboq8gXiBKgyfpckU8TiJez+FaNlLkH59uMWpmm X-Received: by 2002:a63:dc0f:: with SMTP id s15mr1368231pgg.163.1551632749611; Sun, 03 Mar 2019 09:05:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551632749; cv=none; d=google.com; s=arc-20160816; b=yZU3txwQIGUiFBuIMGEppNj9LQTpq1JaqkBWo6xvklFWS9FBK7ITuqg5wZyCcz21tk Z5DAtA+jjZqJrzXd51YeykFQcr8aYV9CZJebpL2deQM5K3b6rdAWk0IRPWIRA6N9Hoiu pB1wG5yHpQKMe1fxdva/Xd1DQTNNzNieNFgLNljSlEMtsTncu1XA6iKgoxiHoUC4SI3D 6PDB1DUKifqBrRXiJ7q3xUYboXbuSdi3nnAcT93Sb5NaC5yL3aWsGLv9KdRKaSXlm1lQ nuDq8BXXm0kdFVM/gnPN1TG8KMKpln5fuQ2zsWztzRgVEsFhXoAO/msyMXfKwQb+GEy1 +NIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=PvH3PSkQa49dwm3/QkaK5+/zzINkN9NyBLJdwDDZ1mI=; b=J/OddrNjma1R3JAeouSIuw6pd/sMdIX2vI94VK8X8fpaI8Oc4i5Z7XpmgSn9WSMkac 9UqFDtWgdbVjVa58VmBhd9PXaM/s8ydXLLEhMejfPmTORnE00FEP4RfC2YIlkpHb9gLE s9zOs/4sleNGkBIIKx6vDchYyZ77QI9AR5veWstx9zsoSLNoSSopcPsmbYwNrRnBFK5t JzEV5Cn32xaDJl5DAQI5qNTJC/Il1uDSCwf5cW5LYOQYGujKimVyv2FYDezqr6X3rjVr k0A+M5UdupPNshXjceZB5nI6VaWdqUdr1eqyyq6mefY68hTW1MlfA42RZw9hRbCTElG9 d8hg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z25si3103907pgv.523.2019.03.03.09.05.34; Sun, 03 Mar 2019 09:05:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726530AbfCCREm (ORCPT + 99 others); Sun, 3 Mar 2019 12:04:42 -0500 Received: from mail-ot1-f68.google.com ([209.85.210.68]:45892 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbfCCREl (ORCPT ); Sun, 3 Mar 2019 12:04:41 -0500 Received: by mail-ot1-f68.google.com with SMTP id i12so2274005otp.12; Sun, 03 Mar 2019 09:04:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PvH3PSkQa49dwm3/QkaK5+/zzINkN9NyBLJdwDDZ1mI=; b=b3RPxt+CR+RhzC4/QlQIpkXtFESTgc63EqRP321i1ZegWff0KHqoAoBHDkF/XldDww /93w+CoxzYmVvAwToh/zspeoIiEk9ppwNrHSuWcGQo1+vDhDqdK3n+3wreuDnLVAdsgH N/pbdZ77SsRjnXZ/iwjrVRvx2eOZPD38tAhjpXblHxUiFRuVWb7rLXrl21r7QIYeOnam FDulcfAOYhF4UGj4LRvkyTvkCq/xSXIwZajX3WvkuITQh6l9+Vr55/9qH3n1dztmJVzf XvYc8og3o0hxB1PIsZh9U0dvrBO2nBVS0SXcBeRsAkD2JDTSKJYUMIg99mKOwLNVnGtY 44Tg== X-Gm-Message-State: APjAAAWq40kkUQQYPQ/htMMXLD6i/0OaR4pypeRlsy5GsId4y0+jo98U O47k22vaVmjKrebKTx0jbknr4fMduByqWXUSmZM= X-Received: by 2002:a9d:7cd3:: with SMTP id r19mr10184394otn.139.1551632680471; Sun, 03 Mar 2019 09:04:40 -0800 (PST) MIME-Version: 1.0 References: <20190302100420.GA7044@chenyu-office.sh.intel.com> In-Reply-To: <20190302100420.GA7044@chenyu-office.sh.intel.com> From: "Rafael J. Wysocki" Date: Sun, 3 Mar 2019 18:04:26 +0100 Message-ID: Subject: Re: [PATCH 2/2][RFC v2] ACPI: Update cpuinfo.max after bootup if necessary To: Yu Chen Cc: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Viresh Kumar , Srinivas Pandruvada , Len Brown , Linux PM , Linux Kernel Mailing List , Yu Chen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 2, 2019 at 10:55 AM Yu Chen wrote: > > On Thu, Feb 28, 2019 at 11:56:48PM +0100, Rafael J. Wysocki wrote: > > On Thu, Feb 28, 2019 at 6:59 PM Chen Yu wrote: > > > > > > On Dell Inc. XPS13 9333, the BIOS changes the value of > > > MSR_IA32_MISC_ENABLE_TURBO_DISABLE at runtime (e.g., when > > > the power source changes), the maximum frequency of the > > > CPU is not updated accordingly. This is due to the policy's > > > cpuinfo.max is not updated when _PPC notifier fires. > > > > > > Fix this problem by updating the policy's cpuinfo.max when > > > necessary. > > > > > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=200759 > > > Reported-and-tested-by: Gabriele Mazzotta > > > Originally-by: Srinivas Pandruvada > > > Signed-off-by: Chen Yu > > > --- > > > drivers/cpufreq/cpufreq.c | 2 ++ > > > drivers/cpufreq/intel_pstate.c | 15 +++++++++++++-- > > > 2 files changed, 15 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > > > index e35a886e00bc..95e08816b512 100644 > > > --- a/drivers/cpufreq/cpufreq.c > > > +++ b/drivers/cpufreq/cpufreq.c > > > @@ -2237,6 +2237,8 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, > > > > > > policy->min = new_policy->min; > > > policy->max = new_policy->max; > > > + policy->cpuinfo.max_freq = new_policy->cpuinfo.max_freq; > > > + policy->cpuinfo.min_freq = new_policy->cpuinfo.min_freq; > > > trace_cpu_frequency_limits(policy); > > > > > > policy->cached_target_freq = UINT_MAX; > > > diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c > > > index dd66decf2087..841c74f69f66 100644 > > > --- a/drivers/cpufreq/intel_pstate.c > > > +++ b/drivers/cpufreq/intel_pstate.c > > > @@ -2081,11 +2081,17 @@ static void intel_pstate_adjust_policy_max(struct cpufreq_policy *policy, > > > > > > static int intel_pstate_verify_policy(struct cpufreq_policy *policy) > > > { > > > + int max_freq; > > > struct cpudata *cpu = all_cpu_data[policy->cpu]; > > > > > > update_turbo_state(); > > > + max_freq = intel_pstate_get_max_freq(cpu); > > > + > > > + if (acpi_ppc && max_freq != policy->cpuinfo.max_freq) > > > + policy->cpuinfo.max_freq = policy->max = max_freq; > > > > Updating cpuinfo.max_freq here only causes the current limit to be > > reported via sysfs, because intel_pstate doesn't actually use > > cpuinfo.max_freq for anything and the core doesn't enforce it as a > > limit. > > > > All of the computations in the active mode in the driver actually use > > the current limit anyway AFAICS. > > > Yes, but it looks like we should also take care of the cpuinfo.max > if it changes, I searched the code, it seems that other components > might use the policy's cpuinfo.max for some purpose. They might use > cpufreq_cpu_get() to get the policy, and use the cpuinfo.max_freq > directly, no matter what the mode intel_pstate is in. Such as kvm > might use it as the max tsc khz if the tsc is not constant. And i915 > might consider the cpuinfo.max_freq to adjust the IA frequency on > gen6 platforms. So changing cpuinfo.max might also impact not only > cpufreq but also other components too. > > > + > > > cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, > > > - intel_pstate_get_max_freq(cpu)); > > > + max_freq); > > > > > > if (policy->policy != CPUFREQ_POLICY_POWERSAVE && > > > policy->policy != CPUFREQ_POLICY_PERFORMANCE) > > > @@ -2192,11 +2198,16 @@ static struct cpufreq_driver intel_pstate = { > > > > > > static int intel_cpufreq_verify_policy(struct cpufreq_policy *policy) > > > { > > > + int max_freq; > > > struct cpudata *cpu = all_cpu_data[policy->cpu]; > > > > > > update_turbo_state(); > > > + max_freq = intel_pstate_get_max_freq(cpu); > > > + > > > + if (acpi_ppc && max_freq != policy->cpuinfo.max_freq) > > > + policy->cpuinfo.max_freq = policy->max = max_freq; > > > > In this case (passive mode) updating cpuinfo.max_freq will actually > > cause governors to use the new value in computations, so the P-state > > selection will work somewhat differently, but that isn't really > > consistent with what acpi-cpufreq does and with setting no_turbo in > > the intel_pstate sysfs to 1 without this patch. > > > > With acpi-cpufreq cpuinfo.max_freq is always the max frequency in the > > _PSS table regardless of what the _PSS limit is. Also setting > > no_turbo to 1 in intel_pstate without this patch doesn't cause > > cpuinfo.max_freq to change and I don't really think that it should. > > > > I would be tempted to always initialize cpuinfo.max_freq to the max > > turbo frequency, but there is a concern about systems in which > > MSR_IA32_MISC_ENABLE_TURBO_DISABLE is never set on the fly (just in > > the BIOS setup as it should be) and where it doesn't make sense to > > consider turbo frequencies at all. > Ok, maybe we can check the bit during boot(consider BIOS's setting)? > > > > > cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, > > > - intel_pstate_get_max_freq(cpu)); > > > + max_freq); > > > > > > intel_pstate_adjust_policy_max(policy, cpu); > > > > > > -- > > > > It looks like I need to think about this a bit more. > Ok, I'll test the patch you sent out. Please do.