From patchwork Thu May 10 09:30:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 135395 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp771945lji; Thu, 10 May 2018 02:30:41 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoOFTJXAIcEzYwSdGzit4cfz5ZDnW75YQUVm17xsSyTtcYaLiCNhev8AojGrXr8GwpxFH4n X-Received: by 2002:a62:d6da:: with SMTP id a87-v6mr659814pfl.200.1525944641254; Thu, 10 May 2018 02:30:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525944641; cv=none; d=google.com; s=arc-20160816; b=DhriCJxgj1RCNVHM1HZctyjRGK5Ts6QSE7MUCIDITRKPiOARRmo4yEP/v1xMOVR7uE xljQ2Qm40L9hMXl2YYMZxnpydstf42TZFbtkyn3PCT+HuYy6l/c5Ox6U68z3lk3HdgQF kvappm81TvD/tgXNN0digu3e2YuZQ26Ti9q0SrlaJZ9sjAT/LJN4ZTEKF82GRgxYR8vQ SSe7PvweNeRFfdjmy/gEBw+jj9Bk3FfCj+UhlQD5cHrWiM86H++LqnSSQzZtvPFjZ+ES mDHOPOTzKo2xMLi9qryRAXHBYf0NVsW2G327Gooe0jyBLb2AryjkuibcRBaYuJ7S5HXU kUqw== 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=zwrYT9WEndmJrklIUjgwnObJzzir5F2/whQWNaA7Lug=; b=zAUDLBmNrOZcH7sRxaYSmxbaEK4m9GSzFBC5YNlrBWEYYlK8e4ypaL4sXs8ZHb9hkP bDBiLUHXTHfKqspKpp/1VjtAF+CxJ97xbOErXwW9+MOyWx6mc212R8gOaC8ipFw039AF B9taQpqJYRK7SHcRQp/supDc0J9QE6yZ1f4tXSoCbFlqogkmJDCPkjVLWjj7rQ3b0Yhb z0/TbWzsFyVKz46HL99wzDSGYsZjsrAW2vEQ4kr/Rw3eCQTBsFgcRS0ZUbdBe5ZUmj1E LnRV2fyo7i9IHAABIvc3jHq0c2eUfD7wHOvXCp1KKQtVj9NAcFH8DGVNHuketh5KJaX1 FEyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YQUxgvXb; 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 p66-v6si343835pga.180.2018.05.10.02.30.40; Thu, 10 May 2018 02:30:41 -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=YQUxgvXb; 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 S1756726AbeEJJaj (ORCPT + 10 others); Thu, 10 May 2018 05:30:39 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:45379 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756665AbeEJJai (ORCPT ); Thu, 10 May 2018 05:30:38 -0400 Received: by mail-pf0-f193.google.com with SMTP id c10-v6so788511pfi.12 for ; Thu, 10 May 2018 02:30:38 -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=zwrYT9WEndmJrklIUjgwnObJzzir5F2/whQWNaA7Lug=; b=YQUxgvXbF9pfl0TH/8whVyMXNGd5k3DvwFYdz7sRgY+LMEKvkkFIs66ZMLtv6/MmDn KJBVeIxm1KOLTrG+xanpFSL2dhUZGG+Zau4wTXx9o6eW3iPwdStIW+HgL7p6Y12mgZWS BIvgsFRZ0Qx1XUl9lbhY1oqzkH3Gcgh2BNp+A= 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=zwrYT9WEndmJrklIUjgwnObJzzir5F2/whQWNaA7Lug=; b=rUxKweI323T7ozsuNZnIsyohA7+ecVSPSppUM2tkLeHOV+HiK7Gc6CRF669BdY5NTe YG0IZnjh9t8JUkEevWy3T1Ch5ZUa+b9R+z4uY3VDhtQ4WKFD+etZX5Ryxqb+M2awuZ2G qQBd5hR99zC1wBjXpi+VFf05IphRlESktE8luQJ6f6EHJadX7nonVxdO82NhZr6A88yt LcYhWWZV+dgiQXDrEoylo6REIX3xvBR0bNhyKVseR57F6TSSrcBVPsZalKflRg/Tn8tQ m+Uz5CTx2KGr/TULltcuyDMPrKyPhNxeaW/CU2NG6XJZA0bBWpqZXH4S4KDRwejC/U7A RtSA== X-Gm-Message-State: ALKqPwc4T9ncPoBwzQIkpr0Knv0PyRWX4zNkQXrO3b8S+NxRga+oM9Bg LjbhrPiRjN6DMyQRVvlASVSSB5k6oL8= X-Received: by 2002:a62:3f4e:: with SMTP id m75-v6mr651833pfa.176.1525944637729; Thu, 10 May 2018 02:30:37 -0700 (PDT) Received: from localhost ([122.167.163.112]) by smtp.gmail.com with ESMTPSA id j10-v6sm1751889pfj.7.2018.05.10.02.30.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 May 2018 02:30:35 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot Subject: [PATCHi V2] cpufreq: optimize cpufreq_notify_transition() Date: Thu, 10 May 2018 15:00:29 +0530 Message-Id: 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, like checking about disabled cpufreq or irqs, adjusting jiffies, updating cpufreq stats and some debug print messages. This commit merges __cpufreq_notify_transition() into cpufreq_notify_transition() and modifies cpufreq_notify_transition() to execute minimum amount of code for each CPU. Also fix the kerneldoc for cpufreq_notify_transition() while at it. Signed-off-by: Viresh Kumar --- V2: - Fixed kerneldoc comment over cpufreq_notify_transition(). - Add more details to the commit log. drivers/cpufreq/cpufreq.c | 63 ++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 31 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 075d18f6ba7a..b79c5324767c 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -300,8 +300,19 @@ 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 - Notify frequency transition and adjust_jiffies. + * @policy: cpufreq policy to enable fast frequency switching for. + * @freqs: contain details of the frequency update. + * @state: set to CPUFREQ_PRECHANGE or CPUFREQ_POSTCHANGE. + * + * 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 +324,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)