From patchwork Thu Aug 12 04:35:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 495944 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp5639691jap; Wed, 11 Aug 2021 21:35:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXcusv2SKQiuNfKEiq07BvnKUhgkQ9iQMcQU/Gct9vv/fCkBiokMS3eN2yYCj6Nri6tfHz X-Received: by 2002:aa7:cb19:: with SMTP id s25mr3243647edt.194.1628742952185; Wed, 11 Aug 2021 21:35:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628742952; cv=none; d=google.com; s=arc-20160816; b=BfAdjAP6Q4aW00KHtTem56sxrGujoAGymZmKU8aey1Gwkzdlk39Uh9D1pp2v2Nms2R TeLIuop9ZHF8BZdBLRVpuwltCWv4ekK8k01zi0YzbTtRGLKzuxNi+wkXgqi06ZUrAOnf nTo7ND8nlNYuDWw0idjzTtVmlwATJFLf6BQgyc5QmgLZFkvOijUysrq1NU+mWfmSwVAX CiWoS7/wPezDMUStfHzGM8Y2cM5/TaPJ3pbcScEhWFLOOUfNN9lJgGRKn92d3yCVtZOu JAHm4qwm+rOI/hfVM/Ip9hjsBiHFBi6/Ct1VgaV1BzQSx+w1sHu4mHZ9uw0s4vJntZLe u8oQ== 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=cJkxi06rEFhzSNPo56wxZ6biRKSh//pEh5NibXjmjwM=; b=qU7nYV/EBPFwrJqlJoV4FINc+7wopHNoH26xybe9j+4wln8R4tRqSB61/JLqhua8Cu uc7rmVwUKVXAtNvQMIy0xPkcNJMc4exftV6zSQeSR1Z871tEJ5J9wjY3czALGnCyqIe5 H7NhzYPfCwFonMGUnSdKCc/ybTWdmhyg/JLMAHA4njKdUVbesUPJgphEzPLbZVue7ZTb V1v+rUFsJt8na8m7bdSm1ZRVZKyfvA3wQzWWD8NywtO6iIDwI9W5E1+OZk6d3sDtI/Nz /LpmpsgoF0d5zLAe/155YeV9VrewYKrIbNtuvdUNTgG0ExM3y/FRvx5wn0GSOiQVrhm+ 96Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RAirbPPx; 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 s5si1550640edr.161.2021.08.11.21.35.52; Wed, 11 Aug 2021 21:35:52 -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=RAirbPPx; 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 S234026AbhHLEgP (ORCPT + 7 others); Thu, 12 Aug 2021 00:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234007AbhHLEgO (ORCPT ); Thu, 12 Aug 2021 00:36:14 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65A4EC0613D3 for ; Wed, 11 Aug 2021 21:35:49 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id a20so5674300plm.0 for ; Wed, 11 Aug 2021 21:35:49 -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=cJkxi06rEFhzSNPo56wxZ6biRKSh//pEh5NibXjmjwM=; b=RAirbPPx9tnYmbm7/B3VW4qbupcBxMwQjkcXHBx+L3yU6yxYBF+d9XUAInkPCyrn5B SRKabkuLIqGhQlNSuABj1NaR0ajNPChwmDUeed35LL86Frnk9LuGSVhl8oC2mIb1cF/b yWV54ZAS63LGN4XEqb8kAUqSNuoOoa9W1N1iNJEHnxpTf8vzopA7ovS5/kMJVQbHxFBn UZpWcqkInRb/D+Bhw1CfSBdQBAQ3aXcnxN9ePDT8ZVUWeA2QLEy/L3VJMXneTioQvsZB xz2bPCW/ZmYqSctomgT4xIc1fkwxBAPCDp7Un6a+dU2aKGT9/k+VH2uL69KgTJNzGdgx I/wQ== 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=cJkxi06rEFhzSNPo56wxZ6biRKSh//pEh5NibXjmjwM=; b=Lw0dLjNrhZr8eS3lKuE5LTkqHxZj2Fzog/N9HhXRlWQcYd/3PgIkoOuz6NIDTIyW6P hfZjreSxXY9xnfbLj2fq9IYXk0z+u8/Fb8XMEe+iMPk45S5K6Mb7VpY4GB4Y4I3bWHNd xgtxyCg8qdryDIluRhBYN8jUqWMnDzn0zTMCZePB9E16uDv0tfFG0suxDIjp+x6Gfnpt UJ4//LB4CFcJiNZjv673TSIt6nHsat1CaDxQolST9Oe/3GFn2TtIJxJ3vI7P0S0Joa8G /r1JLAem0GvOcyDsDjRyjSWsaOFo2Rkfx0yhJjNIADZQkPi5wG0F8eLSyiH93oQKz4c0 oK5g== X-Gm-Message-State: AOAM531vIY6P94p1VdTWl9k3fyhD0afRpol26WlU1hxg7MTU440mnz4p IQDkQMYdf2GSHyGAxb67SKPTDg== X-Received: by 2002:a17:902:a702:b029:12b:aa0f:d553 with SMTP id w2-20020a170902a702b029012baa0fd553mr2035019plq.3.1628742948946; Wed, 11 Aug 2021 21:35:48 -0700 (PDT) Received: from localhost ([122.172.201.85]) by smtp.gmail.com with ESMTPSA id s14sm1268828pfg.220.2021.08.11.21.35.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Aug 2021 21:35:48 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Vincent Donnefort , lukasz.luba@arm.com, Quentin Perret , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH V3 1/9] cpufreq: Add callback to register with energy model Date: Thu, 12 Aug 2021 10:05:14 +0530 Message-Id: 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. Reviewed-by: Quentin Perret Reviewed-by: Lukasz Luba Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 13 +++++++++++++ include/linux/cpufreq.h | 14 ++++++++++++++ 2 files changed, 27 insertions(+) -- 2.31.1.272.g89b43f80a514 Tested-by: Vincent Donnefort diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 45f3416988f1..d301f39248a0 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1491,6 +1491,19 @@ static int cpufreq_online(unsigned int cpu) write_lock_irqsave(&cpufreq_driver_lock, flags); list_add(&policy->policy_list, &cpufreq_policy_list); 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); diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 9fd719475fcd..c65a1d7385f8 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 to register with the energy model after the + * policy is properly initialized, but before the governor is started. + */ + 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 */