power: fix error handling on setting governor
authorDavid Hunt <david.hunt@intel.com>
Tue, 8 Jan 2019 14:59:26 +0000 (14:59 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 15 Jan 2019 01:40:40 +0000 (02:40 +0100)
In the power_set_governor_*() functions, we using fputs() on /sys
filesystem. However, we also need to call fflush() to ensure that
the write completes successfully. Otherwise the attempt to set the
power governor fails and the function returns as if it has
succeeded. This patch adds an fflush to ensure that the
write succeeds, otherwise returns an error.

Fixes: e6c6dc0f96c8 ("power: add p-state driver compatibility")

Signed-off-by: David Hunt <david.hunt@intel.com>
lib/librte_power/power_acpi_cpufreq.c
lib/librte_power/power_pstate_cpufreq.c

index cd5978d..f50897b 100644 (file)
@@ -166,6 +166,10 @@ power_set_governor_userspace(struct rte_power_info *pi)
        val = fputs(POWER_GOVERNOR_USERSPACE, f);
        FOPS_OR_ERR_GOTO(val, out);
 
+       /* We need to flush to see if the fputs succeeds */
+       val = fflush(f);
+       FOPS_OR_ERR_GOTO(val, out);
+
        ret = 0;
        RTE_LOG(INFO, POWER, "Power management governor of lcore %u has been "
                        "set to user space successfully\n", pi->lcore_id);
index 411d0eb..0f8e8f9 100644 (file)
@@ -308,6 +308,10 @@ power_set_governor_performance(struct pstate_power_info *pi)
        val = fputs(POWER_GOVERNOR_PERF, f);
        FOPS_OR_ERR_GOTO(val, out);
 
+       /* We need to flush to see if the fputs succeeds */
+       val = fflush(f);
+       FOPS_OR_ERR_GOTO(val, out);
+
        ret = 0;
        RTE_LOG(INFO, POWER, "Power management governor of lcore %u has been "
                        "set to performance successfully\n", pi->lcore_id);