From patchwork Thu Aug 17 12:04:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 110317 Delivered-To: patch@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp2103955obb; Thu, 17 Aug 2017 05:05:38 -0700 (PDT) X-Received: by 10.99.137.66 with SMTP id v63mr4928014pgd.279.1502971538445; Thu, 17 Aug 2017 05:05:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502971538; cv=none; d=google.com; s=arc-20160816; b=K6h0ZBS9WxrJFJqwtocnlkS5JNtT2k86eCBjrnkWULjdqsfj+5JEsqac+347LOXQUY JBHkShq0Y6Uxn89876x7RRdOtoNKzUYxRfkqU9Mda3/t5aPcEn+Xu3Te09NNSM3TWDAL OpQkDJr19Iejz6heGUvKvbHXyDME0yPW9Eb88XxKPg+27AZFrmnXEsn9P5Hs8fTAeLiH 4ycOg4ffKet/BTupyzgKbQKT4qhtkHOLSzVkjS7CtNDpLc1nsTUJ+P5pK9YkqYLCfKnn 3RNFH5U8dKdwoq3GeoGB8VI5cmxiDwN6IcVzz2ogbWRM3WTBDC0WPhI1TrnSvIRcUX0g CL6g== 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=pAyxltYwSsEAXV9HC81jH7OjOAC/SjeU7/Ejgl92A5o=; b=RrvJ2nuWzl/e8rLBJnsbHzXfxuObn3epaZJUjZKh0CY4aOkd+xeNYdlNkcDL3O/iis gM415mkrwvD1IpvjfVEkStNdl/t0fNMi5WTHlR4v5QA7ok77g+rakm5c5aunZAY6lEbD cZpHAiVJbE2UxJrGUCIBo4ZysnUnfhPrNFdxhICv04CCDVXNNOvTjurcqybja67zCIck GA89dr+7H9j4LZ0V/UFL0Xj6SLh2ccEJqgtiX53kn5yD+6XYK8MrU/wfEYpLiw5DEKaN 6pND/Hcm0p9tPVaQiIhLJF3XKTe47BHoM5auy54QLPv4GXMyxN22apHH5l/8h7VaRDX2 Z0Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Sc5CIF2c; 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 l24si1968508pgu.76.2017.08.17.05.05.38; Thu, 17 Aug 2017 05:05:38 -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=Sc5CIF2c; 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 S1752305AbdHQMFf (ORCPT + 26 others); Thu, 17 Aug 2017 08:05:35 -0400 Received: from mail-pg0-f53.google.com ([74.125.83.53]:35210 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751644AbdHQME6 (ORCPT ); Thu, 17 Aug 2017 08:04:58 -0400 Received: by mail-pg0-f53.google.com with SMTP id v189so41568382pgd.2 for ; Thu, 17 Aug 2017 05:04:58 -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=pAyxltYwSsEAXV9HC81jH7OjOAC/SjeU7/Ejgl92A5o=; b=Sc5CIF2cOq+PrWVa1bLKYQNx2hNVoy3y6H8kuPtVzKaQDu02xvEW54caog/O6DKpau iO8xL1P4mjVmZ+Bya6MSjJRPk+S4kUT13ePXhkTS7oNOaS/u/mGFUKmnbeQ468PDyIwz d7KOFhHgUErRWRBdXnMUovygV1af18RT3/nKc= 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=pAyxltYwSsEAXV9HC81jH7OjOAC/SjeU7/Ejgl92A5o=; b=Bq7+1MdAQnJ4YPhEKf89HuUm3gqSr4yRPXyQ4XB8L4zJPnQZCaZPwMchpQeJ9Cg+OG ZPuEhH9ywja+CcwlDhFz59M6wsWEKabMLV+IfAr8TY8d6mgvynSvPIpikaolozdMq3ui YDz3K7kdMwTv4MLMAnRYTOUTLP2UK8YfFrRs5Az+1Rx4MjqT1ebtZnlRQKzd1ELOMSb9 QMBNBCAOq5ncQ2TSd7X61th74hRMjWgbGFigmZIMrHQROkIwvABBl4ToMAqZ3Ao0dIhW dCHICsix6C07s6dVUhVzsmX/fSP3BW7EmXM1d/7UQgK7gP3YJ3yDMpF/x1RpJI8i/iiK /whg== X-Gm-Message-State: AHYfb5hsZa0jhe2E5ceIVOAByFvhCEoqJ86mc6LJ+/3QaO6kUP2pcgLT 7fRX2pjr5EW11t9B X-Received: by 10.84.210.237 with SMTP id a100mr5536151pli.288.1502971497959; Thu, 17 Aug 2017 05:04:57 -0700 (PDT) Received: from localhost ([122.172.110.130]) by smtp.gmail.com with ESMTPSA id 74sm11443543pfk.58.2017.08.17.05.04.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Aug 2017 05:04:56 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Srinivas Pandruvada , Len Brown , Ingo Molnar , Peter Zijlstra Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH] cpufreq: Don't send callback pointer to cpufreq_add_update_util_hook() Date: Thu, 17 Aug 2017 17:34:48 +0530 Message-Id: X-Mailer: git-send-email 2.14.1.202.g24db08a6e8fe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The callers already have the structure (struct update_util_data) where the function pointer is saved by cpufreq_add_update_util_hook(). And its better if the callers fill it themselves, as they can do it from the governor->init() callback then, which is called only once per policy lifetime rather than doing it from governor->start which can get called multiple times. Note that the schedutil governor isn't updated (for now) to fill update_util.func from the governor->init() callback as its governor->start() callback is doing memset(sg_cpu, 0, ...) which will overwrite the update_util.func. Tested on ARM Hikey board with Ondemand and Schedutil governors. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq_governor.c | 4 ++-- drivers/cpufreq/intel_pstate.c | 4 ++-- include/linux/sched/cpufreq.h | 4 +--- kernel/sched/cpufreq.c | 19 +++++++------------ kernel/sched/cpufreq_schedutil.c | 10 ++++++---- 5 files changed, 18 insertions(+), 23 deletions(-) -- 2.14.1.202.g24db08a6e8fe diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c index 58d4f4e1ad6a..4d48e20720fa 100644 --- a/drivers/cpufreq/cpufreq_governor.c +++ b/drivers/cpufreq/cpufreq_governor.c @@ -330,8 +330,7 @@ static void gov_set_update_util(struct policy_dbs_info *policy_dbs, for_each_cpu(cpu, policy->cpus) { struct cpu_dbs_info *cdbs = &per_cpu(cpu_dbs, cpu); - cpufreq_add_update_util_hook(cpu, &cdbs->update_util, - dbs_update_util_handler); + cpufreq_add_update_util_hook(cpu, &cdbs->update_util); } } @@ -367,6 +366,7 @@ static struct policy_dbs_info *alloc_policy_dbs_info(struct cpufreq_policy *poli struct cpu_dbs_info *j_cdbs = &per_cpu(cpu_dbs, j); j_cdbs->policy_dbs = policy_dbs; + j_cdbs->update_util.func = dbs_update_util_handler; } return policy_dbs; } diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 79452ea83ea1..6b9cfc2d9a5e 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -1696,8 +1696,8 @@ static void intel_pstate_set_update_util_hook(unsigned int cpu_num) /* Prevent intel_pstate_update_util() from using stale data. */ cpu->sample.time = 0; - cpufreq_add_update_util_hook(cpu_num, &cpu->update_util, - intel_pstate_update_util); + cpu->update_util.func = intel_pstate_update_util; + cpufreq_add_update_util_hook(cpu_num, &cpu->update_util); cpu->update_util_set = true; } diff --git a/include/linux/sched/cpufreq.h b/include/linux/sched/cpufreq.h index d2be2ccbb372..4e9fa512ae95 100644 --- a/include/linux/sched/cpufreq.h +++ b/include/linux/sched/cpufreq.h @@ -18,9 +18,7 @@ struct update_util_data { void (*func)(struct update_util_data *data, u64 time, unsigned int flags); }; -void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data, - void (*func)(struct update_util_data *data, u64 time, - unsigned int flags)); +void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data); void cpufreq_remove_update_util_hook(int cpu); #endif /* CONFIG_CPU_FREQ */ diff --git a/kernel/sched/cpufreq.c b/kernel/sched/cpufreq.c index dbc51442ecbc..853987a5775b 100644 --- a/kernel/sched/cpufreq.c +++ b/kernel/sched/cpufreq.c @@ -17,31 +17,26 @@ DEFINE_PER_CPU(struct update_util_data *, cpufreq_update_util_data); * cpufreq_add_update_util_hook - Populate the CPU's update_util_data pointer. * @cpu: The CPU to set the pointer for. * @data: New pointer value. - * @func: Callback function to set for the CPU. * * Set and publish the update_util_data pointer for the given CPU. * - * The update_util_data pointer of @cpu is set to @data and the callback - * function pointer in the target struct update_util_data is set to @func. - * That function will be called by cpufreq_update_util() from RCU-sched - * read-side critical sections, so it must not sleep. @data will always be - * passed to it as the first argument which allows the function to get to the - * target update_util_data structure and its container. + * The update_util_data pointer of @cpu is set to @data. The data->func + * function will be called by cpufreq_update_util() from RCU-sched read-side + * critical sections, so it must not sleep. @data will always be passed to it + * as the first argument which allows the function to get to the target + * update_util_data structure and its container. * * The update_util_data pointer of @cpu must be NULL when this function is * called or it will WARN() and return with no effect. */ -void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data, - void (*func)(struct update_util_data *data, u64 time, - unsigned int flags)) +void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data) { - if (WARN_ON(!data || !func)) + if (WARN_ON(!data || !data->func)) return; if (WARN_ON(per_cpu(cpufreq_update_util_data, cpu))) return; - data->func = func; rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), data); } EXPORT_SYMBOL_GPL(cpufreq_add_update_util_hook); diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 2e74c49776be..0baa7a787cd5 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -643,15 +643,17 @@ static int sugov_start(struct cpufreq_policy *policy) sg_cpu->sg_policy = sg_policy; sg_cpu->flags = SCHED_CPUFREQ_RT; sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq; + + if (policy_is_shared(policy)) + sg_cpu->update_util.func = sugov_update_shared; + else + sg_cpu->update_util.func = sugov_update_single; } for_each_cpu(cpu, policy->cpus) { struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu); - cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util, - policy_is_shared(policy) ? - sugov_update_shared : - sugov_update_single); + cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util); } return 0; }