Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Huisong Li <lihuisong@huawei.com>
To: <linux-hwmon@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <linux@roeck-us.net>, <jdelvare@suse.com>,
	<liuyonglong@huawei.com>, <zhanjie9@hisilicon.com>,
	<zhenglifeng1@huawei.com>, <lihuisong@huawei.com>
Subject: [PATCH v1 3/4] hwmon: (acpi_power_meter) Remove redundant 'sensors_valid' variable
Date: Mon, 25 Nov 2024 17:34:14 +0800	[thread overview]
Message-ID: <20241125093415.21719-4-lihuisong@huawei.com> (raw)
In-Reply-To: <20241125093415.21719-1-lihuisong@huawei.com>

The 'sensors_valid' in acpi_power_meter_resource structure is always one
after querying power once. The default value of this variable is zero which
just ensure user can query power successfully without any time requirement
at first time. We can get power and fill the 'sensors_last_updated' field
at probing phase to make sure that a valid value is returned to user at
first query within the sampling interval. Then this redundant variable can
be safely removed.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/hwmon/acpi_power_meter.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
index 95da73858a0b..3500859ff0bf 100644
--- a/drivers/hwmon/acpi_power_meter.c
+++ b/drivers/hwmon/acpi_power_meter.c
@@ -84,7 +84,6 @@ struct acpi_power_meter_resource {
 	u64		power;
 	u64		cap;
 	u64		avg_interval;
-	int			sensors_valid;
 	unsigned long		sensors_last_updated;
 	struct sensor_device_attribute	sensors[NUM_SENSORS];
 	int			num_sensors;
@@ -316,15 +315,14 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
 }
 
 /* Power meter */
-static int update_meter(struct acpi_power_meter_resource *resource)
+static int update_meter(struct acpi_power_meter_resource *resource, bool check)
 {
 	unsigned long long data;
 	acpi_status status;
 	unsigned long local_jiffies = jiffies;
 
-	if (time_before(local_jiffies, resource->sensors_last_updated +
-			msecs_to_jiffies(resource->caps.sampling_time)) &&
-			resource->sensors_valid)
+	if (check && time_before(local_jiffies, resource->sensors_last_updated +
+			msecs_to_jiffies(resource->caps.sampling_time)))
 		return 0;
 
 	status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PMM",
@@ -336,7 +334,6 @@ static int update_meter(struct acpi_power_meter_resource *resource)
 	}
 
 	resource->power = data;
-	resource->sensors_valid = 1;
 	resource->sensors_last_updated = jiffies;
 	return 0;
 }
@@ -349,7 +346,7 @@ static ssize_t show_power(struct device *dev,
 	struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
 
 	mutex_lock(&resource->lock);
-	update_meter(resource);
+	update_meter(resource, true);
 	mutex_unlock(&resource->lock);
 
 	if (resource->power == UNKNOWN_POWER)
@@ -429,7 +426,7 @@ static ssize_t show_val(struct device *dev,
 			val = 0;
 		break;
 	case 6:
-		ret = update_meter(resource);
+		ret = update_meter(resource, true);
 		if (ret)
 			return ret;
 		ret = update_cap(resource);
@@ -699,6 +696,10 @@ static int setup_attrs(struct acpi_power_meter_resource *resource)
 		return res;
 
 	if (resource->caps.flags & POWER_METER_CAN_MEASURE) {
+		res = update_meter(resource, false);
+		if (res)
+			goto error;
+
 		res = register_attrs(resource, meter_attrs);
 		if (res)
 			goto error;
@@ -890,7 +891,6 @@ static int acpi_power_meter_add(struct acpi_device *device)
 	if (!resource)
 		return -ENOMEM;
 
-	resource->sensors_valid = 0;
 	resource->acpi_dev = device;
 	mutex_init(&resource->lock);
 	strcpy(acpi_device_name(device), ACPI_POWER_METER_DEVICE_NAME);
-- 
2.22.0


  parent reply	other threads:[~2024-11-25  9:45 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-25  9:34 [PATCH v1 0/4] hwmon: (acpi_power_meter) Some trival optimizations Huisong Li
2024-11-25  9:34 ` [PATCH v1 1/4] hwmon: (acpi_power_meter) Fix using uninitialized variables Huisong Li
2024-11-25 16:03   ` Guenter Roeck
2024-11-26  1:56     ` lihuisong (C)
2024-11-26  4:04       ` Guenter Roeck
2024-11-26  7:03         ` lihuisong (C)
2024-11-26 16:19           ` Guenter Roeck
2024-11-27  2:29             ` lihuisong (C)
2024-11-27  3:43             ` lihuisong (C)
2024-12-11  7:41               ` lihuisong (C)
2024-12-12  1:51               ` Guenter Roeck
2024-12-12  3:00                 ` lihuisong (C)
2024-12-19  3:45                   ` lihuisong (C)
2024-12-19  3:50                     ` Guenter Roeck
2024-12-20  6:00                       ` lihuisong (C)
2024-11-25  9:34 ` [PATCH v1 2/4] hwmon: (acpi_power_meter) Fix update the power trip points on failure Huisong Li
2024-11-25 15:22   ` Guenter Roeck
2024-11-26  1:59     ` lihuisong (C)
2024-11-25  9:34 ` Huisong Li [this message]
2024-11-25 15:38   ` [PATCH v1 3/4] hwmon: (acpi_power_meter) Remove redundant 'sensors_valid' variable Guenter Roeck
2024-11-26  2:25     ` lihuisong (C)
2024-11-25  9:34 ` [PATCH v1 4/4] hwmon: (acpi_power_meter) Add the print of no notification that hardware limit is enforced Huisong Li
2024-11-25 16:13   ` Guenter Roeck
2024-11-26  3:15     ` lihuisong (C)
2024-11-26  4:06       ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241125093415.21719-4-lihuisong@huawei.com \
    --to=lihuisong@huawei.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=liuyonglong@huawei.com \
    --cc=zhanjie9@hisilicon.com \
    --cc=zhenglifeng1@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox