Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp302072lqj; Wed, 10 Apr 2024 10:48:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWLU1KjJyzb1Eh0g5hY49TDucv2Hs2llQLmsgBTzOULN6V+x8rj9EkUTFWSzVdNcLteDPT+89hjckPa3IH7EMnTpfkmFDIUonqM5OPwSQ== X-Google-Smtp-Source: AGHT+IGJgyQyJ7agzL9KgHv88HrOybm+OV0EWNmJL8Z3rQ9Qt9O6tU+hcA+SVWnCwY+irpnPXmO8 X-Received: by 2002:a05:622a:286:b0:434:85b3:7cc7 with SMTP id z6-20020a05622a028600b0043485b37cc7mr848650qtw.4.1712771334783; Wed, 10 Apr 2024 10:48:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712771334; cv=pass; d=google.com; s=arc-20160816; b=rcorLrIeQwCHwT8pdrh0f+zUXS3hO72xvB4FxVxXqicqmOJA6z4PnEtDfDR+D9H2xD pkQw/7lyDwbq+DepyNuWMrEm8ZjJhYkXWAxtjKZupXZFH+9gr3BLfbjCjgYGAkWY/pD8 yAlfpAmrXKmee9bV4PqskWNQ5+TW25pwGy8JhJGmUW9fSbr3qId8Qv0E1i8GvPLAJFbF XTwUB+taf/aGqIw3/Oro8/OHfT1ZxZFicwNoE+yV8AYVY/U38wDbcMnbPgGV4SdU7aXQ BWVUxVB2M/6hrgC0onS06oVRW8HxhhJhwzYE0AVmfzvH3IIybJTsJIojF1LoUwK94MA1 2FZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=d/1TT5NgXi9LQY3YdxRgo7j0XVCONZ7gQmCEbxdtOKY=; fh=0I/rqIlL4373pOps8oaBYF1ECx5xbCzL9wLU5PgpMhU=; b=pcbHx682KomCTczOAcfakvxZ4bKwR66+D8AdiMLDpt2Ol6eHC8LM2Vrd6TlTnjTGx+ P1iwnqIc+XBgifO+QsNwBQ/6HHbXBrsJdGPBQyIGDccrtXe9N1IAjwk90Wy7OK6oiI/H s2jrA726IPE1P2bwmhztDrRAgy8re8hvlfkja1oPPxvO1ZMCy3qPIW7sem5ZClCInpCB A1MNbIQ5ANtps5oXTPCgLWDospdCL2xFJmTZmpR/AbHbAbr8bgr3GwEjYx0FREImuoow OTSmgnSuxq7n9fQ54f/qmHDD0ERJUiknQb5HO2oqyJ5wHgG2GF/IFegTCfPBfk5OH3db l3aw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=MxQ2yLXg; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-139135-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139135-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g22-20020ac85d56000000b004346fe9f336si10855150qtx.808.2024.04.10.10.48.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 10:48:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139135-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=MxQ2yLXg; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-139135-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139135-linux.lists.archive=gmail.com@vger.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 744681C20D0D for ; Wed, 10 Apr 2024 17:48:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8E73199EAF; Wed, 10 Apr 2024 17:45:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="MxQ2yLXg" Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A48D1802D6; Wed, 10 Apr 2024 17:44:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712771103; cv=none; b=nj9JFi9upBNoxEFSXH4Cq2tJi9MasWiatzNMgI6Tng1jFCbR0RBiSIEosW9pgyFSk9wSdMNIl0vx1Y6V2e9yPOr5WRPa1XLIssUVmD5mRkwGoSLe04QkqXam6Td9j8r7UwlxxRnGPhjkdy8mKVp3KYTe812iHCrrsK6BOLMw2qA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712771103; c=relaxed/simple; bh=7gKWhycZmUjTMJkPd/ZDFGuQf2EeEblQmHNOYDf0bmA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SbDUBj9Og6S3zEN94Muwai6dd4gbAIrdiBbt6lyvBX4hnqiXm/wHjVBI0/UF8oTSaxVmbN8kfH0nD5R/RKc5F6Q8n6kc364jHszhizSb5/hQ8U0M7jY6vAe3AKwrB6XX/OGx6NlsG+Y/z4vS5Aq46nmNefiITO8hhYImcGCxJ/E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=MxQ2yLXg reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.0.0) id ba490e62e58493f8; Wed, 10 Apr 2024 19:44:52 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id DCB8A66C66F; Wed, 10 Apr 2024 19:44:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1712771092; bh=7gKWhycZmUjTMJkPd/ZDFGuQf2EeEblQmHNOYDf0bmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MxQ2yLXgDS6P/McDyoK30LNF31tyFQP8krWVDW1BqXRxT9nlV1m50Sot9JAFwPWJw 6NFKg83CF4I1bk3k5Mkhi4j/ymKP+giuI3nVh+vZpxNrbLj6ZwKyKyI/4Sd2fDTQaf 5+u8nzIbKfwYZwMxRvKjo896HDtZ5jR17lFMnxzzjiioy3dNk1T0dbc0vjDztnQgzd b3JkxjcHuVNXOftOF0791IeENOTgx65p/B2JejTygB+I5rWjUWdfhxuTpLJ9HTxxP9 /L3N524ysVxDLAg88Qx21X3YUI1odJDgJ+81KpK/n3I5Zaakx1fsivxmbIow/H6MDJ bkEEdftpzybpQ== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Srinivas Pandruvada Subject: [PATCH v1 11/16] thermal: gov_fair_share: Use .manage() callback instead of .throttle() Date: Wed, 10 Apr 2024 18:57:38 +0200 Message-ID: <2411572.NG923GbCHz@kreacher> In-Reply-To: <13515747.uLZWGnKmhe@kreacher> References: <13515747.uLZWGnKmhe@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrudehiedguddugecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeehpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtohepshhr ihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 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);