Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7921480rdb; Thu, 4 Jan 2024 11:56:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdH7ZWUqoOrhK2+emd9O4DkKg3j9XEhG8v0xbbJPnA7bZsL/bvIKh2Zky+hNCmVGV/5hJI X-Received: by 2002:a17:902:f7cb:b0:1d3:e2a6:8709 with SMTP id h11-20020a170902f7cb00b001d3e2a68709mr931582plw.80.1704398176970; Thu, 04 Jan 2024 11:56:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704398176; cv=none; d=google.com; s=arc-20160816; b=xAw06xs1eYnmjRKFm6x68eIoQilOeYmmsQmf8MNnuQ4dAfj/WXyYYhKTvQVYzKqYI8 DPKYwT0vMOxC7wlLWeEb/z72Bp4mQaNCn6AmD6yPujgCwSmHMIkfELHU+1IjIKtjP0fg n9j145I+JmBRAuIYX/TWlTHf00HfkGtqkJg9Dnw7pvkNAnseZacaxcFra4QikDZeEgpN 4EoDVGBq1hSwaBNQMST38ko63+V1k9f9G1ZKFatL8qTfkAEph2m71OcwQSsUr+odng3Q Ezm2WmVc5alD/xFwWXA0YowARIHFJSmvuGw9CRi4ekhN1DsYXMkqfvK+NkdwWVMIZkDi v83A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=0+jZOMYAlf7is9OHtTiWtxt9LBNlP0KIxoNuDCX7eGw=; fh=O6YYF95gEoTquszwa1x1Mp3NZS9Am1klEUxdtkLeXmY=; b=q4zv2ZzFV3GnVvWo/RtA/lJKo0yH8CRlD3GyGE85QdaD1Pao9i0qOgbHewBUMP+NDa OqD+X1YLy6IZ2XiNJ1Y/Qx2whHR/2bBUa/xgZzDQtWjfP6yTxlxbb84j2yesMJC3hMz5 FFBtHlnu6ofZjC4DIV5hwwzR4cauLSsFABsJh22T4Z2qm0zja44DebySTysLpw7W4kAi 3IsCg+m6HXOk2V0t1irZRyiFo/IANrvVihyyBCzkKUVWR/BTuSF8A6PANHA38oS3WpFx 8y2IQLQ3QAKE0Jiv+vDg5SGlbFhwyDfja3E6yv2iXQrjUIHRXZKmSEb1jDNe5fMopdxb SSNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17186-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17186-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q20-20020a170902789400b001d364196057si1657pll.486.2024.01.04.11.56.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:56:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17186-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17186-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17186-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9EA1528567F for ; Thu, 4 Jan 2024 19:56:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88A532C689; Thu, 4 Jan 2024 19:56:08 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE1A62C687; Thu, 4 Jan 2024 19:56:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-59584f41f1eso108890eaf.1; Thu, 04 Jan 2024 11:56:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704398166; x=1705002966; 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=0+jZOMYAlf7is9OHtTiWtxt9LBNlP0KIxoNuDCX7eGw=; b=ka00fHg+gGnSMHt2MpAkqo0lvwXLkCReX9Ev8mKJungOXAUyz1L4/c7qh83wBJX85x NBsAfVkgRVtFhMEtOl6se6dm7fnjFLrTK8HJG+0sUOaf0b7PExJIuU/UwK6x9I6kb4Vl t2FKLsqFBWl77O0FdxFykIDlb2qphrEAjrFZ73MOCgh//RTIAVUCaeysc/QlU5Q4cwec OpRG9kCHtP7pAPh2Ti3CrnQ8IlphX5TrPMscyXvswpKp6RtJZNiCWcXGUmYdhNqbpfnw bLL8xPKG01rn9c6uMkt5GfzBu6CccCjsUjDCZpl9iHWxkQqLqv1c9/F21B8H2BoP12UD 2UXg== X-Gm-Message-State: AOJu0Yxr/hi8rEGKiWa6YAevG8rng5ucEKKGPHBuLeBOPudvVZ3AsGiT QufCy9wd2UX7mSRq0zdSSTLqSjv0rw6vzwpMBJ8= X-Received: by 2002:a4a:ea90:0:b0:595:6028:d8cb with SMTP id r16-20020a4aea90000000b005956028d8cbmr2188042ooh.0.1704398165812; Thu, 04 Jan 2024 11:56:05 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240104171553.2080674-1-lukasz.luba@arm.com> <20240104171553.2080674-13-lukasz.luba@arm.com> In-Reply-To: <20240104171553.2080674-13-lukasz.luba@arm.com> From: "Rafael J. Wysocki" Date: Thu, 4 Jan 2024 20:55:54 +0100 Message-ID: Subject: Re: [PATCH v6 12/23] PM: EM: Add helpers to read under RCU lock the EM table To: Lukasz Luba Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@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: quoted-printable On Thu, Jan 4, 2024 at 6:15=E2=80=AFPM Lukasz Luba wr= ote: > > 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_per= f_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 =3D 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; } > + > #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 > --