Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp825912lqt; Fri, 19 Apr 2024 11:28:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWbo2rOjYS2aERz7Fngw7COKhJfom/49LaM3O+7mkAHtdBevdlv2PYAMs+K4DABlt2wRkFrYb03gUo+Dwdywg8TzSM9N5IBGGgkW8YgmA== X-Google-Smtp-Source: AGHT+IFEmacs6h4/JYP0DR3HO9iJAHRSWK3Jv0xflgR43JeEWGyb1wgudgNhjDZcdR5ybV4vra4/ X-Received: by 2002:a05:6a00:139a:b0:6ed:1c7:8c61 with SMTP id t26-20020a056a00139a00b006ed01c78c61mr3548425pfg.12.1713551339437; Fri, 19 Apr 2024 11:28:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713551339; cv=pass; d=google.com; s=arc-20160816; b=cMo5xEgBFBIgDkjYucVLL/jr9wUvxkpVRf+wbbVt2R3FrNnWcBb5/Ce1DzwlwqEKWw w1K9b+PQPqWGCFSW0Yfz1/yC0tYaaVJMsIKqqOwoKliyLIKMh8L4FVdNMxLSMr5UcdAH 6znd6bwdnsmVsFynmZ1rcqqga5inTVorP3t9ZMUBHxAv6Ut344mKB09sVlLfeS6S590b Lwd2oiLVeTgUy/c8eME37cMpmuMRuEPhX5Pupe8mjOa7jSuuJ5AtZI80/QCKED5rfPs9 TtpbnQlPfUg+nZb4EkY9xIMBJY1SuWlcNHoh7j14xTqzP08I8znjbN469PKUr27dC53w ayMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=Xqs2xYMAMHJtxUVsDpgR9OaFo7/kM/N9oJf3rhFUwbA=; fh=NWbihT0n2LVGI0eIabKMMzs0D4KhesRC0I1HJGdvI0I=; b=gM9lek2xwz4YUU4bAp9Hm2tFyyHsOCTkQpPJq3RmGduBjTlqgR7mgHDEnh82AUDoKz I9+Me/yED5uT++OFDHwKlO2qnIfJl2FOJZgdM8T6ZZrBgGfdECC63dHsTj53ikSA5JHu 4ZqujeQCAexByBU0gxfbVVV2Cr8xdwnJVHYRWYToDYIsws+eCljJlsl9OovD9vZCAMxx Wq94f8pEUaNDCfQSzur/izPg7Uap22MUjf2JqIWm4KgM1qJ8TTpL82D64N3/E94+Ode5 wY1ZwuGomElF90xOM6GfRzBXuqZfd4KnD7ZqZfs497xrr1j1aZASpSAeA1Tz6xLzRmjK 9WjA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-151871-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151871-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h7-20020a056a00230700b006ece6b931adsi3704659pfh.44.2024.04.19.11.28.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:28:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151871-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-151871-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151871-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 084392814A7 for ; Fri, 19 Apr 2024 18:28:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02ADD13C909; Fri, 19 Apr 2024 18:28:48 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 75C601E502; Fri, 19 Apr 2024 18:28:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713551327; cv=none; b=sTy62lzNDNY4WFQA6Z6VwGivRETy9x6oLcDvDRvCcBkuSE/zhrMoY9olUxqgJskYfD7YTqVar8W4L9PIW5ESp9HCqgDvLLKiL25yFPTYnsTf+V2Hppy9kPeSFWioqG7WCrVSfj33De2qRUu1dIXqFjfMZ0zYto89+an28R3/j/M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713551327; c=relaxed/simple; bh=8bmUsk784IioOyBQS180AqAoVXiqQZUfPFKdqag2ld8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MARdyr6v7vthHfNWGLyoa9rOvA1DSeQzRpHFaHzmv5hxI8ri5V8aXEoAfBsaYfo6Dl5hsqsBV1bXVB//jVi2RFUGe4W50W3Ucki+tbCbZ76Xp+47OmbDz/aPKJ5ScYG6kq8swk3FKLAHy4JAlVbxiDM1c6zlNljddrJhiyWy7fs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 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 417AA2F; Fri, 19 Apr 2024 11:29:13 -0700 (PDT) Received: from [10.57.77.69] (unknown [10.57.77.69]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DA33E3F792; Fri, 19 Apr 2024 11:28:43 -0700 (PDT) Message-ID: <370ff15c-fc44-4ba6-a357-f06e89d67250@arm.com> Date: Fri, 19 Apr 2024 19:28:50 +0100 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 v1 11/16] thermal: gov_fair_share: Use .manage() callback instead of .throttle() To: "Rafael J. Wysocki" Cc: LKML , Linux PM , Daniel Lezcano , Srinivas Pandruvada References: <13515747.uLZWGnKmhe@kreacher> <2411572.NG923GbCHz@kreacher> Content-Language: en-US From: Lukasz Luba In-Reply-To: <2411572.NG923GbCHz@kreacher> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 4/10/24 17:57, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > The Fair Share governor tries very hard to be stateless and so it > calls get_trip_level() from fair_share_throttle() every time, even > though the number produced by this function for all of the trips > during a given thermal zone update is actually the same. Since > get_trip_level() walks all of the trips in the thermal zone every > time it is called, doing this may generate quite a bit of completely > useless overhead. > > For this reason, make the governor use the new .manage() callback > instead of .throttle() which allows it to call get_trip_level() just > once and use the value computed by it to handle all of the trips. > > Signed-off-by: Rafael J. Wysocki > --- > drivers/thermal/gov_fair_share.c | 37 ++++++++++++++++++++++++++----------- > 1 file changed, 26 insertions(+), 11 deletions(-) > > Index: linux-pm/drivers/thermal/gov_fair_share.c > =================================================================== > --- linux-pm.orig/drivers/thermal/gov_fair_share.c > +++ linux-pm/drivers/thermal/gov_fair_share.c > @@ -53,6 +53,7 @@ static long get_target_state(struct ther > * fair_share_throttle - throttles devices associated with the given zone > * @tz: thermal_zone_device > * @trip: trip point > + * @trip_level: number of trips crossed by the zone temperature > * > * Throttling Logic: This uses three parameters to calculate the new > * throttle state of the cooling devices associated with the given zone. > @@ -61,22 +62,19 @@ static long get_target_state(struct ther > * P1. max_state: Maximum throttle state exposed by the cooling device. > * P2. percentage[i]/100: > * How 'effective' the 'i'th device is, in cooling the given zone. > - * P3. cur_trip_level/max_no_of_trips: > + * P3. trip_level/max_no_of_trips: > * This describes the extent to which the devices should be throttled. > * We do not want to throttle too much when we trip a lower temperature, > * whereas the throttling is at full swing if we trip critical levels. > - * (Heavily assumes the trip points are in ascending order) > * new_state of cooling device = P3 * P2 * P1 > */ > -static int fair_share_throttle(struct thermal_zone_device *tz, > - const struct thermal_trip *trip) > +static void fair_share_throttle(struct thermal_zone_device *tz, > + const struct thermal_trip *trip, > + int trip_level) > { > struct thermal_instance *instance; > int total_weight = 0; > int total_instance = 0; > - int cur_trip_level = get_trip_level(tz); > - > - lockdep_assert_held(&tz->lock); > > list_for_each_entry(instance, &tz->thermal_instances, tz_node) { > if (instance->trip != trip) > @@ -99,18 +97,35 @@ static int fair_share_throttle(struct th > percentage = (instance->weight * 100) / total_weight; > > instance->target = get_target_state(tz, cdev, percentage, > - cur_trip_level); > + trip_level); > > mutex_lock(&cdev->lock); > __thermal_cdev_update(cdev); > mutex_unlock(&cdev->lock); > } > +} > > - return 0; > +static void fair_share_manage(struct thermal_zone_device *tz) > +{ > + int trip_level = get_trip_level(tz); > + const struct thermal_trip_desc *td; > + > + lockdep_assert_held(&tz->lock); > + > + for_each_trip_desc(tz, td) { > + const struct thermal_trip *trip = &td->trip; > + > + if (trip->temperature == THERMAL_TEMP_INVALID || > + trip->type == THERMAL_TRIP_CRITICAL || > + trip->type == THERMAL_TRIP_HOT) > + continue; > + > + fair_share_throttle(tz, trip, trip_level); > + } > } > > static struct thermal_governor thermal_gov_fair_share = { > - .name = "fair_share", > - .throttle = fair_share_throttle, > + .name = "fair_share", > + .manage = fair_share_manage, > }; > THERMAL_GOVERNOR_DECLARE(thermal_gov_fair_share); > > > LGTM Reviewed-by: Lukasz Luba