Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3890427rdh; Fri, 29 Sep 2023 05:37:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFz82mLb1MFpDGa8JXtGrE1huiE9GYzkEOMur73MOPN7sJVyj/3g640NrsxRKKf1KE/IxNk X-Received: by 2002:a05:6a20:d430:b0:163:2dc7:d077 with SMTP id il48-20020a056a20d43000b001632dc7d077mr904800pzb.55.1695991075659; Fri, 29 Sep 2023 05:37:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695991075; cv=none; d=google.com; s=arc-20160816; b=cDwHxut9DICm2QZTrr01wCE9Is929ms/gvfdCRQCgTbpuh9kUbNwkPudbDgbTpHPLh jsgdGVvj2EPHH2VORDIDg+N3KqpXl8fKrTkECdKn2K3w3vR32bHZ0xP9kwfhpuPE4BoU zcZaA/P0wArBqpfl9pT0SefN6F3Z2J3jFVqySawUh3pRSfMtU6KsPYJ8FMxsXKUFuWOc JPs2KRM2SZweYknnshCOXM2tsvfk8yxNljCTQIwpI2YSUVHM3VBFADy0xPPZy9nFdeab LK+zqXi1vsXFHq3s2LZCKTdaI65Yj7NUyWVW8X89UnDsaffAlyiq5gTGYrRPGctsyDG3 0HqQ== 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=u8CwGeYVZJvqvaMkMO0+1j38ONL0oJDLuef2AcE5ZOA=; fh=AxYt6MmdP30Pa+k1zZXw7Jh5JXowHWQYIaSNFw9Ltio=; b=a4Da99LmQBBNRsfAFYC+TtDYx5kuOgW4hL30//eehiFRNOHootZ12ow4/AvzyICwYg DcYqx9FMH9A1Nyo9/iSfxbbMqrkJ1E63MoZKiBuDi2tQsal7w4+VIrLIEYlT24jp+SUL M2YSNS4+1A0G19yjrLp/ddAvTGAYhLRXqUI+QdNdFqROLiPkEIOS+LyV+LoJD8v3kfvo k3baFgf6A6rbSR6gXrqSuk3TUp86Z/pg9dIZHVs1xtGOv3ao5waEKQV6d1Vdz6eNv2QO 3/6ya80psRROrgTpXaUQ/R03Ki8VlJSUCDx2mv47B8Pn+brMFaAJFE1XcDVsS+ug5WKq wU1A== 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:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id 4-20020a630004000000b00578d1b590b0si21016917pga.699.2023.09.29.05.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 05:37:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 4ED48805DC7D; Fri, 29 Sep 2023 05:27:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232997AbjI2M1T convert rfc822-to-8bit (ORCPT + 99 others); Fri, 29 Sep 2023 08:27:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232896AbjI2M1S (ORCPT ); Fri, 29 Sep 2023 08:27:18 -0400 Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 044C31A4; Fri, 29 Sep 2023 05:27:16 -0700 (PDT) Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-57bc11c197aso1220958eaf.1; Fri, 29 Sep 2023 05:27:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695990435; x=1696595235; 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=YtzJRowMW7e/E03q1lTUM5DVXc8/q+Drl19Zckr7ENQ=; b=xLcibNgp0FRB9aYCsgGKj15qJqrxxZ+RFgtDg76lp9YaDs5DrtY/Mhy9RnTjB67qSq hba/WKFUq/po/2UVoXiF63YUiyKflEcgPF6DwT3dJjTiowp05WdL+nj3bt4ikREDmx3n vLqFqNbkjaQrGvXIVJDHws3He9WDs/MTtIQVV99aLvts37OUMUG6n/t4/Oq2SoIYgloc 1PAhBRr5MY0RWWBUyLYfECUXgoQU5i6v0aEFuo49PIX/wfYTRmzGuDrGQuzYabe05Os7 FS+P8t/9Pn2Ddjepqi8mz49QM4v8+ppf6r+QkKvAahp0m0MvuoBe1M+JDvP67VbTUDBc f47g== X-Gm-Message-State: AOJu0YzfoEJX0h5w+t9SJLVp4a+teEW5AkaqogCb0Le2i1yb8eNs05+h 2w3PMHw2fusIU+gn6pTtFA8Zzd46Ec7hpcGfYvA= X-Received: by 2002:a05:6820:629:b0:57b:7e31:c12 with SMTP id e41-20020a056820062900b0057b7e310c12mr4488775oow.1.1695990435118; Fri, 29 Sep 2023 05:27:15 -0700 (PDT) MIME-Version: 1.0 References: <20230925081139.1305766-1-lukasz.luba@arm.com> <20230925081139.1305766-10-lukasz.luba@arm.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Fri, 29 Sep 2023 14:27:03 +0200 Message-ID: Subject: Re: [PATCH v4 09/18] PM: EM: Introduce runtime modifiable table To: Lukasz Luba Cc: "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Fri, 29 Sep 2023 05:27:32 -0700 (PDT) On Fri, Sep 29, 2023 at 11:15 AM Lukasz Luba wrote: > > > > On 9/26/23 20:12, Rafael J. Wysocki wrote: > > On Mon, Sep 25, 2023 at 10:11 AM Lukasz Luba wrote: > >> > >> The new runtime table would be populated with a new power data to better > >> reflect the actual power. The power can vary over time e.g. due to the > >> SoC temperature change. Higher temperature can increase power values. > >> For longer running scenarios, such as game or camera, when also other > >> devices are used (e.g. GPU, ISP) the CPU power can change. The new > >> EM framework is able to addresses this issue and change the data > >> at runtime safely. > >> > >> The runtime modifiable EM data is used by the Energy Aware Scheduler (EAS) > >> for the task placement. All the other users (thermal, etc.) are still > >> using the default (basic) EM. This fact drove the design of this feature. > >> > >> Signed-off-by: Lukasz Luba > >> --- > >> include/linux/energy_model.h | 4 +++- > >> kernel/power/energy_model.c | 12 +++++++++++- > >> 2 files changed, 14 insertions(+), 2 deletions(-) > >> > >> diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h > >> index 546dee90f716..740e7c25cfff 100644 > >> --- a/include/linux/energy_model.h > >> +++ b/include/linux/energy_model.h > >> @@ -39,7 +39,7 @@ struct em_perf_state { > >> /** > >> * struct em_perf_table - Performance states table > >> * @state: List of performance states, in ascending order > >> - * @rcu: RCU used for safe access and destruction > >> + * @rcu: RCU used only for runtime modifiable table > > > > This still doesn't appear to be used anywhere, so why change it here? > > I will try to move this later in the series. > > > > >> */ > >> struct em_perf_table { > >> struct em_perf_state *state; > >> @@ -49,6 +49,7 @@ struct em_perf_table { > >> /** > >> * struct em_perf_domain - Performance domain > >> * @default_table: Pointer to the default em_perf_table > >> + * @runtime_table: Pointer to the runtime modifiable em_perf_table > > > > "Pointer to em_perf_table that can be dynamically updated" > > OK > > > > >> * @nr_perf_states: Number of performance states > >> * @flags: See "em_perf_domain flags" > >> * @cpus: Cpumask covering the CPUs of the domain. It's here > >> @@ -64,6 +65,7 @@ struct em_perf_table { > >> */ > >> struct em_perf_domain { > >> struct em_perf_table *default_table; > >> + struct em_perf_table __rcu *runtime_table; > >> int nr_perf_states; > >> unsigned long flags; > >> unsigned long cpus[]; > >> diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c > >> index 797141638b29..5b40db38b745 100644 > >> --- a/kernel/power/energy_model.c > >> +++ b/kernel/power/energy_model.c > >> @@ -251,6 +251,9 @@ static int em_create_pd(struct device *dev, int nr_states, > >> return ret; > >> } > >> > >> + /* Initialize runtime table as default table. */ > > > > Redundant comment. > > I'll drop it. > > > > >> + rcu_assign_pointer(pd->runtime_table, default_table); > >> + > >> if (_is_cpu_device(dev)) > >> for_each_cpu(cpu, cpus) { > >> cpu_dev = get_cpu_device(cpu); > >> @@ -448,6 +451,7 @@ EXPORT_SYMBOL_GPL(em_dev_register_perf_domain); > >> */ > >> void em_dev_unregister_perf_domain(struct device *dev) > >> { > >> + struct em_perf_table __rcu *runtime_table; > >> struct em_perf_domain *pd; > >> > >> if (IS_ERR_OR_NULL(dev) || !dev->em_pd) > >> @@ -457,18 +461,24 @@ void em_dev_unregister_perf_domain(struct device *dev) > >> return; > >> > >> pd = dev->em_pd; > >> - > > > > Unrelated change. > > ACK > > > > >> /* > >> * The mutex separates all register/unregister requests and protects > >> * from potential clean-up/setup issues in the debugfs directories. > >> * The debugfs directory name is the same as device's name. > >> */ > >> mutex_lock(&em_pd_mutex); > >> + > > > > Same here. > > ACK > > > > >> em_debug_remove_pd(dev); > >> > >> + runtime_table = pd->runtime_table; > >> + > >> + rcu_assign_pointer(pd->runtime_table, NULL); > >> + synchronize_rcu(); > > > > Is it really a good idea to call this under a mutex? > > This is the unregistration of the EM code path, so a thermal > driver which gets some IRQs might not be aware that the EM > is going to vanish. That's why those two code paths: update > & unregister are protected with the same lock. > > This synchronize_rcu() won't be long, Are you sure? This potentially waits for all of the CPUs in the system to go through a quiescent state which may take a while in principle. In any case, though, this effectively makes everyone waiting for the mutex also wait for the grace period to elapse and they may not care about it. > but makes sure that when we free(dev->em_pd) we don't leak runtime_table. > > > > >> + > >> kfree(pd->default_table->state); > >> kfree(pd->default_table); > >> kfree(dev->em_pd); > >> + > > > > Unrelated change. > > ACK > > > > >> dev->em_pd = NULL; > >> mutex_unlock(&em_pd_mutex); > >> } > >> -- > > > > So this really adds a pointer to a table that can be dynamically > > updated to struct em_perf_domain without any users so far. It is not > > used anywhere as of this patch AFAICS, which is not what the changelog > > is saying. > > Good catch. I will adjust the changlog in header and say: > > 'Add infrastructure and mechanisms for the new runtime table. > The runtime modifiable EM data is used by the Energy Aware Scheduler > (EAS)for the task placement. I would make it more clear that this is going to happen after some other subsequent changes. > All the other users (thermal, etc.) are > still using the default (basic) EM. This fact drove the design of this > feature.'