From patchwork Thu Jun 20 03:05:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 167286 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1492382ilk; Wed, 19 Jun 2019 20:06:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYpIeSGhXSg3xr+aIa85kJvMCj9JCF4D6eS1PfNXV3fAE1vYm/DzxQKgPBSykyOA9qGquv X-Received: by 2002:a17:90a:fa18:: with SMTP id cm24mr604484pjb.120.1561000000880; Wed, 19 Jun 2019 20:06:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561000000; cv=none; d=google.com; s=arc-20160816; b=uR/CTAR3XOXHQ/2XakamOk7V9q/KysNS5XYQRXlY21OMoK4tBsV2aPjJGOcyd/QLId PvMfcwsM6YjmK6YQoWHJejdinESDBoi/0qkEju4UbnbKGzoaYhETsFeZ/P/qItV+D4Wk d+hQn0chF0/4zI+w7f727VH7KkjpSXpo5sRwAV9qP3PQ9T3dyK0TjXcpPcK7o4w3H52q II2L3OS5l+ES9yZ5mv3kMqKyXILCzqCqJ+kx07x/q5648wvIvaWkWG/IGhDD1cCsIyWA CV52VlVq76EXjpO4PSGyLArxV8e/oj7qzueaCwJtF3W0ooNAuli3844NS5IikvVO1eeq kwuw== 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=qfwDig7orMSvJHaqbucTSV2BJ49ck1tcnWGRCykxnUJfluWuNQoYo9vPB7VYoby7SB uhlsjnJofXHta8PVtieVVdSApMumJ9ZpX63tv4ryGHimNjhfp2Q8YWBEw3NZDpTgBjWh SCuBJTIwBBj7URVp+WfqsXdqnAccLJ4Tel8MSQE6X0v7Xn02qTzqmK6or9GtOjSQhwP5 cUca3/IOurxH3LSHIUHNZ6MvdYC74SjmnSNpTKfW2RuOLwgxSAqFtzQQcYzpvxuZEOMI 2MmAOA/mkMTDrcTZ/UiQAOi3rA8N8UmVWvB/Q02gcwvuNX7+qA/tpT/wz6jCYcESUTDh 8VeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DZpCjpoa; 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 i22si3040101pjx.13.2019.06.19.20.06.40; Wed, 19 Jun 2019 20:06:40 -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=DZpCjpoa; 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 S1731612AbfFTDGh (ORCPT + 30 others); Wed, 19 Jun 2019 23:06:37 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42243 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731568AbfFTDGg (ORCPT ); Wed, 19 Jun 2019 23:06:36 -0400 Received: by mail-pl1-f193.google.com with SMTP id ay6so743644plb.9 for ; Wed, 19 Jun 2019 20:06:35 -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=DZpCjpoaZQW45P9CeX3cDnXJU8tmgG817TlOWAKnWM3+mxcgfgm3MwAPNIg9q4WlvV mxtLg3/edOddOGSsNdFJOoqaFkOTbcpVBLqWc2jSUjY4oQRgpg6KvzAKnEV+JWGRuC73 OZ3oZSW5R8KBELMniexMbEYBACrBKo+9LhUcWFjJh9QdgMU9LnxJEAW8jFyse4XNhwdQ puK1HEQGkiyJ2onBQOeVMyTJniUw2w0lHWkbNeg5lHXSm+NdCw64T8mBHyJME0v1l889 DgFB1MSOoZ0JINkcsQMd7q1v31Qw6rjZ3u6h1O3/JhzIXaDbFFaoRiX+Ddv995jaznf2 CONw== 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=e50+A+s7LCTgQey0k6AS6qCBboXBCYLsche4RRIykHVmiWHmlMFa5ByzIIfoQsYQpD SgDzGcywrXoLcHxgkw0UAhB7g0CCJxNNi64l89WpuyPSDnyfG7ZvI/jXgokwA0HDDRsF 25hoUvnKVZGODiIhwJ2bZmU5f3akRBqkHEwGOjLNv3xGZAC6qSB7QHtliPmJ+Zb6B+RI lkFFfkEeinzTVvsFC53HQAFf5G2oeQpRAPVL1mPvO4bJYc4ycVCugL5zkTTN8SiAXGYQ ed3sz+nRxMcixAHam52VGaTBBt0QF5u70DXBr4MSJ/0ai5okYPbanGepHm/aZX80q7Hm ua3A== X-Gm-Message-State: APjAAAW1Ajc6wIUM74jrXQYBp7FreW/TNwpqBb6J6xgGBDI91ugfvYVb yNILVmZthUw+EYrKwm/MYW4hPcMEBa4= X-Received: by 2002:a17:902:27a8:: with SMTP id d37mr123268486plb.150.1560999995255; Wed, 19 Jun 2019 20:06:35 -0700 (PDT) Received: from localhost ([122.172.66.84]) by smtp.gmail.com with ESMTPSA id b135sm19459543pfb.44.2019.06.19.20.06.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jun 2019 20:06:34 -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 V2 5/5] cpufreq: Avoid calling cpufreq_verify_current_freq() from handle_update() Date: Thu, 20 Jun 2019 08:35:50 +0530 Message-Id: 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);