2020-01-16 13:32:41 -08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
selftests/resctrl: Rename CQM test as CMT test
CMT (Cache Monitoring Technology) [1] is a H/W feature that reports cache
occupancy of a process. resctrl selftest suite has a unit test to test CMT
for LLC but the test is named as CQM (Cache Quality Monitoring).
Furthermore, the unit test source file is named as cqm_test.c and several
functions, variables, comments, preprocessors and statements widely use
"cqm" as either suffix or prefix. This rampant misusage of CQM for CMT
might confuse someone who is newly looking at resctrl selftests because
this feature is named CMT in the Intel Software Developer's Manual.
Hence, rename all the occurrences (unit test source file name, functions,
variables, comments and preprocessors) of cqm with cmt.
[1] Please see Intel SDM, Volume 3, chapter 17 and section 18 for more
information on CMT: https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-03-17 02:22:41 +00:00
|
|
|
* Cache Monitoring Technology (CMT) test
|
2020-01-16 13:32:41 -08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Intel Corporation
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>,
|
|
|
|
* Fenghua Yu <fenghua.yu@intel.com>
|
|
|
|
*/
|
|
|
|
#include "resctrl.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
|
selftests/resctrl: Rename CQM test as CMT test
CMT (Cache Monitoring Technology) [1] is a H/W feature that reports cache
occupancy of a process. resctrl selftest suite has a unit test to test CMT
for LLC but the test is named as CQM (Cache Quality Monitoring).
Furthermore, the unit test source file is named as cqm_test.c and several
functions, variables, comments, preprocessors and statements widely use
"cqm" as either suffix or prefix. This rampant misusage of CQM for CMT
might confuse someone who is newly looking at resctrl selftests because
this feature is named CMT in the Intel Software Developer's Manual.
Hence, rename all the occurrences (unit test source file name, functions,
variables, comments and preprocessors) of cqm with cmt.
[1] Please see Intel SDM, Volume 3, chapter 17 and section 18 for more
information on CMT: https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-03-17 02:22:41 +00:00
|
|
|
#define RESULT_FILE_NAME "result_cmt"
|
2020-01-16 13:32:41 -08:00
|
|
|
#define NUM_OF_RUNS 5
|
|
|
|
#define MAX_DIFF 2000000
|
|
|
|
#define MAX_DIFF_PERCENT 15
|
|
|
|
|
2021-03-17 02:22:36 +00:00
|
|
|
static int count_of_bits;
|
|
|
|
static char cbm_mask[256];
|
|
|
|
static unsigned long long_mask;
|
|
|
|
static unsigned long cache_size;
|
2020-01-16 13:32:41 -08:00
|
|
|
|
selftests/resctrl: Rename CQM test as CMT test
CMT (Cache Monitoring Technology) [1] is a H/W feature that reports cache
occupancy of a process. resctrl selftest suite has a unit test to test CMT
for LLC but the test is named as CQM (Cache Quality Monitoring).
Furthermore, the unit test source file is named as cqm_test.c and several
functions, variables, comments, preprocessors and statements widely use
"cqm" as either suffix or prefix. This rampant misusage of CQM for CMT
might confuse someone who is newly looking at resctrl selftests because
this feature is named CMT in the Intel Software Developer's Manual.
Hence, rename all the occurrences (unit test source file name, functions,
variables, comments and preprocessors) of cqm with cmt.
[1] Please see Intel SDM, Volume 3, chapter 17 and section 18 for more
information on CMT: https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-03-17 02:22:41 +00:00
|
|
|
static int cmt_setup(int num, ...)
|
2020-01-16 13:32:41 -08:00
|
|
|
{
|
|
|
|
struct resctrl_val_param *p;
|
|
|
|
va_list param;
|
|
|
|
|
|
|
|
va_start(param, num);
|
|
|
|
p = va_arg(param, struct resctrl_val_param *);
|
|
|
|
va_end(param);
|
|
|
|
|
|
|
|
/* Run NUM_OF_RUNS times */
|
|
|
|
if (p->num_of_runs >= NUM_OF_RUNS)
|
2023-02-15 15:05:59 +02:00
|
|
|
return END_OF_TESTS;
|
2020-01-16 13:32:41 -08:00
|
|
|
|
|
|
|
p->num_of_runs++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int check_results(struct resctrl_val_param *param, int no_of_bits)
|
|
|
|
{
|
|
|
|
char *token_array[8], temp[512];
|
|
|
|
unsigned long sum_llc_occu_resc = 0;
|
|
|
|
int runs = 0;
|
|
|
|
FILE *fp;
|
|
|
|
|
2021-03-17 02:22:42 +00:00
|
|
|
ksft_print_msg("Checking for pass/fail\n");
|
2020-01-16 13:32:41 -08:00
|
|
|
fp = fopen(param->filename, "r");
|
|
|
|
if (!fp) {
|
|
|
|
perror("# Error in opening file\n");
|
|
|
|
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
selftests/resctrl: Enable gcc checks to detect buffer overflows
David reported a buffer overflow error in the check_results() function of
the cmt unit test and he suggested enabling _FORTIFY_SOURCE gcc compiler
option to automatically detect any such errors.
Feature Test Macros man page describes_FORTIFY_SOURCE as below
"Defining this macro causes some lightweight checks to be performed to
detect some buffer overflow errors when employing various string and memory
manipulation functions (for example, memcpy, memset, stpcpy, strcpy,
strncpy, strcat, strncat, sprintf, snprintf, vsprintf, vsnprintf, gets, and
wide character variants thereof). For some functions, argument consistency
is checked; for example, a check is made that open has been supplied with a
mode argument when the specified flags include O_CREAT. Not all problems
are detected, just some common cases.
If _FORTIFY_SOURCE is set to 1, with compiler optimization level 1 (gcc
-O1) and above, checks that shouldn't change the behavior of conforming
programs are performed.
With _FORTIFY_SOURCE set to 2, some more checking is added, but some
conforming programs might fail.
Some of the checks can be performed at compile time (via macros logic
implemented in header files), and result in compiler warnings; other checks
take place at run time, and result in a run-time error if the check fails.
Use of this macro requires compiler support, available with gcc since
version 4.0."
Fix the buffer overflow error in the check_results() function of the cmt
unit test and enable _FORTIFY_SOURCE gcc check to catch any future buffer
overflow errors.
Reported-by: David Binderman <dcb314@hotmail.com>
Suggested-by: David Binderman <dcb314@hotmail.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-03-17 02:22:35 +00:00
|
|
|
while (fgets(temp, sizeof(temp), fp)) {
|
2020-01-16 13:32:41 -08:00
|
|
|
char *token = strtok(temp, ":\t");
|
|
|
|
int fields = 0;
|
|
|
|
|
|
|
|
while (token) {
|
|
|
|
token_array[fields++] = token;
|
|
|
|
token = strtok(NULL, ":\t");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Field 3 is llc occ resc value */
|
|
|
|
if (runs > 0)
|
|
|
|
sum_llc_occu_resc += strtoul(token_array[3], NULL, 0);
|
|
|
|
runs++;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
|
2021-03-17 02:22:43 +00:00
|
|
|
return show_cache_info(sum_llc_occu_resc, no_of_bits, param->span,
|
|
|
|
MAX_DIFF, MAX_DIFF_PERCENT, NUM_OF_RUNS,
|
|
|
|
true, true);
|
2020-01-16 13:32:41 -08:00
|
|
|
}
|
|
|
|
|
selftests/resctrl: Rename CQM test as CMT test
CMT (Cache Monitoring Technology) [1] is a H/W feature that reports cache
occupancy of a process. resctrl selftest suite has a unit test to test CMT
for LLC but the test is named as CQM (Cache Quality Monitoring).
Furthermore, the unit test source file is named as cqm_test.c and several
functions, variables, comments, preprocessors and statements widely use
"cqm" as either suffix or prefix. This rampant misusage of CQM for CMT
might confuse someone who is newly looking at resctrl selftests because
this feature is named CMT in the Intel Software Developer's Manual.
Hence, rename all the occurrences (unit test source file name, functions,
variables, comments and preprocessors) of cqm with cmt.
[1] Please see Intel SDM, Volume 3, chapter 17 and section 18 for more
information on CMT: https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-03-17 02:22:41 +00:00
|
|
|
void cmt_test_cleanup(void)
|
2020-01-16 13:32:41 -08:00
|
|
|
{
|
|
|
|
remove(RESULT_FILE_NAME);
|
|
|
|
}
|
|
|
|
|
selftests/resctrl: Rename CQM test as CMT test
CMT (Cache Monitoring Technology) [1] is a H/W feature that reports cache
occupancy of a process. resctrl selftest suite has a unit test to test CMT
for LLC but the test is named as CQM (Cache Quality Monitoring).
Furthermore, the unit test source file is named as cqm_test.c and several
functions, variables, comments, preprocessors and statements widely use
"cqm" as either suffix or prefix. This rampant misusage of CQM for CMT
might confuse someone who is newly looking at resctrl selftests because
this feature is named CMT in the Intel Software Developer's Manual.
Hence, rename all the occurrences (unit test source file name, functions,
variables, comments and preprocessors) of cqm with cmt.
[1] Please see Intel SDM, Volume 3, chapter 17 and section 18 for more
information on CMT: https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-03-17 02:22:41 +00:00
|
|
|
int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd)
|
2020-01-16 13:32:41 -08:00
|
|
|
{
|
2023-02-15 15:06:04 +02:00
|
|
|
int ret;
|
2020-01-16 13:32:41 -08:00
|
|
|
|
|
|
|
cache_size = 0;
|
|
|
|
|
2023-02-15 15:06:04 +02:00
|
|
|
ret = remount_resctrlfs(true);
|
2020-01-16 13:32:41 -08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
selftests/resctrl: Rename CQM test as CMT test
CMT (Cache Monitoring Technology) [1] is a H/W feature that reports cache
occupancy of a process. resctrl selftest suite has a unit test to test CMT
for LLC but the test is named as CQM (Cache Quality Monitoring).
Furthermore, the unit test source file is named as cqm_test.c and several
functions, variables, comments, preprocessors and statements widely use
"cqm" as either suffix or prefix. This rampant misusage of CQM for CMT
might confuse someone who is newly looking at resctrl selftests because
this feature is named CMT in the Intel Software Developer's Manual.
Hence, rename all the occurrences (unit test source file name, functions,
variables, comments and preprocessors) of cqm with cmt.
[1] Please see Intel SDM, Volume 3, chapter 17 and section 18 for more
information on CMT: https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-03-17 02:22:41 +00:00
|
|
|
if (!validate_resctrl_feature_request(CMT_STR))
|
2020-01-16 13:32:41 -08:00
|
|
|
return -1;
|
|
|
|
|
2021-03-17 02:22:36 +00:00
|
|
|
ret = get_cbm_mask("L3", cbm_mask);
|
2020-01-16 13:32:41 -08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
long_mask = strtoul(cbm_mask, NULL, 16);
|
|
|
|
|
|
|
|
ret = get_cache_size(cpu_no, "L3", &cache_size);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2021-03-17 02:22:42 +00:00
|
|
|
ksft_print_msg("Cache size :%lu\n", cache_size);
|
2020-01-16 13:32:41 -08:00
|
|
|
|
|
|
|
count_of_bits = count_bits(long_mask);
|
|
|
|
|
|
|
|
if (n < 1 || n > count_of_bits) {
|
2021-03-17 02:22:42 +00:00
|
|
|
ksft_print_msg("Invalid input value for numbr_of_bits n!\n");
|
|
|
|
ksft_print_msg("Please enter value in range 1 to %d\n", count_of_bits);
|
2020-01-16 13:32:41 -08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct resctrl_val_param param = {
|
selftests/resctrl: Rename CQM test as CMT test
CMT (Cache Monitoring Technology) [1] is a H/W feature that reports cache
occupancy of a process. resctrl selftest suite has a unit test to test CMT
for LLC but the test is named as CQM (Cache Quality Monitoring).
Furthermore, the unit test source file is named as cqm_test.c and several
functions, variables, comments, preprocessors and statements widely use
"cqm" as either suffix or prefix. This rampant misusage of CQM for CMT
might confuse someone who is newly looking at resctrl selftests because
this feature is named CMT in the Intel Software Developer's Manual.
Hence, rename all the occurrences (unit test source file name, functions,
variables, comments and preprocessors) of cqm with cmt.
[1] Please see Intel SDM, Volume 3, chapter 17 and section 18 for more
information on CMT: https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-03-17 02:22:41 +00:00
|
|
|
.resctrl_val = CMT_STR,
|
2020-01-16 13:32:41 -08:00
|
|
|
.ctrlgrp = "c1",
|
|
|
|
.mongrp = "m1",
|
|
|
|
.cpu_no = cpu_no,
|
2023-02-15 15:06:04 +02:00
|
|
|
.mum_resctrlfs = false,
|
2020-01-16 13:32:41 -08:00
|
|
|
.filename = RESULT_FILE_NAME,
|
|
|
|
.mask = ~(long_mask << n) & long_mask,
|
|
|
|
.span = cache_size * n / count_of_bits,
|
|
|
|
.num_of_runs = 0,
|
selftests/resctrl: Rename CQM test as CMT test
CMT (Cache Monitoring Technology) [1] is a H/W feature that reports cache
occupancy of a process. resctrl selftest suite has a unit test to test CMT
for LLC but the test is named as CQM (Cache Quality Monitoring).
Furthermore, the unit test source file is named as cqm_test.c and several
functions, variables, comments, preprocessors and statements widely use
"cqm" as either suffix or prefix. This rampant misusage of CQM for CMT
might confuse someone who is newly looking at resctrl selftests because
this feature is named CMT in the Intel Software Developer's Manual.
Hence, rename all the occurrences (unit test source file name, functions,
variables, comments and preprocessors) of cqm with cmt.
[1] Please see Intel SDM, Volume 3, chapter 17 and section 18 for more
information on CMT: https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-03-17 02:22:41 +00:00
|
|
|
.setup = cmt_setup,
|
2020-01-16 13:32:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
if (strcmp(benchmark_cmd[0], "fill_buf") == 0)
|
|
|
|
sprintf(benchmark_cmd[1], "%lu", param.span);
|
|
|
|
|
|
|
|
remove(RESULT_FILE_NAME);
|
|
|
|
|
|
|
|
ret = resctrl_val(benchmark_cmd, ¶m);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = check_results(¶m, n);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
selftests/resctrl: Rename CQM test as CMT test
CMT (Cache Monitoring Technology) [1] is a H/W feature that reports cache
occupancy of a process. resctrl selftest suite has a unit test to test CMT
for LLC but the test is named as CQM (Cache Quality Monitoring).
Furthermore, the unit test source file is named as cqm_test.c and several
functions, variables, comments, preprocessors and statements widely use
"cqm" as either suffix or prefix. This rampant misusage of CQM for CMT
might confuse someone who is newly looking at resctrl selftests because
this feature is named CMT in the Intel Software Developer's Manual.
Hence, rename all the occurrences (unit test source file name, functions,
variables, comments and preprocessors) of cqm with cmt.
[1] Please see Intel SDM, Volume 3, chapter 17 and section 18 for more
information on CMT: https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2021-03-17 02:22:41 +00:00
|
|
|
cmt_test_cleanup();
|
2020-01-16 13:32:41 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|