DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	stable@dpdk.org, Anatoly Burakov <anatoly.burakov@intel.com>,
	Sivaprasad Tummala <sivaprasad.tummala@amd.com>,
	Pablo de Lara <pablo.de.lara.guarch@intel.com>,
	Alan Carew <alan.carew@intel.com>,
	Richael Zhuang <richael.zhuang@arm.com>,
	David Hunt <david.hunt@intel.com>
Subject: [PATCH v2 2/3] power: check for errors when writing frequency
Date: Tue,  8 Sep 2026 09:52:33 -0700	[thread overview]
Message-ID: <20260908165447.450006-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20260908165447.450006-1-stephen@networkplumber.org>

The sysfs file is buffered, so fprintf() returns success even when the
kernel rejects the value. The error only shows up when the buffer is
flushed, and the fflush() return was never checked. A failed frequency
change was therefore reported as success.

Use write_core_sysfs_s() which already does the fseek, write and a
checked fflush.

Fixes: 445c6528b55f ("power: common interface for guest and host")
Fixes: ef1cc88f1837 ("power: support cppc_cpufreq driver")
Fixes: 1ed04d33cf19 ("power: support amd-pstate cpufreq driver")
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/power/acpi/acpi_cpufreq.c             | 12 +++++-------
 drivers/power/amd_pstate/amd_pstate_cpufreq.c | 16 +++++++---------
 drivers/power/cppc/cppc_cpufreq.c             | 12 +++++-------
 3 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/drivers/power/acpi/acpi_cpufreq.c b/drivers/power/acpi/acpi_cpufreq.c
index af85a8cdec..4ee3d5bd26 100644
--- a/drivers/power/acpi/acpi_cpufreq.c
+++ b/drivers/power/acpi/acpi_cpufreq.c
@@ -54,6 +54,8 @@ static struct acpi_power_info lcore_power_info[RTE_MAX_LCORE];
 static int
 set_freq_internal(struct acpi_power_info *pi, uint32_t idx)
 {
+	char buf[16];
+
 	if (idx >= RTE_MAX_LCORE_FREQS || idx >= pi->nb_freqs) {
 		POWER_LOG(ERR, "Invalid frequency index %u, which "
 				"should be less than %u", idx, pi->nb_freqs);
@@ -66,17 +68,13 @@ set_freq_internal(struct acpi_power_info *pi, uint32_t idx)
 
 	POWER_DEBUG_LOG("Frequency[%u] %u to be set for lcore %u",
 			idx, pi->freqs[idx], pi->lcore_id);
-	if (fseek(pi->f, 0, SEEK_SET) < 0) {
-		POWER_LOG(ERR, "Fail to set file position indicator to 0 "
-				"for setting frequency for lcore %u", pi->lcore_id);
-		return -1;
-	}
-	if (fprintf(pi->f, "%u", pi->freqs[idx]) < 0) {
+
+	snprintf(buf, sizeof(buf), "%u", pi->freqs[idx]);
+	if (write_core_sysfs_s(pi->f, buf) != 0) {
 		POWER_LOG(ERR, "Fail to write new frequency for "
 				"lcore %u", pi->lcore_id);
 		return -1;
 	}
-	fflush(pi->f);
 	pi->curr_idx = idx;
 
 	return 1;
diff --git a/drivers/power/amd_pstate/amd_pstate_cpufreq.c b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
index 13ffcefc84..f7e32fe0ac 100644
--- a/drivers/power/amd_pstate/amd_pstate_cpufreq.c
+++ b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
@@ -57,17 +57,15 @@ static struct amd_pstate_power_info lcore_power_info[RTE_MAX_LCORE];
 static int
 write_freq(struct amd_pstate_power_info *pi, uint32_t idx)
 {
-	if (fseek(pi->f, 0, SEEK_SET) < 0) {
-		POWER_LOG(ERR, "Fail to set file position indicator to 0 "
-			"for setting frequency for lcore %u", pi->lcore_id);
-		return -1;
-	}
-	if (fprintf(pi->f, "%u", pi->freqs[idx]) < 0) {
-		POWER_LOG(ERR, "Fail to write new frequency for "
-				"lcore %u", pi->lcore_id);
+	char buf[16];
+
+	snprintf(buf, sizeof(buf), "%u", pi->freqs[idx]);
+
+	if (write_core_sysfs_s(pi->f, buf) != 0) {
+		POWER_LOG(ERR, "Fail to write new frequency for lcore %u",
+			  pi->lcore_id);
 		return -1;
 	}
-	fflush(pi->f);
 	pi->curr_idx = idx;
 
 	return 1;
diff --git a/drivers/power/cppc/cppc_cpufreq.c b/drivers/power/cppc/cppc_cpufreq.c
index aed44c1212..3bcd4dec41 100644
--- a/drivers/power/cppc/cppc_cpufreq.c
+++ b/drivers/power/cppc/cppc_cpufreq.c
@@ -63,6 +63,8 @@ static struct cppc_power_info lcore_power_info[RTE_MAX_LCORE];
 static int
 set_freq_internal(struct cppc_power_info *pi, uint32_t idx)
 {
+	char buf[16];
+
 	if (idx >= RTE_MAX_LCORE_FREQS || idx >= pi->nb_freqs) {
 		POWER_LOG(ERR, "Invalid frequency index %u, which "
 				"should be less than %u", idx, pi->nb_freqs);
@@ -75,17 +77,13 @@ set_freq_internal(struct cppc_power_info *pi, uint32_t idx)
 
 	POWER_DEBUG_LOG("Frequency[%u] %u to be set for lcore %u",
 			idx, pi->freqs[idx], pi->lcore_id);
-	if (fseek(pi->f, 0, SEEK_SET) < 0) {
-		POWER_LOG(ERR, "Fail to set file position indicator to 0 "
-			"for setting frequency for lcore %u", pi->lcore_id);
-		return -1;
-	}
-	if (fprintf(pi->f, "%u", pi->freqs[idx]) < 0) {
+
+	snprintf(buf, sizeof(buf), "%u", pi->freqs[idx]);
+	if (write_core_sysfs_s(pi->f, buf) != 0) {
 		POWER_LOG(ERR, "Fail to write new frequency for "
 				"lcore %u", pi->lcore_id);
 		return -1;
 	}
-	fflush(pi->f);
 	pi->curr_idx = idx;
 
 	return 1;
-- 
2.53.0


  parent reply	other threads:[~2026-09-08 16:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-28 19:34 [PATCH] power/amd_pstate: fix frequency matching for continuous scaling Stephen Hemminger
2026-04-03  4:09 ` Tummala, Sivaprasad
2026-06-10 22:25 ` Thomas Monjalon
2026-09-08 16:52 ` [PATCH v2 0/3] power: fixes for amd-pstate frequency scaling Stephen Hemminger
2026-09-08 16:52   ` [PATCH v2 1/3] power/amd_pstate: fix frequency matching for continuous scaling Stephen Hemminger
2026-09-08 16:52   ` Stephen Hemminger [this message]
2026-09-08 16:52   ` [PATCH v2 3/3] test/power: fix nominal frequency check with amd-pstate Stephen Hemminger

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=20260908165447.450006-3-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=alan.carew@intel.com \
    --cc=anatoly.burakov@intel.com \
    --cc=david.hunt@intel.com \
    --cc=dev@dpdk.org \
    --cc=pablo.de.lara.guarch@intel.com \
    --cc=richael.zhuang@arm.com \
    --cc=sivaprasad.tummala@amd.com \
    --cc=stable@dpdk.org \
    /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