Skip to contentSkip to conversation

examples/vm_power_manager: Make branch ratio threshold per core

PATCH Superseded Sexton, Rory 2 participants 6 messages May 18, 2020 – Jun 25, 2020

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 examples/vm_power_manager: Make branch ratio threshold per core

This modification allows for the branch ratio threshold to be set per core rather than system wide. This gives greater flexibility to the branch ration monitoring allowing it to manage different workloads with different characteristics on the same system.

---
 examples/vm_power_manager/main.c            | 40 +++++++++++---------
 examples/vm_power_manager/oob_monitor_x86.c |  2 +-
 examples/vm_power_manager/parse.c           | 42 ++++++++++++++++++++-
 examples/vm_power_manager/parse.h           |  3 ++
 examples/vm_power_manager/power_manager.c   |  2 +-
 examples/vm_power_manager/power_manager.h   |  2 +-
 6 files changed, 68 insertions(+), 23 deletions(-)
examples/vm_power_manager/main.c +23 -18
index 273bfec29..f077e3fe4 100644
@@ -165,15 +165,14 @@ parse_args(int argc, char **argv)
 	static struct option lgopts[] = {
 		{ "mac-updating", no_argument, 0, 1},
 		{ "no-mac-updating", no_argument, 0, 0},
-		{ "core-list", optional_argument, 0, 'l'},
+		{ "core-branch-ratio", optional_argument, 0, 'b'},
 		{ "port-list", optional_argument, 0, 'p'},
-		{ "branch-ratio", optional_argument, 0, 'b'},
 		{NULL, 0, 0, 0}
 	};
 	argvopt = argv;
 	ci = get_core_info();
 
