From patchwork Fri Oct 6 17:40:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 149374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp499169vqo; Fri, 6 Oct 2023 10:52:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFT7GRpq4zh8u18Ha7v6382Y5R5xel0B/BvCOYAkBNzmST2F2MoChvBUHDHHDuv3mqHHBvt X-Received: by 2002:a17:902:e888:b0:1c7:37e2:13fe with SMTP id w8-20020a170902e88800b001c737e213femr9808016plg.2.1696614737478; Fri, 06 Oct 2023 10:52:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696614737; cv=none; d=google.com; s=arc-20160816; b=YhxFbn2BrCmXghEMbNtMznWCSzEMyd4yjaN3/Kbs/CZkLoUOb36CevJvmf9d6sOQ9y ttr2XmYdZN2e05cX8M+CshjAl4OOV/FY27coUHoP1m5l3QJwkIuDKiCcJaqOQeRLrjgF YEXUcjCTvbw5DHfb6+mdtR5rh4JXr1xbKishIMlefEWQTfzPtAdqLoUOg2FX25q9yTlI fF8y1X7s6ZHwsqcI8ecJiym3gLUk73sFUm3bfIgusma/80zGSTRv4XdlUXJgodsIfetX 7Sczz6w5+5AE2VXH+mqcYKjHFx83S18Rg8hA4M8kOPcTNwXv8l1MzlVLGo9k3+L4XBwt ZNtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DlHCI25g2T/r7xRbwh8RipYzcnaZb3rCgd610m6cBC4=; fh=7MtGe3Dn5wgXLQQm5DZb5OyhwmEFEEdRNCLYMJcP5yE=; b=zGlMwigpwoY4OELbmkpEREpgtcpupmfGtW7RIAjou6oKO+lNKNENUbHctAVpVmxHU7 v3TIK4wHKsze33/Rt9XzHclK2rvpMijAFjd5/BGqLA3zlrqjLldRaOdU4pXNNb1v1JUo /HSVPIIG/fvdLCU3SrFBnwRWtxjPl+3VoZCEwWTOWn0B5PdrSHQbTlKdzNAHwjbDM79u 2Gb75UqHPz2DAScXh0aNt5wCotN6QPMTmi0IWjlj6xXr6IAVJonROoDi/jTvegWXm/qr YGfFdmX5Dxqp7npVk3ipL7kp7mWLNkkQkZAmJh5VGceWH+qgr9GV4c7KXdVBok0oZxbf r65A== 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:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id d2-20020a170902cec200b001c61226fe40si4455992plg.392.2023.10.06.10.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 10:52:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 47AFF89630E1; Fri, 6 Oct 2023 10:52:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233127AbjJFRvq (ORCPT + 18 others); Fri, 6 Oct 2023 13:51:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232953AbjJFRvd (ORCPT ); Fri, 6 Oct 2023 13:51:33 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DD5DB6; Fri, 6 Oct 2023 10:51:32 -0700 (PDT) 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 5.2.0) id ad6d2b9f66b12151; Fri, 6 Oct 2023 19:51:30 +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 v370.home.net.pl (Postfix) with ESMTPSA id 30F1D665D08; Fri, 6 Oct 2023 19:51:30 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui , Lukasz Luba Subject: [PATCH v1 1/6] thermal: trip: Simplify computing trip indices Date: Fri, 06 Oct 2023 19:40:25 +0200 Message-ID: <3256881.aeNJFYEL58@kreacher> In-Reply-To: <13365827.uLZWGnKmhe@kreacher> References: <13365827.uLZWGnKmhe@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrgeeigdduudehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgv lhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Fri, 06 Oct 2023 10:52:13 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779029495094794353 X-GMAIL-MSGID: 1779029495094794353 From: Rafael J. Wysocki A trip index can be computed right away as a difference between the value of a trip pointer pointing to the given trip object and the start of the trips[] table in the thermal zone containing the trip, so change thermal_zone_trip_id() accordingly. No intentional functional impact (except for some speedup). Signed-off-by: Rafael J. Wysocki Reviewed-by: Lukasz Luba Tested-by: Lukasz Luba --- drivers/thermal/thermal_trip.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) Index: linux-pm/drivers/thermal/thermal_trip.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_trip.c +++ linux-pm/drivers/thermal/thermal_trip.c @@ -175,14 +175,11 @@ int thermal_zone_set_trip(struct thermal int thermal_zone_trip_id(struct thermal_zone_device *tz, const struct thermal_trip *trip) { - int i; - lockdep_assert_held(&tz->lock); - for (i = 0; i < tz->num_trips; i++) { - if (&tz->trips[i] == trip) - return i; - } - - return -ENODATA; + /* + * Assume the trip to be located within the bounds of the thermal + * zone's trips[] table. + */ + return trip - tz->trips; } From patchwork Fri Oct 6 17:41:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 149371 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp499122vqo; Fri, 6 Oct 2023 10:52:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUCEPph9rhH2W8W6bNSdnFVovdkTzSXsYhw8Tpb9K7o2iYf2Yg/1z01cs2/dNH10C0m62a X-Received: by 2002:a17:90a:8597:b0:274:1bc9:b72 with SMTP id m23-20020a17090a859700b002741bc90b72mr8425994pjn.24.1696614732858; Fri, 06 Oct 2023 10:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696614732; cv=none; d=google.com; s=arc-20160816; b=CzXAhG3vU2t5GESNi9aLfZcOZgBnItsPv3VjgYu2QcennTQEdWRMmbSboYlmzG3NU9 KX3ow9fECuZmcz3uXeCOlNEx/hk0P+ah0m86PSTS9036YLfSMlw7SiG0IexFWFAkuS+C 0xKl6vq3dvewS+Mi1s/KyXUfkp4RFTT63nJ2L7mAQWVqeyOhznnOKkp80BmMRIapcbxK LoRivOg1q9oLbIApr4iDZD1mQ/7X6z1flJuVMl4GP7YSaNZsxSVZ/1FuF8IT8OX982Fx i76+DUyOZsZX/G52VE9QYv7qOA+ZA40a5ND5PwXzVMDcm97U+aPoCGn5QEHf63DZp7Ao OLnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=QK3xt8nYMnK+BkjjRqcxuMqYMHbGq1kiZ1ojWdYZmek=; fh=7MtGe3Dn5wgXLQQm5DZb5OyhwmEFEEdRNCLYMJcP5yE=; b=e4S/U9iv4LIqQ2zF3FyDj/mwbCFiQyUaijVJicJvK6zU1Zur1YuG8xKjkUl94noRrd tBkboWBJeD47u5YcV3VZG99vmhYchfzjwSUWNIkOoVmk7URzs+0Sv8xaRUz2Fzof/OGC UySxQ6iq1GFYmlM8AHh4B5ytIjlKD3QVVxaTZWX7xqxjt32NVYbb3M2Zqe3ybDTC96A2 HGe5wgWf/EE5cp2D5abG0/gicCoi+ZhxPf9uC6LuR8j11apazF+Ky01i/qrbbia3tQWG EdEqcOOY8GZ01ruya34fWjY+7cCLrVumW1ErV1C4nBbKq7B5oQhmnEqDNijb5an6nGTG S9HA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id k6-20020a17090ac50600b002774e11ca41si6260734pjt.67.2023.10.06.10.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 10:52:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id EF35E8172973; Fri, 6 Oct 2023 10:52:10 -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 S233113AbjJFRvl (ORCPT + 18 others); Fri, 6 Oct 2023 13:51:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233066AbjJFRvc (ORCPT ); Fri, 6 Oct 2023 13:51:32 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BD61BE; Fri, 6 Oct 2023 10:51:31 -0700 (PDT) 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 5.2.0) id 1e41d53679a1e7ca; Fri, 6 Oct 2023 19:51:29 +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 v370.home.net.pl (Postfix) with ESMTPSA id 69307665D08; Fri, 6 Oct 2023 19:51:29 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui , Lukasz Luba Subject: [PATCH v1 2/6] thermal: trip: Define for_each_trip() macro Date: Fri, 06 Oct 2023 19:41:56 +0200 Message-ID: <8282829.T7Z3S40VBb@kreacher> In-Reply-To: <13365827.uLZWGnKmhe@kreacher> References: <13365827.uLZWGnKmhe@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrgeeigdduudehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgv lhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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]); Fri, 06 Oct 2023 10:52:11 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779029490301344917 X-GMAIL-MSGID: 1779029490301344917 From: Rafael J. Wysocki Define a new macro for_each_trip() to be used by the thermal core code and thermal governors for walking trips in a given thermal zone. Modify for_each_thermal_trip() to use this macro instead of an open- coded loop over trips. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Acked-by: Daniel Lezcano Reviewed-by: Lukasz Luba --- drivers/thermal/thermal_core.h | 3 +++ drivers/thermal/thermal_trip.c | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.h =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.h +++ linux-pm/drivers/thermal/thermal_core.h @@ -116,6 +116,9 @@ void __thermal_zone_device_update(struct enum thermal_notify_event event); /* Helpers */ +#define for_each_trip(__tz, __trip) \ + for (__trip = __tz->trips; __trip - __tz->trips < __tz->num_trips; __trip++) + void __thermal_zone_set_trips(struct thermal_zone_device *tz); int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, struct thermal_trip *trip); Index: linux-pm/drivers/thermal/thermal_trip.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_trip.c +++ linux-pm/drivers/thermal/thermal_trip.c @@ -13,12 +13,13 @@ int for_each_thermal_trip(struct thermal int (*cb)(struct thermal_trip *, void *), void *data) { - int i, ret; + struct thermal_trip *trip; + int ret; lockdep_assert_held(&tz->lock); - for (i = 0; i < tz->num_trips; i++) { - ret = cb(&tz->trips[i], data); + for_each_trip(tz, trip) { + ret = cb(trip, data); if (ret) return ret; } From patchwork Fri Oct 6 17:42:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 149372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp499132vqo; Fri, 6 Oct 2023 10:52:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHyLfTlzptA1SNglN6BoHl4blbl9Ur6F6zLJR/b84i1mcNjHIuUGWR4vOfAqPJJfn5sC2yb X-Received: by 2002:a17:902:d2cd:b0:1c3:94a4:34bf with SMTP id n13-20020a170902d2cd00b001c394a434bfmr10427337plc.66.1696614733419; Fri, 06 Oct 2023 10:52:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696614733; cv=none; d=google.com; s=arc-20160816; b=p8OO/scPNMYafFOW4FKCYlH94G+vSLQdiGu0uA0DtSnm5FZD4yFJWgwKMiEG5AsjrL 2WLJMONrHdKweY5L9skTa/6BREivtTrE+Eanoi62uHG7K4eAYZdGkFFXr6SEA6lDwucp 6TlK9sWl5tRzO3WHbneoByC4bmdBfHueSgPeKTJ0WsBZIPQ7pJwEOvZ2WCL3qV7vcovG nkOc2TfxCYFJsKTiPvmsvExwrlE1Zjg835y5ldC4+/GSm0I4NlH3alm6W/tM+1KA9QNN TLBX9VSElFTA3NHIdL7OXX9Jx0N0uOp5MLVchbLBWpoju/7Re/T0nbOXIgfvnaHF4b/N anQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=dt51t1EARwQbB7qGxOBEKKgazunXET8SMXJBhbaUkuc=; fh=7MtGe3Dn5wgXLQQm5DZb5OyhwmEFEEdRNCLYMJcP5yE=; b=vU0OhUCpJkxh6oDFaAnTW3KP7AoFLh5/STa6fldG5Ss5N0oR+mVZrHOWyIW/eqSXFC K0kUd+PsS1yz9IHFW9tx16EmoZVt59ThdrfqmzZZ7e18ZlMhspfdheOi5ReWs9Ac2GuT Vpk1ahYxh/jaowSkvaIMRt25PweQrHMr8VNvtu/0H9syg0td7PZJZ2zUTeSwNNEOGgrp A5f2dwK4kFrPKCNuX+JNiMGrBOpInEoO4JH+peM+KGuV3HLU5w64HpZANQoh+BPCFvRx S4zaD75CtyQDFOCTo45jLBU2ug6LoZS/sUuIapux6oawoYsQKv9ZsFpxaW0oJdU/NweM Y6ng== 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:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id n14-20020a170902968e00b001c774a25b3bsi4096700plp.233.2023.10.06.10.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 10:52:13 -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; 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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 32E178262E0E; Fri, 6 Oct 2023 10:52:07 -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 S233105AbjJFRvj (ORCPT + 18 others); Fri, 6 Oct 2023 13:51:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233058AbjJFRvb (ORCPT ); Fri, 6 Oct 2023 13:51:31 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A782FB6; Fri, 6 Oct 2023 10:51:30 -0700 (PDT) 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 5.2.0) id 6f63dadd0b78c61c; Fri, 6 Oct 2023 19:51:29 +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 v370.home.net.pl (Postfix) with ESMTPSA id 9AD47665D08; Fri, 6 Oct 2023 19:51:28 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui , Lukasz Luba Subject: [PATCH v1 3/6] thermal: gov_fair_share: Rearrange get_trip_level() Date: Fri, 06 Oct 2023 19:42:48 +0200 Message-ID: <2244940.iZASKD2KPV@kreacher> In-Reply-To: <13365827.uLZWGnKmhe@kreacher> References: <13365827.uLZWGnKmhe@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrgeeigdduudehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgv lhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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]); Fri, 06 Oct 2023 10:52:07 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779029490916993739 X-GMAIL-MSGID: 1779029490916993739 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; + + 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; + + 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, From patchwork Fri Oct 6 17:47:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 149373 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp499121vqo; Fri, 6 Oct 2023 10:52:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDmuumLaInMIwWU4xTOzGQcXnNGLemU7xcHotWj3Zuc6zkiZRqWmmO6g9e5ZCO1s0rn9gb X-Received: by 2002:a05:6358:999a:b0:134:c37f:4b5c with SMTP id j26-20020a056358999a00b00134c37f4b5cmr7558784rwb.22.1696614732783; Fri, 06 Oct 2023 10:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696614732; cv=none; d=google.com; s=arc-20160816; b=QrT1XyNRe53QW5FtUHQ3BH2iWeSpbMfRLcwC9YWkG0/bnokHK4P9woT/sF+z17Gex6 e2SR97PaD8J6myp3gASTo6C1z/oiiqIcmtzXdCNfjpDSGKIZbXO3XXkOHIKEwAZICoAd 1NQzUDtvCd6V4DEpUQX6CyaHocH9VWl15IHZbX2c145q3XwN0QIR19RkF2coU2a5VpUi m4oBRSClUrD0pD4HOojm5xQByMEtGPgSZxR3uggrwtCUR65dRRwwiFSpxcVQpf5cZDGH 2NkFkJ2w1GuVRWZeqaoD1WdXGMvVygPKLylXp+w+gbTzic1ZUgOE/Necp/1sX6eMNksb QaYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=1InWkQYHuUm9y8F2xmswstPHZpphCBou89fm1R6HCG8=; fh=7MtGe3Dn5wgXLQQm5DZb5OyhwmEFEEdRNCLYMJcP5yE=; b=OT+Fmyy0m16faOE0Tyd/bVN3BmPDFxj03OSfVLCk0QIgL5+EafehBQKr+s4KOSN5F4 b2kYpa1Lpxj7TJsgsR/AxuNS3850UYzfQBjx8wL5CaLvc396DcqaqK4pla7C1B+BMzQU nr0/nY9f+YOanCYLAWvzDkiWzucAsO7/MG/D1SoLzWz9PBy4wBFqQfF9sYH/LBh1grBO dYfOqbTcHUlDlL/UvSz/Aui8RIIJ8JvFy6A8B3hMTrRgRnyreC7uam+vNOiC4kM3kcvE 4AaeB6rT5ghFeJ7cBXzXGDyARDGQH5X13ZMJhrw3Qdp6D5S0a+nkdXGW8vkqC9JAxXUv t/vg== 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 Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id c34-20020a634e22000000b00565fb7714a5si4191030pgb.800.2023.10.06.10.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 10:52:12 -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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 855F1804C539; Fri, 6 Oct 2023 10:52:08 -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 S233119AbjJFRvn (ORCPT + 18 others); Fri, 6 Oct 2023 13:51:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233074AbjJFRvc (ORCPT ); Fri, 6 Oct 2023 13:51:32 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B42CCC5; Fri, 6 Oct 2023 10:51:29 -0700 (PDT) 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 5.2.0) id 2288febb9f555858; Fri, 6 Oct 2023 19:51:28 +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 v370.home.net.pl (Postfix) with ESMTPSA id AFB2D665D08; Fri, 6 Oct 2023 19:51:27 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui , Lukasz Luba Subject: [PATCH v1 4/6] thermal: gov_power_allocator: Use trip pointers instead of trip indices Date: Fri, 06 Oct 2023 19:47:52 +0200 Message-ID: <3768557.kQq0lBPeGt@kreacher> In-Reply-To: <13365827.uLZWGnKmhe@kreacher> References: <13365827.uLZWGnKmhe@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrgeeigdduudehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgv lhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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]); Fri, 06 Oct 2023 10:52:08 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779029489612494424 X-GMAIL-MSGID: 1779029489612494424 From: Rafael J. Wysocki Modify the power allocator thermal governor to use trip pointers instead of trip indices everywhere except for the power_allocator_throttle() second argument that will be changed subsequently along with the definition of the .throttle() governor callback. The general functionality is not expected to be changed. Signed-off-by: Rafael J. Wysocki Reviewed-by: Lukasz Luba Tested-by: Lukasz Luba --- drivers/thermal/gov_power_allocator.c | 123 +++++++++++++--------------------- 1 file changed, 49 insertions(+), 74 deletions(-) Index: linux-pm/drivers/thermal/gov_power_allocator.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_power_allocator.c +++ linux-pm/drivers/thermal/gov_power_allocator.c @@ -16,8 +16,6 @@ #include "thermal_core.h" -#define INVALID_TRIP -1 - #define FRAC_BITS 10 #define int_to_frac(x) ((x) << FRAC_BITS) #define frac_to_int(x) ((x) >> FRAC_BITS) @@ -55,23 +53,23 @@ static inline s64 div_frac(s64 x, s64 y) * @err_integral: accumulated error in the PID controller. * @prev_err: error in the previous iteration of the PID controller. * Used to calculate the derivative term. + * @sustainable_power: Sustainable power (heat) that this thermal zone can + * dissipate * @trip_switch_on: first passive trip point of the thermal zone. The * governor switches on when this trip point is crossed. * If the thermal zone only has one passive trip point, - * @trip_switch_on should be INVALID_TRIP. + * @trip_switch_on should be NULL. * @trip_max_desired_temperature: last passive trip point of the thermal * zone. The temperature we are * controlling for. - * @sustainable_power: Sustainable power (heat) that this thermal zone can - * dissipate */ struct power_allocator_params { bool allocated_tzp; s64 err_integral; s32 prev_err; - int trip_switch_on; - int trip_max_desired_temperature; u32 sustainable_power; + const struct thermal_trip *trip_switch_on; + const struct thermal_trip *trip_max_desired_temperature; }; /** @@ -90,14 +88,12 @@ static u32 estimate_sustainable_power(st u32 sustainable_power = 0; struct thermal_instance *instance; struct power_allocator_params *params = tz->governor_data; - const struct thermal_trip *trip_max_desired_temperature = - &tz->trips[params->trip_max_desired_temperature]; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { struct thermal_cooling_device *cdev = instance->cdev; u32 min_power; - if (instance->trip != trip_max_desired_temperature) + if (instance->trip != params->trip_max_desired_temperature) continue; if (!cdev_is_power_actor(cdev)) @@ -116,24 +112,23 @@ static u32 estimate_sustainable_power(st * estimate_pid_constants() - Estimate the constants for the PID controller * @tz: thermal zone for which to estimate the constants * @sustainable_power: sustainable power for the thermal zone - * @trip_switch_on: trip point number for the switch on temperature + * @trip_switch_on: trip point for the switch on temperature * @control_temp: target temperature for the power allocator governor * * This function is used to update the estimation of the PID * controller constants in struct thermal_zone_parameters. */ static void estimate_pid_constants(struct thermal_zone_device *tz, - u32 sustainable_power, int trip_switch_on, + u32 sustainable_power, + const struct thermal_trip *trip_switch_on, int control_temp) { - struct thermal_trip trip; u32 temperature_threshold = control_temp; int ret; s32 k_i; - ret = __thermal_zone_get_trip(tz, trip_switch_on, &trip); - if (!ret) - temperature_threshold -= trip.temperature; + if (trip_switch_on) + temperature_threshold -= trip_switch_on->temperature; /* * estimate_pid_constants() tries to find appropriate default @@ -386,7 +381,7 @@ static int allocate_power(struct thermal struct thermal_instance *instance; struct power_allocator_params *params = tz->governor_data; const struct thermal_trip *trip_max_desired_temperature = - &tz->trips[params->trip_max_desired_temperature]; + params->trip_max_desired_temperature; u32 *req_power, *max_power, *granted_power, *extra_actor_power; u32 *weighted_req_power; u32 total_req_power, max_allocatable_power, total_weighted_req_power; @@ -496,7 +491,7 @@ static int allocate_power(struct thermal } /** - * get_governor_trips() - get the number of the two trip points that are key for this governor + * get_governor_trips() - get the two trip points that are key for this governor * @tz: thermal zone to operate on * @params: pointer to private data for this governor * @@ -513,46 +508,36 @@ static int allocate_power(struct thermal static void get_governor_trips(struct thermal_zone_device *tz, struct power_allocator_params *params) { - int i, last_active, last_passive; - bool found_first_passive; - - found_first_passive = false; - last_active = INVALID_TRIP; - last_passive = INVALID_TRIP; - - for (i = 0; i < tz->num_trips; i++) { - struct thermal_trip trip; - int ret; - - ret = __thermal_zone_get_trip(tz, i, &trip); - if (ret) { - dev_warn(&tz->device, - "Failed to get trip point %d type: %d\n", i, - ret); - continue; - } - - if (trip.type == THERMAL_TRIP_PASSIVE) { - if (!found_first_passive) { - params->trip_switch_on = i; - found_first_passive = true; - } else { - last_passive = i; + const struct thermal_trip *first_passive = NULL; + const struct thermal_trip *last_passive = NULL; + const struct thermal_trip *last_active = NULL; + const struct thermal_trip *trip; + + for_each_trip(tz, trip) { + switch (trip->type) { + case THERMAL_TRIP_PASSIVE: + if (!first_passive) { + first_passive = trip; + break; } - } else if (trip.type == THERMAL_TRIP_ACTIVE) { - last_active = i; - } else { + last_passive = trip; + break; + case THERMAL_TRIP_ACTIVE: + last_active = trip; + break; + default: break; } } - if (last_passive != INVALID_TRIP) { + if (last_passive) { + params->trip_switch_on = first_passive; params->trip_max_desired_temperature = last_passive; - } else if (found_first_passive) { - params->trip_max_desired_temperature = params->trip_switch_on; - params->trip_switch_on = INVALID_TRIP; + } else if (first_passive) { + params->trip_switch_on = NULL; + params->trip_max_desired_temperature = first_passive; } else { - params->trip_switch_on = INVALID_TRIP; + params->trip_switch_on = NULL; params->trip_max_desired_temperature = last_active; } } @@ -567,14 +552,12 @@ static void allow_maximum_power(struct t { struct thermal_instance *instance; struct power_allocator_params *params = tz->governor_data; - const struct thermal_trip *trip_max_desired_temperature = - &tz->trips[params->trip_max_desired_temperature]; u32 req_power; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { struct thermal_cooling_device *cdev = instance->cdev; - if ((instance->trip != trip_max_desired_temperature) || + if (instance->trip != params->trip_max_desired_temperature || (!cdev_is_power_actor(instance->cdev))) continue; @@ -636,7 +619,6 @@ static int power_allocator_bind(struct t { int ret; struct power_allocator_params *params; - struct thermal_trip trip; ret = check_power_actors(tz); if (ret) @@ -662,12 +644,13 @@ static int power_allocator_bind(struct t get_governor_trips(tz, params); if (tz->num_trips > 0) { - ret = __thermal_zone_get_trip(tz, params->trip_max_desired_temperature, - &trip); - if (!ret) + const struct thermal_trip *trip; + + trip = params->trip_max_desired_temperature; + if (trip) estimate_pid_constants(tz, tz->tzp->sustainable_power, params->trip_switch_on, - trip.temperature); + trip->temperature); } reset_pid_controller(params); @@ -697,11 +680,10 @@ static void power_allocator_unbind(struc tz->governor_data = NULL; } -static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_id) +static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_index) { struct power_allocator_params *params = tz->governor_data; - struct thermal_trip trip; - int ret; + const struct thermal_trip *trip = &tz->trips[trip_index]; bool update; lockdep_assert_held(&tz->lock); @@ -710,12 +692,12 @@ static int power_allocator_throttle(stru * We get called for every trip point but we only need to do * our calculations once */ - if (trip_id != params->trip_max_desired_temperature) + if (trip != params->trip_max_desired_temperature) return 0; - ret = __thermal_zone_get_trip(tz, params->trip_switch_on, &trip); - if (!ret && (tz->temperature < trip.temperature)) { - update = (tz->last_temperature >= trip.temperature); + trip = params->trip_switch_on; + if (trip && tz->temperature < trip->temperature) { + update = tz->last_temperature >= trip->temperature; tz->passive = 0; reset_pid_controller(params); allow_maximum_power(tz, update); @@ -724,14 +706,7 @@ static int power_allocator_throttle(stru tz->passive = 1; - ret = __thermal_zone_get_trip(tz, params->trip_max_desired_temperature, &trip); - if (ret) { - dev_warn(&tz->device, "Failed to get the maximum desired temperature: %d\n", - ret); - return ret; - } - - return allocate_power(tz, trip.temperature); + return allocate_power(tz, params->trip_max_desired_temperature->temperature); } static struct thermal_governor thermal_gov_power_allocator = { From patchwork Fri Oct 6 17:49:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 149369 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp498980vqo; Fri, 6 Oct 2023 10:51:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE31xe2fW67szBsbz77yRoVvAV3K7dlDgSCnkprxIgyoZZbwQYn8cU2Hp3FSK2aQZQGfsAQ X-Received: by 2002:a05:6a00:2196:b0:690:24ff:c80f with SMTP id h22-20020a056a00219600b0069024ffc80fmr9126695pfi.34.1696614711359; Fri, 06 Oct 2023 10:51:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696614711; cv=none; d=google.com; s=arc-20160816; b=nwjcX1vBGYGiGYMLSZhIkIdBQ6LlgQehav6Eg1/0M6CPSL6SCW6QUjcBlQK9xOTjQ8 yH5EqOgT5G03aDkI6Kor9/mZQGbUsZFsbwRqIe2x0QkkGZTnX5NP0c7rv8iHWIqamAAN rCkWYNg8w67xnjaUPvX9DdR2tx0iH+y6sL6Iq4cjB1faZ/Q1X3yFJAknVrhXkHDm3DNf DL+0RZOujLMRRSQId/Fgt/i0REXTUN+PmkYsqo/eoycnvo2nc+de6JL7xPYvNe7dpKDw mny3+ylLf4lF4+NT4bRR1V6uF2/euZcgRqdJWmlXl1GY1DkZZr7Un9XTK+97LaP5Yxa0 E+BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=f7LmQP0UmruflYMCMM6WI92ijpnDS5T1M98XwguGSbs=; fh=7MtGe3Dn5wgXLQQm5DZb5OyhwmEFEEdRNCLYMJcP5yE=; b=GLXAJZSVYYALplYcSL09YxmWqJEhuEYgcG5lAQGIwtMN6cLczhmvNtBXuVpaETNsYC xyfe5oNIEG7hvjWeNp/Jga9Wtsc2r1oWkXSftjFKqXDRwv4lTWXgGsFRfqBHBU20vRRk +xkYKgwUGtOgtQ87pQBTYCL8RGkJMdCo+Y+s8IL8TjPTT9B2FjCdBwzvEqY/2sDE0V/7 lS9R5APsvvylYhgNmtfN35hvJZS66v1kAamHWltU65QAld7qFBb+MYYaygIIkiYI1sd5 2LEcjEnRyMZ0bQZBSitoS+b19liY1F4DaHIm6DYZVO1Xw2iJdNHzB/5C7F7BnMmJfecl +rfw== 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 Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id c23-20020aa78c17000000b00690f291a06esi1798037pfd.1.2023.10.06.10.51.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 10:51:51 -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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 86F018243090; Fri, 6 Oct 2023 10:51:43 -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 S233073AbjJFRvc (ORCPT + 18 others); Fri, 6 Oct 2023 13:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232953AbjJFRva (ORCPT ); Fri, 6 Oct 2023 13:51:30 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D85F5C2; Fri, 6 Oct 2023 10:51:28 -0700 (PDT) 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 5.2.0) id 822ee62ecd4cce57; Fri, 6 Oct 2023 19:51:27 +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 v370.home.net.pl (Postfix) with ESMTPSA id CD019665D08; Fri, 6 Oct 2023 19:51:26 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui , Lukasz Luba Subject: [PATCH v1 5/6] thermal: gov_step_wise: Fold update_passive_instance() into its caller Date: Fri, 06 Oct 2023 19:49:39 +0200 Message-ID: <9177552.CDJkKcVGEf@kreacher> In-Reply-To: <13365827.uLZWGnKmhe@kreacher> References: <13365827.uLZWGnKmhe@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrgeeigdduudeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgv lhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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]); Fri, 06 Oct 2023 10:51:43 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779029468018392174 X-GMAIL-MSGID: 1779029468018392174 From: Rafael J. Wysocki Fold update_passive_instance() into thermal_zone_trip_update() that is its only caller so as to make the code in question easeir to follow. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Acked-by: Daniel Lezcano Reviewed-by: Lukasz Luba --- drivers/thermal/gov_step_wise.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) Index: linux-pm/drivers/thermal/gov_step_wise.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_step_wise.c +++ linux-pm/drivers/thermal/gov_step_wise.c @@ -68,17 +68,6 @@ static unsigned long get_target_state(st return next_target; } -static void update_passive_instance(struct thermal_zone_device *tz, - enum thermal_trip_type type, int value) -{ - /* - * If value is +1, activate a passive instance. - * If value is -1, deactivate a passive instance. - */ - if (type == THERMAL_TRIP_PASSIVE) - tz->passive += value; -} - static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id) { const struct thermal_trip *trip = &tz->trips[trip_id]; @@ -109,14 +98,17 @@ static void thermal_zone_trip_update(str if (instance->initialized && old_target == instance->target) continue; - /* Activate a passive thermal instance */ if (old_target == THERMAL_NO_TARGET && - instance->target != THERMAL_NO_TARGET) - update_passive_instance(tz, trip->type, 1); - /* Deactivate a passive thermal instance */ - else if (old_target != THERMAL_NO_TARGET && - instance->target == THERMAL_NO_TARGET) - update_passive_instance(tz, trip->type, -1); + instance->target != THERMAL_NO_TARGET) { + /* Activate a passive thermal instance */ + if (trip->type == THERMAL_TRIP_PASSIVE) + tz->passive++; + } else if (old_target != THERMAL_NO_TARGET && + instance->target == THERMAL_NO_TARGET) { + /* Deactivate a passive thermal instance */ + if (trip->type == THERMAL_TRIP_PASSIVE) + tz->passive--; + } instance->initialized = true; mutex_lock(&instance->cdev->lock); From patchwork Fri Oct 6 17:51:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 149370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp499049vqo; Fri, 6 Oct 2023 10:52:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFqbS/9ppvHW4pLvEkEO+6vEM94xiFTDnGQ1QUHI0WDK9lZTmFtDmFzpTPU0HjV3TPRAaW+ X-Received: by 2002:a05:6a00:b84:b0:68f:ccea:8e14 with SMTP id g4-20020a056a000b8400b0068fccea8e14mr10313185pfj.32.1696614724501; Fri, 06 Oct 2023 10:52:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696614724; cv=none; d=google.com; s=arc-20160816; b=vTcAU/UpoyupVP/JFhaaTnRegS3gbvJtAigM/i09WpNt83CALchPW7BEZRZLw4/hUe 2yUvdBAXy/ruGinr285lV2gYw//6uAbxOac1IAHYNDAS/yQZvRprMd39agEqcjvcsvZW UdOzNznIvNagk40T3qO4K6N7yYjhaZt6eO3UL8RhYrbndfyZ/BICMdCKiyAOyzH+7Akj 2S9QsKVeMyMekWk34w/R/ZrByLpUVvqCs+NNYEmr0DAtM3nvSgoYL3d1SMDHy68REWIz /YWjg6wUSAG4ryPZ2C5nr+wEQFSCx4F8LTLwefFJlic3/4dT34TzxA5k2Dk+Fj6eNmK4 Qnlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=t18TMbXbcnQVmQjpTMws993cim1KGBjpXj9uHcCGZP4=; fh=7MtGe3Dn5wgXLQQm5DZb5OyhwmEFEEdRNCLYMJcP5yE=; b=WZUxik9W96r6qX/QfL1UVvEUVpOzQQwzNh9cExz4lxPh0hu5ELV9kqiTe0AQ83U4JL /e1y5TTUl5keLuoZCdMcdv3l/EeGFXfCIyPP7u8G0mLNAtS+cN9EjrILrlABM2XGy6qM 0LgVh1UDoPrOSMfuf45vItndoP1t4zYKWyC4jOP8uT1mv5NJ0aQIu7guSiMireUGPQtc KL7whKDGo3CPHZ5/ZCN1YRpmCOdFUaCk+D1ZiJOyUBb7BI7NtKguByfzKrUpnFiRIH09 hZ+EnyVoZq+rX5kbDm5iN4DC/F8eDDrzy0+MxS4V0rOS2zq0hQYVWBfaW8CNcsxnCL8d zYCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id cj27-20020a056a00299b00b00690cb77d5e5si1869861pfb.394.2023.10.06.10.52.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 10:52:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id EDAB08262E07; Fri, 6 Oct 2023 10:51:55 -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 S233090AbjJFRvf (ORCPT + 18 others); Fri, 6 Oct 2023 13:51:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233005AbjJFRvb (ORCPT ); Fri, 6 Oct 2023 13:51:31 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE4A0BF; Fri, 6 Oct 2023 10:51:28 -0700 (PDT) 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 5.2.0) id a3e8c574d8a10ee7; Fri, 6 Oct 2023 19:51:26 +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 v370.home.net.pl (Postfix) with ESMTPSA id EEF3B665D08; Fri, 6 Oct 2023 19:51:25 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui , Lukasz Luba Subject: [PATCH v1 6/6] thermal: core: Pass trip pointer to governor throttle callback Date: Fri, 06 Oct 2023 19:51:06 +0200 Message-ID: <5877301.MhkbZ0Pkbq@kreacher> In-Reply-To: <13365827.uLZWGnKmhe@kreacher> References: <13365827.uLZWGnKmhe@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrgeeigdduudeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgv lhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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]); Fri, 06 Oct 2023 10:51:56 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779029481125769379 X-GMAIL-MSGID: 1779029481125769379 From: Rafael J. Wysocki Modify the governor .throttle() callback definition so that it takes a trip pointer instead of a trip index as its second argument, adjust the governors accordingly and update the core code invoking .throttle(). This causes the governors to become independent of the representation of the list of trips in the thermal zone structure. This change is not expected to alter the general functionality. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/thermal/gov_bang_bang.c | 8 +++-- drivers/thermal/gov_fair_share.c | 6 ++-- drivers/thermal/gov_power_allocator.c | 4 +- drivers/thermal/gov_step_wise.c | 12 ++++---- drivers/thermal/gov_user_space.c | 8 +++-- drivers/thermal/thermal_core.c | 50 +++++++++++++++++----------------- drivers/thermal/thermal_core.h | 2 - drivers/thermal/thermal_helpers.c | 3 -- include/linux/thermal.h | 3 +- 9 files changed, 51 insertions(+), 45 deletions(-) Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -199,7 +199,8 @@ struct thermal_governor { char name[THERMAL_NAME_LENGTH]; int (*bind_to_tz)(struct thermal_zone_device *tz); void (*unbind_from_tz)(struct thermal_zone_device *tz); - int (*throttle)(struct thermal_zone_device *tz, int trip); + int (*throttle)(struct thermal_zone_device *tz, + const struct thermal_trip *trip); struct list_head governor_list; }; Index: linux-pm/drivers/thermal/gov_bang_bang.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_bang_bang.c +++ linux-pm/drivers/thermal/gov_bang_bang.c @@ -13,9 +13,10 @@ #include "thermal_core.h" -static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_index) +static int thermal_zone_trip_update(struct thermal_zone_device *tz, + const struct thermal_trip *trip) { - const struct thermal_trip *trip = &tz->trips[trip_index]; + int trip_index = thermal_zone_trip_id(tz, trip); struct thermal_instance *instance; if (!trip->hysteresis) @@ -89,7 +90,8 @@ static int thermal_zone_trip_update(stru * (trip_temp - hyst) so that the fan gets turned off again. * */ -static int bang_bang_control(struct thermal_zone_device *tz, int trip) +static int bang_bang_control(struct thermal_zone_device *tz, + const struct thermal_trip *trip) { struct thermal_instance *instance; int ret; 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 @@ -47,7 +47,7 @@ static long get_target_state(struct ther /** * fair_share_throttle - throttles devices associated with the given zone * @tz: thermal_zone_device - * @trip_index: trip point index + * @trip: trip point * * Throttling Logic: This uses three parameters to calculate the new * throttle state of the cooling devices associated with the given zone. @@ -63,9 +63,9 @@ static long get_target_state(struct ther * (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, int trip_index) +static int fair_share_throttle(struct thermal_zone_device *tz, + const struct thermal_trip *trip) { - const struct thermal_trip *trip = &tz->trips[trip_index]; struct thermal_instance *instance; int total_weight = 0; int total_instance = 0; Index: linux-pm/drivers/thermal/gov_power_allocator.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_power_allocator.c +++ linux-pm/drivers/thermal/gov_power_allocator.c @@ -680,10 +680,10 @@ static void power_allocator_unbind(struc tz->governor_data = NULL; } -static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_index) +static int power_allocator_throttle(struct thermal_zone_device *tz, + const struct thermal_trip *trip) { struct power_allocator_params *params = tz->governor_data; - const struct thermal_trip *trip = &tz->trips[trip_index]; bool update; lockdep_assert_held(&tz->lock); Index: linux-pm/drivers/thermal/gov_step_wise.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_step_wise.c +++ linux-pm/drivers/thermal/gov_step_wise.c @@ -68,15 +68,16 @@ static unsigned long get_target_state(st return next_target; } -static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id) +static void thermal_zone_trip_update(struct thermal_zone_device *tz, + const struct thermal_trip *trip) { - const struct thermal_trip *trip = &tz->trips[trip_id]; + int trip_id = thermal_zone_trip_id(tz, trip); enum thermal_trend trend; struct thermal_instance *instance; bool throttle = false; int old_target; - trend = get_tz_trend(tz, trip_id); + trend = get_tz_trend(tz, trip); if (tz->temperature >= trip->temperature) { throttle = true; @@ -120,7 +121,7 @@ static void thermal_zone_trip_update(str /** * step_wise_throttle - throttles devices associated with the given zone * @tz: thermal_zone_device - * @trip: trip point index + * @trip: trip point * * Throttling Logic: This uses the trend of the thermal zone to throttle. * If the thermal zone is 'heating up' this throttles all the cooling @@ -128,7 +129,8 @@ static void thermal_zone_trip_update(str * step. If the zone is 'cooling down' it brings back the performance of * the devices by one step. */ -static int step_wise_throttle(struct thermal_zone_device *tz, int trip) +static int step_wise_throttle(struct thermal_zone_device *tz, + const struct thermal_trip *trip) { struct thermal_instance *instance; Index: linux-pm/drivers/thermal/thermal_helpers.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_helpers.c +++ linux-pm/drivers/thermal/thermal_helpers.c @@ -22,9 +22,8 @@ #include "thermal_core.h" #include "thermal_trace.h" -int get_tz_trend(struct thermal_zone_device *tz, int trip_index) +int get_tz_trend(struct thermal_zone_device *tz, const struct thermal_trip *trip) { - struct thermal_trip *trip = tz->trips ? &tz->trips[trip_index] : NULL; enum thermal_trend trend; if (tz->emul_temperature || !tz->ops->get_trend || Index: linux-pm/drivers/thermal/thermal_core.h =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.h +++ linux-pm/drivers/thermal/thermal_core.h @@ -70,7 +70,7 @@ static inline bool cdev_is_power_actor(s void thermal_cdev_update(struct thermal_cooling_device *); void __thermal_cdev_update(struct thermal_cooling_device *cdev); -int get_tz_trend(struct thermal_zone_device *tz, int trip_index); +int get_tz_trend(struct thermal_zone_device *tz, const struct thermal_trip *trip); struct thermal_instance * get_thermal_instance(struct thermal_zone_device *tz, Index: linux-pm/drivers/thermal/gov_user_space.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_user_space.c +++ linux-pm/drivers/thermal/gov_user_space.c @@ -25,11 +25,12 @@ static int user_space_bind(struct therma /** * notify_user_space - Notifies user space about thermal events * @tz: thermal_zone_device - * @trip: trip point index + * @trip: trip point * * This function notifies the user space through UEvents. */ -static int notify_user_space(struct thermal_zone_device *tz, int trip) +static int notify_user_space(struct thermal_zone_device *tz, + const struct thermal_trip *trip) { char *thermal_prop[5]; int i; @@ -38,7 +39,8 @@ static int notify_user_space(struct ther thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type); thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature); - thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", trip); + thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", + thermal_zone_trip_id(tz, trip)); thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event); thermal_prop[4] = NULL; kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop); Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -307,7 +307,8 @@ static void monitor_thermal_zone(struct thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies); } -static void handle_non_critical_trips(struct thermal_zone_device *tz, int trip) +static void handle_non_critical_trips(struct thermal_zone_device *tz, + const struct thermal_trip *trip) { tz->governor ? tz->governor->throttle(tz, trip) : def_governor->throttle(tz, trip); @@ -329,44 +330,43 @@ void thermal_zone_device_critical(struct EXPORT_SYMBOL(thermal_zone_device_critical); static void handle_critical_trips(struct thermal_zone_device *tz, - int trip, int trip_temp, enum thermal_trip_type trip_type) + const struct thermal_trip *trip) { /* If we have not crossed the trip_temp, we do not care. */ - if (trip_temp <= 0 || tz->temperature < trip_temp) + if (trip->temperature <= 0 || tz->temperature < trip->temperature) return; - trace_thermal_zone_trip(tz, trip, trip_type); + trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, trip), trip->type); - if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot) - tz->ops->hot(tz); - else if (trip_type == THERMAL_TRIP_CRITICAL) + if (trip->type == THERMAL_TRIP_CRITICAL) tz->ops->critical(tz); + else if (tz->ops->hot) + tz->ops->hot(tz); } -static void handle_thermal_trip(struct thermal_zone_device *tz, int trip_id) +static void handle_thermal_trip(struct thermal_zone_device *tz, + const struct thermal_trip *trip) { - struct thermal_trip trip; - - __thermal_zone_get_trip(tz, trip_id, &trip); - - if (trip.temperature == THERMAL_TEMP_INVALID) + if (trip->temperature == THERMAL_TEMP_INVALID) return; if (tz->last_temperature != THERMAL_TEMP_INVALID) { - if (tz->last_temperature < trip.temperature && - tz->temperature >= trip.temperature) - thermal_notify_tz_trip_up(tz->id, trip_id, + if (tz->last_temperature < trip->temperature && + tz->temperature >= trip->temperature) + thermal_notify_tz_trip_up(tz->id, + thermal_zone_trip_id(tz, trip), tz->temperature); - if (tz->last_temperature >= trip.temperature && - tz->temperature < (trip.temperature - trip.hysteresis)) - thermal_notify_tz_trip_down(tz->id, trip_id, + if (tz->last_temperature >= trip->temperature && + tz->temperature < trip->temperature - trip->hysteresis) + thermal_notify_tz_trip_down(tz->id, + thermal_zone_trip_id(tz, trip), tz->temperature); } - if (trip.type == THERMAL_TRIP_CRITICAL || trip.type == THERMAL_TRIP_HOT) - handle_critical_trips(tz, trip_id, trip.temperature, trip.type); + if (trip->type == THERMAL_TRIP_CRITICAL || trip->type == THERMAL_TRIP_HOT) + handle_critical_trips(tz, trip); else - handle_non_critical_trips(tz, trip_id); + handle_non_critical_trips(tz, trip); } static void update_temperature(struct thermal_zone_device *tz) @@ -403,7 +403,7 @@ static void thermal_zone_device_init(str void __thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { - int count; + const struct thermal_trip *trip; if (atomic_read(&in_suspend)) return; @@ -422,8 +422,8 @@ void __thermal_zone_device_update(struct tz->notify_event = event; - for (count = 0; count < tz->num_trips; count++) - handle_thermal_trip(tz, count); + for_each_trip(tz, trip) + handle_thermal_trip(tz, trip); monitor_thermal_zone(tz); }