DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Hunt <david.hunt@intel.com>
To: dev@dpdk.org
Cc: david.hunt@intel.com
Subject: [dpdk-dev] [PATCH v1 4/6] examples/vm_power: allow greater than 64 cores
Date: Thu,  7 Jun 2018 08:37:03 +0100	[thread overview]
Message-ID: <20180607073705.32895-5-david.hunt@intel.com> (raw)
In-Reply-To: <20180607073705.32895-1-david.hunt@intel.com>

To facilitate more info per core, change the global_cpu_mask
from a uint64_t to an array. This also removes the limit on
64 cores, allocing the aray at run-time based on the number of
cores found in the system.

Signed-off-by: David Hunt <david.hunt@intel.com>
---
 examples/vm_power_manager/power_manager.c | 115 +++++++++++-----------
 1 file changed, 58 insertions(+), 57 deletions(-)

diff --git a/examples/vm_power_manager/power_manager.c b/examples/vm_power_manager/power_manager.c
index a7849e48a..4bdde23da 100644
--- a/examples/vm_power_manager/power_manager.c
+++ b/examples/vm_power_manager/power_manager.c
@@ -19,14 +19,14 @@
 #include <rte_power.h>
 #include <rte_spinlock.h>
 
+#include "channel_manager.h"
 #include "power_manager.h"
-
-#define RTE_LOGTYPE_POWER_MANAGER RTE_LOGTYPE_USER1
+#include "oob_monitor.h"
 
 #define POWER_SCALE_CORE(DIRECTION, core_num , ret) do { \
-	if (core_num >= POWER_MGR_MAX_CPUS) \
+	if (core_num >= ci.core_count) \
 		return -1; \
-	if (!(global_enabled_cpus & (1ULL << core_num))) \
+	if (!(ci.cd[core_num].global_enabled_cpus)) \
 		return -1; \
 	rte_spinlock_lock(&global_core_freq_info[core_num].power_sl); \
 	ret = rte_power_freq_##DIRECTION(core_num); \