-	while ((opt = getopt_long(argc, argvopt, "l:p:q:T:b:",
+	while ((opt = getopt_long(argc, argvopt, "p:q:T:b:",
 				  lgopts, &option_index)) != EOF) {
 
 		switch (opt) {
@@ -185,7 +184,8 @@ parse_args(int argc, char **argv)
 				return -1;
 			}
 			break;
-		case 'l':
+		case 'b':
+			branch_ratio = BRANCH_RATIO_THRESHOLD;
 			oob_enable = malloc(ci->core_count * sizeof(uint16_t));
 			if (oob_enable == NULL) {
 				printf("Error - Unable to allocate memory\n");
@@ -193,32 +193,37 @@ parse_args(int argc, char **argv)
 			}
 			cnt = parse_set(optarg, oob_enable, ci->core_count);
 			if (cnt < 0) {
-				printf("Invalid core-list - [%s]\n",
+				printf("Invalid core-list section in "
+				       "core-branch-ratio matrix - [%s]\n",
+						optarg);
+				free(oob_enable);
+				break;
+			}
+			cnt = parse_branch_ratio(optarg, &branch_ratio);
+			if (cnt < 0) {
+				printf("Invalid branch-ratio section in "
+				       "core-branch-ratio matrix - [%s]\n",
 						optarg);
 				free(oob_enable);
 				break;
 			}
+			if (branch_ratio <= 0.0) {
+				printf("invalid branch ratio specified\n");
+				return -1;
+			}
 			for (i = 0; i < ci->core_count; i++) {
 				if (oob_enable[i]) {
-					printf("***Using core %d\n", i);
+					printf("***Using core %d "
+					       "with branch ratio %f\n",
+					       i, branch_ratio);
 					ci->cd[i].oob_enabled = 1;
 					ci->cd[i].global_enabled_cpus = 1;
+					ci->cd[i].branch_ratio_threshold =
+								branch_ratio;
 				}
 			}
 			free(oob_enable);
 			break;
-		case 'b':
-			branch_ratio = 0.0;
-			if (strlen(optarg))
-				branch_ratio = atof(optarg);
-			if (branch_ratio <= 0.0) {
-				printf("invalid branch ratio specified\n");
-				return -1;
-			}
-			ci->branch_ratio_threshold = branch_ratio;
-			printf("***Setting branch ratio to %f\n",
-					branch_ratio);
-			break;
 		/* long options */
 		case 0:
 			break;
examples/vm_power_manager/oob_monitor_x86.c +1 -1
index aecfcb2eb..3c514475f 100644
@@ -109,7 +109,7 @@ apply_policy(int core)
 	 * down. Each core_details struct has it's own array.
 	 */
 	freq_window_idx = ci->cd[core].freq_window_idx;
-	if (ratio > ci->branch_ratio_threshold)
+	if (ratio > ci->cd[core].branch_ratio_threshold)
 		ci->cd[core].freq_directions[freq_window_idx] = 1;
 	else
 		ci->cd[core].freq_directions[freq_window_idx] = 0;
examples/vm_power_manager/parse.c +40 -2

54 lines not on this page · raw message

examples/vm_power_manager/parse.h +3 -0
index a5971e9a2..892dee449 100644
@@ -12,6 +12,9 @@ extern "C" {
 int
 parse_set(const char *, uint16_t [], unsigned int);
 
+int
+parse_branch_ratio(const char *input, float *branch_ratio);
+
 #ifdef __cplusplus
 }
 #endif
examples/vm_power_manager/power_manager.c +1 -1
index 7b4f4b3c4..b52128db1 100644
@@ -60,7 +60,6 @@ core_info_init(void)
 	ci = get_core_info();
 
 	ci->core_count = get_nprocs_conf();
-	ci->branch_ratio_threshold = BRANCH_RATIO_THRESHOLD;
 	ci->cd = malloc(ci->core_count * sizeof(struct core_details));
 	memset(ci->cd, 0, ci->core_count * sizeof(struct core_details));
 	if (!ci->cd) {
@@ -69,6 +68,7 @@ core_info_init(void)
 	}
 	for (i = 0; i < ci->core_count; i++) {
 		ci->cd[i].global_enabled_cpus = 1;
+		ci->cd[i].branch_ratio_threshold = BRANCH_RATIO_THRESHOLD;
 	}
 	printf("%d cores in system\n", ci->core_count);
 	return 0;
examples/vm_power_manager/power_manager.h +1 -1
index e324766b6..d35f8cbe0 100644
@@ -26,12 +26,12 @@ struct core_details {
 	uint16_t freq_directions[FREQ_WINDOW_SIZE];
 	uint16_t freq_window_idx;
 	uint16_t freq_state;
+	float branch_ratio_threshold;
 };
 
 struct core_info {
 	uint16_t core_count;
 	struct core_details *cd;
-	float branch_ratio_threshold;
 };
 
 #define BRANCH_RATIO_THRESHOLD 0.1
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 2/3 examples/vm_power_manager: Allowing power managing of idle cores

This change is required to allow the branch ratio algorithm to power manage cores with no workload running on them. This is useful both when idle cores don't use C-states and for a number of hyperthreading scenarios.

---
 examples/vm_power_manager/oob_monitor_x86.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
examples/vm_power_manager/oob_monitor_x86.c +4 -4
index 3c514475f..a5b1c168c 100644
@@ -96,12 +96,12 @@ apply_policy(int core)
 	g_branch_misses = miss_diff;
 
 	if (hits_diff < (INTERVAL*100)) {
-		/* Likely no workload running on this core. Skip. */
-		return -1.0;
+		/* Likely no workload running on this core. */
+		ratio = 0.0;
+	} else {
+		ratio = (float)miss_diff * (float)100 / (float)hits_diff;
 	}
 
-	ratio = (float)miss_diff * (float)100 / (float)hits_diff;
-
 	/*
 	 * Store the last few directions that the ratio indicates
 	 * we should take. If there's on 'up', then we scale up
Signature · 1 line
2.17.1
Reviewed-by on v2 2/3
#2 lore raw

Re: [dpdk-dev] [PATCH v2 2/3] examples/vm_power_manager: Allowing power managing of idle cores

Hi Rory,

Quoted 21 lines · Rory

This change is required to allow the branch ratio algorithm to power manage cores with no workload running on them. This is useful both when idle cores don't use C-states and for a number of hyperthreading scenarios.

---
  examples/vm_power_manager/oob_monitor_x86.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
examples/vm_power_manager/oob_monitor_x86.c +1 -2
index 3c514475f..a5b1c168c 100644
@@ -96,12 +96,12 @@ apply_policy(int core)
  	g_branch_misses = miss_diff;
 
  	if (hits_diff < (INTERVAL*100)) {
-		/* Likely no workload running on this core. Skip. */
-		return -1.0;
+		/* Likely no workload running on this core. */

examples/vm_power_manager/oob_monitor_x86.c apply_policy(int core) · line 107

Quoted 10 lines
examples/vm_power_manager/oob_monitor_x86.c +3 -2
+		ratio = 0.0;
+	} else {
+		ratio = (float)miss_diff * (float)100 / (float)hits_diff;
  	}
 
-	ratio = (float)miss_diff * (float)100 / (float)hits_diff;
-
  	/*
  	 * Store the last few directions that the ratio indicates
  	 * we should take. If there's on 'up', then we scale up

Good enhancement. It hadn't occurred to me to manage non-PMD workloads, but I agree that when C-States are disabled on a system, there may be cases where this algorithm is useful to save power.

#3 lore raw

PATCH v2 3/3 doc: update vm_power_manager cmdline options in doc

In reply to Sexton, Rory
---
 doc/guides/sample_app_ug/vm_power_management.rst | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
doc/guides/sample_app_ug/vm_power_management.rst +5 -8
index e98277ccb..dd0f46158 100644
@@ -410,20 +410,17 @@ There are a couple of command line parameters for enabling the out-of-band
 monitoring of branch ratios on cores doing busy polling using PMDs as
 described below:
 
-``--core-list {list of cores}``
+``--core-branch-ratio {list of cores}:{branch ratio for listed cores}``
    Specify the list of cores to monitor the ratio of branch misses
    to branch hits.  A tightly-polling PMD thread has a very low
    branch ratio, therefore the core frequency scales down to the
    minimum allowed value. On receiving packets, the code path changes,
    causing the branch ratio to increase. When the ratio goes above
    the ratio threshold, the core frequency scales up to the maximum
-   allowed value.
-
-``--branch-ratio {ratio}``
-   Specify a floating-point number that identifies the threshold at which
-   to scale up or down for the given workload. The default branch ratio
-   is 0.01 and needs adjustment for different workloads.
-
+   allowed value. The specified branch-ratio is a floating point number
+   that identifies the threshold at which to scale up or down for the
+   elements of the core-list. If not included the default branch ratio of
+   0.01 but will need adjustment for different workloads
 
 Compiling and Running the Guest Applications
 --------------------------------------------
Signature · 1 line
2.17.1
Reviewed-by on v2 3/3
#4 lore raw

Re: [dpdk-dev] [PATCH v2 3/3] doc: update vm_power_manager cmdline options in doc

Quoted 22 lines · Rory
---
  doc/guides/sample_app_ug/vm_power_management.rst | 13 +++++--------
  1 file changed, 5 insertions(+), 8 deletions(-)
doc/guides/sample_app_ug/vm_power_management.rst +1 -2
index e98277ccb..dd0f46158 100644
@@ -410,20 +410,17 @@ There are a couple of command line parameters for enabling the out-of-band
  monitoring of branch ratios on cores doing busy polling using PMDs as
  described below:
 
-``--core-list {list of cores}``
+``--core-branch-ratio {list of cores}:{branch ratio for listed cores}``
     Specify the list of cores to monitor the ratio of branch misses
     to branch hits.  A tightly-polling PMD thread has a very low
     branch ratio, therefore the core frequency scales down to the
     minimum allowed value. On receiving packets, the code path changes,
     causing the branch ratio to increase. When the ratio goes above
     the ratio threshold, the core frequency scales up to the maximum
-   allowed value.

doc/guides/sample_app_ug/vm_power_management.rst There are a couple of command line parameters for enabling the out-of-band · line 423

Quoted 10 lines
doc/guides/sample_app_ug/vm_power_management.rst +4 -6
-
-``--branch-ratio {ratio}``
-   Specify a floating-point number that identifies the threshold at which
-   to scale up or down for the given workload. The default branch ratio
-   is 0.01 and needs adjustment for different workloads.
-
+   allowed value. The specified branch-ratio is a floating point number
+   that identifies the threshold at which to scale up or down for the
+   elements of the core-list. If not included the default branch ratio of
+   0.01 but will need adjustment for different workloads

Could I suggest adding something along the following lines for further info?

"This parameter can be used multiple times for different sets of cores. The branch ratio mechanism can also be useful for non-PMD cores and hyper-threaded environments where C-States are disabled."

Reviewed-by on v2 1/3
#5 lore raw
In reply to Sexton, Rory

Hi Rory,

Quoted 6 lines · Rory

This modification allows for the branch ratio threshold to be set per core rather than system wide. This gives greater flexibility to the branch ration monitoring allowing it to manage different workloads with different characteristics on the same system.

Quoted 8 lines
---
  examples/vm_power_manager/main.c            | 40 +++++++++++---------
  examples/vm_power_manager/oob_monitor_x86.c |  2 +-
  examples/vm_power_manager/parse.c           | 42 ++++++++++++++++++++-
  examples/vm_power_manager/parse.h           |  3 ++
  examples/vm_power_manager/power_manager.c   |  2 +-
  examples/vm_power_manager/power_manager.h   |  2 +-
  6 files changed, 68 insertions(+), 23 deletions(-)

This change is a good enhancement, as there are usually different types of workload running on the cores in a system, each requiring a different ratio.

Also, it's good that multiple groups of cores can be specified by using the parameter multiple times, e.g. -b 21-23:0.5 -b 24,25:0.4

LGTM.