Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp882383pxf; Wed, 7 Apr 2021 14:04:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMhg2ZanyzRAz6c9U0NNrn7QkYM8CtMr3PNc6tP0tVIJcEbCQuhgDHGfk+8HuoRieBWFmS X-Received: by 2002:a17:906:528d:: with SMTP id c13mr6037184ejm.52.1617829461559; Wed, 07 Apr 2021 14:04:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617829461; cv=none; d=google.com; s=arc-20160816; b=kSc49AgJzIFEZCMRnm+mkz2v0K3RgPFvrw3zPmv4wc10GR9jEIdm/+YnB36NJjU0Mf kEPBRSn00fcu5mmxY0IQFUHVik1lW//3FU9+hOZdui4W0dp91KHvnJT/eCxNSXKMDLxn mvU8K3I8HUn5ploRPQwjLLnX3MtLrLHM8sjiRMb8IxNxJrJOH4XQey1Ap5qex6qaOOO8 xqW7Rf3hbhGaCYrRFo12PPitQ8KxjqlSvsK0z0syCRWEEBWPE21MsSkduzddtQB3pOz+ 2utPVuUk+Z64thl0wPvYW9XY4js4OG83Lb5gorO1HZUEuaKZ+Ra9RuUkEUhLKfA1Kvk0 jMhw== 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=Mw/O7/UYgI/6iMG2eKWZLJH3B1MmHJTdNIj5B8IsvtE=; b=hQLlLSCJlaLV0Cti6hOUGk6xJ0WMyafOVAvXkLU5VR/HLf/Y8uoFPV6w/zVyQzo17m 5qyyWmfWIGBGLIR2cA6ZtAVAlVw+LSM4xGfGSUNecEbmPsckkmlnFw7hOYGQMcAk/U8j eJaPdQmoFJaoTg7o1gVpDb7f8orraGrZBntBQUWcGX/2/x4j2pZ5cOexGH40TKOrlHU1 1uvwkS5Ik6aXdhh27ylhUxtWfgfG/lGho1gSpKhl6Hp36a/8iwQYJA6o+tiyD+FxpuHB 9NVHUY5Fwzn7pQWZSf+hh/8wmb/fdxP2JhUmhX7N2tkFFdWlf8OFFsozarluMHFhurIe zkzQ== 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 u9si13456426ejj.272.2021.04.07.14.03.58; Wed, 07 Apr 2021 14:04:21 -0700 (PDT) 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 S1348361AbhDGOWJ (ORCPT + 99 others); Wed, 7 Apr 2021 10:22:09 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:58500 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348287AbhDGOWI (ORCPT ); Wed, 7 Apr 2021 10:22:08 -0400 Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 2.0.3) id 56eab0b343ef86fc; Wed, 7 Apr 2021 16:21:57 +0200 Received: from kreacher.localnet (89-64-81-116.dynamic.chello.pl [89.64.81.116]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 9AA4E669204; Wed, 7 Apr 2021 16:21:56 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Srinivas Pandruvada , Zhang Rui , Chen Yu Subject: [PATCH] cpufreq: intel_pstate: Simplify intel_pstate_update_perf_limits() Date: Wed, 07 Apr 2021 16:21:55 +0200 Message-ID: <5450142.DvuYhMxLoT@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 89.64.81.116 X-CLIENT-HOSTNAME: 89-64-81-116.dynamic.chello.pl X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduledrudejjedgjeehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufffkggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpefhgedtffejheekgeeljeevvedtuefgffeiieejuddutdekgfejvdehueejjeetvdenucfkphepkeelrdeigedrkedurdduudeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepkeelrdeigedrkedurdduudeipdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohephihurdgtrdgthhgvnhes ihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki Because pstate.max_freq is always equal to the product of pstate.max_pstate and pstate.scaling and, analogously, pstate.turbo_freq is always equal to the product of pstate.turbo_pstate and pstate.scaling, the result of the max_policy_perf computation in intel_pstate_update_perf_limits() is always equal to the quotient of policy_max and pstate.scaling, regardless of whether or not turbo is disabled. Analogously, the result of min_policy_perf in intel_pstate_update_perf_limits() is always equal to the quotient of policy_min and pstate.scaling. Accordingly, intel_pstate_update_perf_limits() need not check whether or not turbo is enabled at all and in order to compute max_policy_perf and min_policy_perf it can always divide policy_max and policy_min, respectively, by pstate.scaling. Make it do so. While at it, move the definition and initialization of the turbo_max local variable to the code branch using it. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- On top of linux-next. --- drivers/cpufreq/intel_pstate.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) Index: linux-pm/drivers/cpufreq/intel_pstate.c =================================================================== --- linux-pm.orig/drivers/cpufreq/intel_pstate.c +++ linux-pm/drivers/cpufreq/intel_pstate.c @@ -2195,9 +2195,8 @@ static void intel_pstate_update_perf_lim unsigned int policy_min, unsigned int policy_max) { + int scaling = cpu->pstate.scaling; int32_t max_policy_perf, min_policy_perf; - int max_state, turbo_max; - int max_freq; /* * HWP needs some special consideration, because HWP_REQUEST uses @@ -2206,33 +2205,24 @@ static void intel_pstate_update_perf_lim if (hwp_active) intel_pstate_get_hwp_cap(cpu); - if (global.no_turbo || global.turbo_disabled) { - max_state = cpu->pstate.max_pstate; - max_freq = cpu->pstate.max_freq; - } else { - max_state = cpu->pstate.turbo_pstate; - max_freq = cpu->pstate.turbo_freq; - } - - turbo_max = cpu->pstate.turbo_pstate; - - max_policy_perf = max_state * policy_max / max_freq; + max_policy_perf = policy_max / scaling; if (policy_max == policy_min) { min_policy_perf = max_policy_perf; } else { - min_policy_perf = max_state * policy_min / max_freq; + min_policy_perf = policy_min / scaling; min_policy_perf = clamp_t(int32_t, min_policy_perf, 0, max_policy_perf); } - pr_debug("cpu:%d max_state %d min_policy_perf:%d max_policy_perf:%d\n", - cpu->cpu, max_state, min_policy_perf, max_policy_perf); + pr_debug("cpu:%d min_policy_perf:%d max_policy_perf:%d\n", + cpu->cpu, min_policy_perf, max_policy_perf); /* Normalize user input to [min_perf, max_perf] */ if (per_cpu_limits) { cpu->min_perf_ratio = min_policy_perf; cpu->max_perf_ratio = max_policy_perf; } else { + int turbo_max = cpu->pstate.turbo_pstate; int32_t global_min, global_max; /* Global limits are in percent of the maximum turbo P-state. */