From patchwork Thu Apr 12 06:29:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 133188 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1366577ljb; Wed, 11 Apr 2018 23:29:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+MH8ZBXSREUSjsL9tdmmyuhT+9zu3727ou28a6VesGzMokqKNHrHDFFWp8JAKqquJQyUgb X-Received: by 10.99.191.12 with SMTP id v12mr5667387pgf.54.1523514586968; Wed, 11 Apr 2018 23:29:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523514586; cv=none; d=google.com; s=arc-20160816; b=dMquliyvWS1Gxx78aK6Z6UeG5nkhuTcLuDLZziGrsvTPfanbb1WpV1ALU/YyyT6avz jzK3vchbZCZSK0qP2GPdIvxSvMzG4Uf59eqCIbCgjQqFbJKIk8FaYL7FmmmGlXq+VnJ3 NPQ3gvhVCGq5M65Qku4S5HL/eKbH00ahFiJ0fuH9YE8m9MDbiXH8ON3o+llyEGDO4Wlq eZ2PmpEhmggUI48AWLo/4zIV5Eqy6MTpDTbxqP3UNgB2l9mXPwuGMYWXaU0hjtJ1EFaa BUshtD54lmShb5iRD6ylV3Di7WLKkN1wI7+zrGwmzjFs7VEoqkIKo7CgMWor/KOUqJ/6 nheg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=PrR6sHuEy9CFxvF/JpqRxiTNpmkUepMUfws270thSg0=; b=WAuvP7Gsm9t0N8WTGav5zh/1HmMy4l3obdE9QspRdRZsiHWlwOt2uz6V5+G7rI00To VbOH5TkifnJhVjqzkADqjDEzolB4NTdILC22Lx9/urj82UTTGcT60N/CMGwzEsfEcIzT ooDdsfqhLS2OPeJXWQ3V5vXr0vlNcIXYWnzQtm4pc9Fsv7WCGslPkhqpW/KuS71uLPcH LHNR2rDgl+BEt8VMeL7YdQo0RBr4hPsY0cWdo/AvqjADanQ6u8JgPTauMaZTWatjKxOp gVqVfs2b7VwssPgK1ZiG+Ql8mbmTA02GB8GEvN1UI6M4NFdqLcBJpVWsm59EdDpT9p7f CtCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GIPYMqBV; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 l2si1823819pgq.460.2018.04.11.23.29.46; Wed, 11 Apr 2018 23:29:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=GIPYMqBV; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1751794AbeDLG3p (ORCPT + 11 others); Thu, 12 Apr 2018 02:29:45 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:38286 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751014AbeDLG3p (ORCPT ); Thu, 12 Apr 2018 02:29:45 -0400 Received: by mail-pf0-f194.google.com with SMTP id y69so2801068pfb.5 for ; Wed, 11 Apr 2018 23:29:45 -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; bh=PrR6sHuEy9CFxvF/JpqRxiTNpmkUepMUfws270thSg0=; b=GIPYMqBV9i1Xu12bC492NlpH506z+cwdgu0JS61KJ0I557qB5c83GUAO1COKwgFoU/ WBAqAPpvZ+vuFxezKXeRst596uigu05lI+FLIPE/QQmUoYRJ6B7oVbzvu5lLQaKtygw3 EWOOpT1MG8gzfBtnz7MupPLdv+fmqnb1LWXj0= 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; bh=PrR6sHuEy9CFxvF/JpqRxiTNpmkUepMUfws270thSg0=; b=U2Fq58Ho20YHhWAzNkrVXwK6Cq5BIX9mF6CEHhXuh1yhA3L3sC+LtfosxYZp/eWhBn 63NFTkyuT/G1kE5mcGGT2QWMe5PTMnxddKpL8AQk19MXx94UH5NWTXGzhoAienpPci84 AGRQ/YTEaW77eL7rELSz5035q33rRM5fkaSuTAnNlspO6GOR6iafvoytftQ6q/Bk7I6y O+aRgWVLjMtawt3yJ+1d16H4f6azsz3stRr/Wjixlvcp58rRBivPspb9oMGT+jfTLE2K zXQskk4JXew0+Htq/kS6Yst7MxcqBqYP6Fg2+yq7KQ/eScoX3ja+u5DqpcrGz25+Oc90 vVeQ== X-Gm-Message-State: ALQs6tCo+ebKj9fO9gwpnIbGLmpYpxCGOCALRy43qKQSQWkEZE71r5ji uGNq1onXt5pjMzeh09rSs5vzjw== X-Received: by 10.99.129.199 with SMTP id t190mr5633473pgd.376.1523514584475; Wed, 11 Apr 2018 23:29:44 -0700 (PDT) Received: from localhost ([122.171.228.188]) by smtp.gmail.com with ESMTPSA id o88sm6355619pfk.91.2018.04.11.23.29.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Apr 2018 23:29:43 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot Subject: [PATCH] cpufreq: optimize cpufreq_notify_transition() Date: Thu, 12 Apr 2018 11:59:40 +0530 Message-Id: <1b02d854fa9d4ba5a597e986e6503ec28e71c092.1523514572.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org cpufreq_notify_transition() calls __cpufreq_notify_transition() for each CPU of a policy. There is a lot of code in __cpufreq_notify_transition() though, which isn't required to be executed for each CPU. This commit merges __cpufreq_notify_transition() into cpufreq_notify_transition() and modifies cpufreq_notify_transition() to execute minimum amount of code for each CPU. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 61 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 31 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 075d18f6ba7a..5f4b8b4ce116 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -300,8 +300,17 @@ static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) #endif } -static void __cpufreq_notify_transition(struct cpufreq_policy *policy, - struct cpufreq_freqs *freqs, unsigned int state) +/** + * cpufreq_notify_transition - call notifier chain and adjust_jiffies + * on frequency transition. + * + * This function calls the transition notifiers and the "adjust_jiffies" + * function. It is called twice on all CPU frequency changes that have + * external effects. + */ +static void cpufreq_notify_transition(struct cpufreq_policy *policy, + struct cpufreq_freqs *freqs, + unsigned int state) { BUG_ON(irqs_disabled()); @@ -313,54 +322,44 @@ static void __cpufreq_notify_transition(struct cpufreq_policy *policy, state, freqs->new); switch (state) { - case CPUFREQ_PRECHANGE: - /* detect if the driver reported a value as "old frequency" + /* + * Detect if the driver reported a value as "old frequency" * which is not equal to what the cpufreq core thinks is * "old frequency". */ if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { - if ((policy) && (policy->cpu == freqs->cpu) && - (policy->cur) && (policy->cur != freqs->old)) { + if (policy->cur && (policy->cur != freqs->old)) { pr_debug("Warning: CPU frequency is %u, cpufreq assumed %u kHz\n", freqs->old, policy->cur); freqs->old = policy->cur; } } - srcu_notifier_call_chain(&cpufreq_transition_notifier_list, - CPUFREQ_PRECHANGE, freqs); + + for_each_cpu(freqs->cpu, policy->cpus) { + srcu_notifier_call_chain(&cpufreq_transition_notifier_list, + CPUFREQ_PRECHANGE, freqs); + } + adjust_jiffies(CPUFREQ_PRECHANGE, freqs); break; case CPUFREQ_POSTCHANGE: adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); - pr_debug("FREQ: %lu - CPU: %lu\n", - (unsigned long)freqs->new, (unsigned long)freqs->cpu); - trace_cpu_frequency(freqs->new, freqs->cpu); + pr_debug("FREQ: %u - CPUs: %*pbl\n", freqs->new, + cpumask_pr_args(policy->cpus)); + + for_each_cpu(freqs->cpu, policy->cpus) { + trace_cpu_frequency(freqs->new, freqs->cpu); + srcu_notifier_call_chain(&cpufreq_transition_notifier_list, + CPUFREQ_POSTCHANGE, freqs); + } + cpufreq_stats_record_transition(policy, freqs->new); - srcu_notifier_call_chain(&cpufreq_transition_notifier_list, - CPUFREQ_POSTCHANGE, freqs); - if (likely(policy) && likely(policy->cpu == freqs->cpu)) - policy->cur = freqs->new; - break; + policy->cur = freqs->new; } } -/** - * cpufreq_notify_transition - call notifier chain and adjust_jiffies - * on frequency transition. - * - * This function calls the transition notifiers and the "adjust_jiffies" - * function. It is called twice on all CPU frequency changes that have - * external effects. - */ -static void cpufreq_notify_transition(struct cpufreq_policy *policy, - struct cpufreq_freqs *freqs, unsigned int state) -{ - for_each_cpu(freqs->cpu, policy->cpus) - __cpufreq_notify_transition(policy, freqs, state); -} - /* Do post notifications when there are chances that transition has failed */ static void cpufreq_notify_post_transition(struct cpufreq_policy *policy, struct cpufreq_freqs *freqs, int transition_failed)