From: Lukasz Luba <lukasz.luba@arm.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: linux-kernel@vger.kernel.org, daniel.lezcano@linaro.org,
linux-pm@vger.kernel.org, rui.zhang@intel.com
Subject: Re: [PATCH v2 6/8] thermal/sysfs: Update instance->weight under tz lock
Date: Wed, 20 Dec 2023 16:23:59 +0000 [thread overview]
Message-ID: <65b879ad-aff2-4f7e-bad1-ac85dc5fd146@arm.com> (raw)
In-Reply-To: <CAJZ5v0hes13rmAgcyMYtz1ZXxV72pM3QgRY=LKF9jK=GbAyS=g@mail.gmail.com>
On 12/20/23 14:53, Rafael J. Wysocki wrote:
> On Tue, Dec 12, 2023 at 2:48 PM Lukasz Luba <lukasz.luba@arm.com> wrote:
>>
>> The user-space can change thermal instance weight value while the
>> throtte() callback is running for a governor.
>
> This needs to be more precise IMV. Something like
>
> "User space can change the weight of a thermal instance via sysfs
> while the .throttle() callback is running for a governor, because
> weight_store() does not use the zone lock."
Agree, I'll use it.
>
>> The IPA governor uses the
>> 'weight' value for power calculation and also keeps it in 'total_weight'.
>> Therefore, the 'weight' value must not change during the throttle()
>> callback. Use 'tz->lock' mutex which also guards the throttle() to make
>> the update value safe.
>
> "The IPA governor uses instance weight values for power calculations
> and caches the sum of them as total_weight, so it gets confused when
> one of them changes while its .throttle() callback is running.
>
> To prevent that from happening, use thermal zone locking in weight_store()."
Agree, thanks.
>
>>
>> Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
>> ---
>> drivers/thermal/thermal_sysfs.c | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
>> index eef40d4f3063..df85df7d4a88 100644
>> --- a/drivers/thermal/thermal_sysfs.c
>> +++ b/drivers/thermal/thermal_sysfs.c
>> @@ -961,6 +961,7 @@ ssize_t weight_store(struct device *dev, struct device_attribute *attr,
>> const char *buf, size_t count)
>> {
>> struct thermal_instance *instance;
>> + struct thermal_zone_device *tz;
>
> IMO the local var doesn't help much. You may as well use
> instance->tz->lock directly below.
OK, I'll change that.
>
>> int ret, weight;
>>
>> ret = kstrtoint(buf, 0, &weight);
>> @@ -968,7 +969,12 @@ ssize_t weight_store(struct device *dev, struct device_attribute *attr,
>> return ret;
>>
>> instance = container_of(attr, struct thermal_instance, weight_attr);
>> + tz = instance->tz;
>> +
>> + /* Don't race with governors using the 'weight' value */
>> + mutex_lock(&tz->lock);
>> instance->weight = weight;
>> + mutex_unlock(&tz->lock);
>>
>> return count;
>> }
>> --
next prev parent reply other threads:[~2023-12-20 16:22 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-12 13:48 [PATCH v2 0/8] Add callback for cooling list update to speed-up IPA Lukasz Luba
2023-12-12 13:48 ` [PATCH v2 1/8] thermal: core: Add governor callback for thermal zone change Lukasz Luba
2023-12-20 13:51 ` Rafael J. Wysocki
2023-12-20 16:17 ` Lukasz Luba
2023-12-20 17:44 ` Rafael J. Wysocki
2023-12-20 17:46 ` Lukasz Luba
2023-12-12 13:48 ` [PATCH v2 2/8] thermal: gov_power_allocator: Refactor check_power_actors() Lukasz Luba
2023-12-12 13:48 ` [PATCH v2 3/8] thermal: gov_power_allocator: Move memory allocation out of throttle() Lukasz Luba
2023-12-20 14:35 ` Rafael J. Wysocki
2023-12-20 16:21 ` Lukasz Luba
2023-12-12 13:48 ` [PATCH v2 4/8] thermal: gov_power_allocator: Simplify checks for valid power actor Lukasz Luba
2023-12-20 14:40 ` Rafael J. Wysocki
2023-12-20 16:22 ` Lukasz Luba
2023-12-12 13:48 ` [PATCH v2 5/8] thermal: gov_power_allocator: Refactor checks in divvy_up_power() Lukasz Luba
2023-12-20 14:41 ` Rafael J. Wysocki
2023-12-12 13:48 ` [PATCH v2 6/8] thermal/sysfs: Update instance->weight under tz lock Lukasz Luba
2023-12-20 14:53 ` Rafael J. Wysocki
2023-12-20 16:23 ` Lukasz Luba [this message]
2023-12-12 13:48 ` [PATCH v2 7/8] thermal/sysfs: Update governors when the 'weight' has changed Lukasz Luba
2023-12-20 14:57 ` Rafael J. Wysocki
2023-12-12 13:48 ` [PATCH v2 8/8] thermal: gov_power_allocator: Support new update callback of weights Lukasz Luba
2023-12-20 14:59 ` Rafael J. Wysocki
2023-12-20 16:14 ` Lukasz Luba
2023-12-20 12:54 ` [PATCH v2 0/8] Add callback for cooling list update to speed-up IPA Lukasz Luba
2023-12-20 13:37 ` Rafael J. Wysocki
2023-12-20 16:25 ` Lukasz Luba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=65b879ad-aff2-4f7e-bad1-ac85dc5fd146@arm.com \
--to=lukasz.luba@arm.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox