selftests/resctrl: Create cache_portion_size() helper

CAT and CMT tests calculate size of the cache portion for the n-bits
cache allocation on their own.

Add cache_portion_size() helper that calculates size of the cache
portion for the given number of bits and use it to replace the existing
span calculations. This also prepares for the new CAT test that will
need to determine the size of the cache portion also during results
processing.

Rename also 'cache_size' local variables to 'cache_total_size' to
prevent misinterpretations.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
Ilpo Järvinen
2023-12-15 17:04:55 +02:00
committed by Shuah Khan
parent 60c2a6926c
commit 19e94a2333
3 changed files with 33 additions and 9 deletions

View File

@@ -72,7 +72,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd)
{
const char * const *cmd = benchmark_cmd;
const char *new_cmd[BENCHMARK_ARGS];
unsigned long cache_size = 0;
unsigned long cache_total_size = 0;
unsigned long long_mask;
char *span_str = NULL;
int count_of_bits;
@@ -83,10 +83,10 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd)
if (ret)
return ret;
ret = get_cache_size(cpu_no, "L3", &cache_size);
ret = get_cache_size(cpu_no, "L3", &cache_total_size);
if (ret)
return ret;
ksft_print_msg("Cache size :%lu\n", cache_size);
ksft_print_msg("Cache size :%lu\n", cache_total_size);
count_of_bits = count_bits(long_mask);
@@ -107,7 +107,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd)
.setup = cmt_setup,
};
span = cache_size * n / count_of_bits;
span = cache_portion_size(cache_total_size, param.mask, long_mask);
if (strcmp(cmd[0], "fill_buf") == 0) {
/* Duplicate the command to be able to replace span in it */