From patchwork Tue Oct 22 15:51:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 837710 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10DD819F10A for ; Tue, 22 Oct 2024 15:51:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729612318; cv=none; b=scDl3Leth/2UIKRbeFz4zsyMUXyZsTT9vqvAp8rz+sNdZEIfDmkDBX+CVZ2R9x84uia6x1aqQyrSklFO6/Cbb0Istt/tZRDZUxvbJuZkKDG74MN8miD9UFUCctt+ldCJS9ZfyYiv/a+v6cMrz/2NMkQb93h0TWzjOwe/ty64uag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729612318; c=relaxed/simple; bh=jYFqmanAtC4z3Xv9g2sjeBSkmmn4JD6BhtS3wjKfxKE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d9/vjZDnpi8RHcHQ69ahJhpZOiNlN4x+xWvaTVXtInHvaEwFTwGKU3pBYFEEqZI/tPDNRH3SvG9w6Av1dHg9aXZAvLoFubRt9Ol12ZZEb0ToaUyaGXpcumepecguwohDx0uEGV9ZEkVFYsBHTl38IPxbJqkS1PQXgOoyxmHaono= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=mriwX4wi; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="mriwX4wi" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-37d63a79bb6so4435974f8f.0 for ; Tue, 22 Oct 2024 08:51:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729612315; x=1730217115; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZE0q2U/Fta68Sa8AGydENIt604JqyWqTTBMJpPleP9s=; b=mriwX4wiJ9V+wKXlMxza5JyGQ02dCeY9jA06JO/VEqf4YLoKsKgFbxfAKrb01BJ6XL aNVfVbVx5C1gRTNSmA5VO0CiwhxGSmky50TP4ctebPY7ZBoQqZpAz41oZh9DupoOtUQK AJqP6npnfo1FYzl/HCvELvSXWLJQov3pyyvn8R3FzBA/gx1PTZNx9Mtnd1EWBT47yjI8 Gq+IjNGoMSsMR19TE4zb5yMKlMvHtwGfg71riu3CMmHK1j+hvc6CKnufQWLI1Usz8nI/ cPKhsEDED/0FixcSN0oJ8maVwNuHG5bmmRChlBPCBGWn2l3oiMGNMXucW1FBKC2YO/pW 4gSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729612315; x=1730217115; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZE0q2U/Fta68Sa8AGydENIt604JqyWqTTBMJpPleP9s=; b=FapXBVQnIkhEJlITyYlb5It134eZHlL9bB4KWTETex09ELBLh1w8FTvUlf5MVS9KLu gwLoazOdCzv3ZQ5CZaBpgtIgk8pTSbNtu4BNot9aHJJDWxETmmkSdH20B41XOgExCZEy 0sLQNFLswsm38sHf87hZi6tn1kYqBJnKRX9zDIOu/Mt1MHqiE66+4njgXdFjUWtfF6RM b40dgOJjfg9NSORBQxmrEkt5ww4WA7Uu9HBiVCHUJc9Ea0TBVZCSXMP4lKgRcEhnIU31 5wyK5ZrIo1IOuzs8fbwzmkqDAk3vh1UYDoZ++Oor4yZL0vLGiKLr1Poc8iSVKDQ2pMg5 ufag== X-Gm-Message-State: AOJu0YzOdJ8klrh9QWYr5ncZoAjv7MfVbaCF255ulu//0hq9xLyWgFDr 6exPGZDUOMZf6aj+URACuryPqxHk80AKPI7dV4oq2aCn490JGVJnCYZxhqwSeu0= X-Google-Smtp-Source: AGHT+IEXX673aPeKbBpjqbNortBxM29PyZzCOlSqAG13qbabpBDiFRe6VKrx034Ve9CJ9lCRL4Y41Q== X-Received: by 2002:a5d:4349:0:b0:37d:5143:c695 with SMTP id ffacd0b85a97d-37ef21bb2femr2164511f8f.53.1729612315323; Tue, 22 Oct 2024 08:51:55 -0700 (PDT) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f58aef6sm91538075e9.22.2024.10.22.08.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 08:51:55 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, quic_manafm@quicinc.com, lukasz.luba@arm.com Subject: [PATCH v6 1/5] thermal: core: Connect the threshold with the core Date: Tue, 22 Oct 2024 17:51:41 +0200 Message-ID: <20241022155147.463475-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241022155147.463475-1-daniel.lezcano@linaro.org> References: <20241022155147.463475-1-daniel.lezcano@linaro.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Initialize, de-initialize and handle the threshold in the same place than the trip points. Signed-off-by: Daniel Lezcano Link: https://patch.msgid.link/20240923100005.2532430-3-daniel.lezcano@linaro.org [ rjw: Subject edit ] Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_core.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 8f03985f971c..1e87256e86be 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -585,6 +585,8 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz, high = td->threshold; } + thermal_thresholds_handle(tz, &low, &high); + thermal_zone_set_trips(tz, low, high); list_sort(NULL, &way_up_list, thermal_trip_notify_cmp); @@ -1491,6 +1493,10 @@ thermal_zone_device_register_with_trips(const char *type, goto unregister; } + result = thermal_thresholds_init(tz); + if (result) + goto remove_hwmon; + mutex_lock(&thermal_list_lock); mutex_lock(&tz->lock); @@ -1514,6 +1520,8 @@ thermal_zone_device_register_with_trips(const char *type, return tz; +remove_hwmon: + thermal_remove_hwmon_sysfs(tz); unregister: device_del(&tz->device); release_device: @@ -1601,6 +1609,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) thermal_set_governor(tz, NULL); + thermal_thresholds_exit(tz); thermal_remove_hwmon_sysfs(tz); ida_free(&thermal_tz_ida, tz->id); ida_destroy(&tz->ida); From patchwork Tue Oct 22 15:51:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 837709 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEABF1BC9F6 for ; Tue, 22 Oct 2024 15:51:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729612321; cv=none; b=ad8N5NSJ4Ljo11W8w4V0Zh4r+Oz1lGFOGi0lomvG2uqdfKRSZMoFPHt4EMKpVWosJbUdr2spJuVy0xibW9rEFlCFw6l1X+OcxofEbI6hkN+w22iBQ83082baft9Ca0Qvt6Kp9S+/mZrWFSncTrMXmCMmKe0MyeRx3qs6cumlcVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729612321; c=relaxed/simple; bh=Vape9wmPRqvxV9y6aEkeCHyg0PIZjoI3tZA4z2EcPLg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=juj6AmJYR9haZW8drriFZYATNDdHRO6sPjP+B6x4/jhvYfMX3UunnIYMtRHoZkY/Jk0CSlFtd81a66GCu8+06LhecWw+zX/7rc9NOG+MGO80MipTWkd+iqN9XUNZxvDewsica42vuI4OuOE2a3R97f0xXQ4HFRvRQEzRUOH6wwk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=gAnxlRfh; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="gAnxlRfh" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-431616c23b5so29935475e9.0 for ; Tue, 22 Oct 2024 08:51:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729612318; x=1730217118; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N6N0J/aO9QVYhgRdsmiLuSTn61Oe0bhTn6ZqjO0maUY=; b=gAnxlRfhy5F4gW1Lrp43JUB5JkEN7i7A3BUEKEV1FpFpjn5+LKJZlkJICZ03Oc6xPJ 9u8QG+Z2G3TtRxE4hPb3hgb3Q2R5AtCuCxwN6VXM2JJ3NqUN+ObX8DigLokRA+ki0T3J bBZGCw5MT2SMEZ6ZoGo8YRzFbyI2zW/pGaKwhQRVfz/L9cH4Dag/fSqRtxHQPu3bnhh2 LJzrkXXpOW3WMC5Rt6DXUemSlCBgnA0iD+XVdjSxzMa1YpHuiI471F77bJDWg3QWkS/y DX9I68nBmH+frZ59K6g8kWTgUk+8633ua5/qibkijI3EIP7cihB8gbqYnUeL9y5/2G6W 1vPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729612318; x=1730217118; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N6N0J/aO9QVYhgRdsmiLuSTn61Oe0bhTn6ZqjO0maUY=; b=vQCXg3iQpf781uxYY6W5UYczVDLg7UoMVo++I6SuCTsLCZRM+IuRslQ2WnUpkd4pgG oTstnKaGiYUDz5xU0MoYc7+z3b6lDpg4XsLeZss85SRZ4fP0i2H7IN3G7Pks+fCU4tt/ GL5XgxZH6EGc1d51kGADmSP/10nKIRy/0uzYx0Y/6TIl5biVA9F+XzPAXnNHFOEG5UdY o4ktrdmmaPH941QDqB6hfr6DBD2cXUlI2UNsy69RbzjRAKGHtgdpy1G9iXjFrgll78Qf wusaGQ8fDR6si3qGxqUg6qDAC5sDOOcLpObrLhVuX1c9mpYwcSj49sY1VveikMRLA/tO B+wg== X-Gm-Message-State: AOJu0YwJuUAHHIH7k9Zq6WxIBE5cR6wilELG/P2FMjm6ODGMjezfiJOS Gz+sckT6Gm8jI9+qAEHqeGkwNah0k9gu2eUa5IVvjAgB+RMaCwTwJqjs25ZKEIk= X-Google-Smtp-Source: AGHT+IFZGJxkruqz5VdSXHb/Pj6KWmupMMwvDiT8bndC65B+zIRBRSjzxvTqzMnwWKNX+qsKfk7EuQ== X-Received: by 2002:a05:600c:1d10:b0:424:a7f1:ba2 with SMTP id 5b1f17b1804b1-4317beb1da3mr22486685e9.17.1729612318070; Tue, 22 Oct 2024 08:51:58 -0700 (PDT) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f58aef6sm91538075e9.22.2024.10.22.08.51.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 08:51:57 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, quic_manafm@quicinc.com, lukasz.luba@arm.com Subject: [PATCH v6 3/5] tools/lib/thermal: Make more generic the command encoding function Date: Tue, 22 Oct 2024 17:51:43 +0200 Message-ID: <20241022155147.463475-4-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241022155147.463475-1-daniel.lezcano@linaro.org> References: <20241022155147.463475-1-daniel.lezcano@linaro.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The thermal netlink has been extended with more commands which require an encoding with more information. The generic encoding function puts the thermal zone id with the command name. It is the unique parameters. The next changes will provide more parameters to the command. Set the scene for those new parameters by making the encoding function more generic. Signed-off-by: Daniel Lezcano Reviewed-by: Lukasz Luba --- tools/lib/thermal/commands.c | 41 ++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/tools/lib/thermal/commands.c b/tools/lib/thermal/commands.c index 73d4d4e8d6ec..a9223df91dcf 100644 --- a/tools/lib/thermal/commands.c +++ b/tools/lib/thermal/commands.c @@ -261,8 +261,23 @@ static struct genl_ops thermal_cmd_ops = { .o_ncmds = ARRAY_SIZE(thermal_cmds), }; -static thermal_error_t thermal_genl_auto(struct thermal_handler *th, int id, int cmd, - int flags, void *arg) +struct cmd_param { + int tz_id; +}; + +typedef int (*cmd_cb_t)(struct nl_msg *, struct cmd_param *); + +static int thermal_genl_tz_id_encode(struct nl_msg *msg, struct cmd_param *p) +{ + if (p->tz_id >= 0 && nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_ID, p->tz_id)) + return -1; + + return 0; +} + +static thermal_error_t thermal_genl_auto(struct thermal_handler *th, cmd_cb_t cmd_cb, + struct cmd_param *param, + int cmd, int flags, void *arg) { struct nl_msg *msg; void *hdr; @@ -276,7 +291,7 @@ static thermal_error_t thermal_genl_auto(struct thermal_handler *th, int id, int if (!hdr) return THERMAL_ERROR; - if (id >= 0 && nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_ID, id)) + if (cmd_cb && cmd_cb(msg, param)) return THERMAL_ERROR; if (nl_send_msg(th->sk_cmd, th->cb_cmd, msg, genl_handle_msg, arg)) @@ -289,30 +304,38 @@ static thermal_error_t thermal_genl_auto(struct thermal_handler *th, int id, int thermal_error_t thermal_cmd_get_tz(struct thermal_handler *th, struct thermal_zone **tz) { - return thermal_genl_auto(th, -1, THERMAL_GENL_CMD_TZ_GET_ID, + return thermal_genl_auto(th, NULL, NULL, THERMAL_GENL_CMD_TZ_GET_ID, NLM_F_DUMP | NLM_F_ACK, tz); } thermal_error_t thermal_cmd_get_cdev(struct thermal_handler *th, struct thermal_cdev **tc) { - return thermal_genl_auto(th, -1, THERMAL_GENL_CMD_CDEV_GET, + return thermal_genl_auto(th, NULL, NULL, THERMAL_GENL_CMD_CDEV_GET, NLM_F_DUMP | NLM_F_ACK, tc); } thermal_error_t thermal_cmd_get_trip(struct thermal_handler *th, struct thermal_zone *tz) { - return thermal_genl_auto(th, tz->id, THERMAL_GENL_CMD_TZ_GET_TRIP, - 0, tz); + struct cmd_param p = { .tz_id = tz->id }; + + return thermal_genl_auto(th, thermal_genl_tz_id_encode, &p, + THERMAL_GENL_CMD_TZ_GET_TRIP, 0, tz); } thermal_error_t thermal_cmd_get_governor(struct thermal_handler *th, struct thermal_zone *tz) { - return thermal_genl_auto(th, tz->id, THERMAL_GENL_CMD_TZ_GET_GOV, 0, tz); + struct cmd_param p = { .tz_id = tz->id }; + + return thermal_genl_auto(th, thermal_genl_tz_id_encode, &p, + THERMAL_GENL_CMD_TZ_GET_GOV, 0, tz); } thermal_error_t thermal_cmd_get_temp(struct thermal_handler *th, struct thermal_zone *tz) { - return thermal_genl_auto(th, tz->id, THERMAL_GENL_CMD_TZ_GET_TEMP, 0, tz); + struct cmd_param p = { .tz_id = tz->id }; + + return thermal_genl_auto(th, thermal_genl_tz_id_encode, &p, + THERMAL_GENL_CMD_TZ_GET_TEMP, 0, tz); } thermal_error_t thermal_cmd_exit(struct thermal_handler *th) From patchwork Tue Oct 22 15:51:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 837708 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C49B41BCA07 for ; Tue, 22 Oct 2024 15:52:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729612323; cv=none; b=Hgq0IJlW1gsqfobaAFMmdFfNxU0Dmia5VtDZ7LBdzVeAMhBV1mwt9WhD0yFvts5bPsOjT8uLh+IcGBv+Lr2OU2pIuTIdN/+MYPtXs5rh9ZcdbjRAJ0nq5Xf8pta53tQVPf5aVSiQSmKsjoES24soMaqwjoU4Q0WfAiVQDQ2LYjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729612323; c=relaxed/simple; bh=wnuS4jCjWeWaZfA5VKXzBfe1spB2VUFtXbdTIp8fiYg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YR659hqGMYT2m9G3jiorrKiinwQ17jlXwenCJDmFNslXsDxzJw1l20cy+ei5F3mqD1W+E2gKSqa+RUT3LKkKKyJblE9Shmud+pvFG4f+JzCFrfmz0tzszOwEAj9fyG+cCz7F69F9kB7MpHxg5q00n4WWnKGthpjsS87W4G21a70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=XhGPpvq/; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="XhGPpvq/" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4315c1c7392so53553235e9.1 for ; Tue, 22 Oct 2024 08:52:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729612320; x=1730217120; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TQdcwI3tFVDhwU2PKpTHQ4+HIG66kx8TPmW1H/qWXJY=; b=XhGPpvq/wVV0VB8bjrJ85pGs2rQQ0PvKs57kaMPFR6dUCzinZFQ+xzQDg/6UqRg7e2 2+bqD5l4iOKLtlERd7iEwpllo7LaEY75+SmCAxMf2+VMVRXp3v996GfkMDWTv5O+rvMi tT9T0gVk5j2rhXa21+l+uW6vpykzv+sGOhfMzZzqgbLqEnaqi0GYjYeYKQ5Yw8bEvyRn zy3Tw6IfjKziW8zOI5Bmik8LtiTLcMFxLGQ6msreW8ARKTB9pWBJjEYv2uciy9avlQLz o++fxSwzcgoiktbTHI3lFCs+V1x4YH5vPjwYWhKkDYra92Q98U3LdGL997kQ90F5dECi GqbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729612320; x=1730217120; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TQdcwI3tFVDhwU2PKpTHQ4+HIG66kx8TPmW1H/qWXJY=; b=vQ6RUqKKhoz/IW1W5USDmLlpRvTJhxBHpFJvaR7oSj5QjH54nxHYgTG7j88iLIlgP5 lLp2xv1UDUKqMmJQyU/8OQzZ0PpRubwXPu6QLbkXpWsfS6DH60iKQ1zeIaom9qfRf1eH Id+UUhvfoaTEPwh3WfxKa+mxRhuJ6Fft2IfnKwwMP/X5mY/sRpKtAVbaHsc887N2tt+k kgzsbh2TW6WxnVtfJIb7+vdG09fyL9KEYWkFfHAtfX5liwKlSCviBdJYmpXAsIvs93PH g57mAycAX/awEArUwDZSgqlmzNb4xXFnfbkfLIYhMB48rOkTdfw4GsRYae1B/zmc0Krt Lo2w== X-Gm-Message-State: AOJu0YwBEOmq/9YvBcsxwnNu/u8aTwq5G21GVectP9a9Hp/CZeBRjvZl d9qn+fVa6CNXGGV2DjwNnP6yXsAUV3g6bG9dtyiwNjFoopCin++sMmZJ8Ntfdp0= X-Google-Smtp-Source: AGHT+IFMKTj1MstPZDTv/EAGt+gTUjRxSNkt9qz9uHF5PEwIkPP2/0GWHEjtbQNtbLrxQmNShnoxiQ== X-Received: by 2002:a05:600c:5493:b0:431:537d:b3b4 with SMTP id 5b1f17b1804b1-43161642331mr126123335e9.11.1729612320145; Tue, 22 Oct 2024 08:52:00 -0700 (PDT) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f58aef6sm91538075e9.22.2024.10.22.08.51.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 08:51:59 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, quic_manafm@quicinc.com, lukasz.luba@arm.com Subject: [PATCH v6 5/5] tools/thermal/thermal-engine: Take into account the thresholds API Date: Tue, 22 Oct 2024 17:51:45 +0200 Message-ID: <20241022155147.463475-6-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241022155147.463475-1-daniel.lezcano@linaro.org> References: <20241022155147.463475-1-daniel.lezcano@linaro.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Enhance the thermal-engine skeleton with the thresholds added in the kernel and use the API exported by the thermal library. Signed-off-by: Daniel Lezcano Reviewed-by: Lukasz Luba --- tools/thermal/thermal-engine/thermal-engine.c | 105 +++++++++++++++--- 1 file changed, 92 insertions(+), 13 deletions(-) diff --git a/tools/thermal/thermal-engine/thermal-engine.c b/tools/thermal/thermal-engine/thermal-engine.c index 9b1476a2680f..0764dc754771 100644 --- a/tools/thermal/thermal-engine/thermal-engine.c +++ b/tools/thermal/thermal-engine/thermal-engine.c @@ -38,6 +38,14 @@ struct thermal_data { struct thermal_handler *th; }; +static int show_threshold(struct thermal_threshold *th, __maybe_unused void *arg) +{ + INFO("threshold temp=%d, direction=%d\n", + th->temperature, th->direction); + + return 0; +} + static int show_trip(struct thermal_trip *tt, __maybe_unused void *arg) { INFO("trip id=%d, type=%d, temp=%d, hyst=%d\n", @@ -70,6 +78,8 @@ static int show_tz(struct thermal_zone *tz, __maybe_unused void *arg) for_each_thermal_trip(tz->trip, show_trip, NULL); + for_each_thermal_threshold(tz->thresholds, show_threshold, NULL); + show_temp(tz, arg); show_governor(tz, arg); @@ -77,6 +87,30 @@ static int show_tz(struct thermal_zone *tz, __maybe_unused void *arg) return 0; } +static int set_threshold(struct thermal_zone *tz, __maybe_unused void *arg) +{ + struct thermal_handler *th = arg; + int thresholds[] = { 43000, 65000, 49000, 55000, 57000 }; + size_t i; + + INFO("Setting threshold for thermal zone '%s', id=%d\n", tz->name, tz->id); + + if (thermal_cmd_threshold_flush(th, tz)) { + ERROR("Failed to flush all previous thresholds\n"); + return -1; + } + + for (i = 0; i < sizeof(thresholds) / sizeof(thresholds[0]); i++) + if (thermal_cmd_threshold_add(th, tz, thresholds[i], + THERMAL_THRESHOLD_WAY_UP | + THERMAL_THRESHOLD_WAY_DOWN)) { + ERROR("Failed to set threshold\n"); + return -1; + } + + return 0; +} + static int tz_create(const char *name, int tz_id, __maybe_unused void *arg) { INFO("Thermal zone '%s'/%d created\n", name, tz_id); @@ -197,20 +231,62 @@ static int gov_change(int tz_id, const char *name, __maybe_unused void *arg) return 0; } +static int threshold_add(int tz_id, int temp, int direction, __maybe_unused void *arg) +{ + INFO("Threshold added tz_id=%d: temp=%d, direction=%d\n", tz_id, temp, direction); + + return 0; +} + +static int threshold_delete(int tz_id, int temp, int direction, __maybe_unused void *arg) +{ + INFO("Threshold deleted tz_id=%d: temp=%d, direction=%d\n", tz_id, temp, direction); + + return 0; +} + +static int threshold_flush(int tz_id, __maybe_unused void *arg) +{ + INFO("Thresholds flushed tz_id=%d\n", tz_id); + + return 0; +} + +static int threshold_up(int tz_id, int temp, int prev_temp, __maybe_unused void *arg) +{ + INFO("Threshold crossed way up tz_id=%d: temp=%d, prev_temp=%d\n", + tz_id, temp, prev_temp); + + return 0; +} + +static int threshold_down(int tz_id, int temp, int prev_temp, __maybe_unused void *arg) +{ + INFO("Threshold crossed way down tz_id=%d: temp=%d, prev_temp=%d\n", + tz_id, temp, prev_temp); + + return 0; +} + static struct thermal_ops ops = { - .events.tz_create = tz_create, - .events.tz_delete = tz_delete, - .events.tz_disable = tz_disable, - .events.tz_enable = tz_enable, - .events.trip_high = trip_high, - .events.trip_low = trip_low, - .events.trip_add = trip_add, - .events.trip_delete = trip_delete, - .events.trip_change = trip_change, - .events.cdev_add = cdev_add, - .events.cdev_delete = cdev_delete, - .events.cdev_update = cdev_update, - .events.gov_change = gov_change + .events.tz_create = tz_create, + .events.tz_delete = tz_delete, + .events.tz_disable = tz_disable, + .events.tz_enable = tz_enable, + .events.trip_high = trip_high, + .events.trip_low = trip_low, + .events.trip_add = trip_add, + .events.trip_delete = trip_delete, + .events.trip_change = trip_change, + .events.cdev_add = cdev_add, + .events.cdev_delete = cdev_delete, + .events.cdev_update = cdev_update, + .events.gov_change = gov_change, + .events.threshold_add = threshold_add, + .events.threshold_delete = threshold_delete, + .events.threshold_flush = threshold_flush, + .events.threshold_up = threshold_up, + .events.threshold_down = threshold_down, }; static int thermal_event(__maybe_unused int fd, __maybe_unused void *arg) @@ -280,6 +356,7 @@ enum { THERMAL_ENGINE_DAEMON_ERROR, THERMAL_ENGINE_LOG_ERROR, THERMAL_ENGINE_THERMAL_ERROR, + THERMAL_ENGINE_THRESHOLD_ERROR, THERMAL_ENGINE_MAINLOOP_ERROR, }; @@ -318,6 +395,8 @@ int main(int argc, char *argv[]) return THERMAL_ENGINE_THERMAL_ERROR; } + for_each_thermal_zone(td.tz, set_threshold, td.th); + for_each_thermal_zone(td.tz, show_tz, td.th); if (mainloop_init()) {