@@ -37,7 +37,7 @@
 	int i; \
 	for (i = 0; core_mask; core_mask &= ~(1 << i++)) { \
 		if ((core_mask >> i) & 1) { \
-			if (!(global_enabled_cpus & (1ULL << i))) \
+			if (!(ci.cd[i].global_enabled_cpus)) \
 				continue; \
 			rte_spinlock_lock(&global_core_freq_info[i].power_sl); \
 			if (rte_power_freq_##DIRECTION(i) != 1) \
@@ -56,28 +56,9 @@ struct freq_info {
 static struct freq_info global_core_freq_info[POWER_MGR_MAX_CPUS];
 
 struct core_info ci;
-static uint64_t global_enabled_cpus;
 
 #define SYSFS_CPU_PATH "/sys/devices/system/cpu/cpu%u/topology/core_id"
 
-static unsigned
-set_host_cpus_mask(void)
-{
-	char path[PATH_MAX];
-	unsigned i;
-	unsigned num_cpus = 0;
-
-	for (i = 0; i < POWER_MGR_MAX_CPUS; i++) {
-		snprintf(path, sizeof(path), SYSFS_CPU_PATH, i);
-		if (access(path, F_OK) == 0) {
-			global_enabled_cpus |= 1ULL << i;
-			num_cpus++;
-		} else
-			return num_cpus;
-	}
-	return num_cpus;
-}
-
 struct core_info *
 get_core_info(void)
 {
@@ -110,38 +91,45 @@ core_info_init(void)
 int
 power_manager_init(void)
 {
-	unsigned int i, num_cpus, num_freqs;
-	uint64_t cpu_mask;
+	unsigned int i, num_cpus = 0, num_freqs = 0;
 	int ret = 0;
+	struct core_info *ci;
+
+	rte_power_set_env(PM_ENV_ACPI_CPUFREQ);
 
-	num_cpus = set_host_cpus_mask();
-	if (num_cpus == 0) {
-		RTE_LOG(ERR, POWER_MANAGER, "Unable to detected host CPUs, please "
-			"ensure that sufficient privileges exist to inspect sysfs\n");
+	ci = get_core_info();
+	if (!ci) {
+		RTE_LOG(ERR, POWER_MANAGER,
+				"Failed to get core info!\n");
 		return -1;
 	}
-	rte_power_set_env(PM_ENV_ACPI_CPUFREQ);
-	cpu_mask = global_enabled_cpus;
-	for (i = 0; cpu_mask; cpu_mask &= ~(1 << i++)) {
-		if (rte_power_init(i) < 0)
-			RTE_LOG(ERR, POWER_MANAGER,
-					"Unable to initialize power manager "
-					"for core %u\n", i);
-		num_freqs = rte_power_freqs(i, global_core_freq_info[i].freqs,
+
+	for (i = 0; i < ci->core_count; i++) {
+		if (ci->cd[i].global_enabled_cpus) {
+			if (rte_power_init(i) < 0)
+				RTE_LOG(ERR, POWER_MANAGER,
+						"Unable to initialize power manager "
+						"for core %u\n", i);
+			num_cpus++;
+			num_freqs = rte_power_freqs(i,
+					global_core_freq_info[i].freqs,
 					RTE_MAX_LCORE_FREQS);
-		if (num_freqs == 0) {
-			RTE_LOG(ERR, POWER_MANAGER,
-				"Unable to get frequency list for core %u\n",
-				i);
-			global_enabled_cpus &= ~(1 << i);
-			num_cpus--;
-			ret = -1;
+			if (num_freqs == 0) {
+				RTE_LOG(ERR, POWER_MANAGER,
+					"Unable to get frequency list for core %u\n",
+					i);
+				ci->cd[i].oob_enabled = 0;
+				ret = -1;
+			}
+			global_core_freq_info[i].num_freqs = num_freqs;
+
+			rte_spinlock_init(&global_core_freq_info[i].power_sl);
 		}
-		global_core_freq_info[i].num_freqs = num_freqs;
-		rte_spinlock_init(&global_core_freq_info[i].power_sl);
+		if (ci->cd[i].oob_enabled)
+			add_core_to_monitor(i);
 	}
-	RTE_LOG(INFO, POWER_MANAGER, "Detected %u host CPUs , enabled core mask:"
-					" 0x%"PRIx64"\n", num_cpus, global_enabled_cpus);
+	RTE_LOG(INFO, POWER_MANAGER, "Managing %u cores out of %u available host cores\n",
+			num_cpus, ci->core_count);
 	return ret;
 
 }
@@ -156,7 +144,7 @@ power_manager_get_current_frequency(unsigned core_num)
 				core_num, POWER_MGR_MAX_CPUS-1);
 		return -1;
 	}
-	if (!(global_enabled_cpus & (1ULL << core_num)))
+	if (!(ci.cd[core_num].global_enabled_cpus))
 		return 0;
 
 	rte_spinlock_lock(&global_core_freq_info[core_num].power_sl);
@@ -175,15 +163,26 @@ power_manager_exit(void)
 {
 	unsigned int i;
 	int ret = 0;
+	struct core_info *ci;
 
-	for (i = 0; global_enabled_cpus; global_enabled_cpus &= ~(1 << i++)) {
-		if (rte_power_exit(i) < 0) {
-			RTE_LOG(ERR, POWER_MANAGER, "Unable to shutdown power manager "
-					"for core %u\n", i);
-			ret = -1;
+	ci = get_core_info();
+	if (!ci) {
+		RTE_LOG(ERR, POWER_MANAGER,
+				"Failed to get core info!\n");
+		return -1;
+	}
+
+	for (i = 0; i < ci->core_count; i++) {
+		if (ci->cd[i].global_enabled_cpus) {
+			if (rte_power_exit(i) < 0) {
+				RTE_LOG(ERR, POWER_MANAGER, "Unable to shutdown power manager "
+						"for core %u\n", i);
+				ret = -1;
+			}
+			ci->cd[i].global_enabled_cpus = 0;
 		}
+		remove_core_from_monitor(i);
 	}
-	global_enabled_cpus = 0;
 	return ret;
 }
 
@@ -299,10 +298,12 @@ int
 power_manager_scale_core_med(unsigned int core_num)
 {
 	int ret = 0;
+	struct core_info *ci;
 
+	ci = get_core_info();
 	if (core_num >= POWER_MGR_MAX_CPUS)
 		return -1;
-	if (!(global_enabled_cpus & (1ULL << core_num)))
+	if (!(ci->cd[core_num].global_enabled_cpus))
 		return -1;
 	rte_spinlock_lock(&global_core_freq_info[core_num].power_sl);
 	ret = rte_power_set_freq(core_num,
-- 
2.17.0

  parent reply	other threads:[~2018-06-07 14:39 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-07  7:36 [dpdk-dev] [PATCH v1 0/6] examples/vm_power: 100% Busy Polling David Hunt
2018-06-07  7:37 ` [dpdk-dev] [PATCH v1 1/6] examples/vm_power: add check for port count David Hunt
2018-06-21 13:24   ` [dpdk-dev] [PATCH v2 0/8] examples/vm_power: 100% Busy Polling David Hunt
2018-06-21 13:24     ` [dpdk-dev] [PATCH v2 1/8] examples/vm_power: add check for port count David Hunt
2018-06-26  9:23       ` [dpdk-dev] [0/9] examples/vm_power: 100% Busy Polling David Hunt
2018-06-26  9:23         ` [dpdk-dev] [PATCH v3 1/9] examples/vm_power: add check for port count David Hunt
2018-07-13 14:22           ` [dpdk-dev] [PATCH v4 0/9] examples/vm_power: 100% Busy Polling David Hunt
2018-07-13 14:22             ` [dpdk-dev] [PATCH v4 1/9] examples/vm_power: add check for port count David Hunt
2018-07-13 14:22             ` [dpdk-dev] [PATCH v4 2/9] examples/vm_power: add core list parameter David Hunt
2018-07-13 14:22             ` [dpdk-dev] [PATCH v4 3/9] examples/vm_power: add oob monitoring functions David Hunt
2018-07-13 14:22             ` [dpdk-dev] [PATCH v4 4/9] examples/vm_power: allow greater than 64 cores David Hunt
2018-07-13 14:22             ` [dpdk-dev] [PATCH v4 5/9] examples/vm_power: add thread for oob core monitor David Hunt
2018-07-13 14:22             ` [dpdk-dev] [PATCH v4 6/9] examples/vm_power: add port-list to command line David Hunt
2018-07-13 14:23             ` [dpdk-dev] [PATCH v4 7/9] examples/vm_power: add branch ratio policy type David Hunt
2018-07-13 14:23             ` [dpdk-dev] [PATCH v4 8/9] examples/vm_power: add cli args to guest app David Hunt
2018-07-13 14:23             ` [dpdk-dev] [PATCH v4 9/9] examples/vm_power: make branch ratio configurable David Hunt
2018-07-20 22:06             ` [dpdk-dev] [PATCH v4 0/9] examples/vm_power: 100% Busy Polling Thomas Monjalon
2018-06-26  9:23         ` [dpdk-dev] [PATCH v3 2/9] examples/vm_power: add core list parameter David Hunt
2018-06-26  9:23         ` [dpdk-dev] [PATCH v3 3/9] examples/vm_power: add oob monitoring functions David Hunt
2018-07-12 19:13           ` Thomas Monjalon
2018-07-12 22:18             ` Stephen Hemminger
2018-07-13  8:24             ` Hunt, David
2018-06-26  9:23         ` [dpdk-dev] [PATCH v3 4/9] examples/vm_power: allow greater than 64 cores David Hunt
2018-06-26  9:23         ` [dpdk-dev] [PATCH v3 5/9] examples/vm_power: add thread for oob core monitor David Hunt
2018-06-26  9:23         ` [dpdk-dev] [PATCH v3 6/9] examples/vm_power: add port-list to command line David Hunt
2018-06-26  9:23         ` [dpdk-dev] [PATCH v3 7/9] examples/vm_power: add branch ratio policy type David Hunt
2018-06-26  9:23         ` [dpdk-dev] [PATCH v3 8/9] examples/vm_power: add cli args to guest app David Hunt
2018-06-26  9:23         ` [dpdk-dev] [PATCH v3 9/9] examples/vm_power: make branch ratio configurable David Hunt
2018-07-12 19:09         ` [dpdk-dev] [0/9] examples/vm_power: 100% Busy Polling Thomas Monjalon
2018-07-13  8:31           ` Hunt, David
2018-07-13  8:33             ` Thomas Monjalon
2018-07-13  8:43               ` Hunt, David
2018-07-18 15:23                 ` Thomas Monjalon
2018-06-21 13:24     ` [dpdk-dev] [PATCH v2 2/8] examples/vm_power: add core list parameter David Hunt
2018-06-21 13:24     ` [dpdk-dev] [PATCH v2 3/8] examples/vm_power: add oob monitoring functions David Hunt
2018-06-21 13:24     ` [dpdk-dev] [PATCH v2 4/8] examples/vm_power: allow greater than 64 cores David Hunt
2018-06-21 13:24     ` [dpdk-dev] [PATCH v2 5/8] examples/vm_power: add thread for oob core monitor David Hunt
2018-06-21 13:24     ` [dpdk-dev] [PATCH v2 6/8] examples/vm_power: add port-list to command line David Hunt
2018-06-21 13:24     ` [dpdk-dev] [PATCH v2 7/8] examples/vm_power: add branch ratio policy type David Hunt
2018-06-21 13:24     ` [dpdk-dev] [PATCH v2 8/8] examples/vm_power: add cli args to guest app David Hunt
2018-06-21 14:28     ` [dpdk-dev] [PATCH v2 0/8] examples/vm_power: 100% Busy Polling Radu Nicolau
2018-06-07  7:37 ` [dpdk-dev] [PATCH v1 2/6] examples/vm_power: add core list parameter David Hunt
2018-06-07  7:37 ` [dpdk-dev] [PATCH v1 3/6] examples/vm_power: add oob monitoring functions David Hunt
2018-06-07  7:37 ` David Hunt [this message]
2018-06-07  7:37 ` [dpdk-dev] [PATCH v1 5/6] examples/vm_power: add thread for oob core monitor David Hunt
2018-06-07  7:37 ` [dpdk-dev] [PATCH v1 6/6] examples/vm_power: add port-list to command line David Hunt

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=20180607073705.32895-5-david.hunt@intel.com \
    --to=david.hunt@intel.com \
    --cc=dev@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).