Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp614201rdb; Fri, 6 Oct 2023 13:08:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFF4ueimw1GZotcU3xtctQjcohWYxxdDmM7GhOObTY01kazTSZZyPde1ykpY2no+9euAVo6 X-Received: by 2002:a17:902:e84d:b0:1c5:ec97:1718 with SMTP id t13-20020a170902e84d00b001c5ec971718mr9924367plg.6.1696622883366; Fri, 06 Oct 2023 13:08:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696622883; cv=none; d=google.com; s=arc-20160816; b=A91MyyZny7nnyE/Zr8SbpuLfFzm7ClCIAqqWJZPaWFOnTR5NZv9qw4FqTz3hCFAqa4 E5MBYIlWPn9bFRuDXINbJjFMucUsyQi9znRgy2FDawIt6/VB23IWHCxzowjtozSROnho Z+nYd5uJljiBi83NtiVl66IqcAbMWPNGAPHtrnnYEqGXvvVkrvDI7Dj+7BnhEolZQkUH c0vgGhK0dB1gzEwHkeq7Oeg2630sr+zBixoP30mFZWbizEfa8veJbvtfIGGRrZR3qEqk reQG/IoiV/iDpKxuUWsOXiIZSiyk2M8K9jGbYu/A3Qa3bYFjeX2R+FZfEzDYvP2TtHl+ uaVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=CKb4BaukEawTMR4UgO16bFL62ohS78Y7GkLpzNd9wAY=; fh=0sgDFRUyWB8NxmDXuofEKnebfv6e+q2MJfj8hABMlBc=; b=pBuvojcVw75NvXC+lVrDlO7hYx3lrCaryAmUAVZW+X2zW8F+6z5saijQp0F5Mg0rcj 2qIL8DZus3oT5I/hWKHY1jhZdSFEtmHcT/+WUSmcey8HQ+8vi+uP2MoC/Sj9PvGAD+Yk yR4fJBDmiuEZFZMiPsiBce+sTk7+49KH4lMprdgLfvB+HWSYOjMV7NGGRPO1us3tf0gs lOsKD+XCjaTd6Ib53yf5+gya5lNcW4ATYJ9gWFyJMdY3B9Bb6Z+tJ1NzORVzchgDGCY+ L7ULASDyhWcHiwaAcB6xuHJnN7WJd6FXFog1i4VOihujbE7DTUCsGuLYKdSb3tAISUzm osmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id n11-20020a170902e54b00b001c60d1da0d9si4670611plf.243.2023.10.06.13.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 13:08:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 45EA98265B46; Fri, 6 Oct 2023 13:08:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233384AbjJFUHz convert rfc822-to-8bit (ORCPT + 99 others); Fri, 6 Oct 2023 16:07:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233306AbjJFUHy (ORCPT ); Fri, 6 Oct 2023 16:07:54 -0400 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64D47BD; Fri, 6 Oct 2023 13:07:53 -0700 (PDT) Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-57de3096e25so468179eaf.1; Fri, 06 Oct 2023 13:07:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696622872; x=1697227672; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yi8IHkhUe0aac+4wlgQ6/aSkZ2gvlW+JPHDq/3mOla0=; b=tEXBpTPSXU2T3MQXxPGKb2ka+1B3mC/6jHEZKtH/5P+/Zk9t41IPd3SZzk+taBF2XB UBb/b8sfedGCOlcHTjWQGQMspxqU1mAsLeoHh/NUWNPRO0GW2lTMCjHeOgEt7xc/pum4 LhKMwqFLh/GV7gbwOiyi6HuX91RbZiQjRLFdooinOEzJlw6foob3IyNbOkUypzZ5s8IR nuOz4W8uSWO6hzlYxKbS26fIxwoD04AcgOi1EPLR8ouaPJ5EasJxRtQrjgAvk3YmXNPF CDNG+ScrrdKstmrNA2uSYTTLNHl/WGEQzztnDszgDHT22FU8npO1fKC620yokrj3k++g 9BsQ== X-Gm-Message-State: AOJu0Yyhjq8f3s66WJWSAf+iG4OPxVh76r35Evjcbtaz0ekydSGiWZsK 6F7A+ytT1rMYAiFPDTh7TuYP04t64phzAEjIk/c= X-Received: by 2002:a4a:c509:0:b0:57e:c9bf:696e with SMTP id i9-20020a4ac509000000b0057ec9bf696emr9112969ooq.1.1696622872620; Fri, 06 Oct 2023 13:07:52 -0700 (PDT) MIME-Version: 1.0 References: <20231005134120.1217829-1-pierre.gondois@arm.com> <20231006070707.ia4qa25citvvbn45@vireshk-i7> In-Reply-To: <20231006070707.ia4qa25citvvbn45@vireshk-i7> From: "Rafael J. Wysocki" Date: Fri, 6 Oct 2023 22:07:41 +0200 Message-ID: Subject: Re: [PATCH v2] cpufreq: Rebuild sched-domains when removing cpufreq driver To: Viresh Kumar , Pierre Gondois Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-pm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 06 Oct 2023 13:08:02 -0700 (PDT) On Fri, Oct 6, 2023 at 9:07 AM Viresh Kumar wrote: > > On 05-10-23, 15:41, Pierre Gondois wrote: > > The Energy Aware Scheduler (EAS) relies on the schedutil governor. > > When moving to/from the schedutil governor, sched domains must be > > rebuilt to allow re-evaluating the enablement conditions of EAS. > > This is done through sched_cpufreq_governor_change(). > > > > Having a cpufreq governor assumes a cpufreq driver is running. > > Inserting/removing a cpufreq driver should trigger a re-evaluation > > of EAS enablement conditions, avoiding to see EAS enabled when > > removing a running cpufreq driver. > > > > Rebuild the sched domains in schedutil's sugov_init()/sugov_exit(), > > allowing to check EAS's enablement condition whenever schedutil > > governor is initialized/exited from. > > Move relevant code up in schedutil.c to avoid a split and conditional > > function declaration. > > Rename sched_cpufreq_governor_change() to sugov_eas_rebuild_sd(). > > > > Signed-off-by: Pierre Gondois > > --- > > drivers/cpufreq/cpufreq.c | 3 +- > > include/linux/cpufreq.h | 8 ----- > > kernel/sched/cpufreq_schedutil.c | 55 +++++++++++++++++--------------- > > 3 files changed, 30 insertions(+), 36 deletions(-) > > > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > > index 60ed89000e82..4bc15634d49c 100644 > > --- a/drivers/cpufreq/cpufreq.c > > +++ b/drivers/cpufreq/cpufreq.c > > @@ -1544,7 +1544,7 @@ static int cpufreq_online(unsigned int cpu) > > > > /* > > * Register with the energy model before > > - * sched_cpufreq_governor_change() is called, which will result > > + * sugov_eas_rebuild_sd() 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. > > @@ -2652,7 +2652,6 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, > > ret = cpufreq_start_governor(policy); > > if (!ret) { > > pr_debug("governor change\n"); > > - sched_cpufreq_governor_change(policy, old_gov); > > return 0; > > } > > cpufreq_exit_governor(policy); > > diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h > > index 71d186d6933a..1c5ca92a0555 100644 > > --- a/include/linux/cpufreq.h > > +++ b/include/linux/cpufreq.h > > @@ -1193,14 +1193,6 @@ static inline int of_perf_domain_get_sharing_cpumask(int pcpu, const char *list_ > > } > > #endif > > > > -#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL) > > -void sched_cpufreq_governor_change(struct cpufreq_policy *policy, > > - struct cpufreq_governor *old_gov); > > -#else > > -static inline void sched_cpufreq_governor_change(struct cpufreq_policy *policy, > > - struct cpufreq_governor *old_gov) { } > > -#endif > > - > > extern unsigned int arch_freq_get_on_cpu(int cpu); > > > > #ifndef arch_set_freq_scale > > diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c > > index 4492608b7d7f..901cada51ba7 100644 > > --- a/kernel/sched/cpufreq_schedutil.c > > +++ b/kernel/sched/cpufreq_schedutil.c > > @@ -555,6 +555,31 @@ static const struct kobj_type sugov_tunables_ktype = { > > > > /********************** cpufreq governor interface *********************/ > > > > +#ifdef CONFIG_ENERGY_MODEL > > +static void rebuild_sd_workfn(struct work_struct *work) > > +{ > > + rebuild_sched_domains_energy(); > > +} > > + > > +static DECLARE_WORK(rebuild_sd_work, rebuild_sd_workfn); > > + > > +/* > > + * EAS shouldn't be attempted without sugov, so rebuild the sched_domains > > + * on governor changes to make sure the scheduler knows about it. > > + */ > > +static void sugov_eas_rebuild_sd(void) > > +{ > > + /* > > + * When called from the cpufreq_register_driver() path, the > > + * cpu_hotplug_lock is already held, so use a work item to > > + * avoid nested locking in rebuild_sched_domains(). > > + */ > > + schedule_work(&rebuild_sd_work); > > +} > > +#else > > +static inline void sugov_eas_rebuild_sd(void) { }; > > +#endif > > + > > struct cpufreq_governor schedutil_gov; > > > > static struct sugov_policy *sugov_policy_alloc(struct cpufreq_policy *policy) > > @@ -709,6 +734,8 @@ static int sugov_init(struct cpufreq_policy *policy) > > if (ret) > > goto fail; > > > > + sugov_eas_rebuild_sd(); > > + > > out: > > mutex_unlock(&global_tunables_lock); > > return 0; > > @@ -750,6 +777,8 @@ static void sugov_exit(struct cpufreq_policy *policy) > > sugov_kthread_stop(sg_policy); > > sugov_policy_free(sg_policy); > > cpufreq_disable_fast_switch(policy); > > + > > + sugov_eas_rebuild_sd(); > > } > > > > static int sugov_start(struct cpufreq_policy *policy) > > @@ -838,29 +867,3 @@ struct cpufreq_governor *cpufreq_default_governor(void) > > #endif > > > > cpufreq_governor_init(schedutil_gov); > > - > > -#ifdef CONFIG_ENERGY_MODEL > > -static void rebuild_sd_workfn(struct work_struct *work) > > -{ > > - rebuild_sched_domains_energy(); > > -} > > -static DECLARE_WORK(rebuild_sd_work, rebuild_sd_workfn); > > - > > -/* > > - * EAS shouldn't be attempted without sugov, so rebuild the sched_domains > > - * on governor changes to make sure the scheduler knows about it. > > - */ > > -void sched_cpufreq_governor_change(struct cpufreq_policy *policy, > > - struct cpufreq_governor *old_gov) > > -{ > > - if (old_gov == &schedutil_gov || policy->governor == &schedutil_gov) { > > - /* > > - * When called from the cpufreq_register_driver() path, the > > - * cpu_hotplug_lock is already held, so use a work item to > > - * avoid nested locking in rebuild_sched_domains(). > > - */ > > - schedule_work(&rebuild_sd_work); > > - } > > - > > -} > > -#endif > > Acked-by: Viresh Kumar Applied as 6.7 material, thanks!