Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3680905pxt; Tue, 10 Aug 2021 08:58:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyB/8DIQ9cid1oYc0F77vknCG7k25qhaA3lNQXMAg2b5aHaU4AFnRQzAdAprp3qxKI6+DpQ X-Received: by 2002:a17:907:2674:: with SMTP id ci20mr29119644ejc.84.1628611081979; Tue, 10 Aug 2021 08:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628611081; cv=none; d=google.com; s=arc-20160816; b=bF7Crmwobxy2irlZtfs1xrfJu3/UyPzXJJqfsTvYG/iaEdJHVoM53Uxag4mHZHXDG2 HMvQUGLMt2L9WNuxR0rJJF4appXYiOGtF/Bql4quCYUYzmlYOe/hWq/RtpsjpJ/MWvqA fY+LitSPavDs/OeV8zuCbjFxsSLj7NpPceVW9gNhKbTIAeBzHbSERhcFQep0i+N5GbtZ JKa9W8i5RdmDYFi/HozbhUX2Vz6tw1CC/El65yuIYhGVEDil8AkGSE99Gej7BOk8sdeJ fw6tVSM0HdzBkAGVrbFfnUIPywrkCzcAMOfDd90Zjd2MIpyS5mV7Crhi326f0DUIPybf 1uJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=VImu/+4aLd2pcykKW3/Eqyj5w31Z5WisTrYDJi8rCDY=; b=aKtflFW8h3T5H1m4+cATwIoPFzS7YzML8kj1uC89ZFQiwZpIwRNyZ8jhAwpzKBuec3 16o3Gyy/81yj0h2tSxTHCN5qDw6st48bMeGjE5p0Jzdfay6MH1Vvk1JYZprfHOZ2jzIO VZvM3NX4KSGQ5O5TjCbYZgQ1c7OWuxHSYmgnPZq9gSKkuQ18lbHGZM2INBe44pbKBFoo ixqYtBynRmIbvaTWsFYaAIQYjWaxbiq0CDdv11+zoFa+FB2y/qnl05t2aBPZGLQoNLmZ 6AnkMblRlGHmQymWuFOmxPhco4wlZSXIS3nlsRm/xVxJnsa+aaZSHcaKtaFCh0YatuVl hgdw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pj24si20686262ejb.143.2021.08.10.08.57.23; Tue, 10 Aug 2021 08:58:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237984AbhHJJhW (ORCPT + 99 others); Tue, 10 Aug 2021 05:37:22 -0400 Received: from foss.arm.com ([217.140.110.172]:52142 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbhHJJhV (ORCPT ); Tue, 10 Aug 2021 05:37:21 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C0DD11063; Tue, 10 Aug 2021 02:36:59 -0700 (PDT) Received: from [10.57.9.181] (unknown [10.57.9.181]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 51F413F718; Tue, 10 Aug 2021 02:36:58 -0700 (PDT) Subject: Re: [PATCH 1/8] cpufreq: Auto-register with energy model if asked To: Viresh Kumar Cc: Rafael Wysocki , Vincent Donnefort , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org References: From: Lukasz Luba Message-ID: Date: Tue, 10 Aug 2021 10:36:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/10/21 8:36 AM, Viresh Kumar wrote: > 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 cpufreq driver flag so drivers can ask the cpufreq core to > register with the EM core on their behalf. This allows us to get rid of > duplicated code in the drivers. > > Signed-off-by: Viresh Kumar > --- > drivers/cpufreq/cpufreq.c | 9 +++++++++ > include/linux/cpufreq.h | 6 ++++++ > 2 files changed, 15 insertions(+) > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > index 06c526d66dd3..a060dc2aa2f2 100644 > --- a/drivers/cpufreq/cpufreq.c > +++ b/drivers/cpufreq/cpufreq.c > @@ -23,6 +23,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1511,6 +1512,11 @@ static int cpufreq_online(unsigned int cpu) > if (cpufreq_thermal_control_enabled(cpufreq_driver)) > policy->cdev = of_cpufreq_cooling_register(policy); The of_cpufreq_cooling_register() should be called after the EM is present for the CPU device. When you check that function, you will see that we call em_cpu_get(policy->cpu) to get the EM pointer. Otherwise IPA might fail. > > + if (cpufreq_driver->flags & CPUFREQ_REGISTER_WITH_EM) { > + dev_pm_opp_of_register_em(get_cpu_device(policy->cpu), > + policy->related_cpus); > + } > + So please move these new code above the thermal registration few lines above. > pr_debug("initialization complete\n"); > > return 0; > @@ -1602,6 +1608,9 @@ static int cpufreq_offline(unsigned int cpu) > goto unlock; > } > > + if (cpufreq_driver->flags & CPUFREQ_REGISTER_WITH_EM) > + dev_pm_opp_of_unregister_em(get_cpu_device(cpu)); > + Here is similar situation. Move the EM unregister after the thermal is done. For consistency it's OK, the real EM struct won't be freed for CPUs (due to scheduler reasons), though. > if (cpufreq_thermal_control_enabled(cpufreq_driver)) { > cpufreq_cooling_unregister(policy->cdev); > policy->cdev = NULL; > diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h > index 9fd719475fcd..f11723cd4cca 100644 > --- a/include/linux/cpufreq.h > +++ b/include/linux/cpufreq.h > @@ -424,6 +424,12 @@ struct cpufreq_driver { > */ > #define CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING BIT(6) > > +/* > + * Set by drivers that want the core to automatically register the CPU device > + * with Energy Model. > + */ > +#define CPUFREQ_REGISTER_WITH_EM BIT(7) > + > int cpufreq_register_driver(struct cpufreq_driver *driver_data); > int cpufreq_unregister_driver(struct cpufreq_driver *driver_data); > >