DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/2] power: switching to unbuffered stdio for /sys file access
@ 2017-10-16 13:47 Radoslaw Biernacki
  2017-10-16 13:47 ` [dpdk-dev] [PATCH 2/2] power: check if userspace governor is available Radoslaw Biernacki
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Radoslaw Biernacki @ 2017-10-16 13:47 UTC (permalink / raw)
  To: dev, david.hunt; +Cc: stable, alan.carew, pablo.de.lara.guarch

This patch fixes the bug caused by improper use of buffered
stdio file access for switching the CPU frequency and
governor. Each write operation when using buffered stdio
must be flushed out and the return code from fflush() must
be verified. In buffered mode, write() syscall return value
is is not returned by fwrite()/fputs()/fprintf().
Since with buffered approatch, fflush() need to be done
every time it is better to use unbuffered mode or not use
stdio at all (instead use plain open/write functions). To
minimize amount of changes this fix use first approach.

Signed-off-by: Radoslaw Biernacki <radoslaw.biernacki@linaro.org>
---
 lib/librte_power/rte_power_acpi_cpufreq.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/lib/librte_power/rte_power_acpi_cpufreq.c b/lib/librte_power/rte_power_acpi_cpufreq.c
index 01ac5ac..8bf5685 100644
--- a/lib/librte_power/rte_power_acpi_cpufreq.c
+++ b/lib/librte_power/rte_power_acpi_cpufreq.c
@@ -143,12 +143,13 @@ set_freq_internal(struct rte_power_info *pi, uint32_t idx)
 				"for setting frequency for lcore %u\n", pi->lcore_id);
 		return -1;
 	}
+	/* we use unbuffered mode so following will fail if kernel will refuse
+	 * freq setting */
 	if (fprintf(pi->f, "%u", pi->freqs[idx]) < 0) {
 		RTE_LOG(ERR, POWER, "Fail to write new frequency for "
 				"lcore %u\n", pi->lcore_id);
 		return -1;
 	}
-	fflush(pi->f);
 	pi->curr_idx = idx;
 
 	return 1;
@@ -174,6 +175,11 @@ power_set_governor_userspace(struct rte_power_info *pi)
 	f = fopen(fullpath, "rw+");
 	FOPEN_OR_ERR_RET(f, ret);
 
+	if (setvbuf(f, NULL, _IONBF, 0)) {
+		RTE_LOG(ERR, POWER, "Cannot set unbuffered mode\n");
+		goto out;
+	}
+
 	s = fgets(buf, sizeof(buf), f);
 	FOPS_OR_NULL_GOTO(s, out);
 
@@ -292,6 +298,11 @@ power_init_for_setting_freq(struct rte_power_info *pi)
 	f = fopen(fullpath, "rw+");
 	FOPEN_OR_ERR_RET(f, -1);
 
+	if (setvbuf(f, NULL, _IONBF, 0)) {
+		RTE_LOG(ERR, POWER, "Cannot set unbuffered mode\n");
+		goto out;
+	}
+
 	s = fgets(buf, sizeof(buf), f);
 	FOPS_OR_NULL_GOTO(s, out);
 
@@ -389,6 +400,11 @@ power_set_governor_original(struct rte_power_info *pi)
 	f = fopen(fullpath, "rw+");
 	FOPEN_OR_ERR_RET(f, ret);
 
+	if (setvbuf(f, NULL, _IONBF, 0)) {
+		RTE_LOG(ERR, POWER, "Cannot set unbuffered mode\n");
+		goto out;
+	}
+
 	s = fgets(buf, sizeof(buf), f);
 	FOPS_OR_NULL_GOTO(s, out);
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2018-01-31 23:39 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-16 13:47 [dpdk-dev] [PATCH 1/2] power: switching to unbuffered stdio for /sys file access Radoslaw Biernacki
2017-10-16 13:47 ` [dpdk-dev] [PATCH 2/2] power: check if userspace governor is available Radoslaw Biernacki
2017-10-18 10:53   ` Hunt, David
2017-10-18 14:02     ` Radoslaw Biernacki
2017-10-18 10:28 ` [dpdk-dev] [PATCH 1/2] power: switching to unbuffered stdio for /sys file access Hunt, David
2017-10-18 10:33 ` Hunt, David
2017-10-18 13:56   ` Radoslaw Biernacki
2017-11-11 18:55 ` [dpdk-dev] [PATCH 0/3] power: fixes for power ACPI through sysfs Radoslaw Biernacki
2017-11-11 18:55   ` [dpdk-dev] [PATCH 1/3] power: removing code macros Radoslaw Biernacki
2017-11-11 18:55   ` [dpdk-dev] [PATCH 2/3] power: switching to unbuffered access for /sys files Radoslaw Biernacki
2017-11-23 14:42     ` Hunt, David
2017-12-01 21:01       ` Radoslaw Biernacki
2018-01-31 23:38         ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
2017-11-11 18:55   ` [dpdk-dev] [PATCH 3/3] power: check if userspace governor is available Radoslaw Biernacki
2017-11-21 11:09   ` [dpdk-dev] [PATCH 0/3] power: fixes for power ACPI through sysfs Radoslaw Biernacki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).