DPDK patches and discussions
 help / color / mirror / Atom feed
From: Radoslaw Biernacki <radoslaw.biernacki@linaro.org>
To: dev@dpdk.org, david.hunt@intel.com
Cc: stable@dpdk.org, alan.carew@intel.com, pablo.de.lara.guarch@intel.com
Subject: [dpdk-dev] [PATCH 3/3] power: check if userspace governor is available
Date: Sat, 11 Nov 2017 19:55:07 +0100	[thread overview]
Message-ID: <1510426507-28245-4-git-send-email-radoslaw.biernacki@linaro.org> (raw)
In-Reply-To: <1510426507-28245-1-git-send-email-radoslaw.biernacki@linaro.org>

Since for new Intel CPU's kernel use intel_pstate driver, which does
not offer userspace governor, it is wise to check the userspace
governor availability before trying to perform governor switch. The
outcome from this patch is direct information for user about the root
cause of failure during the rte_power_acpi_cpufreq_init().

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

diff --git a/lib/librte_power/rte_power_acpi_cpufreq.c b/lib/librte_power/rte_power_acpi_cpufreq.c
index f811bd3..0d9a2a5 100644
--- a/lib/librte_power/rte_power_acpi_cpufreq.c
+++ b/lib/librte_power/rte_power_acpi_cpufreq.c
@@ -65,6 +65,11 @@
 #define POWER_CONVERT_TO_DECIMAL 10
 
 #define POWER_GOVERNOR_USERSPACE "userspace"
+#define POWER_SCALING_DRIVER_INTEL_PSTATE "intel_pstate"
+#define POWER_SYSFILE_SCALING_DRIVER \
+		"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_driver"
+#define POWER_SYSFILE_AVAIL_GOVERNOR \
+		"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_available_governors"
 #define POWER_SYSFILE_GOVERNOR   \
 		"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_governor"
 #define POWER_SYSFILE_AVAIL_FREQ \
@@ -139,6 +144,70 @@ set_freq_internal(struct rte_power_info *pi, uint32_t idx)
 	return 1;
 }
 
+/* check /sys file for presence of given string */
+static int
+power_check_sysfile_string(const char *fullpath, const char *string)
+{
+	int fd;
+	int count;
+	int ret = -1;
+	char buf[BUFSIZ];
+
+	fd = open(fullpath, O_RDONLY);
+	if (fd < 0) {
+		RTE_LOG(ERR, POWER, "Failed to open %s\n", fullpath);
+		return ret;
+	}
+
+	count = read(fd, buf, sizeof(buf));
+	if (count < 0) {
+		RTE_LOG(ERR, POWER, "Failed to read from %s\n", fullpath);
+		goto out;
+	}
+	buf[min((size_t)count, sizeof(buf)-1)] = '\0';
+
+	if (strstr(buf, string))
+		ret = 0; /* substring found */
+
+out:
+	if (close(fd)) {
+		RTE_LOG(ERR, POWER, "Error while closing file %s\n", fullpath);
+		return -1;
+	}
+
+	return ret;
+}
+
+/* check if userspace governor is offered by the kernel */
+static int power_check_gov_userspace(unsigned int lcore_id)
+{
+	char fullpath[PATH_MAX];
+
+	snprintf(fullpath, sizeof(fullpath),
+		 POWER_SYSFILE_AVAIL_GOVERNOR, lcore_id);
+	if (power_check_sysfile_string(
+		fullpath, POWER_GOVERNOR_USERSPACE)) {
+
+		RTE_LOG(ERR, POWER, "Userspace governor is not available\n");
+
+		snprintf(fullpath, sizeof(fullpath),
+			 POWER_SYSFILE_SCALING_DRIVER, lcore_id);
+		if (!power_check_sysfile_string(
+			fullpath, POWER_SCALING_DRIVER_INTEL_PSTATE)) {
+
+			RTE_LOG(WARNING, POWER,
+				POWER_SCALING_DRIVER_INTEL_PSTATE "was detected"
+				" which does not offer userspace power governor"
+				". \"intel_pstate=disable\" needs to be added "
+				"to the kernel boot parameters.\n");
+		}
+
+		return -1;
+	}
+
+	return 0;
+}
+
 /**
  * It is to check the current scaling governor by reading sys file, and then
  * set it into 'userspace' if it is not by writing the sys file. The original
@@ -154,6 +223,11 @@ power_set_governor(unsigned int lcore_id, const char *new_gov, char *old_gov,
 	char buf[BUFSIZ];
 	char fullpath[PATH_MAX];
 
+	/* check if userspace governor is available */
+	if (power_check_gov_userspace(lcore_id))
+		return ret;
+
+	/* store current governor and set userspace governor */
 	snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR,
 		 lcore_id);
 	fd = open(fullpath, O_RDWR);
-- 
2.7.4

  parent reply	other threads:[~2017-11-11 18:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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   ` Radoslaw Biernacki [this message]
2017-11-21 11:09   ` [dpdk-dev] [PATCH 0/3] power: fixes for power ACPI through sysfs Radoslaw Biernacki

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=1510426507-28245-4-git-send-email-radoslaw.biernacki@linaro.org \
    --to=radoslaw.biernacki@linaro.org \
    --cc=alan.carew@intel.com \
    --cc=david.hunt@intel.com \
    --cc=dev@dpdk.org \
    --cc=pablo.de.lara.guarch@intel.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;
as well as URLs for NNTP newsgroup(s).