Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2680112rdh; Wed, 27 Sep 2023 09:27:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEX1djrEKcWPWoCuXkF71Yblc3GhOeNr0j76FYRQfE6vl7mTNijlNFeBIFWY1lo8ItB1P3I X-Received: by 2002:a17:90a:a681:b0:269:85d:2aef with SMTP id d1-20020a17090aa68100b00269085d2aefmr2168027pjq.20.1695832035206; Wed, 27 Sep 2023 09:27:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695832035; cv=none; d=google.com; s=arc-20160816; b=ap9/rH6UGBfgzYzT9ZFG2HmjHD7YqwXU4Zqw3+WWQ9Ov8H1q5vBIBZLK3f61+Wfdu3 4KvG+WxediQzlD77tFL1YprMTZGf0yFCEYVhef6DVHOJCdpzfOa2rtCXX+YOxYKaPe46 gQEWi1uJv5gxqJxNNvrAqwFHMVrMpltmeUk0L/rO9eeyIQ2wU93mBfAkusCTjv7faInK g43eQPKChD3anrvMkZFhfnU6UCag43UmDrZEebWf2jF8SdIYE2nABs5/LOwZBGO630LL 7aiRvfJ22InZxRGWGKpftuohQgDol5FfUYDe5kDZyWprq//L8XH2kVYvLjaiBZ2Izh6n Gdbw== 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=Df4n5Hg4FyPN6OAbQGq+0195dn1+JiVWUBvusrglAb4=; fh=3/NdhQlFmQMIexUcfJh7yNgX6uSuhfym9quW26wpb4k=; b=S6YiAMKX2JCdtWX6Y5sxQ+J3ARKPYUfP1CBpK3BGNnqKz2lNmg56ECjf9RJx45SEf4 JKykyT4FpLLNohI9woUC3Ut3o07fg19KqsnS4NTH/PnsEwht3xkH2FRqUIOflAt9DYnW HUtuS+YfsNpOassaoM8obJGyLMgrmPBTHdNrScQEK5/coR3/fO09ntlpIyTHN3U1Zqys avM5kFxF0OAh6gg8IXSbN/P/PFmh6DTuES/2u7tglzJgTCWlOww2/4hqIK6PferUzcI5 PDywyijhjGRtcAg/wwm/8H9P6U/xjpFvTFCbHzsehquEJbTcCzAQLFycKT4gDV9lFyFJ l1mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id e4-20020a17090a804400b0026b7c4eee42si17539800pjw.66.2023.09.27.09.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 09:27:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 0CF13807CF6B; Wed, 27 Sep 2023 09:10:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231965AbjI0QKJ convert rfc822-to-8bit (ORCPT + 99 others); Wed, 27 Sep 2023 12:10:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231481AbjI0QKC (ORCPT ); Wed, 27 Sep 2023 12:10:02 -0400 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8C7B1B8; Wed, 27 Sep 2023 09:09:56 -0700 (PDT) Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-57bf04841ccso444706eaf.0; Wed, 27 Sep 2023 09:09:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695830996; x=1696435796; 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=uoBx4haDwLKQQRn3ZmCIvGY1ND5OJ+IJ+kQUcWjxXZg=; b=tPgQxZ3U4FJh2OB1AmEHhIkB3I9oLbaDeLNHHmFlhKcBEmjaQ7KAHHkMU9EBny2VF3 bsQG4Jt5AH94x3AJvzH/11F+xglLGGJlVt5KAUIsyw0/9RntD/gM43R80jXWbkOUQ62W m2p0euFGCWJ14+Pn5581lpO07ebcY6kw6VutC+/BGUIVAemfbfldPDCPuINxIcoaLJOM PQEkkfwsX19xUPJgcwVFuiLNgnISYpKMLwkcjrjddu3P/IJQ/Loq6mJvZ1ABVZI6j/uk cQKRrKvbeBtAU53uGqsYG7I2JWh2n/GmRQDBRmq+lyLJwGlU6NdJ0xdJkRcn2nzvKa/4 ezIw== X-Gm-Message-State: AOJu0Yyp/uSe8YtzpHEw+58/5sLuzStbuDjtJ+lOJIRC2nVVjTYee074 2pnu9y/91HPIVb3pda5CfrAKCGFIAVCOW20d0kc= X-Received: by 2002:a4a:c58f:0:b0:57b:7804:9d72 with SMTP id x15-20020a4ac58f000000b0057b78049d72mr2771381oop.1.1695830995803; Wed, 27 Sep 2023 09:09:55 -0700 (PDT) MIME-Version: 1.0 References: <1957441.PYKUYFuaPT@kreacher> <1882755.CQOukoFCf9@kreacher> <3c9f7b7d-a9ca-79ae-4e64-367a82f953bc@linaro.org> In-Reply-To: From: "Rafael J. Wysocki" Date: Wed, 27 Sep 2023 18:09:44 +0200 Message-ID: Subject: Re: [PATCH v1 06/13] thermal: gov_fair_share: Rearrange get_trip_level() To: Daniel Lezcano Cc: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Linux PM , LKML , Linux ACPI , 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 pete.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 (pete.vger.email [0.0.0.0]); Wed, 27 Sep 2023 09:10:57 -0700 (PDT) On Wed, Sep 27, 2023 at 5:37 PM Daniel Lezcano wrote: > > On 27/09/2023 17:06, Rafael J. Wysocki wrote: > > On Wed, Sep 27, 2023 at 5:00 PM Daniel Lezcano > > wrote: > >> > >> On 21/09/2023 19:54, Rafael J. Wysocki wrote: > >>> From: Rafael J. Wysocki > >>> > >>> Make get_trip_level() access the thermal zone's trip table directly > >>> instead of using __thermal_zone_get_trip() which adds overhead related > >>> to the unnecessary bounds checking and copying the trip point data. > >>> > >>> Also rearrange the code in it to make it somewhat easier to follow. > >>> > >>> The general functionality is not expected to be changed. > >>> > >>> Signed-off-by: Rafael J. Wysocki > >>> --- > >>> drivers/thermal/gov_fair_share.c | 22 ++++++++++------------ > >>> 1 file changed, 10 insertions(+), 12 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 > >>> @@ -21,23 +21,21 @@ > >>> */ > >>> static int get_trip_level(struct thermal_zone_device *tz) > >>> { > >>> - struct thermal_trip trip; > >>> - int count; > >>> + const struct thermal_trip *trip = tz->trips; > >>> + int i; > >>> > >>> - for (count = 0; count < tz->num_trips; count++) { > >>> - __thermal_zone_get_trip(tz, count, &trip); > >>> - if (tz->temperature < trip.temperature) > >>> + if (tz->temperature < trip->temperature) > >>> + return 0; > >>> + > >>> + for (i = 0; i < tz->num_trips - 1; i++) { > >>> + trip++; > >>> + if (tz->temperature < trip->temperature) > >>> break; > >>> } > >> > >> Is it possible to use for_each_thermal_trip() instead ? That would make > >> the code more self-encapsulate > > > > It is possible in principle, but this is a governor which is regarded > > as part of the core, isn't it? > > > > So is an extra overhead related to using a callback (which may be > > subject to retpolines and such) really justified in this case? > > From my POV, all trip points browsing should be replaced by > for_each_thermal_trip() so any change in the future in how we go through > the existing thermal trips will impact one place. > > If the routine needs to be optimized, that is something we can do also > (may be an inline the callback?) OK