test/power: fix check for cpu frequency
PATCH 1/4 test/power: fix check for cpu frequency
Different drivers present the current cpu core frequency in different sysfs iles. Some present it in cpuinfo_cur_freq, some in scaling_cur_freq, and some actually present it in both.
This patch attempts to open one, if that fails, tries the other.
--- app/test/test_power_cpufreq.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
app/test/test_power_cpufreq.c +12 -3
@@ -39,8 +39,10 @@ test_power_caps(void)#define TEST_FREQ_ROUNDING_DELTA 50000#define TEST_ROUND_FREQ_TO_N_100000 100000 -#define TEST_POWER_SYSFILE_CUR_FREQ \ +#define TEST_POWER_SYSFILE_CPUINFO_FREQ \ "/sys/devices/system/cpu/cpu%u/cpufreq/cpuinfo_cur_freq" +#define TEST_POWER_SYSFILE_SCALING_FREQ \ + "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq"static uint32_t total_freq_num;static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX ];
@@ -58,12 +60,19 @@ check_cur_freq(unsigned lcore_id, uint32_t idx)int i;if (snprintf (fullpath,sizeof (fullpath), -TEST_POWER_SYSFILE_CUR_FREQ , lcore_id) <0 ) { +TEST_POWER_SYSFILE_SCALING_FREQ , lcore_id) <0 ) {return 0 ; } f =fopen (fullpath,"r" );if (f ==NULL ) { -return 0 ; +if (snprintf (fullpath,sizeof (fullpath), +TEST_POWER_SYSFILE_CPUINFO_FREQ , lcore_id) <0 ) { +return 0 ; + } + f =fopen (fullpath,"r" ); +if (f ==NULL ) { +return 0 ; + } }for (i =0 ; i <MAX_LOOP ; i++) {fflush (f);
Signature · 1 line
2.17.1
PATCH 2/4 test/power: add turbo mode to freq check function
With the intel_pstate driver and turbo enabled, the top frequency in the frequency array is the P1+1, i.e. 2300001, whereas the frequency shown in scaling_cur_freq could be a lot higher.
This patch adds a flag to the check_cur_freq function so that we can specify if a frequency is greater than expected (turbo mode), in which case the check should be successful.
--- app/test/test_power_cpufreq.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
app/test/test_power_cpufreq.c +15 -12
@@ -48,7 +48,7 @@ static uint32_t total_freq_num;static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX ];static int -check_cur_freq (unsigned lcore_id,uint32_t idx) +check_cur_freq (unsigned int lcore_id,uint32_t idx,int turbo) {#define TEST_POWER_CONVERT_TO_DECIMAL 10#define MAX_LOOP 100
@@ -90,7 +90,10 @@ check_cur_freq(unsigned lcore_id, uint32_t idx) / TEST_ROUND_FREQ_TO_N_100000; freq_conv = freq_conv *TEST_ROUND_FREQ_TO_N_100000 ; - ret = (freqs[idx] == freq_conv ?0 :-1 ); +if (turbo) + ret = (freqs[idx] <= freq_conv ?0 :-1 ); +else + ret = (freqs[idx] == freq_conv ?0 :-1 );if (ret ==0 )break ;
@@ -183,7 +186,7 @@ check_power_get_freq(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID , count); + ret =check_cur_freq (TEST_POWER_LCORE_ID , count,0 );if (ret <0 )return -1 ;
@@ -233,7 +236,7 @@ check_power_set_freq(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -1 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -1 ,0 );if (ret <0 )return -1 ;
@@ -269,7 +272,7 @@ check_power_freq_down(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -1 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -1 ,0 );if (ret <0 )return -1 ;
@@ -288,7 +291,7 @@ check_power_freq_down(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID ,1 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID ,1 ,0 );if (ret <0 )return -1 ;
@@ -324,7 +327,7 @@ check_power_freq_up(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -2 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -2 ,0 );if (ret <0 )return -1 ;
@@ -343,7 +346,7 @@ check_power_freq_up(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 ,1 );if (ret <0 )return -1 ;
@@ -371,7 +374,7 @@ check_power_freq_max(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 ,1 );if (ret <0 )return -1 ;
@@ -399,7 +402,7 @@ check_power_freq_min(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -1 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -1 ,0 );if (ret <0 )return -1 ;
@@ -433,7 +436,7 @@ check_power_turbo(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 ,1 );if (ret <0 )return -1 ;
@@ -452,7 +455,7 @@ check_power_turbo(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID ,1 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID ,1 ,0 );if (ret <0 )return -1 ;
Signature · 1 line
2.17.1
Re: [dpdk-dev] [PATCH v1 2/4] test/power: add turbo mode to freq check function
Quoted 21 lines · David Hunt
With the
intel_pstatedriver and turbo enabled, the top frequency in the frequency array is the P1+1, i.e. 2300001, whereas the frequency shown inscaling_cur_freqcould be a lot higher.This patch adds a flag to the
check_cur_freqfunction so that we can specify if a frequency is greater than expected (turbo mode), in which case the check should be successful.Fixes aeaeaf5f2d62 ("test/power: add cases for turbo feature")Signed-off-by David Hunt <[email protected]>--- app/test/test_power_cpufreq.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)app/test/test_power_cpufreq.c +0
-0
app/test/test_power_cpufreq.c static uint32_t total_freq_num; · line 51
Quoted 5 lines
app/test/test_power_cpufreq.c +1
-1@@ -48,7 +48,7 @@ static uint32_t total_freq_num;static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX ];static int -check_cur_freq (unsigned lcore_id,uint32_t idx) +check_cur_freq (unsigned int lcore_id,uint32_t idx,int turbo)
Nitpicking, but stdbool exists :) it would be nice to use bool type for bool variables, not int.
Signature · 2 lines
Thanks, Anatoly
Re: [dpdk-dev] [dpdk-stable] [PATCH v1 2/4] test/power: add turbo mode to freq check function
22/04/2021 18:13, Burakov, Anatoly:
Quoted 6 lines · David Hunt
Quoted 5 lines
app/test/test_power_cpufreq.c +0
-0@@ -48,7 +48,7 @@ static uint32_t total_freq_num;static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX ];
Quoted 6 lines
app/test/test_power_cpufreq.c static uint32_t total_freq_num; · line 51
Quoted 3 lines
app/test/test_power_cpufreq.c +1
-1static int -check_cur_freq (unsigned lcore_id,uint32_t idx) +check_cur_freq (unsigned int lcore_id,uint32_t idx,int turbo)Nitpicking, but stdbool exists :) it would be nice to use bool type for bool variables, not int.
Dave, I think you missed this comment.
Re: [dpdk-dev] [dpdk-stable] [PATCH v1 2/4] test/power: add turbo mode to freq check function
Quoted 7 lines · Thomas Monjalon
22/04/2021 18:13, Burakov, Anatoly:
Quoted 6 lines · David Hunt
Quoted 5 lines
app/test/test_power_cpufreq.c +0
-0@@ -48,7 +48,7 @@ static uint32_t total_freq_num;static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX ];
Quoted 7 lines
Quoted 5 lines
app/test/test_power_cpufreq.c static uint32_t total_freq_num; · line 51
Quoted 3 lines
app/test/test_power_cpufreq.c +1
-1static int -check_cur_freq (unsigned lcore_id,uint32_t idx) +check_cur_freq (unsigned int lcore_id,uint32_t idx,int turbo)Nitpicking, but stdbool exists :) it would be nice to use bool type for bool variables, not int.
Dave, I think you missed this comment.
Thanks for the reminder Thomas, I've just pushed a new version replacing the int with a bool.
Regards,
Dave.
PATCH 3/4 test/power: fix low freq test when turbo enabled
In reply to David HuntWith the intel_pstate driver and turbo enabled, indexing is slightly different to normal, so to get the test to work properly, enable turbo at the start.
--- app/test/test_power_cpufreq.c | 2 ++ 1 file changed, 2 insertions(+)
app/test/test_power_cpufreq.c +2 -0
@@ -249,6 +249,8 @@ check_power_freq_down(void) {int ret; +rte_power_freq_enable_turbo (TEST_POWER_LCORE_ID ); +/* test with an invalid lcore id */ ret =rte_power_freq_down (TEST_POWER_LCORE_INVALID );if (ret >=0 ) {
Signature · 1 line
2.17.1
PATCH 4/4 test/power: fix turbo test
In reply to David Huntwhen turbo is enabled or disabled, the frequency is set to a low non-turbo frequency, so we need to set to the frequency expected by the test before checking.
--- app/test/test_power_cpufreq.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
app/test/test_power_cpufreq.c +12 -0
@@ -436,6 +436,12 @@ check_power_turbo(void) TEST_POWER_LCORE_ID);return -1 ; } + ret =rte_power_freq_max (TEST_POWER_LCORE_ID ); +if (ret <0 ) { +printf ("Fail to scale up the freq to max on lcore %u\n" , +TEST_POWER_LCORE_ID ); +return -1 ; + }/* Check the current frequency */ ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 ,1 );
@@ -455,6 +461,12 @@ check_power_turbo(void) TEST_POWER_LCORE_ID);return -1 ; } + ret =rte_power_freq_max (TEST_POWER_LCORE_ID ); +if (ret <0 ) { +printf ("Fail to scale up the freq to max on lcore %u\n" , +TEST_POWER_LCORE_ID ); +return -1 ; + }/* Check the current frequency */ ret =check_cur_freq (TEST_POWER_LCORE_ID ,1 ,0 );
Signature · 1 line
2.17.1
app/test/test_power_cpufreq.c check_cur_freq(unsigned lcore_id, uint32_t idx) · line 64
Quoted 7 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of David Huntapp/test/test_power_cpufreq.c +1
-0+ TEST_POWER_SYSFILE_SCALING_FREQ, lcore_id) < 0) {return 0 ;
[Reshma]: Do we need to return -1 here and in other failure scenarios below.
Quoted 17 lines
app/test/test_power_cpufreq.c +8
-2} f =fopen (fullpath,"r" );if (f ==NULL ) { -return 0 ; +if (snprintf (fullpath,sizeof (fullpath), +TEST_POWER_SYSFILE_CPUINFO_FREQ , lcore_id) <0 ) { +return 0 ; + } + f =fopen (fullpath,"r" ); +if (f ==NULL ) { +return 0 ; + } }for (i =0 ; i <MAX_LOOP ; i++) {fflush (f); --2.17.1
This patch series is stucked.
That's too often the case for the power lib/example/test patches.
29/04/2021 12:34, Pattan, Reshma:
Quoted 20 lines
From: dev <[email protected]> On Behalf Of David Hunt
Quoted 3 lines
+TEST_POWER_SYSFILE_SCALING_FREQ,
lcore_id) < 0) {return 0;
[Reshma]: Do we need to return -1 here and in other failure scenarios below.
Quoted 13 lines
}
f =fopen(fullpath, "r");
if (f == NULL) {app/test/test_power_cpufreq.c +8
-1-return 0 ; +if (snprintf (fullpath,sizeof (fullpath), +TEST_POWER_SYSFILE_CPUINFO_FREQ , lcore_id) <0 ) { +return 0 ; +} +f =fopen (fullpath,"r" ); +if (f ==NULL ) { +return 0 ; +} }
Quoted 6 lines · Reshma
Quoted 5 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of David Hunt +TEST_POWER_SYSFILE_SCALING_FREQ,lcore_id) < 0) {
return 0;[Reshma]: Do we need to return -1 here and in other failure scenarios below.
Hi Reshma,
We might do, but that's not something I had intended to address in this patch set.
We should look at this in a future patch, OK?
Rgds,
Dave.
Quoted 9 lines
-----Original Message-----
From: Hunt, David <[email protected]>Quoted 1 line
[Reshma]: Do we need to return -1 here and in other failure scenarios below.
Hi Reshma,
Quoted 10 lines
We might do, but that's not something I had intended to address in this patch set.
We should look at this in a future patch, OK?
Rgds,
Dave.
Fine with me. Thanks for checking.
PATCH v2 1/4 test/power: fix check for cpu frequency
In reply to David HuntDifferent drivers present the current cpu core frequency in different sysfs iles. Some present it in cpuinfo_cur_freq, some in scaling_cur_freq, and some actually present it in both.
This patch attempts to open one, if that fails, tries the other.
---
changes in v2
none
--- app/test/test_power_cpufreq.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
app/test/test_power_cpufreq.c +12 -3
@@ -39,8 +39,10 @@ test_power_caps(void)#define TEST_FREQ_ROUNDING_DELTA 50000#define TEST_ROUND_FREQ_TO_N_100000 100000 -#define TEST_POWER_SYSFILE_CUR_FREQ \ +#define TEST_POWER_SYSFILE_CPUINFO_FREQ \ "/sys/devices/system/cpu/cpu%u/cpufreq/cpuinfo_cur_freq" +#define TEST_POWER_SYSFILE_SCALING_FREQ \ + "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq"static uint32_t total_freq_num;static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX ];
@@ -58,12 +60,19 @@ check_cur_freq(unsigned lcore_id, uint32_t idx)int i;if (snprintf (fullpath,sizeof (fullpath), -TEST_POWER_SYSFILE_CUR_FREQ , lcore_id) <0 ) { +TEST_POWER_SYSFILE_SCALING_FREQ , lcore_id) <0 ) {return 0 ; } f =fopen (fullpath,"r" );if (f ==NULL ) { -return 0 ; +if (snprintf (fullpath,sizeof (fullpath), +TEST_POWER_SYSFILE_CPUINFO_FREQ , lcore_id) <0 ) { +return 0 ; + } + f =fopen (fullpath,"r" ); +if (f ==NULL ) { +return 0 ; + } }for (i =0 ; i <MAX_LOOP ; i++) {fflush (f);
Signature · 1 line
2.17.1
PATCH v2 2/4 test/power: add turbo mode to freq check function
With the intel_pstate driver and turbo enabled, the top frequency in the frequency array is the P1+1, i.e. 2300001, whereas the frequency shown in scaling_cur_freq could be a lot higher.
This patch adds a flag to the check_cur_freq function so that we can specify if a frequency is greater than expected (turbo mode), in which case the check should be successful.
---
changes in v2
changed check_cur_freq() to take a bool instead of an int, as suggested by Anatoly, and changed all the calls to use true/false.
--- app/test/test_power_cpufreq.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
app/test/test_power_cpufreq.c +15 -12
@@ -48,7 +48,7 @@ static uint32_t total_freq_num;static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX ];static int -check_cur_freq (unsigned lcore_id,uint32_t idx) +check_cur_freq (unsigned int lcore_id,uint32_t idx,bool turbo) {#define TEST_POWER_CONVERT_TO_DECIMAL 10#define MAX_LOOP 100
@@ -90,7 +90,10 @@ check_cur_freq(unsigned lcore_id, uint32_t idx) / TEST_ROUND_FREQ_TO_N_100000; freq_conv = freq_conv *TEST_ROUND_FREQ_TO_N_100000 ; - ret = (freqs[idx] == freq_conv ?0 :-1 ); +if (turbo) + ret = (freqs[idx] <= freq_conv ?0 :-1 ); +else + ret = (freqs[idx] == freq_conv ?0 :-1 );if (ret ==0 )break ;
@@ -183,7 +186,7 @@ check_power_get_freq(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID , count); + ret =check_cur_freq (TEST_POWER_LCORE_ID , count, false);if (ret <0 )return -1 ;
@@ -233,7 +236,7 @@ check_power_set_freq(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -1 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -1 , false);if (ret <0 )return -1 ;
@@ -269,7 +272,7 @@ check_power_freq_down(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -1 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -1 , false);if (ret <0 )return -1 ;
@@ -288,7 +291,7 @@ check_power_freq_down(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID ,1 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID ,1 , false);if (ret <0 )return -1 ;
@@ -324,7 +327,7 @@ check_power_freq_up(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -2 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -2 , false);if (ret <0 )return -1 ;
@@ -343,7 +346,7 @@ check_power_freq_up(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 , true);if (ret <0 )return -1 ;
@@ -371,7 +374,7 @@ check_power_freq_max(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 , true);if (ret <0 )return -1 ;
@@ -399,7 +402,7 @@ check_power_freq_min(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -1 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID , total_freq_num -1 , false);if (ret <0 )return -1 ;
@@ -433,7 +436,7 @@ check_power_turbo(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 , true);if (ret <0 )return -1 ;
@@ -452,7 +455,7 @@ check_power_turbo(void) }/* Check the current frequency */ - ret =check_cur_freq (TEST_POWER_LCORE_ID ,1 ); + ret =check_cur_freq (TEST_POWER_LCORE_ID ,1 , false);if (ret <0 )return -1 ;
Signature · 1 line
2.17.1
PATCH v2 3/4 test/power: fix low freq test when turbo enabled
In reply to David HuntWith the intel_pstate driver and turbo enabled, indexing is slightly different to normal, so to get the test to work properly, enable turbo at the start.
---
changes in v2
none
--- app/test/test_power_cpufreq.c | 2 ++ 1 file changed, 2 insertions(+)
app/test/test_power_cpufreq.c +2 -0
@@ -249,6 +249,8 @@ check_power_freq_down(void) {int ret; +rte_power_freq_enable_turbo (TEST_POWER_LCORE_ID ); +/* test with an invalid lcore id */ ret =rte_power_freq_down (TEST_POWER_LCORE_INVALID );if (ret >=0 ) {
Signature · 1 line
2.17.1
PATCH v2 4/4 test/power: fix turbo test
In reply to David Huntwhen turbo is enabled or disabled, the frequency is set to a low non-turbo frequency, so we need to set to the frequency expected by the test before checking.
---
changes in v2
none
--- app/test/test_power_cpufreq.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
app/test/test_power_cpufreq.c +12 -0
@@ -436,6 +436,12 @@ check_power_turbo(void) TEST_POWER_LCORE_ID);return -1 ; } + ret =rte_power_freq_max (TEST_POWER_LCORE_ID ); +if (ret <0 ) { +printf ("Fail to scale up the freq to max on lcore %u\n" , +TEST_POWER_LCORE_ID ); +return -1 ; + }/* Check the current frequency */ ret =check_cur_freq (TEST_POWER_LCORE_ID ,0 , true);
@@ -455,6 +461,12 @@ check_power_turbo(void) TEST_POWER_LCORE_ID);return -1 ; } + ret =rte_power_freq_max (TEST_POWER_LCORE_ID ); +if (ret <0 ) { +printf ("Fail to scale up the freq to max on lcore %u\n" , +TEST_POWER_LCORE_ID ); +return -1 ; + }/* Check the current frequency */ ret =check_cur_freq (TEST_POWER_LCORE_ID ,1 , false);
Signature · 1 line
2.17.1
Re: [dpdk-dev] [dpdk-stable] [PATCH v2 4/4] test/power: fix turbo test
12/05/2021 18:32, David Hunt:
Quoted 8 lines
when turbo is enabled or disabled, the frequency is set to a low non-turbo frequency, so we need to set to the frequency expected by the test before checking.
Fixes aeaeaf5f2d62 ("test/power: add cases for turbo feature")Signed-off-by David Hunt <[email protected]>
Series applied, thanks.