From patchwork Wed Aug 11 11:58:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 495162 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp4899947jap; Wed, 11 Aug 2021 05:06:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNDr3kQnmT7zOG914n6fdYTIcjqyFgUuyslsr0rjx5CAriVW60VMfw3P05JN0bawlI2zcc X-Received: by 2002:aa7:c4d4:: with SMTP id p20mr10909524edr.382.1628683584133; Wed, 11 Aug 2021 05:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628683584; cv=none; d=google.com; s=arc-20160816; b=c1X2dMQ7irnr38ifMOvjXQJWO7wjqwPdGNCsF2MMZ/5SfO5t17BEiLN9iv+B5BKqAB OjF2eiTyol+VM4bL6VGz0vAmo9FillhpthdrC+iIv44jAlL+R0lI2XYQVn2qoogINkSd EoNMU8p4htjj9ghU5tHByiAkhEb7D5xcHCw9eJmjsWEwlTAlxzZflmsDXRWqEe4PDEuM sJszzUc4ZAcTh/QMMLARL9Rp+psFrEr6QWjOwFvalcpP6zqGYx5G9uGUjhxJjqlMhhOC fIo4WYxsbJeyVGkMAT8Lc2NTpxkPOLXA7wuHbRRgeR4juO1aEmdgA5BI7j+Zg/nfwtb6 JqTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PCfZOEpIhIENyNI7NFl9TKqagaadd2OPxUYrFvWYUZk=; b=aBa/NwpEyRMrEjbf0pOkI8slZ+NqpiODCbaZ76w0pczr4JUmIbyNS7jK88fOm7VFlz 1b9829kJ5BZqff1PYb8nhENXM6fdSS5+RGILvK3VOnjiPwZpkTdeZ+0ZP0d8o4aE+YnE iwlWVzAV0tU2mFM/N3EmmlArMI5qaNaU0DieeBhT1kr4f8bbvTZrD+7/RhRof0YlwRXO dU2fU9YCPRHcAtiNrUszZ7fy+7o7ZnTmRBihifrVOG9BwZ9FWRZTxbP+KYBpTCyHUOKc DsyuMUa2tN9yVzNr9Euaf7oEjPmfeUMZ09XveTUXmbmmSoyPvP3555/CseunpRwN96g4 Esrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N0+z2ZI5; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id w11si24410170edd.252.2021.08.11.05.06.23; Wed, 11 Aug 2021 05:06:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N0+z2ZI5; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 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 S237522AbhHKMGm (ORCPT + 7 others); Wed, 11 Aug 2021 08:06:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237497AbhHKMGm (ORCPT ); Wed, 11 Aug 2021 08:06:42 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A22FC0613D3 for ; Wed, 11 Aug 2021 05:06:18 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id a8so2970994pjk.4 for ; Wed, 11 Aug 2021 05:06:18 -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=PCfZOEpIhIENyNI7NFl9TKqagaadd2OPxUYrFvWYUZk=; b=N0+z2ZI5wdHwMuZJpOC52Yxq1cpcYeyyFJ06OSD2lZSHVAZCISKIzdeDukQ/oN3CdI J9+ZezPKKCSnLLTT2NIyKVcXd10uZFruG8Ua5ul1sPmziqln/pUVioG3h5r6/t0PSxxe NhbXigYmE1MR4lQcoFkv3RlIrh59Z6HqJAj6qSpAx2alGFTB2bQ4/WBYp6nLJ0it96gM ShOiv7G4wLXTUBSeCm3rB32YwyiBVLTcG5LIdbdsCZRM1WANgE8bhilW3B1RvzODpMgh v+Sd/Aw5n3sLZ8qvJWO+O1ToWi+GZA7NkO7kqyBLOzDwy2qQEZS9oRY6u6SIk2loGcrH 6K7A== 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=PCfZOEpIhIENyNI7NFl9TKqagaadd2OPxUYrFvWYUZk=; b=jrNsEfBdzqMaTXHo3naHjEh0Odhd5tGHOQelYDJbYiPs3Pp5YcIzY0q6+QjW1N6kXD ZcKU+I/EHtz4JS3epfXRS5MJ5J2vdO0LzJrOCK47ILBj9PIx2B0BHJ84w8QQGAQ4cXhS 9IHYmL2uE8vopz1aENe3+Bh9Q9U26oReU79DT+Q8kt2xtrA1bkMC1sqCgQ0vl7gHQmWF 4Y76xrHCKMv/Pn5etJ/QwOL5e4OkSIbRYXFJ00yncSUamNrUS5NjBcXL6ncY7BULmmd8 UUZS50oPuHStmWNgUWU2rNgBXFniEbHGEfRwi5AzRF63mZnrjl03NEbQA6KeAx/73LtW 0pHg== X-Gm-Message-State: AOAM530Z/6Oa3+PDWk4cWpf9ZjUBNW2ppTQk+8pCc0lsEQds8iS2BlPj PQMjTiGq2/feN0ObR1dptRwRwt8QbIuNXg== X-Received: by 2002:a17:903:2309:b029:12c:f6bd:23a4 with SMTP id d9-20020a1709032309b029012cf6bd23a4mr4014927plh.75.1628683577546; Wed, 11 Aug 2021 05:06:17 -0700 (PDT) Received: from localhost ([122.172.201.85]) by smtp.gmail.com with ESMTPSA id o22sm26851065pfu.87.2021.08.11.05.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Aug 2021 05:06:17 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , Lukasz Luba , Quentin Perret , linux-kernel@vger.kernel.org Subject: [PATCH V2 1/9] cpufreq: Auto-register with energy model if asked Date: Wed, 11 Aug 2021 17:28:39 +0530 Message-Id: <9ca302a02d6b51240af8668634c93972183b593f.1628682874.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Many cpufreq drivers register with the energy model for each policy and do exactly the same thing. Follow the footsteps of thermal-cooling, to get it done from the cpufreq core itself. Provide a new callback, which will be called, if present, by the cpufreq core at the right moment (more on that in the code's comment). Also provide a generic implementation that uses dev_pm_opp_of_register_em(). This also allows us to register with the EM at a later point of time, compared to ->init(), from where the EM core can access cpufreq policy directly using cpufreq_cpu_get() type of helpers and perform other work, like marking few frequencies inefficient, this will be done separately. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 12 ++++++++++++ include/linux/cpufreq.h | 14 ++++++++++++++ 2 files changed, 26 insertions(+) -- 2.31.1.272.g89b43f80a514 Reviewed-by: Quentin Perret Reviewed-by: Lukasz Luba diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 06c526d66dd3..75974e7d6cc5 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1493,6 +1493,18 @@ static int cpufreq_online(unsigned int cpu) write_unlock_irqrestore(&cpufreq_driver_lock, flags); } + /* + * Register with the energy model before sched_cpufreq_governor_change() + * is called, which will result in rebuilding of the sched domains, + * which should only be done once the energy model is properly + * initialized for the policy first. + * + * Also, this should be called before the policy is registered with + * cooling framework. + */ + if (cpufreq_driver->register_em) + cpufreq_driver->register_em(policy); + ret = cpufreq_init_policy(policy); if (ret) { pr_err("%s: Failed to initialize policy for cpu: %d (%d)\n", diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 9fd719475fcd..1295621f6c28 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -9,10 +9,12 @@ #define _LINUX_CPUFREQ_H #include +#include #include #include #include #include +#include #include #include #include @@ -373,6 +375,12 @@ struct cpufreq_driver { /* platform specific boost support code */ bool boost_enabled; int (*set_boost)(struct cpufreq_policy *policy, int state); + + /* + * Set by drivers that want the core to automatically register the + * policy's devices with Energy Model. + */ + void (*register_em)(struct cpufreq_policy *policy); }; /* flags */ @@ -1046,4 +1054,10 @@ unsigned int cpufreq_generic_get(unsigned int cpu); void cpufreq_generic_init(struct cpufreq_policy *policy, struct cpufreq_frequency_table *table, unsigned int transition_latency); + +static inline void cpufreq_register_em_with_opp(struct cpufreq_policy *policy) +{ + dev_pm_opp_of_register_em(get_cpu_device(policy->cpu), + policy->related_cpus); +} #endif /* _LINUX_CPUFREQ_H */