Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp372797rdg; Thu, 12 Oct 2023 08:04:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4Dw9xyRpopLGxPJmO5VVFSgevoYMtTCat5U6cqXxLpfAQOUoby4DjsNKZ3YgYWWFa4mtG X-Received: by 2002:a17:902:cec7:b0:1c9:9144:574b with SMTP id d7-20020a170902cec700b001c99144574bmr11939080plg.49.1697123087633; Thu, 12 Oct 2023 08:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697123087; cv=none; d=google.com; s=arc-20160816; b=EJna79tPjdfhR7IhRNRHWg/UUrE4nRMLJskPDQCcbTNSqQJbIXrzUMNO7HZSENXez4 sifQk7dDyktVhLJKzdQGVpNt3/MNqLRbsJ562ADJF0Lhs9d+nHlF2BkMd9rT2oUTK6Xd HBRGobm+4525g5u6m7Hz4K031B8aWDKCTb5/7Q4uuaSoIlF1YF0m0S31UyYHjSOE8q+C rfT2mrAVoZHi94Of5rWlbRXASD+b7v9CJU6kU5F7IwnFCJ5PIhLsDf/V0IXQMa7el3lW +ABsEgv9nwvA7U4mf9C6hdXv7bhRkMV6QnxwLnuLpOnO60mPa1BMFqwsNgbky6Ig2/KW 61aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=P6/hE83dFOY8xzxiFaTi6nXaEfmM6cCFOZ7/7sFQHGk=; fh=lwSoWzxFgElz870zfiYjK9IUzI6DgmKcUjvGVkpbGwE=; b=R5p6zx1WWpO7ZBvOnqQvP3IzGcisfxFPDqCGHutgJZ5NxSxtbVNLe77IdiHMCP2/7W g43T/dEhCs2dYFVLwA1RfHyQpm+7fmLGhDoT9OqoZ7gPukdbq8Wj1sDp6SwV95e7hUUe XNvK4tsMMSBH3T3nwcbbHdD4C1P175fUNqCr0AE4YiqmY8QwN44tXCB2CgJMeggta4St kjm/toNrYDkidV7kt+oPvIoVR/qyeAiZEQqqgnEPfjJD9C25zC/wSFQrM6s4KA5ay6YB ulMLXUBDU+Dp+Cy8eyv35rDfDcQRF7hyx1l/Zoi6knJs1QDcInlkTAbW98HxPbUgwCvn ADGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dV5J+rLf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id d1-20020a170902b70100b001c9e75f87edsi1020pls.152.2023.10.12.08.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 08:04:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dV5J+rLf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id DDAC982357A5; Thu, 12 Oct 2023 08:04:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346817AbjJLPEa (ORCPT + 99 others); Thu, 12 Oct 2023 11:04:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379045AbjJLPE3 (ORCPT ); Thu, 12 Oct 2023 11:04:29 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 114C9CC for ; Thu, 12 Oct 2023 08:04:27 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4066241289bso11672195e9.0 for ; Thu, 12 Oct 2023 08:04:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697123065; x=1697727865; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=P6/hE83dFOY8xzxiFaTi6nXaEfmM6cCFOZ7/7sFQHGk=; b=dV5J+rLf/BUMcDfUmM+7rUAfrOD9LChKnQYKT/tsR0d5OR+3J9UC/k3FVOzkX09Euv xO5zRpfRoqAiKH/4yyR39DoqSFVjPmtLy87mSlW/B/IzjY5DOvEcsWiVvKKI1iteMKTX 2s4gYj3NvTYwg1RVcXq6bORxjgGCu3kFc68gwSYLjGwJAbRHPV9jHx3UfaPOgA8POgRP MpMfFcNEjiIhBjq1IJMiK6hkY/BLHkJi4/SgcSJI3vzyeGqvIJUAbwjdTzbfHNE7f1Xa CSdorFg/PhZqRFeDBhoOTxoKz8kY0KSe9BDa7jB8jGUdTBMpA/OGmzROxwFPUrsqflyj VIwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697123065; x=1697727865; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=P6/hE83dFOY8xzxiFaTi6nXaEfmM6cCFOZ7/7sFQHGk=; b=D3Z3sgoO06RepCHBBgkj5VZ+/6xOSsmpSdvYJPhXJUzvwaNilKqn9gyWtOigRhxPGr 9qcaFOGTHZHDDmfZnwgU8a67sTtcjZHOlC3hvj0bPqdfiFfwZAXMCnNuoLE4a+V+ZI4t Mp4HU/B4PwO4TNog2Es64ry8h78HZ/ssqu+NrdMcc0rPWwI6YLoPHTOEV6u1SS2pTluk lWPiyrMO+9gKGzfykQlW7reReKo/y4LZaQ/73CxEFn1BTUGwzAsYswdOi+FeZFy4Y/4Z t15SkYPNBShsZrilrVVgukKjse2Ru+WWoUoKc06kJr3sZvydF5QpxCuB7Vu/gTz7S52U ca+A== X-Gm-Message-State: AOJu0YzsvTjbre8Q0nI3piz3VZse4DMvD4qal5DrRdwdAuRpx2xmZL6R bvzcvYEtykS7v9JdNYtUH/56NA== X-Received: by 2002:a05:600c:211:b0:405:3dbc:8823 with SMTP id 17-20020a05600c021100b004053dbc8823mr21915774wmi.12.1697123065350; Thu, 12 Oct 2023 08:04:25 -0700 (PDT) Received: from ?IPV6:2a05:6e02:1041:c10:c49e:e1a5:3210:b8c0? ([2a05:6e02:1041:c10:c49e:e1a5:3210:b8c0]) by smtp.googlemail.com with ESMTPSA id q19-20020a1cf313000000b0040596352951sm71876wmq.5.2023.10.12.08.04.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Oct 2023 08:04:24 -0700 (PDT) Message-ID: Date: Thu, 12 Oct 2023 17:04:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 3/6] thermal: gov_fair_share: Rearrange get_trip_level() Content-Language: en-US To: "Rafael J. Wysocki" , Linux PM Cc: LKML , Srinivas Pandruvada , Zhang Rui , Lukasz Luba References: <13365827.uLZWGnKmhe@kreacher> <2244940.iZASKD2KPV@kreacher> From: Daniel Lezcano In-Reply-To: <2244940.iZASKD2KPV@kreacher> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 12 Oct 2023 08:04:44 -0700 (PDT) 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? > + 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. > + 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, > > > -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog