Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3791668rdh; Fri, 29 Sep 2023 02:23:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE6Z0miN6ltv2mWvDOYtwcGpZM7mQ+CHj4xIBZv75KXAPcpSPmK8Cyw+d1PGeu9bD+5rvcO X-Received: by 2002:a05:6a20:918d:b0:15d:d3b3:1843 with SMTP id v13-20020a056a20918d00b0015dd3b31843mr4189288pzd.3.1695979405729; Fri, 29 Sep 2023 02:23:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695979405; cv=none; d=google.com; s=arc-20160816; b=HdQQanIlEDTWwMqq3QdgiPUua67jcWDZ+gzrdbWHsXUG/7DL9wgBZA+I7R3AFfjzOY EFiVqn7EpffcQqb7cXAkBxMfniaxfJr9jjSghBKEIaHRq6TAixMrxaQf49XNjaXzdVlE M5o8gpOVRyeXgUSvgH/ZylXiLrclQ3x3hz0mu+QhsforePzkZnjmp7/+fQdBapwdzD4y 33vV3jPRCNFTScTAvEd3FmNVjuLmN7H70oUMAiak8Deu012SzY2TIjTu/4zP/H1JZCW4 3KqSXFZ2P2cijC19fbQWY5eLMUx9nD4x5o3SLkYBQUDuYgCn/aMPH+sqevm+rQABJqCt ILPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=GTHyuC2RElxGYlh7ydfW7+CnIxRAJb35yijlR8F/e5I=; fh=Sntd+G0CthFoKfHeh5KAtcEJMuc35jsG6LFomUCRudQ=; b=dm+cq/wgMVAj5uKQE4L0MWu+rdoqgivf2zbyTUw0xlG+7tPcduiyjGkXOtHonKLqtd kwFd1q4ME0CTGxHw1ZhClpKzOPnrzKZ/vTEKgJCOMl0uuALIjxCRxurwxRtxIs4+Pg3t dqI095AdN6qbIPHT7LiKig03Kw8p82lbqI+Ll2O3j1jgEXAzo6tTJRJSy35Trfy6hupU kWfX6UpPDI558/lzdOT7JIGrlmFyOoWW4jsZd7ZzChy/psW4m7O4aqln/iOSTrzwy6ZS kO115FA9f47ikCczkVZsAmOBxg7kjrzE7qggh+VCXaDGvAtDwkrO4CiChXNlZdW0EB/k yxOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id c1-20020a170902d48100b001b7eb771d5esi23050827plg.527.2023.09.29.02.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 02:23:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 1B02E8096FD7; Fri, 29 Sep 2023 02:15:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232938AbjI2JPb (ORCPT + 99 others); Fri, 29 Sep 2023 05:15:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232814AbjI2JPa (ORCPT ); Fri, 29 Sep 2023 05:15:30 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5665619F; Fri, 29 Sep 2023 02:15:28 -0700 (PDT) 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 6A6341FB; Fri, 29 Sep 2023 02:16:06 -0700 (PDT) Received: from [10.57.93.169] (unknown [10.57.93.169]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C319A3F5A1; Fri, 29 Sep 2023 02:15:25 -0700 (PDT) Message-ID: Date: Fri, 29 Sep 2023 10:16:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v4 09/18] PM: EM: Introduce runtime modifiable table Content-Language: en-US To: "Rafael J. Wysocki" Cc: 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 References: <20230925081139.1305766-1-lukasz.luba@arm.com> <20230925081139.1305766-10-lukasz.luba@arm.com> From: Lukasz Luba In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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 groat.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 (groat.vger.email [0.0.0.0]); Fri, 29 Sep 2023 02:15:50 -0700 (PDT) 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, 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. All the other users (thermal, etc.) are still using the default (basic) EM. This fact drove the design of this feature.'