Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1906691rwd; Thu, 18 May 2023 20:28:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5mzuXPGvYKkfWhIfQFSSxCf9Ye7tPifPy3aOj/j0uEhb9gzS3Dw83pG+2G3nnR4+6J2Hnu X-Received: by 2002:a05:6a20:6a04:b0:f6:2287:e05d with SMTP id p4-20020a056a206a0400b000f62287e05dmr788182pzk.10.1684466924827; Thu, 18 May 2023 20:28:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684466924; cv=none; d=google.com; s=arc-20160816; b=OWkxo/RY5cJMpTc+ua8WKytsbQfISeYgcdQ6zxcWIIgBcr/o/fWIxhHzaoPyx6wvVw wdQf72GXjwNNNfyPl5GpI1CxvUBF8QGLqHT/tLc1q3G+qMZEUjDA2Q2Jysvrbn0uuGFy FsY2K89ZHW9aJwSrTXSahRfOjduYAOq/jeNkeJC2qPJRcvb+SmV+jLlhPjg+5Xv24H5f ZFI09QEbS2uNFWyky6qBNLUxy3c7E8J0cmgJhGnVEfBQSxb/xJA9j71HED/qHaJYmsXJ IQZat2gvilF/DeyDj0F05CCjR0FeDciBPa7kMkhFPD8P0ZH1Md0jd3iZWdd2gvJiDF46 6DVg== 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 :dkim-signature; bh=IFA05wBuxUKaos8woOpBHKEXowwG8jBGHf9o9WETsTE=; b=x3OVmEhEzQCuvlkuaPcbpyZHioG7ld5//I10AsAOSN1NuaBDpskRq68uF3rmFBov3A vfzrO2lo2twTKWxeJfd7O5TG2TkB0D77gNVP+WTDKYYKejB5atRQkFUOk1CsFn+M/xss iVjzqIi7Rdep7qEFE8U6XaxZiD/QbYQoyji4qsu2YGkVu2UQ3T/azfmcrsk/GkfyMFQe I+xEfIHY+g8sc//5O19/90hObMUbelidJ4ep6U3HURNFrQhWk6QBbihMMD6uJqJH78Mk OwtXERsw+/nxOpunWbATAtohFfgT7NWMK+qvxep7wGX5GAqzGcEiG0subFYRs2+Q6eGU 5J1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=P+bo5OpE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m185-20020a633fc2000000b005348a615896si614397pga.113.2023.05.18.20.28.32; Thu, 18 May 2023 20:28:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=P+bo5OpE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230109AbjESD14 (ORCPT + 99 others); Thu, 18 May 2023 23:27:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbjESD1n (ORCPT ); Thu, 18 May 2023 23:27:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB5AA10D9; Thu, 18 May 2023 20:27:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 51612653C7; Fri, 19 May 2023 03:27:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 579A2C433EF; Fri, 19 May 2023 03:27:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684466860; bh=JeGq5bHAyBk0/sBP8+VGNu9E8xx/n54+KnUQPBhLFEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P+bo5OpEFRDeSS0JtAu63TcLpa6qhTAqyq7Nd8cSo7t1oJr4CPouWeyA7eTaZ2i6l Pjc1+YrrtVIdriGBdn/tHMuMyREsgb+41bmSf/GjtsBd9Y8ajXkcdYG9pWltDY0xgx GsmTGqaEfv9G62QWVzBf8lbmaXwk++BC+kLFAn8XbxE4XpcHt5f/XwMw/QQFbUOUhk hy8xwk5dTZPhfZMKbPLNPhgUTB8fgN7u4a1KSLNIPJswS51gO9JKvlqIimA9q+pG1O kX2YAc6JEZumTGRjcXWUdD704b5iDiHXNlDJLWi6VE2ito+4Azx0wgKE9Ge9XLDa6Y 33XZiy87H8KSA== From: Eduardo Valentin To: eduval@amazon.com, linux-pm@vger.kernel.org Cc: "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/7] thermal: stats: track number of change requests due to tz Date: Thu, 18 May 2023 20:27:14 -0700 Message-Id: <20230519032719.2581689-3-evalenti@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230519032719.2581689-1-evalenti@kernel.org> References: <20230519032719.2581689-1-evalenti@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eduardo Valentin This patch improves the current cooling device statistics by adding a new file under cdev/stats/requests_of_thermal_zone to represent the number of times each thermal zone requested the cooling device to effectively change. If the request associated was not serviced because another thermal zone asked for a higher cooling level, this counter does not increase. The file format is: thermal_zone: Samples: $ cat cdev0/stats/requests_of_thermal_zone thermal_zone: amb0 2 In this example, it means the thermal zone 'amb0' has requested 2 times for cdev0 to change state. Cc: "Rafael J. Wysocki" (supporter:THERMAL) Cc: Daniel Lezcano (supporter:THERMAL) Cc: Amit Kucheria (reviewer:THERMAL) Cc: Zhang Rui (reviewer:THERMAL) Cc: Jonathan Corbet (maintainer:DOCUMENTATION) Cc: linux-pm@vger.kernel.org (open list:THERMAL) Cc: linux-doc@vger.kernel.org (open list:DOCUMENTATION) Cc: linux-kernel@vger.kernel.org (open list) Signed-off-by: Eduardo Valentin --- .../driver-api/thermal/sysfs-api.rst | 2 + drivers/thermal/thermal_core.h | 1 + drivers/thermal/thermal_sysfs.c | 52 +++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/Documentation/driver-api/thermal/sysfs-api.rst b/Documentation/driver-api/thermal/sysfs-api.rst index caa50d61a5bc..75309a51d9b3 100644 --- a/Documentation/driver-api/thermal/sysfs-api.rst +++ b/Documentation/driver-api/thermal/sysfs-api.rst @@ -369,6 +369,8 @@ Thermal cooling device sys I/F, created once it's registered:: |---stats/trans_table: Cooling state transition table |---stats/time_in_thermal_zone_ms: Time that this cooling device was driven each associated thermal zone. + |---stats/requests_of_thermal_zone: Total number of times this cooling device + changed due to each associated thermal zone. Then next two dynamic attributes are created/removed in pairs. They represent diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index 3cce60c6e065..ed6511c3b794 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -103,6 +103,7 @@ struct thermal_instance { unsigned int weight; /* The weight of the cooling device */ bool upper_no_limit; #if IS_ENABLED(CONFIG_THERMAL_STATISTICS) + unsigned long total_requests; ktime_t time_in; /* time spent in this instance */ #endif }; diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index a3b71f03db75..0bce1415f7e8 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -723,6 +723,7 @@ void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, stats->trans_table[stats->state * (cdev->max_state + 1) + new_state]++; stats->state = new_state; stats->total_trans++; + stats->curr_instance->total_requests++; unlock: spin_unlock(&stats->lock); @@ -867,6 +868,54 @@ time_in_thermal_zone_ms_show(struct device *dev, struct device_attribute *attr, return ret < 0 ? ret : len; } +static ssize_t +requests_of_thermal_zone_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + LIST_HEAD(cdev_thermal_zone_list); + struct thermal_cooling_device *cdev = to_cooling_device(dev); + struct cooling_dev_stats *stats = cdev->stats; + struct cdev_thermal_zone_residency *res, *next; + struct thermal_instance *instance; + ssize_t len = 0, ret = 0; + + mutex_lock(&cdev->lock); + + spin_lock(&stats->lock); + update_time_in_state(stats, stats->curr_instance); + spin_unlock(&stats->lock); + + build_cdev_thermal_zone_residency(&cdev_thermal_zone_list, cdev); + + list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) + list_for_each_entry(res, &cdev_thermal_zone_list, node) + if (strncmp(res->thermal_zone, instance->tz->type, + THERMAL_NAME_LENGTH) == 0) + res->counter += instance->total_requests; + + mutex_unlock(&cdev->lock); + + list_for_each_entry_safe(res, next, &cdev_thermal_zone_list, node) { + ret = sprintf(buf + len, "thermal_zone: %s\t%lu\n", + res->thermal_zone, res->counter); + + if (ret == 0) + ret = -EOVERFLOW; + + if (ret < 0) + break; + + len += ret; + } + + list_for_each_entry_safe(res, next, &cdev_thermal_zone_list, node) { + list_del(&res->node); + kfree(res); + } + + return ret < 0 ? ret : len; +} + static ssize_t reset_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -897,6 +946,7 @@ reset_store(struct device *dev, struct device_attribute *attr, const char *buf, /* Make sure we reset all counters per instance */ list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) { + instance->total_requests = 0; instance->time_in = ktime_set(0, 0); } @@ -971,6 +1021,7 @@ static ssize_t trans_table_show(struct device *dev, static DEVICE_ATTR_RO(total_trans); static DEVICE_ATTR_RO(time_in_state_ms); static DEVICE_ATTR_RO(time_in_thermal_zone_ms); +static DEVICE_ATTR_RO(requests_of_thermal_zone); static DEVICE_ATTR_WO(reset); static DEVICE_ATTR_RO(trans_table); @@ -978,6 +1029,7 @@ static struct attribute *cooling_device_stats_attrs[] = { &dev_attr_total_trans.attr, &dev_attr_time_in_state_ms.attr, &dev_attr_time_in_thermal_zone_ms.attr, + &dev_attr_requests_of_thermal_zone.attr, &dev_attr_reset.attr, &dev_attr_trans_table.attr, NULL -- 2.34.1