Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2638160rdh; Wed, 27 Sep 2023 08:22:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFt9codxmpsso7XaqBTG2I09JObJCwqYAiilBvj9vY1JI/KTc2gFEQcsBNqZp6ibCt53Vr2 X-Received: by 2002:a17:90b:1e0e:b0:269:2682:11fb with SMTP id pg14-20020a17090b1e0e00b00269268211fbmr2024518pjb.8.1695828165960; Wed, 27 Sep 2023 08:22:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695828165; cv=none; d=google.com; s=arc-20160816; b=LxJBOel7P5wl0OWSN3ANlc6IyTPm61XZMMmOGYxwXeJcQSJouvqw4rC9xWiCFSeY0A EnvjaJNIdWOQPVIlG+imlCuIOBlK6j52Luo6UIwUW06oRyQyw0CYRAFhTnsfRhgphB+5 fkUHdvA3P4hAkyngjLQH434LSgBXaw2lvmHdV8X1IJgp8xAn3iV2SSD8b/X9Hwn86aOx srABABvbt0yIMw/PFMoNvjspAe6pgMHPCEpAwQti5IZCNgZmqKukn3WgtzDJeYMy5dvy gQMn6L4d2uwilxxqO7I88O2bHb7i6cMCSe91HzIz0vGpXGNS4QX6cHCeTjBSETBLOi5d Bfhg== 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=wpRMS33wq9Mtc8gnmx8CjGygwlRBqI3BtEoTjXLvDbo=; fh=+2JxztEu7bN4hj58I/W/Di3Tmm589BaaoQWR/Ob+TLo=; b=CXSEJhkbLq3BbmOfLT9N535SSHkNZbYYk+I3UC6QnW2Moz3zF3nvQz30LS9d82icLM 3yaQAW3rOvVGMjFPmcOjEdS8LX8Za/ia0QywI/ojXa/sB3Mbbbll4al2+fK2NbiiEK1D qCaeT8aupcfMe42z4/5bODn8QUHKs2tXVMKBNNPlQL0wNQiDpOApUMGOUvPbacbY3+ip /P0WcOuI49nHnnrW+X7KAtWYdc0A41D1N0lDexSi0AXnr31MY6dwJE7kzX2nhAXh+JN4 Sz3MZEX4Su+lP2ikXE1UAUqzgTPBalPGtSC8+qOAkC7bObhhxkOQLlC9UAaai6lpNLIw T9vg== 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:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id s9-20020a17090aad8900b00262f798b614si2399657pjq.51.2023.09.27.08.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 08:22:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id B9F5880787EF; Wed, 27 Sep 2023 08:06:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232294AbjI0PG3 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 27 Sep 2023 11:06:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232285AbjI0PG2 (ORCPT ); Wed, 27 Sep 2023 11:06:28 -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 DA4B6F9; Wed, 27 Sep 2023 08:06:26 -0700 (PDT) Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-57bc11c197aso813417eaf.1; Wed, 27 Sep 2023 08:06:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695827186; x=1696431986; 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=IOU2TsYoHI87o4MQ2qgkhZ2w81LG4U8JjmVaBsHW46M=; b=Y286ki/9nVqIz94z3jG+5TW4bwlwplWSKxouwkazTaqbOLLuqxNw+U8LaL9oxMjAwC ngCIwcd79mimx2MOviB3YHpmPfnPXLiX8t8wvAdESBm9CZclSJu+XGpnw7gB1svfL+sC gE/hW7Ek8Xvanxd3KPzYU29XXAmQflkFc7Ye26xWve+Vo/PRDC/JJAUt7eNbYock3Hpv 3F2U391KGoz7OyByyV+0LjJ6vDCdJjWT8gf35HJD+IIbUXmoCc4sWEDmUc7ieTa+NrYO x2A9qsIDdWjvouBEM+lH57I8yTN0G4tmvhSqfEzWXmyZJT5w6mBKTGq/6lCwDJzDMhxs YYow== X-Gm-Message-State: AOJu0YwhD9eG9SKyRbOtnNR+TOnfC2QkrVNHyfznB/R3VzmfrBXR9CHF TV4ZjBvoHkl+brytRnfWl7amSh9RZ1M5I3/PB5E= X-Received: by 2002:a05:6820:2182:b0:57b:7e31:c12 with SMTP id ce2-20020a056820218200b0057b7e310c12mr2355007oob.1.1695827185901; Wed, 27 Sep 2023 08:06:25 -0700 (PDT) MIME-Version: 1.0 References: <1957441.PYKUYFuaPT@kreacher> <1882755.CQOukoFCf9@kreacher> <3c9f7b7d-a9ca-79ae-4e64-367a82f953bc@linaro.org> In-Reply-To: <3c9f7b7d-a9ca-79ae-4e64-367a82f953bc@linaro.org> From: "Rafael J. Wysocki" Date: Wed, 27 Sep 2023 17:06:14 +0200 Message-ID: Subject: Re: [PATCH v1 06/13] thermal: gov_fair_share: Rearrange get_trip_level() To: Daniel Lezcano Cc: "Rafael J. Wysocki" , Linux PM , LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Lukasz Luba , "Rafael J. Wysocki" 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 27 Sep 2023 08:06:38 -0700 (PDT) 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? > > > - /* > > - * 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); > > + trace_thermal_zone_trip(tz, i, tz->trips[i].type); > > > > - return count; > > + return i; > > } > > > > static long get_target_state(struct thermal_zone_device *tz, > > > > > > > > --