Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1008059rdd; Wed, 10 Jan 2024 06:10:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZDbx5Z3yUlzFeKqqMyOOLwiJSlrK83gp9s76dWuYR9cFepZZ9ZGIGlBJJBUj0I/kE7/rh X-Received: by 2002:a17:902:c10c:b0:1d5:36b3:bd85 with SMTP id 12-20020a170902c10c00b001d536b3bd85mr941485pli.29.1704895825632; Wed, 10 Jan 2024 06:10:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704895825; cv=none; d=google.com; s=arc-20160816; b=jeMfaaPd1gzvRLD9EpnBn5jD4ciFsYyrWp3AxKhxmP4wguwGlVn6rYjhaooYVZOM2f zp5y5CS075F5dvIyJgMYlO1KuXv5EBnjcnAvvUmr1OJTCEsMZNoAgPrHuMLbSk0IPTKw Ol0Gi8kyYQEFC9aTBqXnuryucMQG1NqeXzYuRgqjc1dMp/PQAKyOrHT9e3Bup3fpIh1Q Tbsp9LXFk/iW2jTIMU4cgfO7Sy1NZMvJ3+BhLeORPpiUX4R61u+fGxf6S41xBbBnlQ9X LHvs9TstomkKec8C4N0UtmEm3BAeOHDFFrzrJaDm5Gfd9Yc2CyfUqXPZyaDct8krbq6S ktGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=76T73KNhJKDkzSXgD5g54tCKal9Yyw3TvhJny9wXhbM=; fh=Sntd+G0CthFoKfHeh5KAtcEJMuc35jsG6LFomUCRudQ=; b=Ds1zzfI+pphxN5DIRpcqjWIuKPaDxt+vWLTt7rkG7+qb5QczX5qxmuD+SmYOZ8qFT3 LQs7EG72x5U4fLabEIFOCLwMjKQiI/vukArusriyZqlJUXx1AIdtpBJnO8FPc4h6B9Eh TUldHyoL4h/3Q938XC5X+86rkINKmhurcYRlOGrwz3V3sItis1HYX+qlKeP2QhFLBf77 0mISGo855WkqtOTjb+8JgWSaBfdYSs9hzGV+i5IbqNLyje4Di3wPvcojSI2WZ2pYBOZV 7Lfod81hCad1MZSmj9+A9Swu35xzoPBMkEcSKCrHxzto4pCllz4nF4mSIGXeglhsA41T WbUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-22300-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22300-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q13-20020a17090311cd00b001d54c483bbasi3703003plh.323.2024.01.10.06.10.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 06:10:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22300-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-22300-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22300-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B4254B2518C for ; Wed, 10 Jan 2024 14:05:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 36B6C495F1; Wed, 10 Jan 2024 14:05:09 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB1F7495E0; Wed, 10 Jan 2024 14:05:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 C12152F4; Wed, 10 Jan 2024 06:05:51 -0800 (PST) Received: from [10.57.87.179] (unknown [10.57.87.179]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B85F43F5A1; Wed, 10 Jan 2024 06:05:03 -0800 (PST) Message-ID: <429fbf32-f347-4d6a-88dc-362c898c3dfd@arm.com> Date: Wed, 10 Jan 2024 14:06:25 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 12/23] PM: EM: Add helpers to read under RCU lock the EM 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: <20240104171553.2080674-1-lukasz.luba@arm.com> <20240104171553.2080674-13-lukasz.luba@arm.com> From: Lukasz Luba In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 1/4/24 19:55, Rafael J. Wysocki wrote: > On Thu, Jan 4, 2024 at 6:15 PM Lukasz Luba wrote: >> >> To use the runtime modifiable EM table there is a need to use RCU >> read locking properly. Add helper functions for the device drivers and >> frameworks to make sure it's done properly. >> >> Signed-off-by: Lukasz Luba >> --- >> include/linux/energy_model.h | 19 +++++++++++++++++++ >> 1 file changed, 19 insertions(+) >> >> diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h >> index f33257ed83fd..cfaf5d8b1aad 100644 >> --- a/include/linux/energy_model.h >> +++ b/include/linux/energy_model.h >> @@ -338,6 +338,20 @@ static inline int em_pd_nr_perf_states(struct em_perf_domain *pd) >> return pd->nr_perf_states; >> } >> >> +static inline struct em_perf_state *em_get_table(struct em_perf_domain *pd) >> +{ >> + struct em_perf_table __rcu *table; >> + >> + rcu_read_lock(); >> + table = rcu_dereference(pd->em_table); >> + return table->state; >> +} >> + >> +static inline void em_put_table(void) >> +{ >> + rcu_read_unlock(); >> +} > > The lack of symmetry between em_get_table() and em_put_table() is kind > of confusing. > > I don't really like these wrappers. > > IMO it would be better to use rcu_read_lock()/rcu_read_unlock() > directly everywhere they are needed and there can be a wrapper around > rcu_dereference(pd->em_table), something like > > static inline struct em_perf_state *em_perf_state_from_pd(struct > em_perf_domain *pd) > { > return rcu_dereference(pd->em_table)->state; > } Fair enough, I will change this and use explicit rcu_read_lock/unlock() in the thermal/DTPM code together with this above function. I will add comment to it that it needs to be called under the RCU read section locked. Then also it would be easier to handle the function names in patch 10/23 that you have also commented. > >> + >> #else >> struct em_data_callback {}; >> #define EM_ADV_DATA_CB(_active_power_cb, _cost_cb) { } >> @@ -384,6 +398,11 @@ int em_dev_update_perf_domain(struct device *dev, >> { >> return -EINVAL; >> } >> +static inline struct em_perf_state *em_get_table(struct em_perf_domain *pd) >> +{ >> + return NULL; >> +} >> +static inline void em_put_table(void) {} >> #endif >> >> #endif >> -- >