From: Naveen Krishna Chatradhi <nchatrad@amd.com>
To: linux-hwmon@vger.kernel.org
Cc: naveenkrishna.ch@gmail.com, Naveen Krishna Chatradhi <nchatrad@amd.com>
Subject: [PATCH v2 2/4] hwmon: amd_energy: optimize accumulation interval
Date: Tue, 29 Sep 2020 16:23:20 +0530 [thread overview]
Message-ID: <20200929105322.8919-3-nchatrad@amd.com> (raw)
In-Reply-To: <20200929105322.8919-1-nchatrad@amd.com>
On a system with course grain resolution of energy unit (milli J) the
accumulation thread can be executed less frequently than on the system
with fine grain resolution(micro J).
This patch sets the accumulation thread interval to an optimum value
calculated based on the (energy unit) resolution supported by the
hardware (assuming a peak wattage of 240W).
Signed-off-by: Naveen Krishna Chatradhi <nchatrad@amd.com>
---
Changes since v1:
1. Generalized formula as suggested by Guenter.
2. Use milli seconds for interval
drivers/hwmon/amd_energy.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/drivers/hwmon/amd_energy.c b/drivers/hwmon/amd_energy.c
index 9580a16185b8..c413adfc6a73 100644
--- a/drivers/hwmon/amd_energy.c
+++ b/drivers/hwmon/amd_energy.c
@@ -46,8 +46,9 @@ struct amd_energy_data {
struct mutex lock;
/* An accumulator for each core and socket */
struct sensor_accumulator *accums;
+ unsigned int timeout_ms;
/* Energy Status Units */
- u64 energy_units;
+ int energy_units;
int nr_cpus;
int nr_socks;
int core_id;
@@ -215,6 +216,7 @@ static umode_t amd_energy_is_visible(const void *_data,
static int energy_accumulator(void *p)
{
struct amd_energy_data *data = (struct amd_energy_data *)p;
+ unsigned int timeout = data->timeout_ms;
while (!kthread_should_stop()) {
/*
@@ -227,14 +229,7 @@ static int energy_accumulator(void *p)
if (kthread_should_stop())
break;
- /*
- * On a 240W system, with default resolution the
- * Socket Energy status register may wrap around in
- * 2^32*15.3 e-6/240 = 273.8041 secs (~4.5 mins)
- *
- * let us accumulate for every 100secs
- */
- schedule_timeout(msecs_to_jiffies(100000));
+ schedule_timeout(msecs_to_jiffies(timeout));
}
return 0;
}
@@ -331,6 +326,13 @@ static int amd_energy_probe(struct platform_device *pdev)
if (IS_ERR(hwmon_dev))
return PTR_ERR(hwmon_dev);
+ /*
+ * On a system with peak wattage of 250W
+ * timeout = 2 ^ 32 / 2 ^ energy_units / 250 secs
+ */
+ data->timeout_ms = 1000 *
+ BIT(min(28, 31 - data->energy_units)) / 250;
+
data->wrap_accumulate = kthread_run(energy_accumulator, data,
"%s", dev_name(hwmon_dev));
if (IS_ERR(data->wrap_accumulate))
--
2.17.1
next prev parent reply other threads:[~2020-09-29 10:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-29 10:53 [PATCH v2 0/4] hwmon: improvements to amd_energy driver Naveen Krishna Chatradhi
2020-09-29 10:53 ` [PATCH v2 1/4] hwmon: amd_energy: Move label out of accumulation structure Naveen Krishna Chatradhi
2020-09-30 5:03 ` Guenter Roeck
2020-09-29 10:53 ` Naveen Krishna Chatradhi [this message]
2020-09-29 10:53 ` [PATCH v2 3/4] hwmon: amd_energy: Improve the accumulation logic Naveen Krishna Chatradhi
2020-09-29 10:53 ` [PATCH v2 4/4] hwmon: (amd_energy) Update driver documentation Naveen Krishna Chatradhi
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=20200929105322.8919-3-nchatrad@amd.com \
--to=nchatrad@amd.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=naveenkrishna.ch@gmail.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