Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2107784rdh; Tue, 26 Sep 2023 12:39:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYCzBVdHwB5X5KzHtFxAv6ktc/HjdDHxhZQZIGOeUnOYP8Ixs/ZX/FQD4IurP38FmxP2rK X-Received: by 2002:a05:6358:281e:b0:140:fbfe:d941 with SMTP id k30-20020a056358281e00b00140fbfed941mr54643rwb.20.1695757199341; Tue, 26 Sep 2023 12:39:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695757199; cv=none; d=google.com; s=arc-20160816; b=w+LWmnCUMWsGEYEUNhvWoWKyCMxKjxrFHBBrpH3Z7nW/G9ipb+UYzenvNduKnSuyEp gQY1O0kdFDPW/YY+xyTmc5g2N98IzQv+y2/wMHXjVKhAhbAJ7F5uJgDF0fMKk7Q5RESz YOQGbAmOAvVZbD+yPhekHPjJY9f3ZjiGJGTiYQK6M9i1TOIesztuR8q0KYG0zvkjzNT1 oTN2vm9WSd5NVQ8F5v9cru6x6eFaaRClAHCVYPM6N3tpb3K5yXIIApzONtc/ndPNPzlt IJYRT7251o9yXaELvm5WVgr3U+2hb6Ud9TWJSE4bmeVXTmn8Jdit1P9He7rWjqM+AldN 7wTQ== 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=wyw78SI1Nj07/CFaqUK+LM8spk+aWH9khcjiHe0Uabw=; fh=O6YYF95gEoTquszwa1x1Mp3NZS9Am1klEUxdtkLeXmY=; b=jmSiJp9HJz3GkhtMnyK5xEGHPfdQmZ6n4FdVgHXG9qyBH61se99advr5y1GTVR6Z7W MFIyV9io5QXxMB3KTI2RMrX0LgJ0Nrm4SBijtOaXytSEEGMAZPBprHPOQpODa4fPPaSk /FGc1d3deGcAiMloc9HOj4UHYo5aeDzD6YvwbmkWVHoRqX6VPVwmsy7Y6RbNvvf5sYLg XutaQehvLP1Dp9LPBY8g/X1pGClfVB5Ahq1Lrj1CAMa46iRNJlGIHlI/a7SFNmgP00jt WyNPFDxV12dvMFu2T5a4deP91Z43cKx7llfXc+kYUoNn96kENuB+BPMiNFDaSCEkJeFy BZcA== 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 az1-20020a056a02004100b0055fd1bfb109si13341131pgb.679.2023.09.26.12.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 12:39:59 -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 E4A92802B40B; Tue, 26 Sep 2023 12:26:34 -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 S235741AbjIZT0g convert rfc822-to-8bit (ORCPT + 99 others); Tue, 26 Sep 2023 15:26:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235724AbjIZT0f (ORCPT ); Tue, 26 Sep 2023 15:26:35 -0400 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 852D311F; Tue, 26 Sep 2023 12:26:28 -0700 (PDT) Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-57de3096e25so80284eaf.1; Tue, 26 Sep 2023 12:26:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695756388; x=1696361188; 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=i4Jq5nSjfc/CI/cvpv3MrTFI/arZy6OI2bEoo1gBoe8=; b=RlYAYGu/E9PyNPADMtSwGFmWq+LKF/HxldbK2O/laa9pRGe+J4JJUUYnTzMwcJu3gw nZWVQMzmn2VvdugEmk+Ca+qo0mnpWGTE70XithwyqP5MZyF5NmquuJnJ7gpHCXDKq9FR Plda6hOE/stq1GknyWWPb+eZ8RSwdotsSyfG72FYSZF37K8UZ6CxOwp59qPWG6H8AjtE j1PxwNA5L9S8aULmitly7TYhjFu9HaM0YDtREPfU73vty+zD5ix0vfnEYlXG7wUuF5iU FxgMYVclLuojFMu0hh9sVOQv7KuD5H8J5grJEuliXVBjwCLidM9F8lQOUPQfmnqipQ/t mktQ== X-Gm-Message-State: AOJu0Yz29bvPRk5YpBcl7K0095i0gMBwBGKb5zeTulhBvqHC6LbgNL+J 3pb2x2d09czQQvbGp5PM95htCipJg5Z4zichlJg= X-Received: by 2002:a4a:e704:0:b0:57b:94b7:c6ba with SMTP id y4-20020a4ae704000000b0057b94b7c6bamr78238oou.0.1695756387728; Tue, 26 Sep 2023 12:26:27 -0700 (PDT) MIME-Version: 1.0 References: <20230925081139.1305766-1-lukasz.luba@arm.com> <20230925081139.1305766-11-lukasz.luba@arm.com> In-Reply-To: <20230925081139.1305766-11-lukasz.luba@arm.com> From: "Rafael J. Wysocki" Date: Tue, 26 Sep 2023 21:26:16 +0200 Message-ID: Subject: Re: [PATCH v4 10/18] PM: EM: Add RCU mechanism which safely cleans the old data 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: 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]); Tue, 26 Sep 2023 12:26:35 -0700 (PDT) On Mon, Sep 25, 2023 at 10:11 AM Lukasz Luba wrote: > > The EM is going to support runtime modifications of the power data. > Introduce RCU safe mechanism to clean up the old allocated EM data. "RCU-based" probably and "to clean up the old EM data safely". > It also adds a mutex for the EM structure to serialize the modifiers. This part doesn't match the code changes in the patch. > Signed-off-by: Lukasz Luba > --- > kernel/power/energy_model.c | 29 +++++++++++++++++++++++++++++ > 1 file changed, 29 insertions(+) > > diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c > index 5b40db38b745..2345837bfd2c 100644 > --- a/kernel/power/energy_model.c > +++ b/kernel/power/energy_model.c > @@ -23,6 +23,9 @@ > */ > static DEFINE_MUTEX(em_pd_mutex); > > +static void em_cpufreq_update_efficiencies(struct device *dev, > + struct em_perf_state *table); > + > static bool _is_cpu_device(struct device *dev) > { > return (dev->bus == &cpu_subsys); > @@ -104,6 +107,32 @@ static void em_debug_create_pd(struct device *dev) {} > static void em_debug_remove_pd(struct device *dev) {} > #endif > > +static void em_destroy_rt_table_rcu(struct rcu_head *rp) Adding static functions without callers will obviously cause the compiler to complain, which is one of the reasons to avoid doing that. The other is that it is hard to say how these functions are going to be used without reviewing multiple patches simultaneously, which is a pain as far as I'm concerned. > +{ > + struct em_perf_table *runtime_table; > + > + runtime_table = container_of(rp, struct em_perf_table, rcu); > + kfree(runtime_table->state); > + kfree(runtime_table); If runtime_table and its state were allocated in one go, it would be possible to free them in one go either. For some reason, you don't seem to want to do that, but why? > +} > + > +static void em_perf_runtime_table_set(struct device *dev, > + struct em_perf_table *runtime_table) > +{ > + struct em_perf_domain *pd = dev->em_pd; > + struct em_perf_table *tmp; > + > + tmp = pd->runtime_table; > + > + rcu_assign_pointer(pd->runtime_table, runtime_table); > + > + em_cpufreq_update_efficiencies(dev, runtime_table->state); > + > + /* Don't free default table since it's used by other frameworks. */ Apparently, some frameworks are only going to use the default table while the runtime-updatable table will be used somewhere else at the same time. I'm not really sure if this is a good idea. > + if (tmp != pd->default_table) > + call_rcu(&tmp->rcu, em_destroy_rt_table_rcu); > +} > + > static int em_compute_costs(struct device *dev, struct em_perf_state *table, > struct em_data_callback *cb, int nr_states, > unsigned long flags) > --