From patchwork Wed Jun 19 11:35:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 167227 Delivered-To: patch@linaro.org Received: by 2002:ac9:6410:0:0:0:0:0 with SMTP id r16csp500726ock; Wed, 19 Jun 2019 04:36:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqyAmfm1hd+tPUgs0U7tyQVvuBx5WMbo3EqiRP2/IXGvEU9JL4Om8tfqPtVkFW+l2PcQ+ILM X-Received: by 2002:a17:90a:35e6:: with SMTP id r93mr10787550pjb.20.1560944169337; Wed, 19 Jun 2019 04:36:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560944169; cv=none; d=google.com; s=arc-20160816; b=tdJ+Z4aOv7GRpLuIK3WcK78YIDvo8Zpb2Vra+/+j4CA16jJ4tEQ17EwQmYPI2BHlVV WXqXNK2ydl4tU8L0kQhyMgbGwiVy6OUr5GMw6QpryLULir6Obttyi1u2D7OijBdnNkcg DctwtT1iE/oOe1KdNr4AIqbzKD+DzcvbqtCcryJ20IBhSsgjCkt94wdq5oRPGqz2ev6H c91s5bgpwzSxyobJqfrRcPyS4lakU/iXvhc2CzeCcaA5DbS959kEJ/D81Suv6VLlIHgE Ll9hKPvAi7qzVulvUPuOOPcCOuMnCYlhlNuWvrt6JtnY6+KQVHnE6jEw4PBRYKlc4xku JegQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=e2RYmyEcM16uV8QAfPAD1VnbVzdNHH04eTPp0y1GpdE=; b=psXIl0hga4sSxOKhKOThfNaFkRepzpPtAEs69w2RgOb9es62qVNCw1bkl0WC2GjOWA 8sqKbWPV4A1FVTjUxmAreL3gEO7cuVTpKbKN+GZf8D4H6poqnmcQfAhVKNrLZGTJdkRE qCMS0Dy5R/p7Qe9q7r9JJelhGU4WsHGdtr+djhs28MlWmumpZNMhi9Fn5CnHYyeEC/3Q e9Ts3n0NjaNfdZOxOtZhKMskjBilv8hho/P2u3jXM+cXjei/zkC/NzXG6gzodFcj2IKb 5nkDdaRKvEPDTbAnvo1d+Wf1EmSB07LR1VBgIkAS/+mlnNgTChli79X0gu6Uu4nXn9bp KzDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zVOW+9TL; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t14si2866146pgh.51.2019.06.19.04.36.09; Wed, 19 Jun 2019 04:36:09 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=zVOW+9TL; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731754AbfFSLgI (ORCPT + 30 others); Wed, 19 Jun 2019 07:36:08 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:46403 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731743AbfFSLgF (ORCPT ); Wed, 19 Jun 2019 07:36:05 -0400 Received: by mail-pg1-f196.google.com with SMTP id v9so9484509pgr.13 for ; Wed, 19 Jun 2019 04:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e2RYmyEcM16uV8QAfPAD1VnbVzdNHH04eTPp0y1GpdE=; b=zVOW+9TLBbgrCy2ayvjj309DIcUy8Isl/jbni4YWmZwpa+P5KsEELYytIxnt+FC7lN dDsV4tWAtwZiyVyrcwibduuryY73DML3oL+dlnFKX+O2yiB7+uKgJUHzq7RV4o0MSLL+ cfFGac3xplbC+SP8kybt1kOHadOCK3YHUuu26GtorIEgRQzgGrHiZrYimgKcRu26O9M5 JykjfOtKMz31ughKph5Z5CLOp9fCVHt0gr2FUa7kaYmTFh9vXWEPmVWbuSJBE34GL15q d+YVPOmbAUrZM1jmDKiRuYvMxBgj2M/M72J/cSgtofN7h7Y2x0W6Lj35CdJcRtqjdOwV kBew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e2RYmyEcM16uV8QAfPAD1VnbVzdNHH04eTPp0y1GpdE=; b=VVpaFpfmChrPMNwroi9QBpO+Y28MsGclEzMht0Kl21o6BEiaBqJI4WynJka1srHRoX CcgjmKjjRYaVF+vRa7+3zs/fYG/FajMtrNwVR+/3Dn7PoPn90b36ld71ukOonVY12ppN U+/GobWZK1qfjiBKxkD8mmR16DbYIYkccSKmrIb7b+twXM7d7K2Bs1EQuiLyLOuuVnQi NUQVhl7H4kJmsU8qnovmDo/kAMK2AxMhLEVwFlbE4IDV1JzwC3pUYhYpsHfODXZZFUYP 2KWablcBpTI1EzoUGzuHL3JhDddDDbaf8CF7W/u/1eVqlelJgqVNdlmtL+LHW23Ce9WN djBA== X-Gm-Message-State: APjAAAUrl8ysEWN9gDkh7Yw+6uWURKMiUzYRoEr4V09mk9SVM4USC5LA kBAoFMLYH7oFBrhHtfqQYKWlhg== X-Received: by 2002:a63:1459:: with SMTP id 25mr7319713pgu.201.1560944164850; Wed, 19 Jun 2019 04:36:04 -0700 (PDT) Received: from localhost ([122.172.66.84]) by smtp.gmail.com with ESMTPSA id y22sm17954119pfm.70.2019.06.19.04.36.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jun 2019 04:36:04 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 6/6] cpufreq: Avoid calling cpufreq_verify_current_freq() from handle_update() Date: Wed, 19 Jun 2019 17:05:42 +0530 Message-Id: <5068dd1b268d5beb1c074ca97a3e031dbd560999.1560944014.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On some occasions cpufreq_verify_current_freq() schedules a work whose callback is handle_update(), which further calls cpufreq_update_policy() which may end up calling cpufreq_verify_current_freq() again. On the other hand, when cpufreq_update_policy() is called from handle_update(), the pointer to the cpufreq policy is already available but we still call cpufreq_cpu_acquire() to get it in cpufreq_update_policy(), which should be avoided as well. Fix both the issues by creating another helper reeval_frequency_limits(). Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 4556a53fc764..0a73de7aae54 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1115,13 +1115,25 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cp return ret; } +static void reeval_frequency_limits(struct cpufreq_policy *policy) +{ + struct cpufreq_policy new_policy = *policy; + + pr_debug("updating policy for CPU %u\n", policy->cpu); + + new_policy.min = policy->user_policy.min; + new_policy.max = policy->user_policy.max; + + cpufreq_set_policy(policy, &new_policy); +} + static void handle_update(struct work_struct *work) { struct cpufreq_policy *policy = container_of(work, struct cpufreq_policy, update); - unsigned int cpu = policy->cpu; - pr_debug("handle_update for cpu %u called\n", cpu); - cpufreq_update_policy(cpu); + + pr_debug("handle_update for cpu %u called\n", policy->cpu); + reeval_frequency_limits(policy); } static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) @@ -2378,7 +2390,6 @@ int cpufreq_set_policy(struct cpufreq_policy *policy, void cpufreq_update_policy(unsigned int cpu) { struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu); - struct cpufreq_policy new_policy; if (!policy) return; @@ -2391,12 +2402,7 @@ void cpufreq_update_policy(unsigned int cpu) (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false)))) goto unlock; - pr_debug("updating policy for CPU %u\n", cpu); - memcpy(&new_policy, policy, sizeof(*policy)); - new_policy.min = policy->user_policy.min; - new_policy.max = policy->user_policy.max; - - cpufreq_set_policy(policy, &new_policy); + reeval_frequency_limits(policy); unlock: cpufreq_cpu_release(policy);