Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp427889rdg; Thu, 12 Oct 2023 09:29:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHc54GFROQ2xtZQBs5AOwvRop0kVE3kJxYYvfSxCwI6eccEG+h+xeatgLgMqUWqcrtFBXq X-Received: by 2002:a05:6358:7e07:b0:139:c75f:63eb with SMTP id o7-20020a0563587e0700b00139c75f63ebmr28585034rwm.21.1697128196267; Thu, 12 Oct 2023 09:29:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697128196; cv=none; d=google.com; s=arc-20160816; b=y2Fh3kkWurlsmoBQ94AKkGnG5kJl856wjnkueRuznF3+GBZ2DIt9hY+Q/wX0zi1d2C Fk4z4qIgEacpJHN5izSdDPozACjC6bil52jwl9m7N2L0zqtHga2PYG3qeNI6dDa0eB9e RkClo4WlqjPz+BY1I7NWTOZaYJhDtCgdnhugSsM05H5+CgLE3T7kp5GBYyB9p8x6/ll1 fI2KY0+e1gBYGBUhdAxXcUp62uaCkpUCNmUbSvyPWv5L/gpQsWcHPwSKcaErfUOAh9WD sIlJ4Wuj050+D3dyPvWH1I7xOZKAie/5XBYPD6ylLPBe1MaArvzgGhjMXbnGd4AbTXEF +ujQ== 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=QmLgNvu3ZO3ZYpA/6yZu4XAnFDKWy5g1wNCJQiODxwE=; fh=RjkRc/FhKx0ouKQ9JcARy/W3YEos4nBH55yWPTBs/m8=; b=kcKAGsOMKC3AzVp4Yu3Kn7wi2lo0Yv4+bCs7d96n/cbqWgYnC5O7YSbo0UXHxL56DI fw07O4d3pvytQYpXjc36r9lOOJl7OXWJgFpE0vQeT/kp7nKq1NU6lyDu8w/lRgsq4swM lyhwAVLlz/0fZANtwjZHh9GZd/iydNv+gggH4uQuGONys1yDoqbvF3dbkOkmpa6+p25n G30lSIQIV2R6bBCgEGctvs7xtG5wOWa+zooUZ1GxttETnd2Gu6hZxHhB3HqbHVM7GJ0C 2oh3C2N9llzF6lTSoTxx+InquQVVEXFwimfyuKivWvlW3cJUCQQ5kWUsxImUhM1s89uL ZCfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id h15-20020a056a001a4f00b00690d42e334fsi15037587pfv.181.2023.10.12.09.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 09:29:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id E6A928064571; Thu, 12 Oct 2023 09:29:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379566AbjJLQ3n convert rfc822-to-8bit (ORCPT + 99 others); Thu, 12 Oct 2023 12:29:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379582AbjJLQ3l (ORCPT ); Thu, 12 Oct 2023 12:29:41 -0400 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F5F9D3; Thu, 12 Oct 2023 09:29:40 -0700 (PDT) Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-57b68555467so26292eaf.0; Thu, 12 Oct 2023 09:29:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697128179; x=1697732979; 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=sAl3+uNQYC6UB13kffuDk/amKGx+yj+5/jXC7+UiWUQ=; b=cgGkWAwPyiAcf3yczETm34FV9hgQB1wEvWsTL1YK91007CXGiFtmqNZfoYyOe1R/Fj DSDZw8BV0PklhiyX01UHVihEJg8lytclg6rb1uOybA9noiuIhVuC2+CNoza5PBvM73S/ Gq/jvIo7FRyHd39ouJr+Sn6WGHkBYXgcaSbAiiN0XNwCbPdi08/V6XUgZWmHj1cG2jOf njR0ZTj6rbDQiuRiI63S1YxpxFbjc7RdLqlr/3rEeFSOgOgmhU+eF8HAc1IDLdXoEXRF WcS77DnslJ9D0wFSg3UhtCOMkIVun3VX7T/1hHFvwjuloQWUHuNOQouizFaNXJgeDMXP 0gpA== X-Gm-Message-State: AOJu0YyvHPcC5ES193TR0CzMhoelsrhJ22ZodmFYVpIOII+H7Rqa7Yye 304X0COyncat+OvfaYh1fu5G9rFG9UzPNbYtNyA= X-Received: by 2002:a4a:df07:0:b0:57b:73f6:6f80 with SMTP id i7-20020a4adf07000000b0057b73f66f80mr24662463oou.0.1697128179431; Thu, 12 Oct 2023 09:29:39 -0700 (PDT) MIME-Version: 1.0 References: <13365827.uLZWGnKmhe@kreacher> <2244940.iZASKD2KPV@kreacher> In-Reply-To: From: "Rafael J. Wysocki" Date: Thu, 12 Oct 2023 18:29:28 +0200 Message-ID: Subject: Re: [PATCH v1 3/6] thermal: gov_fair_share: Rearrange get_trip_level() To: Daniel Lezcano Cc: "Rafael J. Wysocki" , Linux PM , LKML , Srinivas Pandruvada , Zhang Rui , Lukasz Luba Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Thu, 12 Oct 2023 09:29:54 -0700 (PDT) On Thu, Oct 12, 2023 at 5:04 PM Daniel Lezcano wrote: > > On 06/10/2023 19:42, Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki > > > > Make get_trip_level() use for_each_trip() to iterate over trip points > > and make it call thermal_zone_trip_id() to obtain the integer ID of a > > given trip point so as to avoid relying on the knowledge of struct > > thermal_zone_device internals. > > > > The general functionality is not expected to be changed. > > > > This change causes the governor to use trip pointers instead of trip > > indices everywhere except for the fair_share_throttle() second argument > > that will be modified subsequently along with the definition of the > > governor .throttle() callback. > > > > Signed-off-by: Rafael J. Wysocki > > --- > > drivers/thermal/gov_fair_share.c | 30 ++++++++++++++---------------- > > 1 file changed, 14 insertions(+), 16 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 > > @@ -15,29 +15,27 @@ > > > > #include "thermal_core.h" > > > > -/** > > - * get_trip_level: - obtains the current trip level for a zone > > - * @tz: thermal zone device > > - */ > > static int get_trip_level(struct thermal_zone_device *tz) > > { > > - struct thermal_trip trip; > > - int count; > > + const struct thermal_trip *trip, *level_trip = NULL; > > + int trip_level; > > > > - for (count = 0; count < tz->num_trips; count++) { > > - __thermal_zone_get_trip(tz, count, &trip); > > - if (tz->temperature < trip.temperature) > > + for_each_trip(tz, trip) { > > + if (level_trip && trip->temperature >= tz->temperature) > > break; > > Even if very likely the trip points are ordered by the hardware > enumeration, strictly we don't have yet the guarantee the trips are > ordered (as that is the final goal to correctly detect thresholds > crossing with the generic trip). We should go through all the trip > points, no? Well, I just retained the existing logic, because changing it is not the purpose of this patch. Such a change can certainly be considered, but not in this patch and not in this patch series. > > + level_trip = trip; > > } > > > > - /* > > - * count > 0 only if temperature is greater than first trip > > - * point, in which case, trip_point = count - 1 > > - */ > > - if (count > 0) > > - trace_thermal_zone_trip(tz, count - 1, trip.type); > > + /* Bail out if the temperature is not greater than any trips. */ > > + if (level_trip->temperature >= tz->temperature) > > + return 0; > > Isn't simpler to remove the test level_trip != NULL in the loop and then > check here if it is NULL and then return 0. Yes, good point. > > + trip_level = thermal_zone_trip_id(tz, level_trip); > > + > > + trace_thermal_zone_trip(tz, trip_level, level_trip->type); > > > > - return count; > > + return trip_level; > > } > > > > static long get_target_state(struct thermal_zone_device *tz, > > > > > > > > --