diff mbox series

[2/4] selftests/resctrl: Don't hard code divisor in MBM results

Message ID 20230208094026.22529-3-ilpo.jarvinen@linux.intel.com (mailing list archive)
State New
Headers show
Series selftests/resctrl: Small cleanups | expand

Commit Message

Ilpo Järvinen Feb. 8, 2023, 9:40 a.m. UTC
From: Fenghua Yu <fenghua.yu@intel.com>

Presently, while calculating MBM results, the divisor is hard coded as 4.
It's hard coded to 4 because "NUM_OF_RUNS" is defined as 5 and the test
does not count first result and hence 4. So, instead of hard coding the
value to 4, change it to NUM_OF_RUNS - 1.

Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
---
 tools/testing/selftests/resctrl/mbm_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Reinette Chatre Feb. 14, 2023, 12:59 a.m. UTC | #1
Hi Ilpo,

The subject is "Don't hard code divisor ..." yet it seems to me
that the hard coding persists. It is just changed from a magic
constant to a macro.

On 2/8/2023 1:40 AM, Ilpo Järvinen wrote:
> From: Fenghua Yu <fenghua.yu@intel.com>
> 
> Presently, while calculating MBM results, the divisor is hard coded as 4.

"Presently" can be removed. Here and in the rest of the series the usage of
"presently" and "currently" can usually be removed to improve clarity.

> It's hard coded to 4 because "NUM_OF_RUNS" is defined as 5 and the test
> does not count first result and hence 4. So, instead of hard coding the
> value to 4, change it to NUM_OF_RUNS - 1.

Are there any plans surrounding using struct resctrl_val_param::num_of_runs
instead?

> 
> Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>

Missing your Signed-off-by?

> ---
>  tools/testing/selftests/resctrl/mbm_test.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c
> index 8392e5c55ed0..4f85cbbfd037 100644
> --- a/tools/testing/selftests/resctrl/mbm_test.c
> +++ b/tools/testing/selftests/resctrl/mbm_test.c
> @@ -31,8 +31,8 @@ show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, int span)
>  		sum_bw_resc += bw_resc[runs];
>  	}
>  
> -	avg_bw_imc = sum_bw_imc / 4;
> -	avg_bw_resc = sum_bw_resc / 4;
> +	avg_bw_imc = sum_bw_imc / (NUM_OF_RUNS - 1);
> +	avg_bw_resc = sum_bw_resc / (NUM_OF_RUNS - 1);
>  	avg_diff = (float)labs(avg_bw_resc - avg_bw_imc) / avg_bw_imc;
>  	avg_diff_per = (int)(avg_diff * 100);
>  


Reinette
Ilpo Järvinen Feb. 14, 2023, 10 a.m. UTC | #2
On Mon, 13 Feb 2023, Reinette Chatre wrote:

> Hi Ilpo,
> 
> The subject is "Don't hard code divisor ..." yet it seems to me
> that the hard coding persists. It is just changed from a magic
> constant to a macro.

Yeah, it was a bad wording.

> On 2/8/2023 1:40 AM, Ilpo Järvinen wrote:
> > From: Fenghua Yu <fenghua.yu@intel.com>
> > 
> > Presently, while calculating MBM results, the divisor is hard coded as 4.
> 
> "Presently" can be removed. Here and in the rest of the series the usage of
> "presently" and "currently" can usually be removed to improve clarity.
> 
> > It's hard coded to 4 because "NUM_OF_RUNS" is defined as 5 and the test
> > does not count first result and hence 4. So, instead of hard coding the
> > value to 4, change it to NUM_OF_RUNS - 1.
> 
> Are there any plans surrounding using struct resctrl_val_param::num_of_runs
> instead?

Actually no.

What I'd want to do is that the functions which call these result 
calculator functions would specify the number of tests they passed
into the result calculator. It seems safer because the results are read 
back from a file which could have changed (or got deleted due to an 
ipc bug prematurely cleaning up the file) and would better take account 
those cases where the first value is skipped when reading the results.

I think I'll drop this patch for now.
Reinette Chatre Feb. 14, 2023, 5:01 p.m. UTC | #3
Hi Ilpo,

On 2/14/2023 2:00 AM, Ilpo Järvinen wrote:
> On Mon, 13 Feb 2023, Reinette Chatre wrote:
>> On 2/8/2023 1:40 AM, Ilpo Järvinen wrote:
>>> From: Fenghua Yu <fenghua.yu@intel.com>
>>>
>>> Presently, while calculating MBM results, the divisor is hard coded as 4.
>>
>> "Presently" can be removed. Here and in the rest of the series the usage of
>> "presently" and "currently" can usually be removed to improve clarity.
>>
>>> It's hard coded to 4 because "NUM_OF_RUNS" is defined as 5 and the test
>>> does not count first result and hence 4. So, instead of hard coding the
>>> value to 4, change it to NUM_OF_RUNS - 1.
>>
>> Are there any plans surrounding using struct resctrl_val_param::num_of_runs
>> instead?
> 
> Actually no.
> 
> What I'd want to do is that the functions which call these result 
> calculator functions would specify the number of tests they passed
> into the result calculator. It seems safer because the results are read 

Would it not simplify things to pass the test parameters (struct resctrl_val_param)
to the result calculator? That contains the number of tests run and would
reign in the hard coding.

> back from a file which could have changed (or got deleted due to an 
> ipc bug prematurely cleaning up the file) and would better take account 
> those cases where the first value is skipped when reading the results.
> 

This sounds good. Thank you.

Reinette
diff mbox series

Patch

diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c
index 8392e5c55ed0..4f85cbbfd037 100644
--- a/tools/testing/selftests/resctrl/mbm_test.c
+++ b/tools/testing/selftests/resctrl/mbm_test.c
@@ -31,8 +31,8 @@  show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, int span)
 		sum_bw_resc += bw_resc[runs];
 	}
 
-	avg_bw_imc = sum_bw_imc / 4;
-	avg_bw_resc = sum_bw_resc / 4;
+	avg_bw_imc = sum_bw_imc / (NUM_OF_RUNS - 1);
+	avg_bw_resc = sum_bw_resc / (NUM_OF_RUNS - 1);
 	avg_diff = (float)labs(avg_bw_resc - avg_bw_imc) / avg_bw_imc;
 	avg_diff_per = (int)(avg_diff * 100);