selftests/resctrl: CAT test improvements & generalized test framework
Subsystems (2)
v3 cover selftests/resctrl: CAT test improvements & generalized test framework
Hi all,
Here's v3 series to improve resctrl selftests with generalized test framework and rewritten CAT test. As agreed, v3 does not include the group naming patch which will become part of Maciej's non-contiguous serie. The error handling cleanups (return errno, perror() & return value comment cleanups) and CPU affinity restore for CAT test add to the patch count.
The series contains following improvements:
- Excludes shareable bits from CAT test allocation to avoid interference
- Replaces file "sink" with a volatile variable
- Alters read pattern to defeat HW prefetcher optimizations
- Rewrites CAT test to make the CAT test reliable and truly measure if CAT is working or not
- Introduces generalized test framework making easier to add new tests
- Lots of other cleanups & refactoring
This serie have been tested across a large number of systems from different generations.
v3:
- New patches to handle return errno, perror() and return value comments
- Tweak changelogs
- Moved error printout removal to other patch
- Zero bit CBM returns error
- Tweak comments
- Make get_shareable_mask() static
- Return directly without storing result into ret variable first
- llc -> LLC
- Altered changelog and removed "the whole time" wording because llc occu results are still unsigned long
- Altered changelog's wording to not say "a volatile pointer"
- Make min_diff_percent and MIN_DIFF_PERCENT_PER_BIT unsigned long
- Add patch to restore CPU affinity after CAT test
- Move uparams clear into init function
- Add CPU vendor ID bitmask comment
- Use test_resource_feature_check(test) in CMT
- "feature" -> "resource" in function comment
v2:
- Postpone adding L2 CAT test as more investigations are necessary
- Add patch to remove ctrlc_handler() from wrong place
- Improvements to changelogs
- Function comments improvements & comment cleanups
- Move some parts of the changes into more logical patch
- If checks: buf == NULL -> !buf
- Variable naming:
- p -> buf
- cbm_mask_path -> cbm_path
- Function naming:
- get_cbm_mask() -> get_full_cbm()
- cache_size() -> cache_portion_size()
- Use PATH_MAX
- Improved cache_portion_size() parameter names
- int count -> unsigned int
- Pass filename to measurement taking functions instead of resctrl_val_param
- !lines ? : reversal
- Removed bogus static from function local variable
- Open perf fd only once, reset & enable in the innermost test loop
- Add perf fd ioctl() error handling
- Add patch to change compiler optimization prevention "sink" from file to volatile variable
- Remove cpu_no and resource (the latter was added in v1) members from resctrl_val_param (pass uparams and test where those are needed)
- Removed ARRAY_SIZE() macro
- Add patch to rename "resource_id" to "domain_id"
Ilpo Järvinen (29):
selftests/resctrl: Convert perror() to ksft_perror() or
ksft_print_msg()
selftests/resctrl: Return -1 instead of errno on error selftests/resctrl: Don't use ctrlc_handler() outside signal handling selftests/resctrl: Change function comments to say < 0 on error selftests/resctrl: Split fill_buf to allow tests finer-grained control selftests/resctrl: Refactor fill_buf functions selftests/resctrl: Refactor get_cbm_mask() and rename to
get_full_cbm()
selftests/resctrl: Mark get_cache_size() cache_type const
selftests/resctrl: Create cache_portion_size() helper
selftests/resctrl: Exclude shareable bits from schemata in CAT test
selftests/resctrl: Split measure_cache_vals()
selftests/resctrl: Split show_cache_info() to test specific and
generic parts
selftests/resctrl: Remove unnecessary __u64 -> unsigned long
conversion
selftests/resctrl: Remove nested calls in perf event handling
selftests/resctrl: Consolidate naming of perf event related things
selftests/resctrl: Improve perf init
selftests/resctrl: Convert perf related globals to locals
selftests/resctrl: Move cat_val() to cat_test.c and rename to
cat_test() selftests/resctrl: Open perf fd before start & add error handling selftests/resctrl: Replace file write with volatile variable selftests/resctrl: Read in less obvious order to defeat prefetch
optimizations
selftests/resctrl: Rewrite Cache Allocation Technology (CAT) test selftests/resctrl: Restore the CPU affinity after CAT test selftests/resctrl: Create struct for input parameters selftests/resctrl: Introduce generalized test framework selftests/resctrl: Pass write_schemata() resource instead of test name selftests/resctrl: Add helper to convert L2/3 to integer selftests/resctrl: Rename resource ID to domain ID selftests/resctrl: Get domain id from cache id
tools/testing/selftests/resctrl/cache.c | 287 +++++---------- tools/testing/selftests/resctrl/cat_test.c | 337 +++++++++++------- tools/testing/selftests/resctrl/cmt_test.c | 80 +++-- tools/testing/selftests/resctrl/fill_buf.c | 132 ++++--- tools/testing/selftests/resctrl/mba_test.c | 30 +- tools/testing/selftests/resctrl/mbm_test.c | 32 +- tools/testing/selftests/resctrl/resctrl.h | 126 +++++-- .../testing/selftests/resctrl/resctrl_tests.c | 197 ++++------ tools/testing/selftests/resctrl/resctrl_val.c | 138 +++---- tools/testing/selftests/resctrl/resctrlfs.c | 321 +++++++++++------ 10 files changed, 936 insertions(+), 744 deletions(-)
Signature · 1 line
2.30.2
PATCH v3 1/29 selftests/resctrl: Convert perror() to ksft_perror() or ksft_print_msg()
The resctrl selftest code contains a number of perror() calls. Some of them come with hash character and some don't. The kselftest framework provides ksft_perror() that is compatible with test output formatting so it should be used instead of adding custom hash signs.
Some perror() calls are too far away from anything that sets error. For those call sites, ksft_print_msg() must be used instead.
Convert perror() to ksft_perror() or ksft_print_msg().
Other related changes:
- Remove hash signs
- Remove trailing stops & newlines from ksft_perror()
- Add terminating newlines for converted ksft_print_msg()
- Use consistent capitalization
---
v3:
- New patch
--- tools/testing/selftests/resctrl/cache.c | 10 +-- tools/testing/selftests/resctrl/cat_test.c | 8 +- tools/testing/selftests/resctrl/cmt_test.c | 2 +- tools/testing/selftests/resctrl/fill_buf.c | 2 +- tools/testing/selftests/resctrl/mba_test.c | 2 +- tools/testing/selftests/resctrl/mbm_test.c | 2 +- tools/testing/selftests/resctrl/resctrl.h | 3 +- tools/testing/selftests/resctrl/resctrl_val.c | 76 ++++++++++--------- tools/testing/selftests/resctrl/resctrlfs.c | 42 +++++----- 9 files changed, 77 insertions(+), 70 deletions(-)
tools/testing/selftests/resctrl/cache.c +5 -5
@@ -40,7 +40,7 @@ static int perf_event_open_llc_miss(pid_t pid, int cpu_no) fd_lm =perf_event_open (&pea_llc_miss, pid, cpu_no,-1 ,PERF_FLAG_FD_CLOEXEC );if (fd_lm ==-1 ) { -perror ("Error opening leader" ); +ksft_perror ("Error opening leader" );ctrlc_handler (0 ,NULL ,NULL );return -1 ; }
@@ -95,7 +95,7 @@ static int get_llc_perf(unsigned long *llc_perf_miss) ret =read (fd_lm, &rf_cqm,sizeof (struct read_format ));if (ret ==-1 ) { -perror ("Could not get llc misses through perf" ); +ksft_perror ("Could not get llc misses through perf" );return -1 ; }
@@ -124,12 +124,12 @@ static int get_llc_occu_resctrl(unsigned long *llc_occupancy) fp =fopen (llc_occup_path,"r" );if (!fp) { -perror ("Failed to open results file" ); +ksft_perror ("Failed to open results file" );return errno; }if (fscanf (fp,"%lu" , llc_occupancy) <=0 ) { -perror ("Could not get llc occupancy" ); +ksft_perror ("Could not get llc occupancy" );fclose (fp);return -1 ;
@@ -159,7 +159,7 @@ static int print_results_cache(char *filename, int bm_pid, }else { fp =fopen (filename,"a" );if (!fp) { -perror ("Cannot open results file" ); +ksft_perror ("Cannot open results file" );return errno; }
tools/testing/selftests/resctrl/cat_test.c +4 -4
@@ -51,7 +51,7 @@ static int check_results(struct resctrl_val_param *param, size_t span)ksft_print_msg ("Checking for pass/fail\n" ); fp =fopen (param->filename,"r" );if (!fp) { -perror ("# Cannot open file" ); +ksft_perror ("Cannot open file" );return errno; }
@@ -149,7 +149,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) param.num_of_runs =0 ;if (pipe (pipefd)) { -perror ("# Unable to create pipe" ); +ksft_perror ("Unable to create pipe" );return errno; }
@@ -185,7 +185,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)* Just print the error message. * Let while(1) run and wait for itself to be killed. */ -perror ("# failed signaling parent process" ); +ksft_perror ("Failed signaling parent process" );close (pipefd[1 ]);while (1 )
@@ -197,7 +197,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)while (pipe_message !=1 ) {if (read (pipefd[0 ], &pipe_message,sizeof (pipe_message)) <sizeof (pipe_message)) { -perror ("# failed reading from child process" ); +ksft_perror ("Failed reading from child process" );break ; } }
tools/testing/selftests/resctrl/cmt_test.c +1 -1
@@ -37,7 +37,7 @@ static int check_results(struct resctrl_val_param *param, size_t span, int no_ofksft_print_msg ("Checking for pass/fail\n" ); fp =fopen (param->filename,"r" );if (!fp) { -perror ("# Error in opening file\n" ); +ksft_perror ("Error in opening file" );return errno; }
tools/testing/selftests/resctrl/fill_buf.c +1 -1
@@ -115,7 +115,7 @@ static int fill_cache_read(unsigned char *buf, size_t buf_size, bool once)/* Consume read result so that reading memory is not optimized out. */ fp =fopen ("/dev/null" ,"w" );if (!fp) { -perror ("Unable to write to /dev/null" ); +ksft_perror ("Unable to write to /dev/null" );return -1 ; }fprintf (fp,"Sum: %d " , ret);
tools/testing/selftests/resctrl/mba_test.c +1 -1
@@ -109,7 +109,7 @@ static int check_results(void) fp =fopen (output,"r" );if (!fp) { -perror (output); +ksft_perror (output);return errno; }
tools/testing/selftests/resctrl/mbm_test.c +1 -1
@@ -59,7 +59,7 @@ static int check_results(size_t span) fp =fopen (output,"r" );if (!fp) { -perror (output); +ksft_perror (output);return errno; }
tools/testing/selftests/resctrl/resctrl.h +1 -2
@@ -37,9 +37,8 @@#define DEFAULT_SPAN (250 * MB) -#define PARENT_EXIT (err_msg) \ +#define PARENT_EXIT () \ do { \ - perror(err_msg); \ kill(ppid, SIGKILL); \ umount_resctrlfs(); \ exit(EXIT_FAILURE); \
tools/testing/selftests/resctrl/resctrl_val.c +42 -34
239 lines not on this page · raw message
tools/testing/selftests/resctrl/resctrlfs.c +21 -21
157 lines not on this page · raw message
Signature · 1 line
2.30.2
Reinette Chatre
maintainerRe: [PATCH v3 01/29] selftests/resctrl: Convert perror() to ksft_perror() or ksft_print_msg()
Hi Ilpo,
Quoted 8 lines · Ilpo Järvinen
The resctrl selftest code contains a number of
perror()calls. Some of them come with hash character and some don't. The kselftest framework providesksft_perror()that is compatible with test output formatting so it should be used instead of adding custom hash signs.Some
perror()calls are too far away from anything that sets error. For those call sites,ksft_print_msg()must be used instead.
Quoted 8 lines
Convert
perror()toksft_perror()orksft_print_msg().Other related changes:
- Remove hash signs
- Remove trailing stops & newlines fromksft_perror()
- Add terminating newlines for convertedksft_print_msg()
- Use consistent capitalization
Another great cleanup. Also thanks for fixing some non-sensical messages.
...
Quoted 10 lines
tools/testing/selftests/resctrl/cat_test.c +1
-1@@ -149,7 +149,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) param.num_of_runs =0 ;if (pipe (pipefd)) { -perror ("# Unable to create pipe" ); +ksft_perror ("Unable to create pipe" );return errno; }
tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char *cache_type) · line 189
Quoted 6 lines
tools/testing/selftests/resctrl/cat_test.c +1
-1@@ -185,7 +185,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)* Just print the error message. * Let while(1) run and wait for itself to be killed. */ -perror ("# failed signaling parent process" ); +ksft_perror ("Failed signaling parent process" );
Partial writes are not actually errors and it cannot be expected that errno be set in these cases. In these cases I think ksft_print_msg() would be more appropriate.
tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char *cache_type) · line 202
Quoted 10 lines
tools/testing/selftests/resctrl/cat_test.c +1
-1close (pipefd[1 ]);while (1 )@@ -197,7 +197,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)while (pipe_message !=1 ) {if (read (pipefd[0 ], &pipe_message,sizeof (pipe_message)) <sizeof (pipe_message)) { -perror ("# failed reading from child process" ); +ksft_perror ("Failed reading from child process" );break ; }
Same with partial reads.
...
Quoted 6 lines
tools/testing/selftests/resctrl/resctrl_val.c +1
-1@@ -540,14 +540,14 @@ static int print_results_bw(char *filename, int bm_pid, float bw_imc, }else { fp =fopen (filename,"a" );if (!fp) { -perror ("Cannot open results file" ); +ksft_perror ("Cannot open results file" );
tools/testing/selftests/resctrl/resctrl_val.c static int print_results_bw(char *filename, int bm_pid, float bw_imc, · line 552
Quoted 10 lines
tools/testing/selftests/resctrl/resctrl_val.c +1
-1return errno; }if (fprintf (fp,"Pid: %d \t Mem_BW_iMC: %f \t Mem_BW_resc: %lu \t Difference: %lu\n" , bm_pid, bw_imc, bw_resc, diff) <=0 ) { +ksft_perror ("Could not log results" );fclose (fp); -perror ("Could not log results." );return errno;
From what I can tell fprintf() does not set errno on error. Perhaps this should rather be ksft_print_msg()?
...
Quoted 10 lines
tools/testing/selftests/resctrl/resctrl_val.c +4
-2@@ -738,15 +743,17 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par sigact.sa_flags =SA_SIGINFO ;/* Register for "SIGUSR1" signal from parent */ -if (sigaction (SIGUSR1 , &sigact,NULL )) -PARENT_EXIT ("Can't register child for signal" ); +if (sigaction (SIGUSR1 , &sigact,NULL )) { +ksft_perror ("Can't register child for signal" ); +PARENT_EXIT (); + }
tools/testing/selftests/resctrl/resctrl_val.c int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par · line 758
Quoted 10 lines
tools/testing/selftests/resctrl/resctrl_val.c +1
-1/* Tell parent that child is ready */ close (pipefd[0 ]); pipe_message =1 ;if (write (pipefd[1 ], &pipe_message,sizeof (pipe_message)) <sizeof (pipe_message)) { -perror ("# failed signaling parent process" ); +ksft_perror ("Failed signaling parent process" );close (pipefd[1 ]);return -1 ;
another partial write possibility
Quoted 12 lines
tools/testing/selftests/resctrl/resctrl_val.c +2
-1}@@ -755,7 +762,8 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par/* Suspend child until delivery of "SIGUSR1" from parent */ sigsuspend (&sigact.sa_mask); -PARENT_EXIT ("Child is done" ); +ksft_perror ("Child is done" ); +PARENT_EXIT (); }ksft_print_msg ("Benchmark PID: %d\n" , bm_pid);
tools/testing/selftests/resctrl/resctrl_val.c int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par · line 809
Quoted 7 lines
tools/testing/selftests/resctrl/resctrl_val.c +1
-1@@ -796,7 +804,7 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *parwhile (pipe_message !=1 ) {if (read (pipefd[0 ], &pipe_message,sizeof (pipe_message)) <sizeof (pipe_message)) { -perror ("# failed reading message from child process" ); +ksft_perror ("Failed reading message from child process" );close (pipefd[0 ]); goto out;
another partial read possibility
...
Quoted 4 lines
tools/testing/selftests/resctrl/resctrlfs.c +0
-0@@ -348,12 +348,12 @@ static int write_pid_to_tasks(char *tasks, pid_t pid) fp =fopen (tasks,"w" );if (!fp) {
tools/testing/selftests/resctrl/resctrlfs.c static int write_pid_to_tasks(char *tasks, pid_t pid) · line 358
Quoted 10 lines
tools/testing/selftests/resctrl/resctrlfs.c +2
-2-perror ("Failed to open tasks file" ); +ksft_perror ("Failed to open tasks file" );return -1 ; }if (fprintf (fp,"%d\n" , pid) <0 ) { -perror ("Failed to wr pid to tasks file" ); +ksft_perror ("Failed to wr pid to tasks file" );fclose (fp);
another fprintf() that I do not think sets errno on error.
Reinette
Re: [PATCH v3 01/29] selftests/resctrl: Convert perror() to ksft_perror() or ksft_print_msg()
Quoted 33 lines · Reinette Chatre
Hi Ilpo,
Quoted 8 lines · Ilpo Järvinen
The resctrl selftest code contains a number of
perror()calls. Some of them come with hash character and some don't. The kselftest framework providesksft_perror()that is compatible with test output formatting so it should be used instead of adding custom hash signs.Some
perror()calls are too far away from anything that sets error. For those call sites,ksft_print_msg()must be used instead.Quoted 8 lines
Convert
perror()toksft_perror()orksft_print_msg().Other related changes:
- Remove hash signs
- Remove trailing stops & newlines fromksft_perror()
- Add terminating newlines for convertedksft_print_msg()
- Use consistent capitalizationAnother great cleanup. Also thanks for fixing some non-sensical messages.
...
Quoted 9 lines
tools/testing/selftests/resctrl/cat_test.c +1
-1@@ -149,7 +149,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) param.num_of_runs =0 ;if (pipe (pipefd)) { -perror ("# Unable to create pipe" ); +ksft_perror ("Unable to create pipe" );return errno; }
Quoted 10 lines
tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char *cache_type) · line 189
Quoted 7 lines
tools/testing/selftests/resctrl/cat_test.c +1
-1@@ -185,7 +185,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)* Just print the error message. * Let while(1) run and wait for itself to be killed. */ -perror ("# failed signaling parent process" ); +ksft_perror ("Failed signaling parent process" );Partial writes are not actually errors and it cannot be expected that errno be set in these cases. In these cases I think
ksft_print_msg()would be more appropriate.
I can change those to use print instead although I don't think these will fail for other reasons than a real error as the pipe should be empty and only single byte is written to it.
Quoted 10 lines
Quoted 9 lines
tools/testing/selftests/resctrl/resctrl_val.c +1
-1if (fprintf (fp,"Pid: %d \t Mem_BW_iMC: %f \t Mem_BW_resc: %lu \t Difference: %lu\n" , bm_pid, bw_imc, bw_resc, diff) <=0 ) { +ksft_perror ("Could not log results" );fclose (fp); -perror ("Could not log results." );return errno;From what I can tell
fprintf()does not set errno on error. Perhaps thisshould rather be
ksft_print_msg()?
Oh, what a stupid gotcha in libc. I just assumed it does set errno without even checking... because why it wouldn't follow the custom. ...It seems nothing can be relied on :-/.
Signature · 1 line
i.
Reinette Chatre
maintainerRe: [PATCH v3 01/29] selftests/resctrl: Convert perror() to ksft_perror() or ksft_print_msg()
Hi Ilpo,
Quoted 46 lines · Ilpo Järvinen
Quoted 33 lines · Reinette Chatre
Hi Ilpo,
Quoted 8 lines · Ilpo Järvinen
The resctrl selftest code contains a number of
perror()calls. Some of them come with hash character and some don't. The kselftest framework providesksft_perror()that is compatible with test output formatting so it should be used instead of adding custom hash signs.Some
perror()calls are too far away from anything that sets error. For those call sites,ksft_print_msg()must be used instead.Quoted 8 lines
Convert
perror()toksft_perror()orksft_print_msg().Other related changes:
- Remove hash signs
- Remove trailing stops & newlines fromksft_perror()
- Add terminating newlines for convertedksft_print_msg()
- Use consistent capitalizationAnother great cleanup. Also thanks for fixing some non-sensical messages.
...
Quoted 9 lines
tools/testing/selftests/resctrl/cat_test.c +1
-1@@ -149,7 +149,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) param.num_of_runs =0 ;if (pipe (pipefd)) { -perror ("# Unable to create pipe" ); +ksft_perror ("Unable to create pipe" );return errno; }Quoted 10 lines
tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char *cache_type) · line 189
Quoted 7 lines
tools/testing/selftests/resctrl/cat_test.c +1
-1@@ -185,7 +185,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)* Just print the error message. * Let while(1) run and wait for itself to be killed. */ -perror ("# failed signaling parent process" ); +ksft_perror ("Failed signaling parent process" );Partial writes are not actually errors and it cannot be expected that errno be set in these cases. In these cases I think
ksft_print_msg()would be more appropriate.
Quoted 4 lines
I can change those to use print instead although I don't think these will fail for other reasons than a real error as the pipe should be empty and only single byte is written to it.
Apologies, I did not pay attention to the actual size of the message. Yes, leaving it as ksft_perror() is reasonable.
Reinette
PATCH v3 2/29 selftests/resctrl: Return -1 instead of errno on error
In reply to Ilpo JärvinenA number of functions in the resctrl selftests return errno. It is problematic because errno is positive which is often counterintuitive. Also, every sites returning errno prints the error message already with ksft_perror() so there is not much added value in returning the precise error code.
Simply convert all places returning errno to return -1 that is typical userspace error code in case of failures.
While at it, improve resctrl_val() comment to state that 0 means the test was run (either pass or fail).
---
v3:
- New patch
--- tools/testing/selftests/resctrl/cache.c | 6 +++--- tools/testing/selftests/resctrl/cat_test.c | 4 ++-- tools/testing/selftests/resctrl/cmt_test.c | 2 +- tools/testing/selftests/resctrl/mba_test.c | 2 +- tools/testing/selftests/resctrl/mbm_test.c | 2 +- tools/testing/selftests/resctrl/resctrl_val.c | 10 +++++----- tools/testing/selftests/resctrl/resctrlfs.c | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-)
tools/testing/selftests/resctrl/cache.c +3 -3
@@ -126,7 +126,7 @@ static int get_llc_occu_resctrl(unsigned long *llc_occupancy)if (!fp) {ksft_perror ("Failed to open results file" ); -return errno; +return -1 ; }if (fscanf (fp,"%lu" , llc_occupancy) <=0 ) {ksft_perror ("Could not get llc occupancy" );
@@ -146,7 +146,7 @@ static int get_llc_occu_resctrl(unsigned long *llc_occupancy)* @llc_value: perf miss value / * llc occupancy value reported by resctrl FS * -* Return: 0 on success. non-zero on failure. +* Return: 0 on success, < 0 on error. */ static int print_results_cache (char *filename,int bm_pid,unsigned long llc_value)
@@ -161,7 +161,7 @@ static int print_results_cache(char *filename, int bm_pid,if (!fp) {ksft_perror ("Cannot open results file" ); -return errno; +return -1 ; }fprintf (fp,"Pid: %d \t llc_value: %lu\n" , bm_pid, llc_value);fclose (fp);
tools/testing/selftests/resctrl/cat_test.c +2 -2
@@ -53,7 +53,7 @@ static int check_results(struct resctrl_val_param *param, size_t span)if (!fp) {ksft_perror ("Cannot open file" ); -return errno; +return -1 ; }while (fgets (temp,sizeof (temp), fp)) {
@@ -150,7 +150,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)if (pipe (pipefd)) {ksft_perror ("Unable to create pipe" ); -return errno; +return -1 ; }fflush (stdout);
tools/testing/selftests/resctrl/cmt_test.c +1 -1
@@ -39,7 +39,7 @@ static int check_results(struct resctrl_val_param *param, size_t span, int no_ofif (!fp) {ksft_perror ("Error in opening file" ); -return errno; +return -1 ; }while (fgets (temp,sizeof (temp), fp)) {
tools/testing/selftests/resctrl/mba_test.c +1 -1
@@ -111,7 +111,7 @@ static int check_results(void)if (!fp) {ksft_perror (output); -return errno; +return -1 ; } runs =0 ;
tools/testing/selftests/resctrl/mbm_test.c +1 -1
@@ -61,7 +61,7 @@ static int check_results(size_t span)if (!fp) {ksft_perror (output); -return errno; +return -1 ; } runs =0 ;
tools/testing/selftests/resctrl/resctrl_val.c +5 -5
@@ -526,7 +526,7 @@ void signal_handler_unregister(void)* @bw_imc: perf imc counter value * @bw_resc: memory bandwidth value * -* Return: 0 on success. non-zero on failure. +* Return: 0 on success, < 0 on error. */ static int print_results_bw (char *filename,int bm_pid,float bw_imc,unsigned long bw_resc)
@@ -542,14 +542,14 @@ static int print_results_bw(char *filename, int bm_pid, float bw_imc,if (!fp) {ksft_perror ("Cannot open results file" ); -return errno; +return -1 ; }if (fprintf (fp,"Pid: %d \t Mem_BW_iMC: %f \t Mem_BW_resc: %lu \t Difference: %lu\n" , bm_pid, bw_imc, bw_resc, diff) <=0 ) {ksft_perror ("Could not log results" );fclose (fp); -return errno; +return -1 ; }fclose (fp); }
@@ -686,7 +686,7 @@ static void run_benchmark(int signum, siginfo_t *info, void *ucontext)* @benchmark_cmd: benchmark command and its arguments * @param: parameters passed to resctrl_val() * -* Return: 0 on success. non-zero on failure. +* Return: 0 when the test was run, < 0 on error. */ int resctrl_val (const char *const *benchmark_cmd,struct resctrl_val_param *param) {
@@ -814,7 +814,7 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par/* Signal child to start benchmark */ if (sigqueue (bm_pid,SIGUSR1 , value) ==-1 ) {ksft_perror ("sigqueue SIGUSR1 to child" ); - ret = errno; + ret =-1 ; goto out; }
tools/testing/selftests/resctrl/resctrlfs.c +1 -1
@@ -88,7 +88,7 @@ int umount_resctrlfs(void)if (umount (mountpoint)) {ksft_perror ("Unable to umount resctrl" ); -return errno; +return -1 ; }return 0 ;
Signature · 1 line
2.30.2
Re: [PATCH v3 02/29] selftests/resctrl: Return -1 instead of errno on error
Hi Ilpo,
Quoted 3 lines · Ilpo Järvinen
A number of functions in the resctrl selftests return errno. It is problematic because errno is positive which is often counterintuitive. Also, every sites returning errno prints the error message already with
every sites -> every site
Quoted 11 lines
ksft_perror()so there is not much added value in returning the precise error code.Simply convert all places returning errno to return -1 that is typical userspace error code in case of failures.
While at it, improve
resctrl_val()comment to state that 0 means the test was run (either pass or fail).Signed-off-by Ilpo Järvinen <[email protected]>---
Reinette
PATCH v3 3/29 selftests/resctrl: Don't use ctrlc_handler() outside signal handling
In reply to Ilpo Järvinenperf_event_open_llc_miss() calls ctrlc_handler() to cleanup if perf_event_open() returns an error. Those cleanups, however, are not the responsibility of perf_event_open_llc_miss() and it thus interferes unnecessarily with the usual cleanup pattern. Worse yet, ctrlc_handler() calls exit() in the end preventing the ordinary cleanup done in the calling function from executing.
ctrlc_handler() should only be used as a signal handler, not during normal error handling.
Remove call to ctrlc_handler() from perf_event_open_llc_miss(). As unmounting resctrlfs and test cleanup are already handled properly by error rollbacks in the calling functions, no other changes are necessary.
---
v3:
- Corrected typo in the changelog
--- tools/testing/selftests/resctrl/cache.c | 1 - 1 file changed, 1 deletion(-)
tools/testing/selftests/resctrl/cache.c +0 -1
@@ -41,7 +41,6 @@ static int perf_event_open_llc_miss(pid_t pid, int cpu_no) PERF_FLAG_FD_CLOEXEC);if (fd_lm ==-1 ) {ksft_perror ("Error opening leader" ); -ctrlc_handler (0 ,NULL ,NULL );return -1 ; }
Signature · 1 line
2.30.2
PATCH v3 4/29 selftests/resctrl: Change function comments to say < 0 on error
In reply to Ilpo JärvinenA number function comments state the function return non-zero on failure but in reality they can only return 0 on success and < 0 on error.
Update the comments to say < 0 on error to match the behavior.
While at it, improve cat_val() comment to state that 0 means the test was run (either pass or fail).
---
v3:
- New patch
--- tools/testing/selftests/resctrl/cache.c | 2 +- tools/testing/selftests/resctrl/resctrlfs.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/resctrl/cache.c +1 -1
@@ -206,7 +206,7 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid)* @param: parameters passed to cache_val() * @span: buffer size for the benchmark * -* Return: 0 on success. non-zero on failure. +* Return: 0 when the test was run, < 0 on error. */ int cat_val (struct resctrl_val_param *param,size_t span) {
tools/testing/selftests/resctrl/resctrlfs.c +5 -5
@@ -56,7 +56,7 @@ static int find_resctrl_mount(char *buffer)* Mounts resctrl FS. Fails if resctrl FS is already mounted to avoid * pre-existing settings interfering with the test results. * -* Return: 0 on success, non-zero on failure +* Return: 0 on success, < 0 on error. */ int mount_resctrlfs (void ) {
@@ -276,7 +276,7 @@ int get_core_sibling(int cpu_no)* @bm_pid: PID that should be binded * @cpu_no: CPU number at which the PID would be binded * -* Return: 0 on success, non-zero on failure +* Return: 0 on success, < 0 on error. */ int taskset_benchmark (pid_t bm_pid,int cpu_no) {
@@ -300,7 +300,7 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no)* @grp: Full path and name of the group * @parent_grp: Full path and name of the parent group * -* Return: 0 on success, non-zero on failure +* Return: 0 on success, < 0 on error. */ static int create_grp (const char *grp_name,char *grp,const char *parent_grp) {
@@ -376,7 +376,7 @@ static int write_pid_to_tasks(char *tasks, pid_t pid)* pid is not written, this means that pid is in con_mon grp and hence * should consult con_mon grp's mon_data directory for results. * -* Return: 0 on success, non-zero on failure +* Return: 0 on success, < 0 on error. */ int write_bm_pid_to_resctrl (pid_t bm_pid,char *ctrlgrp,char *mongrp,char *resctrl_val)
@@ -435,7 +435,7 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,* Update schemata of a con_mon grp *only* if requested resctrl feature is * allocation type * -* Return: 0 on success, non-zero on failure +* Return: 0 on success, < 0 on error. */ int write_schemata (char *ctrlgrp,char *schemata,int cpu_no,char *resctrl_val) {
Signature · 1 line
2.30.2
Re: [PATCH v3 04/29] selftests/resctrl: Change function comments to say < 0 on error
Hi Ilpo,
Quoted 11 lines · Ilpo Järvinen
A number function comments state the function return non-zero on failure but in reality they can only return 0 on success and < 0 on error.
Update the comments to say < 0 on error to match the behavior.
While at it, improve
cat_val()comment to state that 0 means the test was run (either pass or fail).Signed-off-by Ilpo Järvinen <[email protected]>---
Reinette
PATCH v3 5/29 selftests/resctrl: Split fill_buf to allow tests finer-grained control
In reply to Ilpo JärvinenMBM, MBA and CMT test cases call run_fill_buf() that in turn calls fill_cache() to alloc and loop indefinitely around the buffer. This binds buffer allocation and running the benchmark into a single bundle so that a selftest cannot allocate a buffer once and reuse it. CAT test doesn't want to loop around the buffer continuously and after rewrite it needs the ability to allocate the buffer separately.
Split buffer allocation out of fill_cache() into alloc_buffer(). This change is part of preparation for the new CAT test that allocates a buffer and does multiple passes over the same buffer (but not in an infinite loop).
---
v3:
- Moved error printout removal to other patch
--- tools/testing/selftests/resctrl/fill_buf.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
tools/testing/selftests/resctrl/fill_buf.c +15 -6
@@ -135,24 +135,34 @@ static int fill_cache_write(unsigned char *buf, size_t buf_size, bool once)return 0 ; } -static int fill_cache (size_t buf_size,int memflush,int op,bool once) +static unsigned char *alloc_buffer (size_t buf_size,int memflush) {unsigned char *buf; -int ret; buf =malloc_and_init_memory (buf_size);if (!buf) -return -1 ; +return NULL ;/* Flush the memory before using to avoid "cache hot pages" effect */ if (memflush)mem_flush (buf, buf_size); +return buf; +} + +static int fill_cache (size_t buf_size,int memflush,int op,bool once) +{ +unsigned char *buf; +int ret; + + buf =alloc_buffer (buf_size, memflush); +if (!buf) +return -1 ; +if (op ==0 ) ret =fill_cache_read (buf, buf_size, once);else ret =fill_cache_write (buf, buf_size, once); -free (buf);if (ret) {
@@ -160,8 +170,7 @@ static int fill_cache(size_t buf_size, int memflush, int op, bool once)return -1 ; } - -return 0 ; +return ret; }int run_fill_buf (size_t span,int memflush,int op,bool once)
Signature · 1 line
2.30.2
PATCH v3 6/29 selftests/resctrl: Refactor fill_buf functions
In reply to Ilpo JärvinenThere are unnecessary nested calls in fill_buf.c:
- run_fill_buf() calls fill_cache()
- alloc_buffer() calls malloc_and_init_memory()
Simplify the code flow and remove those unnecessary call levels by moving the called code inside the calling function and remove the duplicated error print.
Resolve the difference in run_fill_buf() and fill_cache() parameter name into 'buf_size' which is more descriptive than 'span'. Also, while moving the allocation related code, rename 'p' into 'buf' to be consistent in naming the variables.
---
v3:
- Moved error printout remove to this patch
--- tools/testing/selftests/resctrl/fill_buf.c | 59 +++++++--------------- tools/testing/selftests/resctrl/resctrl.h | 2 +- 2 files changed, 18 insertions(+), 43 deletions(-)
tools/testing/selftests/resctrl/fill_buf.c +17 -42
@@ -51,29 +51,6 @@ static void mem_flush(unsigned char *buf, size_t buf_size)sb (); } -static void *malloc_and_init_memory (size_t buf_size) -{ -void *p =NULL ; -uint64_t *p64; -size_t s64; -int ret; - - ret =posix_memalign (&p,PAGE_SIZE , buf_size); -if (ret <0 ) -return NULL ; - - p64 = (uint64_t *)p; - s64 = buf_size /sizeof (uint64_t ); - -while (s64 >0 ) { - *p64 = (uint64_t )rand (); - p64 += (CL_SIZE /sizeof (uint64_t )); - s64 -= (CL_SIZE /sizeof (uint64_t )); - } - -return p; -} -static int fill_one_span_read (unsigned char *buf,size_t buf_size) {unsigned char *end_ptr = buf + buf_size;
@@ -137,12 +114,25 @@ static int fill_cache_write(unsigned char *buf, size_t buf_size, bool once)static unsigned char *alloc_buffer (size_t buf_size,int memflush) { -unsigned char *buf; +void *buf =NULL ; +uint64_t *p64; +size_t s64; +int ret; - buf =malloc_and_init_memory (buf_size); -if (!buf) + ret =posix_memalign (&buf,PAGE_SIZE , buf_size); +if (ret <0 )return NULL ; +/* Initialize the buffer */ + p64 = buf; + s64 = buf_size /sizeof (uint64_t ); + +while (s64 >0 ) { + *p64 = (uint64_t )rand (); + p64 += (CL_SIZE /sizeof (uint64_t )); + s64 -= (CL_SIZE /sizeof (uint64_t )); + } +/* Flush the memory before using to avoid "cache hot pages" effect */ if (memflush)mem_flush (buf, buf_size);
@@ -150,7 +140,7 @@ static unsigned char *alloc_buffer(size_t buf_size, int memflush)return buf; } -static int fill_cache (size_t buf_size,int memflush,int op,bool once) +int run_fill_buf (size_t buf_size,int memflush,int op,bool once) {unsigned char *buf;int ret;
@@ -164,21 +154,6 @@ static int fill_cache(size_t buf_size, int memflush, int op, bool once)else ret =fill_cache_write (buf, buf_size, once);free (buf); - -if (ret) { -printf ("\n Error in fill cache read/write...\n" ); -return -1 ; - } - -return ret; -} - -int run_fill_buf (size_t span,int memflush,int op,bool once) -{ -size_t cache_size = span; -int ret; - - ret =fill_cache (cache_size, memflush, op, once);if (ret) {printf ("\n Error in fill cache\n" );return -1 ;
tools/testing/selftests/resctrl/resctrl.h +1 -1
@@ -91,7 +91,7 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, char *resctrl_val);int perf_event_open (struct perf_event_attr *hw_event,pid_t pid,int cpu,int group_fd,unsigned long flags); -int run_fill_buf (size_t span,int memflush,int op,bool once); +int run_fill_buf (size_t buf_size,int memflush,int op,bool once);int resctrl_val (const char *const *benchmark_cmd,struct resctrl_val_param *param);int mbm_bw_change (int cpu_no,const char *const *benchmark_cmd);void tests_cleanup (void );
Signature · 1 line
2.30.2
PATCH v3 7/29 selftests/resctrl: Refactor get_cbm_mask() and rename to get_full_cbm()
In reply to Ilpo JärvinenCallers of get_cbm_mask() are required to pass a string into which the capacity bitmask (CBM) is read. Neither CAT nor CMT tests need the bitmask as string but just convert it into an unsigned long value.
Another limitation is that the bit mask reader can only read .../cbm_mask files.
Generalize the bit mask reading function into get_bit_mask() such that it can be used to handle other files besides the .../cbm_mask and handles the unsigned long conversion within get_bit_mask() using fscanf(). Change get_cbm_mask() to use get_bit_mask() and rename it to get_full_cbm() to better indicate what the function does.
Return error from get_full_cbm() if the bitmask is zero for some reason because it makes the code more robust as the selftests naturally assume the bitmask has some bits.
Also mark cache_type const while at it and remove useless comments that are related to processing of CBM bits.
---
v3:
- Grammar fix changelog
- Zero bit mask returns error
--- tools/testing/selftests/resctrl/cat_test.c | 7 +-- tools/testing/selftests/resctrl/cmt_test.c | 5 +- tools/testing/selftests/resctrl/resctrl.h | 2 +- tools/testing/selftests/resctrl/resctrlfs.c | 51 +++++++++++++++------ 4 files changed, 41 insertions(+), 24 deletions(-)
tools/testing/selftests/resctrl/cat_test.c +1 -6
@@ -93,25 +93,20 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)int ret, pipefd[2 ], sibling_cpu_no;unsigned long cache_size =0 ;unsigned long long_mask; -char cbm_mask[256 ];int count_of_bits;char pipe_message;size_t span; -/* Get default cbm mask for L3/L2 cache */ - ret =get_cbm_mask (cache_type, cbm_mask); + ret =get_full_cbm (cache_type, &long_mask);if (ret)return ret; - long_mask =strtoul (cbm_mask,NULL ,16 ); -/* Get L3/L2 cache size */ ret =get_cache_size (cpu_no, cache_type, &cache_size);if (ret)return ret;ksft_print_msg ("Cache size :%lu\n" , cache_size); -/* Get max number of bits from default-cabm mask */ count_of_bits =count_bits (long_mask);if (!n)
tools/testing/selftests/resctrl/cmt_test.c +1 -4
@@ -75,17 +75,14 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd)unsigned long cache_size =0 ;unsigned long long_mask;char *span_str =NULL ; -char cbm_mask[256 ];int count_of_bits;size_t span;int ret, i; - ret =get_cbm_mask ("L3" , cbm_mask); + ret =get_full_cbm ("L3" , &long_mask);if (ret)return ret; - long_mask =strtoul (cbm_mask,NULL ,16 ); - ret =get_cache_size (cpu_no,"L3" , &cache_size);if (ret)return ret;
tools/testing/selftests/resctrl/resctrl.h +1 -1
@@ -98,7 +98,7 @@ void tests_cleanup(void);void mbm_test_cleanup (void );int mba_schemata_change (int cpu_no,const char *const *benchmark_cmd);void mba_test_cleanup (void ); -int get_cbm_mask (char *cache_type,char *cbm_mask); +int get_full_cbm (const char *cache_type,unsigned long *mask);int get_cache_size (int cpu_no,char *cache_type,unsigned long *cache_size);void ctrlc_handler (int signum,siginfo_t *info,void *ptr);int signal_handler_register (void );
tools/testing/selftests/resctrl/resctrlfs.c +38 -13
74 lines not on this page · raw message
Signature · 1 line
2.30.2
Reinette Chatre
maintainerRe: [PATCH v3 07/29] selftests/resctrl: Refactor get_cbm_mask() and rename to get_full_cbm()
Hi Ilpo,
Quoted 20 lines · Ilpo Järvinen
tools/testing/selftests/resctrl/resctrlfs.c +5
-8-int get_cbm_mask (char *cache_type,char *cbm_mask) +static int get_bit_mask (const char *filename,unsigned long *mask) { -char cbm_mask_path[1024 ];FILE *fp; -if (!cbm_mask) +if (!filename || !mask)return -1 ; -sprintf (cbm_mask_path,"%s/%s/cbm_mask" ,INFO_PATH , cache_type); - - fp =fopen (cbm_mask_path,"r" ); + fp =fopen (filename,"r" );if (!fp) { -ksft_perror ("Failed to open cache level" ); - +fprintf (stderr,"Failed to open bit mask file '%s': %s\n" , + filename,strerror (errno));return -1 ;
tools/testing/selftests/resctrl/resctrlfs.c int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size) · line 224
Quoted 10 lines
tools/testing/selftests/resctrl/resctrlfs.c +4
-2} -if (fscanf (fp,"%s" , cbm_mask) <=0 ) { -ksft_perror ("Could not get max cbm_mask" ); + +if (fscanf (fp,"%lx" , mask) <=0 ) { +fprintf (stderr,"Could not read bit mask file '%s': %s\n" , + filename,strerror (errno));fclose (fp);return -1 ;
After seeing the new effort to correct the perror() messages it is not obvious to me why this patch changes these particular messages to use fprintf(stderr, ...).
Reinette
Re: [PATCH v3 07/29] selftests/resctrl: Refactor get_cbm_mask() and rename to get_full_cbm()
Quoted 33 lines · Reinette Chatre
Hi Ilpo,
Quoted 29 lines · Ilpo Järvinen
tools/testing/selftests/resctrl/resctrlfs.c +9
-10-int get_cbm_mask (char *cache_type,char *cbm_mask) +static int get_bit_mask (const char *filename,unsigned long *mask) { -char cbm_mask_path[1024 ];FILE *fp; -if (!cbm_mask) +if (!filename || !mask)return -1 ; -sprintf (cbm_mask_path,"%s/%s/cbm_mask" ,INFO_PATH , cache_type); - - fp =fopen (cbm_mask_path,"r" ); + fp =fopen (filename,"r" );if (!fp) { -ksft_perror ("Failed to open cache level" ); - +fprintf (stderr,"Failed to open bit mask file '%s': %s\n" , + filename,strerror (errno));return -1 ; } -if (fscanf (fp,"%s" , cbm_mask) <=0 ) { -ksft_perror ("Could not get max cbm_mask" ); + +if (fscanf (fp,"%lx" , mask) <=0 ) { +fprintf (stderr,"Could not read bit mask file '%s': %s\n" , + filename,strerror (errno));fclose (fp);
Quoted 5 lines
Quoted 1 line
return -1;
After seeing the new effort to correct the
perror()messages it is not obvious to me why this patch changes these particular messages to usefprintf(stderr, ...).
Yeah, good point, thanks. Somehow I dismissed the opportunity and thought there's no need to do anything even if this came up during series conflict resolution phase.
Signature · 1 line
i.
PATCH v3 8/29 selftests/resctrl: Mark get_cache_size() cache_type const
In reply to Ilpo Järvinenget_cache_size() does not modify cache_type so it could be const.
Mark cache_type const so that const char * can be passed to it. This prevents warnings once many of the test parameters are marked const.
--- tools/testing/selftests/resctrl/resctrl.h | 2 +- tools/testing/selftests/resctrl/resctrlfs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/resctrl/resctrl.h +1 -1
@@ -99,7 +99,7 @@ void mbm_test_cleanup(void);int mba_schemata_change (int cpu_no,const char *const *benchmark_cmd);void mba_test_cleanup (void );int get_full_cbm (const char *cache_type,unsigned long *mask); -int get_cache_size (int cpu_no,char *cache_type,unsigned long *cache_size); +int get_cache_size (int cpu_no,const char *cache_type,unsigned long *cache_size);void ctrlc_handler (int signum,siginfo_t *info,void *ptr);int signal_handler_register (void );void signal_handler_unregister (void );
tools/testing/selftests/resctrl/resctrlfs.c +1 -1
@@ -138,7 +138,7 @@ int get_resource_id(int cpu_no, int *resource_id)* * Return: = 0 on success, < 0 on failure. */ -int get_cache_size (int cpu_no,char *cache_type,unsigned long *cache_size) +int get_cache_size (int cpu_no,const char *cache_type,unsigned long *cache_size) {char cache_path[1024 ], cache_str[64 ];int length, i, cache_num;
Signature · 1 line
2.30.2
PATCH v3 9/29 selftests/resctrl: Create cache_portion_size() helper
In reply to Ilpo JärvinenCAT 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.
--- tools/testing/selftests/resctrl/cat_test.c | 10 +++++----- tools/testing/selftests/resctrl/cmt_test.c | 8 ++++---- tools/testing/selftests/resctrl/resctrl.h | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-)
tools/testing/selftests/resctrl/cat_test.c +5 -5
@@ -91,7 +91,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) {unsigned long l_mask, l_mask_1;int ret, pipefd[2 ], sibling_cpu_no; -unsigned long cache_size =0 ; +unsigned long cache_total_size =0 ;unsigned long long_mask;int count_of_bits;char pipe_message;
@@ -102,10 +102,10 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)return ret;/* Get L3/L2 cache size */ - ret =get_cache_size (cpu_no, cache_type, &cache_size); + ret =get_cache_size (cpu_no, cache_type, &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);
@@ -136,7 +136,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)/* Set param values for parent thread which will be allocated bitmask * with (max_bits - n) bits */ - span = cache_size * (count_of_bits - n) / count_of_bits; + span =cache_portion_size (cache_total_size, l_mask, long_mask);strcpy (param.ctrlgrp,"c2" );strcpy (param.mongrp,"m2" );strcpy (param.filename,RESULT_FILE_NAME2 );
@@ -158,7 +158,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) param.mask = l_mask_1;strcpy (param.ctrlgrp,"c1" );strcpy (param.mongrp,"m1" ); - span = cache_size * n / count_of_bits; + span =cache_portion_size (cache_total_size, l_mask_1, long_mask);strcpy (param.filename,RESULT_FILE_NAME1 ); param.num_of_runs =0 ; param.cpu_no = sibling_cpu_no;
tools/testing/selftests/resctrl/cmt_test.c +4 -4
@@ -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 */
tools/testing/selftests/resctrl/resctrl.h +15 -0
@@ -116,4 +116,19 @@ int show_cache_info(unsigned long sum_llc_val, int no_of_bits, unsigned long max_diff_percent, unsigned long num_of_runs, bool platform, bool cmt); +/* +* cache_portion_size - Calculate the size of a cache portion +* @cache_size: Total cache size in bytes +* @portion_mask: Cache portion mask +* @full_cache_mask: Full Cache Bit Mask (CBM) for the cache +* +* Return: The size of the cache portion in bytes. +*/ +static inline int cache_portion_size (unsigned long cache_size, +unsigned long portion_mask, +unsigned long full_cache_mask) +{ +return cache_size *count_bits (portion_mask) /count_bits (full_cache_mask); +} +#endif /* RESCTRL_H */
Signature · 1 line
2.30.2
Reinette Chatre
maintainerRe: [PATCH v3 09/29] selftests/resctrl: Create cache_portion_size() helper
Hi Ilpo,
Quoted 5 lines · Ilpo Järvinen
tools/testing/selftests/resctrl/resctrl.h +5
-0+/* +* cache_portion_size - Calculate the size of a cache portion +* @cache_size: Total cache size in bytes +* @portion_mask: Cache portion mask +* @full_cache_mask: Full Cache Bit Mask (CBM) for the cache
tools/testing/selftests/resctrl/resctrl.h int show_cache_info(unsigned long sum_llc_val, int no_of_bits, · line 133
Quoted 10 lines
tools/testing/selftests/resctrl/resctrl.h +10
-0+* +* Return: The size of the cache portion in bytes. +*/ +static inline int cache_portion_size (unsigned long cache_size, +unsigned long portion_mask, +unsigned long full_cache_mask) +{ +return cache_size *count_bits (portion_mask) /count_bits (full_cache_mask); +} +
Even after you added the new zero check the static checker I tried was not able to recognize that this is safe. Could you please add a check to ensure that there will be no divide-by-zero here?
Reinette
Re: [PATCH v3 09/29] selftests/resctrl: Create cache_portion_size() helper
Quoted 14 lines · Reinette Chatre
Hi Ilpo,
Quoted 11 lines · Ilpo Järvinen
tools/testing/selftests/resctrl/resctrl.h +11
-0+/* +* cache_portion_size - Calculate the size of a cache portion +* @cache_size: Total cache size in bytes +* @portion_mask: Cache portion mask +* @full_cache_mask: Full Cache Bit Mask (CBM) for the cache +* +* Return: The size of the cache portion in bytes. +*/ +static inline int cache_portion_size (unsigned long cache_size, +unsigned long portion_mask, +unsigned long full_cache_mask)
Quoted 8 lines
tools/testing/selftests/resctrl/resctrl.h int show_cache_info(unsigned long sum_llc_val, int no_of_bits, · line 133
Quoted 4 lines
tools/testing/selftests/resctrl/resctrl.h +4
-0+{ +return cache_size *count_bits (portion_mask) /count_bits (full_cache_mask); +} +Even after you added the new zero check the static checker I tried was not able to recognize that this is safe. Could you please add a check to ensure that there will be no divide-by-zero here?
Okay. I also now noticed the return type is not what it should be.
Signature · 1 line
i.
PATCH v3 10/29 selftests/resctrl: Exclude shareable bits from schemata in CAT test
In reply to Ilpo JärvinenCAT test doesn't take shareable bits into account, i.e., the test might be sharing cache with some devices (e.g., graphics).
Introduce get_mask_no_shareable() and use it to provision an environment for CAT test where the allocated LLC is isolated better. Excluding shareable_bits may create hole(s) into the cbm_mask, thus add a new helper count_contiguous_bits() to find the longest contiguous set of CBM bits.
create_bit_mask() is needed by an upcoming CAT test rewrite so make it available in resctrl.h right away.
---
v3:
- Tweak comments
- Make get_shareable_mask() static
--- tools/testing/selftests/resctrl/cat_test.c | 12 ++- tools/testing/selftests/resctrl/resctrl.h | 2 + tools/testing/selftests/resctrl/resctrlfs.c | 89 +++++++++++++++++++++ 3 files changed, 99 insertions(+), 4 deletions(-)
tools/testing/selftests/resctrl/cat_test.c +8 -4
@@ -89,15 +89,19 @@ void cat_test_cleanup(void)int cat_perf_miss_val (int cpu_no,int n,char *cache_type) { +unsigned long full_cache_mask, long_mask;unsigned long l_mask, l_mask_1;int ret, pipefd[2 ], sibling_cpu_no;unsigned long cache_total_size =0 ; -unsigned long long_mask;int count_of_bits;char pipe_message;size_t span; - ret =get_full_cbm (cache_type, &long_mask); + ret =get_full_cbm (cache_type, &full_cache_mask); +if (ret) +return ret; +/* Get the largest contiguous exclusive portion of the cache */ + ret =get_mask_no_shareable (cache_type, &long_mask);if (ret)return ret;
@@ -136,7 +140,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)/* Set param values for parent thread which will be allocated bitmask * with (max_bits - n) bits */ - span =cache_portion_size (cache_total_size, l_mask, long_mask); + span =cache_portion_size (cache_total_size, l_mask, full_cache_mask);strcpy (param.ctrlgrp,"c2" );strcpy (param.mongrp,"m2" );strcpy (param.filename,RESULT_FILE_NAME2 );
@@ -158,7 +162,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) param.mask = l_mask_1;strcpy (param.ctrlgrp,"c1" );strcpy (param.mongrp,"m1" ); - span =cache_portion_size (cache_total_size, l_mask_1, long_mask); + span =cache_portion_size (cache_total_size, l_mask_1, full_cache_mask);strcpy (param.filename,RESULT_FILE_NAME1 ); param.num_of_runs =0 ; param.cpu_no = sibling_cpu_no;
tools/testing/selftests/resctrl/resctrl.h +2 -0
@@ -98,7 +98,9 @@ void tests_cleanup(void);void mbm_test_cleanup (void );int mba_schemata_change (int cpu_no,const char *const *benchmark_cmd);void mba_test_cleanup (void ); +unsigned long create_bit_mask (unsigned int start,unsigned int len);int get_full_cbm (const char *cache_type,unsigned long *mask); +int get_mask_no_shareable (const char *cache_type,unsigned long *mask);int get_cache_size (int cpu_no,const char *cache_type,unsigned long *cache_size);void ctrlc_handler (int signum,siginfo_t *info,void *ptr);int signal_handler_register (void );
tools/testing/selftests/resctrl/resctrlfs.c +89 -0
101 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH v3 10/29] selftests/resctrl: Exclude shareable bits from schemata in CAT test
Hi Ilpo,
Quoted 9 lines · Ilpo Järvinen
CAT test doesn't take shareable bits into account, i.e., the test might be sharing cache with some devices (e.g., graphics).
Introduce
get_mask_no_shareable()and use it to provision an environment for CAT test where the allocated LLC is isolated better. Excludingshareable_bitsmay create hole(s) into thecbm_mask, thus add a new helpercount_contiguous_bits()to find the longest contiguous set of CBM bits.
Quoted 5 lines
create_bit_mask()is needed by an upcoming CAT test rewrite so make it available inresctrl.hright away.Signed-off-by Ilpo Järvinen <[email protected]>---
Reinette
PATCH v3 11/29 selftests/resctrl: Split measure_cache_vals()
In reply to Ilpo Järvinenmeasure_cache_vals() does a different thing depending on the test case that called it:
- For CAT, it measures LLC misses through perf.
- For CMT, it measures LLC occupancy through resctrl.
Split these two functionalities into own functions the CAT and CMT tests can call directly. Replace passing the struct resctrl_val_param parameter with the filename because it's more generic and all those functions need out of resctrl_val.
---
v3:
- Return directly without storing result into ret variable first
- llc -> LLC
--- tools/testing/selftests/resctrl/cache.c | 64 +++++++++++-------- tools/testing/selftests/resctrl/resctrl.h | 2 +- tools/testing/selftests/resctrl/resctrl_val.c | 2 +- 3 files changed, 41 insertions(+), 27 deletions(-)
tools/testing/selftests/resctrl/cache.c +39 -25
@@ -147,7 +147,7 @@ static int get_llc_occu_resctrl(unsigned long *llc_occupancy)* * Return: 0 on success, < 0 on error. */ -static int print_results_cache (char *filename,int bm_pid, +static int print_results_cache (const char *filename,int bm_pid,unsigned long llc_value) {FILE *fp;
@@ -169,35 +169,49 @@ static int print_results_cache(char *filename, int bm_pid,return 0 ; } -int measure_cache_vals (struct resctrl_val_param *param,int bm_pid) +/* +* perf_event_measure - Measure perf events +* @filename: Filename for writing the results +* @bm_pid: PID that runs the benchmark +* +* Measures perf events (e.g., cache misses) and writes the results into +* @filename. @bm_pid is written to the results file along with the measured +* value. +* +* Return: =0 on success. <0 on failure. +*/ +static int perf_event_measure (const char *filename,int bm_pid) { -unsigned long llc_perf_miss =0 , llc_occu_resc =0 , llc_value =0 ; +unsigned long llc_perf_miss =0 ;int ret; -/* -* Measure cache miss from perf. -*/ -if (!strncmp (param->resctrl_val,CAT_STR ,sizeof (CAT_STR ))) { - ret =get_llc_perf (&llc_perf_miss); -if (ret <0 ) -return ret; - llc_value = llc_perf_miss; - } + ret =get_llc_perf (&llc_perf_miss); +if (ret <0 ) +return ret; -/* -* Measure llc occupancy from resctrl. -*/ -if (!strncmp (param->resctrl_val,CMT_STR ,sizeof (CMT_STR ))) { - ret =get_llc_occu_resctrl (&llc_occu_resc); -if (ret <0 ) -return ret; - llc_value = llc_occu_resc; - } - ret =print_results_cache (param->filename, bm_pid, llc_value); -if (ret) +return print_results_cache (filename, bm_pid, llc_perf_miss); +} + +/* +* measure_llc_resctrl - Measure resctrl LLC value from resctrl +* @filename: Filename for writing the results +* @bm_pid: PID that runs the benchmark +* +* Measures LLC occupancy from resctrl and writes the results into @filename. +* @bm_pid is written to the results file along with the measured value. +* +* Return: =0 on success. <0 on failure. +*/ +int measure_llc_resctrl (const char *filename,int bm_pid) +{ +unsigned long llc_occu_resc =0 ; +int ret; + + ret =get_llc_occu_resctrl (&llc_occu_resc); +if (ret <0 )return ret; -return 0 ; +return print_results_cache (filename, bm_pid, llc_occu_resc); }/*
@@ -252,7 +266,7 @@ int cat_val(struct resctrl_val_param *param, size_t span) }sleep (1 ); - ret =measure_cache_vals (param, bm_pid); + ret =perf_event_measure (param->filename, bm_pid);if (ret) goto pe_close; }
tools/testing/selftests/resctrl/resctrl.h +1 -1
@@ -112,7 +112,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd);unsigned int count_bits (unsigned long n);void cmt_test_cleanup (void );int get_core_sibling (int cpu_no); -int measure_cache_vals (struct resctrl_val_param *param,int bm_pid); +int measure_llc_resctrl (const char *filename,int bm_pid); int show_cache_info(unsigned long sum_llc_val, int no_of_bits, size_t cache_span, unsigned long max_diff, unsigned long max_diff_percent, unsigned long num_of_runs,
tools/testing/selftests/resctrl/resctrl_val.c +1 -1
@@ -838,7 +838,7 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *parbreak ; }else if (!strncmp (resctrl_val,CMT_STR ,sizeof (CMT_STR ))) {sleep (1 ); - ret =measure_cache_vals (param, bm_pid); + ret =measure_llc_resctrl (param->filename, bm_pid);if (ret)break ; }
Signature · 1 line
2.30.2
Re: [PATCH v3 11/29] selftests/resctrl: Split measure_cache_vals()
Hi Ilpo,
Quoted 10 lines · Ilpo Järvinen
measure_cache_vals()does a different thing depending on the test case that called it:
- For CAT, it measures LLC misses through perf.
- For CMT, it measures LLC occupancy through resctrl.Split these two functionalities into own functions the CAT and CMT tests can call directly. Replace passing the struct
resctrl_val_paramparameter with the filename because it's more generic and all those functions need out ofresctrl_val.
Quoted 4 lines
Co-developed-by Fenghua Yu <[email protected]>Signed-off-by Fenghua Yu <[email protected]>Signed-off-by Ilpo Järvinen <[email protected]>---
Reinette
PATCH v3 12/29 selftests/resctrl: Split show_cache_info() to test specific and generic parts
In reply to Ilpo Järvinenshow_cache_info() calculates results and provides generic cache information. This makes it hard to alter pass/fail conditions.
Separate the test specific checks into CAT and CMT test files and leave only the generic information part into show_cache_info().
--- tools/testing/selftests/resctrl/cache.c | 42 +++++----------------- tools/testing/selftests/resctrl/cat_test.c | 30 ++++++++++++++-- tools/testing/selftests/resctrl/cmt_test.c | 32 +++++++++++++++-- tools/testing/selftests/resctrl/resctrl.h | 6 ++-- 4 files changed, 66 insertions(+), 44 deletions(-)
tools/testing/selftests/resctrl/cache.c +8 -34
@@ -279,43 +279,17 @@ int cat_val(struct resctrl_val_param *param, size_t span) }/* -* show_cache_info: show cache test result information -* @sum_llc_val: sum of LLC cache result data -* @no_of_bits: number of bits -* @cache_span: cache span in bytes for CMT or in lines for CAT -* @max_diff: max difference -* @max_diff_percent: max difference percentage -* @num_of_runs: number of runs -* @platform: show test information on this platform -* @cmt: CMT test or CAT test -* -* Return: 0 on success. non-zero on failure. +* show_cache_info - Show generic cache test information +* @no_of_bits: Number of bits +* @avg_llc_val: Average of LLC cache result data +* @cache_span: Cache span +* @lines: @cache_span in lines or bytes */ -int show_cache_info (unsigned long sum_llc_val,int no_of_bits, -size_t cache_span,unsigned long max_diff, -unsigned long max_diff_percent,unsigned long num_of_runs, -bool platform,bool cmt) +void show_cache_info (int no_of_bits,unsigned long avg_llc_val, +size_t cache_span,bool lines) { -unsigned long avg_llc_val =0 ; -float diff_percent; -long avg_diff =0 ; -int ret; - - avg_llc_val = sum_llc_val / num_of_runs; - avg_diff = (long )abs (cache_span - avg_llc_val); - diff_percent = ((float )cache_span - avg_llc_val) / cache_span *100 ; - - ret = platform &&abs ((int )diff_percent) > max_diff_percent && - (cmt ? (abs (avg_diff) > max_diff) : true); - -ksft_print_msg ("%s Check cache miss rate within %lu%%\n" , - ret ?"Fail:" :"Pass:" , max_diff_percent); - -ksft_print_msg ("Percent diff=%d\n" ,abs ((int )diff_percent));ksft_print_msg ("Number of bits: %d\n" , no_of_bits);ksft_print_msg ("Average LLC val: %lu\n" , avg_llc_val); -ksft_print_msg ("Cache span (%s): %zu\n" , cmt ?"bytes" :"lines" , +ksft_print_msg ("Cache span (%s): %zu\n" , lines ?"lines" :"bytes" , cache_span); - -return ret; }
tools/testing/selftests/resctrl/cat_test.c +27 -3
@@ -41,6 +41,30 @@ static int cat_setup(struct resctrl_val_param *p)return ret; } +static int show_results_info (unsigned long sum_llc_val,int no_of_bits, +unsigned long cache_span,unsigned long max_diff, +unsigned long max_diff_percent,unsigned long num_of_runs, +bool platform) +{ +unsigned long avg_llc_val =0 ; +float diff_percent; +int ret; + + avg_llc_val = sum_llc_val / num_of_runs; + diff_percent = ((float )cache_span - avg_llc_val) / cache_span *100 ; + + ret = platform &&abs ((int )diff_percent) > max_diff_percent; + +ksft_print_msg ("%s Check cache miss rate within %lu%%\n" , + ret ?"Fail:" :"Pass:" , max_diff_percent); + +ksft_print_msg ("Percent diff=%d\n" ,abs ((int )diff_percent)); + +show_cache_info (no_of_bits, avg_llc_val, cache_span, true); + +return ret; +} +static int check_results (struct resctrl_val_param *param,size_t span) {char *token_array[8 ], temp[512 ];
@@ -76,9 +100,9 @@ static int check_results(struct resctrl_val_param *param, size_t span)fclose (fp); no_of_bits =count_bits (param->mask); -return show_cache_info (sum_llc_perf_miss, no_of_bits, span /64 , -MAX_DIFF ,MAX_DIFF_PERCENT , runs -1 , -get_vendor () ==ARCH_INTEL , false); +return show_results_info (sum_llc_perf_miss, no_of_bits, span /64 , +MAX_DIFF ,MAX_DIFF_PERCENT , runs -1 , +get_vendor () ==ARCH_INTEL ); }void cat_test_cleanup (void )
tools/testing/selftests/resctrl/cmt_test.c +29 -3
@@ -27,6 +27,33 @@ static int cmt_setup(struct resctrl_val_param *p)return 0 ; } +static int show_results_info (unsigned long sum_llc_val,int no_of_bits, +unsigned long cache_span,unsigned long max_diff, +unsigned long max_diff_percent,unsigned long num_of_runs, +bool platform) +{ +unsigned long avg_llc_val =0 ; +float diff_percent; +long avg_diff =0 ; +int ret; + + avg_llc_val = sum_llc_val / num_of_runs; + avg_diff = (long )abs (cache_span - avg_llc_val); + diff_percent = ((float )cache_span - avg_llc_val) / cache_span *100 ; + + ret = platform &&abs ((int )diff_percent) > max_diff_percent && +abs (avg_diff) > max_diff; + +ksft_print_msg ("%s Check cache miss rate within %lu%%\n" , + ret ?"Fail:" :"Pass:" , max_diff_percent); + +ksft_print_msg ("Percent diff=%d\n" ,abs ((int )diff_percent)); + +show_cache_info (no_of_bits, avg_llc_val, cache_span, false); + +return ret; +} +static int check_results (struct resctrl_val_param *param,size_t span,int no_of_bits) {char *token_array[8 ], temp[512 ];
@@ -58,9 +85,8 @@ static int check_results(struct resctrl_val_param *param, size_t span, int no_of }fclose (fp); -return show_cache_info (sum_llc_occu_resc, no_of_bits, span, -MAX_DIFF ,MAX_DIFF_PERCENT , runs -1 , - true, true); +return show_results_info (sum_llc_occu_resc, no_of_bits, span, +MAX_DIFF ,MAX_DIFF_PERCENT , runs -1 , true); }void cmt_test_cleanup (void )
tools/testing/selftests/resctrl/resctrl.h +2 -4
@@ -113,10 +113,8 @@ unsigned int count_bits(unsigned long n);void cmt_test_cleanup (void );int get_core_sibling (int cpu_no);int measure_llc_resctrl (const char *filename,int bm_pid); -int show_cache_info (unsigned long sum_llc_val,int no_of_bits, -size_t cache_span,unsigned long max_diff, -unsigned long max_diff_percent,unsigned long num_of_runs, -bool platform,bool cmt); +void show_cache_info (int no_of_bits,unsigned long avg_llc_val, +size_t cache_span,bool lines);/* * cache_portion_size - Calculate the size of a cache portion
Signature · 1 line
2.30.2
PATCH v3 13/29 selftests/resctrl: Remove unnecessary __u64 -> unsigned long conversion
In reply to Ilpo JärvinenPerf counters are __u64 but the code converts them to unsigned long before printing them out.
Remove unnecessary type conversion and retain the perf originating value as __u64.
---
v3:
- Altered changelog and removed "the whole time" wording because llc occu results are still unsigned long
--- tools/testing/selftests/resctrl/cache.c | 21 ++++++++------------- tools/testing/selftests/resctrl/cat_test.c | 8 ++++---- tools/testing/selftests/resctrl/resctrl.h | 3 +-- 3 files changed, 13 insertions(+), 19 deletions(-)
tools/testing/selftests/resctrl/cache.c +8 -13
@@ -83,9 +83,8 @@ static int reset_enable_llc_perf(pid_t pid, int cpu_no)* * Return: =0 on success. <0 on failure. */ -static int get_llc_perf (unsigned long *llc_perf_miss) +static int get_llc_perf (__u64 *llc_perf_miss) { -__u64 total_misses;int ret;/* Stop counters after one span to get miss rate */
@@ -98,8 +97,7 @@ static int get_llc_perf(unsigned long *llc_perf_miss)return -1 ; } - total_misses = rf_cqm.values[0 ].value; - *llc_perf_miss = total_misses; + *llc_perf_miss = rf_cqm.values[0 ].value;return 0 ; }
@@ -147,14 +145,12 @@ static int get_llc_occu_resctrl(unsigned long *llc_occupancy)* * Return: 0 on success, < 0 on error. */ -static int print_results_cache (const char *filename,int bm_pid, -unsigned long llc_value) +static int print_results_cache (const char *filename,int bm_pid,__u64 llc_value) {FILE *fp;if (strcmp (filename,"stdio" ) ==0 ||strcmp (filename,"stderr" ) ==0 ) { -printf ("Pid: %d \t LLC_value: %lu\n" , bm_pid, - llc_value); +printf ("Pid: %d \t LLC_value: %llu\n" , bm_pid, llc_value); }else { fp =fopen (filename,"a" );if (!fp) {
@@ -162,7 +158,7 @@ static int print_results_cache(const char *filename, int bm_pid,return -1 ; } -fprintf (fp,"Pid: %d \t llc_value: %lu\n" , bm_pid, llc_value); +fprintf (fp,"Pid: %d \t llc_value: %llu\n" , bm_pid, llc_value);fclose (fp); }
@@ -182,7 +178,7 @@ static int print_results_cache(const char *filename, int bm_pid,*/ static int perf_event_measure (const char *filename,int bm_pid) { -unsigned long llc_perf_miss =0 ; +__u64 llc_perf_miss =0 ;int ret; ret =get_llc_perf (&llc_perf_miss);
@@ -285,11 +281,10 @@ int cat_val(struct resctrl_val_param *param, size_t span)* @cache_span: Cache span * @lines: @cache_span in lines or bytes */ -void show_cache_info (int no_of_bits,unsigned long avg_llc_val, -size_t cache_span,bool lines) +void show_cache_info (int no_of_bits,__u64 avg_llc_val,size_t cache_span,bool lines) {ksft_print_msg ("Number of bits: %d\n" , no_of_bits); -ksft_print_msg ("Average LLC val: %lu\n" , avg_llc_val); +ksft_print_msg ("Average LLC val: %llu\n" , avg_llc_val);ksft_print_msg ("Cache span (%s): %zu\n" , lines ?"lines" :"bytes" , cache_span); }
tools/testing/selftests/resctrl/cat_test.c +4 -4
@@ -41,12 +41,12 @@ static int cat_setup(struct resctrl_val_param *p)return ret; } -static int show_results_info (unsigned long sum_llc_val,int no_of_bits, +static int show_results_info (__u64 sum_llc_val,int no_of_bits,unsigned long cache_span,unsigned long max_diff,unsigned long max_diff_percent,unsigned long num_of_runs,bool platform) { -unsigned long avg_llc_val =0 ; +__u64 avg_llc_val =0 ;float diff_percent;int ret;
@@ -68,8 +68,8 @@ static int show_results_info(unsigned long sum_llc_val, int no_of_bits,static int check_results (struct resctrl_val_param *param,size_t span) {char *token_array[8 ], temp[512 ]; -unsigned long sum_llc_perf_miss =0 ;int runs =0 , no_of_bits =0 ; +__u64 sum_llc_perf_miss =0 ;FILE *fp;ksft_print_msg ("Checking for pass/fail\n" );
@@ -93,7 +93,7 @@ static int check_results(struct resctrl_val_param *param, size_t span)* setup transition phase. */ if (runs >0 ) - sum_llc_perf_miss +=strtoul (token_array[3 ],NULL ,0 ); + sum_llc_perf_miss +=strtoull (token_array[3 ],NULL ,0 ); runs++; }
tools/testing/selftests/resctrl/resctrl.h +1 -2
@@ -113,8 +113,7 @@ unsigned int count_bits(unsigned long n);void cmt_test_cleanup (void );int get_core_sibling (int cpu_no);int measure_llc_resctrl (const char *filename,int bm_pid); -void show_cache_info (int no_of_bits,unsigned long avg_llc_val, -size_t cache_span,bool lines); +void show_cache_info (int no_of_bits,__u64 avg_llc_val,size_t cache_span,bool lines);/* * cache_portion_size - Calculate the size of a cache portion
Signature · 1 line
2.30.2
PATCH v3 14/29 selftests/resctrl: Remove nested calls in perf event handling
In reply to Ilpo JärvinenPerf event handling has functions that are the sole caller of another perf event handling related function:
- reset_enable_llc_perf() calls perf_event_open_llc_miss()
- perf_event_measure() calls get_llc_perf()
Remove the extra layer of calls to make the code easier to follow by moving the code into the calling function.
--- tools/testing/selftests/resctrl/cache.c | 64 ++++++------------------- 1 file changed, 14 insertions(+), 50 deletions(-)
tools/testing/selftests/resctrl/cache.c +14 -50
@@ -29,24 +29,13 @@ static void initialize_perf_event_attr(void) pea_llc_miss.disabled =1 ; } +/* Start counters to log values */ static void ioctl_perf_event_ioc_reset_enable (void ) {ioctl (fd_lm,PERF_EVENT_IOC_RESET ,0 );ioctl (fd_lm,PERF_EVENT_IOC_ENABLE ,0 ); } -static int perf_event_open_llc_miss (pid_t pid,int cpu_no) -{ - fd_lm =perf_event_open (&pea_llc_miss, pid, cpu_no,-1 , -PERF_FLAG_FD_CLOEXEC ); -if (fd_lm ==-1 ) { -ksft_perror ("Error opening leader" ); -return -1 ; - } - -return 0 ; -} -static void initialize_llc_perf (void ) {memset (&pea_llc_miss,0 ,sizeof (struct perf_event_attr ));
@@ -62,42 +51,13 @@ static void initialize_llc_perf(void)static int reset_enable_llc_perf (pid_t pid,int cpu_no) { -int ret =0 ; - - ret =perf_event_open_llc_miss (pid, cpu_no); -if (ret <0 ) -return ret; - -/* Start counters to log values */ -ioctl_perf_event_ioc_reset_enable (); - -return 0 ; -} - -/* -* get_llc_perf: llc cache miss through perf events -* @llc_perf_miss: LLC miss counter that is filled on success -* -* Perf events like HW_CACHE_MISSES could be used to validate number of -* cache lines allocated. -* -* Return: =0 on success. <0 on failure. -*/ -static int get_llc_perf (__u64 *llc_perf_miss) -{ -int ret; - -/* Stop counters after one span to get miss rate */ - -ioctl (fd_lm,PERF_EVENT_IOC_DISABLE ,0 ); - - ret =read (fd_lm, &rf_cqm,sizeof (struct read_format )); -if (ret ==-1 ) { -ksft_perror ("Could not get llc misses through perf" ); + fd_lm =perf_event_open (&pea_llc_miss, pid, cpu_no,-1 ,PERF_FLAG_FD_CLOEXEC ); +if (fd_lm ==-1 ) { +ksft_perror ("Error opening leader" );return -1 ; } - *llc_perf_miss = rf_cqm.values[0 ].value; +ioctl_perf_event_ioc_reset_enable ();return 0 ; }
@@ -178,14 +138,18 @@ static int print_results_cache(const char *filename, int bm_pid, __u64 llc_value*/ static int perf_event_measure (const char *filename,int bm_pid) { -__u64 llc_perf_miss =0 ;int ret; - ret =get_llc_perf (&llc_perf_miss); -if (ret <0 ) -return ret; +/* Stop counters after one span to get miss rate */ +ioctl (fd_lm,PERF_EVENT_IOC_DISABLE ,0 ); + + ret =read (fd_lm, &rf_cqm,sizeof (struct read_format )); +if (ret ==-1 ) { +ksft_perror ("Could not get perf value" ); +return -1 ; + } -return print_results_cache (filename, bm_pid, llc_perf_miss); +return print_results_cache (filename, bm_pid, rf_cqm.values[0 ].value); }/*
Signature · 1 line
2.30.2
PATCH v3 15/29 selftests/resctrl: Consolidate naming of perf event related things
In reply to Ilpo JärvinenNaming for perf event related functions, types, and variables is inconsistent.
Make struct read_format and all functions related to perf events start with "perf_". Adjust variable names towards the same direction but use shorter names for variables where appropriate (pe prefix).
---
v3:
- removed "currently" from changelog
--- tools/testing/selftests/resctrl/cache.c | 42 ++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-)
tools/testing/selftests/resctrl/cache.c +21 -21
@@ -3,7 +3,7 @@#include <stdint.h> #include "resctrl.h" -struct read_format { +struct perf_event_read {__u64 nr;/* The number of events */ struct {__u64 value;/* The value of the event */
@@ -11,11 +11,11 @@ struct read_format { };static struct perf_event_attr pea_llc_miss; -static struct read_format rf_cqm; -static int fd_lm; +static struct perf_event_read pe_read; +static int pe_fd;char llc_occup_path[1024 ]; -static void initialize_perf_event_attr (void ) +static void perf_event_attr_initialize (void ) { pea_llc_miss.type =PERF_TYPE_HARDWARE ; pea_llc_miss.size =sizeof (struct perf_event_attr );
@@ -30,34 +30,34 @@ static void initialize_perf_event_attr(void) }/* Start counters to log values */ -static void ioctl_perf_event_ioc_reset_enable (void ) +static void perf_event_reset_enable (void ) { -ioctl (fd_lm,PERF_EVENT_IOC_RESET ,0 ); -ioctl (fd_lm,PERF_EVENT_IOC_ENABLE ,0 ); +ioctl (pe_fd,PERF_EVENT_IOC_RESET ,0 ); +ioctl (pe_fd,PERF_EVENT_IOC_ENABLE ,0 ); } -static void initialize_llc_perf (void ) +static void perf_event_initialize (void ) {memset (&pea_llc_miss,0 ,sizeof (struct perf_event_attr )); -memset (&rf_cqm,0 ,sizeof (struct read_format )); +memset (&pe_read,0 ,sizeof (struct perf_event_read ));/* Initialize perf_event_attr structures for HW_CACHE_MISSES */ -initialize_perf_event_attr (); +perf_event_attr_initialize (); pea_llc_miss.config =PERF_COUNT_HW_CACHE_MISSES ; - rf_cqm.nr =1 ; + pe_read.nr =1 ; } -static int reset_enable_llc_perf (pid_t pid,int cpu_no) +static int perf_open (pid_t pid,int cpu_no) { - fd_lm =perf_event_open (&pea_llc_miss, pid, cpu_no,-1 ,PERF_FLAG_FD_CLOEXEC ); -if (fd_lm ==-1 ) { + pe_fd =perf_event_open (&pea_llc_miss, pid, cpu_no,-1 ,PERF_FLAG_FD_CLOEXEC ); +if (pe_fd ==-1 ) {ksft_perror ("Error opening leader" );return -1 ; } -ioctl_perf_event_ioc_reset_enable (); +perf_event_reset_enable ();return 0 ; }
@@ -141,15 +141,15 @@ static int perf_event_measure(const char *filename, int bm_pid)int ret;/* Stop counters after one span to get miss rate */ -ioctl (fd_lm,PERF_EVENT_IOC_DISABLE ,0 ); +ioctl (pe_fd,PERF_EVENT_IOC_DISABLE ,0 ); - ret =read (fd_lm, &rf_cqm,sizeof (struct read_format )); + ret =read (pe_fd, &pe_read,sizeof (struct perf_event_read ));if (ret ==-1 ) {ksft_perror ("Could not get perf value" );return -1 ; } -return print_results_cache (filename, bm_pid, rf_cqm.values[0 ].value); +return print_results_cache (filename, bm_pid, pe_read.values[0 ].value); }/*
@@ -204,7 +204,7 @@ int cat_val(struct resctrl_val_param *param, size_t span)if (ret)return ret; -initialize_llc_perf (); +perf_event_initialize ();/* Test runs until the callback setup() tells the test to stop. */ while (1 ) {
@@ -215,7 +215,7 @@ int cat_val(struct resctrl_val_param *param, size_t span) }if (ret <0 )break ; - ret =reset_enable_llc_perf (bm_pid, param->cpu_no); + ret =perf_open (bm_pid, param->cpu_no);if (ret)break ;
@@ -234,7 +234,7 @@ int cat_val(struct resctrl_val_param *param, size_t span)return ret; pe_close: -close (fd_lm); +close (pe_fd);return ret; }
Signature · 1 line
2.30.2
PATCH v3 16/29 selftests/resctrl: Improve perf init
In reply to Ilpo Järvinenstruct perf_event_attr initialization is spread into perf_event_initialize() and perf_event_attr_initialize() and setting ->config is hardcoded by the deepest level.
perf_event_attr init belongs to perf_event_attr_initialize() so move it entirely there. Rename the other function perf_event_initialized_read_format().
Call each init function directly from the test as they will take different parameters (especially true after the perf related global variables are moved to local variables).
--- tools/testing/selftests/resctrl/cache.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
tools/testing/selftests/resctrl/cache.c +6 -10
@@ -15,8 +15,9 @@ static struct perf_event_read pe_read;static int pe_fd;char llc_occup_path[1024 ]; -static void perf_event_attr_initialize (void ) +static void perf_event_attr_initialize (__u64 config) { +memset (&pea_llc_miss,0 ,sizeof (struct perf_event_attr )); pea_llc_miss.type =PERF_TYPE_HARDWARE ; pea_llc_miss.size =sizeof (struct perf_event_attr ); pea_llc_miss.read_format =PERF_FORMAT_GROUP ;
@@ -27,6 +28,7 @@ static void perf_event_attr_initialize(void) pea_llc_miss.inherit =1 ; pea_llc_miss.exclude_guest =1 ; pea_llc_miss.disabled =1 ; + pea_llc_miss.config = config; }/* Start counters to log values */
@@ -36,16 +38,9 @@ static void perf_event_reset_enable(void)ioctl (pe_fd,PERF_EVENT_IOC_ENABLE ,0 ); } -static void perf_event_initialize (void ) +static void perf_event_initialize_read_format (void ) { -memset (&pea_llc_miss,0 ,sizeof (struct perf_event_attr ));memset (&pe_read,0 ,sizeof (struct perf_event_read )); - -/* Initialize perf_event_attr structures for HW_CACHE_MISSES */ -perf_event_attr_initialize (); - - pea_llc_miss.config =PERF_COUNT_HW_CACHE_MISSES ; - pe_read.nr =1 ; }
@@ -204,7 +199,8 @@ int cat_val(struct resctrl_val_param *param, size_t span)if (ret)return ret; -perf_event_initialize (); +perf_event_attr_initialize (PERF_COUNT_HW_CACHE_MISSES ); +perf_event_initialize_read_format ();/* Test runs until the callback setup() tells the test to stop. */ while (1 ) {
Signature · 1 line
2.30.2
PATCH v3 17/29 selftests/resctrl: Convert perf related globals to locals
In reply to Ilpo JärvinenPerf related variables pea_llc_miss, pe_read, and pe_fd are globals in cache.c.
Convert them to locals for better scoping and make pea_llc_miss simpler by renaming it to pea. Make close(pe_fd) handling easier to understand by doing it inside cat_val().
Make also sizeof()s use safer way to determine the right struct.
--- tools/testing/selftests/resctrl/cache.c | 72 ++++++++++++++----------- 1 file changed, 40 insertions(+), 32 deletions(-)
tools/testing/selftests/resctrl/cache.c +40 -32
@@ -10,51 +10,50 @@ struct perf_event_read { } values[2 ]; }; -static struct perf_event_attr pea_llc_miss; -static struct perf_event_read pe_read; -static int pe_fd;char llc_occup_path[1024 ]; -static void perf_event_attr_initialize (__u64 config) +static void perf_event_attr_initialize (struct perf_event_attr *pea,__u64 config) { -memset (&pea_llc_miss,0 ,sizeof (struct perf_event_attr )); - pea_llc_miss.type =PERF_TYPE_HARDWARE ; - pea_llc_miss.size =sizeof (struct perf_event_attr ); - pea_llc_miss.read_format =PERF_FORMAT_GROUP ; - pea_llc_miss.exclude_kernel =1 ; - pea_llc_miss.exclude_hv =1 ; - pea_llc_miss.exclude_idle =1 ; - pea_llc_miss.exclude_callchain_kernel =1 ; - pea_llc_miss.inherit =1 ; - pea_llc_miss.exclude_guest =1 ; - pea_llc_miss.disabled =1 ; - pea_llc_miss.config = config; +memset (pea,0 ,sizeof (*pea)); + pea->type =PERF_TYPE_HARDWARE ; + pea->size =sizeof (*pea); + pea->read_format =PERF_FORMAT_GROUP ; + pea->exclude_kernel =1 ; + pea->exclude_hv =1 ; + pea->exclude_idle =1 ; + pea->exclude_callchain_kernel =1 ; + pea->inherit =1 ; + pea->exclude_guest =1 ; + pea->disabled =1 ; + pea->config = config; }/* Start counters to log values */ -static void perf_event_reset_enable (void ) +static void perf_event_reset_enable (int pe_fd) {ioctl (pe_fd,PERF_EVENT_IOC_RESET ,0 );ioctl (pe_fd,PERF_EVENT_IOC_ENABLE ,0 ); } -static void perf_event_initialize_read_format (void ) +static void perf_event_initialize_read_format (struct perf_event_read *pe_read) { -memset (&pe_read,0 ,sizeof (struct perf_event_read )); - pe_read.nr =1 ; +memset (pe_read,0 ,sizeof (*pe_read)); + pe_read->nr =1 ; } -static int perf_open (pid_t pid,int cpu_no) +static int perf_open (struct perf_event_attr *pea,pid_t pid,int cpu_no) { - pe_fd =perf_event_open (&pea_llc_miss, pid, cpu_no,-1 ,PERF_FLAG_FD_CLOEXEC ); +int pe_fd; + + pe_fd =perf_event_open (pea, pid, cpu_no,-1 ,PERF_FLAG_FD_CLOEXEC );if (pe_fd ==-1 ) {ksft_perror ("Error opening leader" );return -1 ; } -perf_event_reset_enable (); +perf_event_reset_enable (pe_fd); -return 0 ; +return pe_fd; }/*
@@ -131,20 +130,21 @@ static int print_results_cache(const char *filename, int bm_pid, __u64 llc_value* * Return: =0 on success. <0 on failure. */ -static int perf_event_measure (const char *filename,int bm_pid) +static int perf_event_measure (int pe_fd,struct perf_event_read *pe_read, +const char *filename,int bm_pid) {int ret;/* Stop counters after one span to get miss rate */ ioctl (pe_fd,PERF_EVENT_IOC_DISABLE ,0 ); - ret =read (pe_fd, &pe_read,sizeof (struct perf_event_read )); + ret =read (pe_fd, pe_read,sizeof (*pe_read));if (ret ==-1 ) {ksft_perror ("Could not get perf value" );return -1 ; } -return print_results_cache (filename, bm_pid, pe_read.values[0 ].value); +return print_results_cache (filename, bm_pid, pe_read->values[0 ].value); }/*
@@ -181,7 +181,10 @@ int cat_val(struct resctrl_val_param *param, size_t span) {int memflush =1 , operation =0 , ret =0 ;char *resctrl_val = param->resctrl_val; +struct perf_event_read pe_read; +struct perf_event_attr pea;pid_t bm_pid; +int pe_fd;if (strcmp (param->filename,"" ) ==0 )sprintf (param->filename,"stdio" );
@@ -199,8 +202,8 @@ int cat_val(struct resctrl_val_param *param, size_t span)if (ret)return ret; -perf_event_attr_initialize (PERF_COUNT_HW_CACHE_MISSES ); -perf_event_initialize_read_format (); +perf_event_attr_initialize (&pea,PERF_COUNT_HW_CACHE_MISSES ); +perf_event_initialize_read_format (&pe_read);/* Test runs until the callback setup() tells the test to stop. */ while (1 ) {
@@ -211,9 +214,12 @@ int cat_val(struct resctrl_val_param *param, size_t span) }if (ret <0 )break ; - ret =perf_open (bm_pid, param->cpu_no); -if (ret) + + pe_fd =perf_open (&pea, bm_pid, param->cpu_no); +if (pe_fd <0 ) { + ret =-1 ;break ; + }if (run_fill_buf (span, memflush, operation, true)) {fprintf (stderr,"Error-running fill buffer\n" );
@@ -222,9 +228,11 @@ int cat_val(struct resctrl_val_param *param, size_t span) }sleep (1 ); - ret =perf_event_measure (param->filename, bm_pid); + ret =perf_event_measure (pe_fd, &pe_read, param->filename, bm_pid);if (ret) goto pe_close; + +close (pe_fd); }return ret;
Signature · 1 line
2.30.2
PATCH v3 18/29 selftests/resctrl: Move cat_val() to cat_test.c and rename to cat_test()
In reply to Ilpo JärvinenThe main CAT test function is called cat_val() and resides in cache.c which is illogical.
Rename the function to cat_test() and move it into cat_test.c.
--- tools/testing/selftests/resctrl/cache.c | 90 ++-------------------- tools/testing/selftests/resctrl/cat_test.c | 73 +++++++++++++++++- tools/testing/selftests/resctrl/resctrl.h | 14 +++- 3 files changed, 90 insertions(+), 87 deletions(-)
tools/testing/selftests/resctrl/cache.c +5 -85
@@ -3,16 +3,9 @@#include <stdint.h> #include "resctrl.h" -struct perf_event_read { -__u64 nr;/* The number of events */ -struct { -__u64 value;/* The value of the event */ - } values[2 ]; -}; -char llc_occup_path[1024 ]; -static void perf_event_attr_initialize (struct perf_event_attr *pea,__u64 config) +void perf_event_attr_initialize (struct perf_event_attr *pea,__u64 config) {memset (pea,0 ,sizeof (*pea)); pea->type =PERF_TYPE_HARDWARE ;
@@ -35,13 +28,13 @@ static void perf_event_reset_enable(int pe_fd)ioctl (pe_fd,PERF_EVENT_IOC_ENABLE ,0 ); } -static void perf_event_initialize_read_format (struct perf_event_read *pe_read) +void perf_event_initialize_read_format (struct perf_event_read *pe_read) {memset (pe_read,0 ,sizeof (*pe_read)); pe_read->nr =1 ; } -static int perf_open (struct perf_event_attr *pea,pid_t pid,int cpu_no) +int perf_open (struct perf_event_attr *pea,pid_t pid,int cpu_no) {int pe_fd;
@@ -130,8 +123,8 @@ static int print_results_cache(const char *filename, int bm_pid, __u64 llc_value* * Return: =0 on success. <0 on failure. */ -static int perf_event_measure (int pe_fd,struct perf_event_read *pe_read, -const char *filename,int bm_pid) +int perf_event_measure (int pe_fd,struct perf_event_read *pe_read, +const char *filename,int bm_pid) {int ret;
@@ -169,79 +162,6 @@ int measure_llc_resctrl(const char *filename, int bm_pid)return print_results_cache (filename, bm_pid, llc_occu_resc); } -/* -* cache_val: execute benchmark and measure LLC occupancy resctrl -* and perf cache miss for the benchmark -* @param: parameters passed to cache_val() -* @span: buffer size for the benchmark -* -* Return: 0 when the test was run, < 0 on error. -*/ -int cat_val (struct resctrl_val_param *param,size_t span) -{ -int memflush =1 , operation =0 , ret =0 ; -char *resctrl_val = param->resctrl_val; -struct perf_event_read pe_read; -struct perf_event_attr pea; -pid_t bm_pid; -int pe_fd; - -if (strcmp (param->filename,"" ) ==0 ) -sprintf (param->filename,"stdio" ); - - bm_pid =getpid (); - -/* Taskset benchmark to specified cpu */ - ret =taskset_benchmark (bm_pid, param->cpu_no); -if (ret) -return ret; - -/* Write benchmark to specified con_mon grp, mon_grp in resctrl FS*/ - ret =write_bm_pid_to_resctrl (bm_pid, param->ctrlgrp, param->mongrp, - resctrl_val); -if (ret) -return ret; - -perf_event_attr_initialize (&pea,PERF_COUNT_HW_CACHE_MISSES ); -perf_event_initialize_read_format (&pe_read); - -/* Test runs until the callback setup() tells the test to stop. */ -while (1 ) { - ret = param->setup (param); -if (ret ==END_OF_TESTS ) { - ret =0 ; -break ; - } -if (ret <0 ) -break ; - - pe_fd =perf_open (&pea, bm_pid, param->cpu_no); -if (pe_fd <0 ) { - ret =-1 ; -break ; - } - -if (run_fill_buf (span, memflush, operation, true)) { -fprintf (stderr,"Error-running fill buffer\n" ); - ret =-1 ; - goto pe_close; - } - -sleep (1 ); - ret =perf_event_measure (pe_fd, &pe_read, param->filename, bm_pid); -if (ret) - goto pe_close; - -close (pe_fd); - } - -return ret; - -pe_close: -close (pe_fd); -return ret; -} -/* * show_cache_info - Show generic cache test information * @no_of_bits: Number of bits
tools/testing/selftests/resctrl/cat_test.c +72 -1
85 lines not on this page · raw message
tools/testing/selftests/resctrl/resctrl.h +13 -1
@@ -66,6 +66,13 @@ struct resctrl_val_param {int (*setup)(struct resctrl_val_param *param); }; +struct perf_event_read { +__u64 nr;/* The number of events */ +struct { +__u64 value;/* The value of the event */ + } values[2 ]; +}; +#define MBM_STR "mbm"#define MBA_STR "mba"#define CMT_STR "cmt"
@@ -105,13 +112,18 @@ int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_sizevoid ctrlc_handler (int signum,siginfo_t *info,void *ptr);int signal_handler_register (void );void signal_handler_unregister (void ); -int cat_val (struct resctrl_val_param *param,size_t span);void cat_test_cleanup (void );int cat_perf_miss_val (int cpu_no,int no_of_bits,char *cache_type);int cmt_resctrl_val (int cpu_no,int n,const char *const *benchmark_cmd);unsigned int count_bits (unsigned long n);void cmt_test_cleanup (void );int get_core_sibling (int cpu_no); + +void perf_event_attr_initialize (struct perf_event_attr *pea,__u64 config); +void perf_event_initialize_read_format (struct perf_event_read *pe_read); +int perf_open (struct perf_event_attr *pea,pid_t pid,int cpu_no); +int perf_event_measure (int pe_fd,struct perf_event_read *pe_read, +const char *filename,int bm_pid);int measure_llc_resctrl (const char *filename,int bm_pid);void show_cache_info (int no_of_bits,__u64 avg_llc_val,size_t cache_span,bool lines);
Signature · 1 line
2.30.2
PATCH v3 19/29 selftests/resctrl: Open perf fd before start & add error handling
In reply to Ilpo JärvinenPerf fd (pe_fd) is opened, reset, and enabled during every test the CAT selftest runs. Also, ioctl(pe_fd, ...) calls are not error checked even if ioctl() could return an error.
Open perf fd only once before the tests and only reset and enable the counter within the test loop. Add error checking to pe_fd ioctl() calls.
--- tools/testing/selftests/resctrl/cache.c | 19 +++++++++++++++---- tools/testing/selftests/resctrl/cat_test.c | 14 +++++++------- tools/testing/selftests/resctrl/resctrl.h | 1 + 3 files changed, 23 insertions(+), 11 deletions(-)
tools/testing/selftests/resctrl/cache.c +15 -4
@@ -22,10 +22,19 @@ void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config) }/* Start counters to log values */ -static void perf_event_reset_enable (int pe_fd) +int perf_event_reset_enable (int pe_fd) { -ioctl (pe_fd,PERF_EVENT_IOC_RESET ,0 ); -ioctl (pe_fd,PERF_EVENT_IOC_ENABLE ,0 ); +int ret; + + ret =ioctl (pe_fd,PERF_EVENT_IOC_RESET ,0 ); +if (ret <0 ) +return ret; + + ret =ioctl (pe_fd,PERF_EVENT_IOC_ENABLE ,0 ); +if (ret <0 ) +return ret; + +return 0 ; }void perf_event_initialize_read_format (struct perf_event_read *pe_read)
@@ -129,7 +138,9 @@ int perf_event_measure(int pe_fd, struct perf_event_read *pe_read,int ret;/* Stop counters after one span to get miss rate */ -ioctl (pe_fd,PERF_EVENT_IOC_DISABLE ,0 ); + ret =ioctl (pe_fd,PERF_EVENT_IOC_DISABLE ,0 ); +if (ret <0 ) +return ret; ret =read (pe_fd, pe_read,sizeof (*pe_read));if (ret ==-1 ) {
tools/testing/selftests/resctrl/cat_test.c +7 -7
@@ -145,6 +145,9 @@ static int cat_test(struct resctrl_val_param *param, size_t span)perf_event_attr_initialize (&pea,PERF_COUNT_HW_CACHE_MISSES );perf_event_initialize_read_format (&pe_read); + pe_fd =perf_open (&pea, bm_pid, param->cpu_no); +if (pe_fd <0 ) +return pe_fd;/* Test runs until the callback setup() tells the test to stop. */ while (1 ) {
@@ -155,11 +158,10 @@ static int cat_test(struct resctrl_val_param *param, size_t span) }if (ret <0 )break ; - pe_fd =perf_open (&pea, bm_pid, param->cpu_no); -if (pe_fd <0 ) { - ret =-1 ; -break ; - } + + ret =perf_event_reset_enable (pe_fd); +if (ret) + goto pe_close;if (run_fill_buf (span, memflush, operation, true)) {fprintf (stderr,"Error-running fill buffer\n" );
@@ -171,8 +173,6 @@ static int cat_test(struct resctrl_val_param *param, size_t span) ret =perf_event_measure (pe_fd, &pe_read, param->filename, bm_pid);if (ret) goto pe_close; - -close (pe_fd); }return ret;
tools/testing/selftests/resctrl/resctrl.h +1 -0
@@ -122,6 +122,7 @@ int get_core_sibling(int cpu_no);void perf_event_attr_initialize (struct perf_event_attr *pea,__u64 config);void perf_event_initialize_read_format (struct perf_event_read *pe_read);int perf_open (struct perf_event_attr *pea,pid_t pid,int cpu_no); +int perf_event_reset_enable (int pe_fd);int perf_event_measure (int pe_fd,struct perf_event_read *pe_read,const char *filename,int bm_pid);int measure_llc_resctrl (const char *filename,int bm_pid);
Signature · 1 line
2.30.2
PATCH v3 20/29 selftests/resctrl: Replace file write with volatile variable
In reply to Ilpo JärvinenThe fill_buf code prevents compiler optimizating the entire read loop away by writing the final value of the variable into a file. While it achieves the goal, writing into a file requires significant amount of work within the innermost test loop and also error handling.
A simpler approach is to take advantage of volatile. Writing through a pointer to a volatile variable is enough to prevent compiler from optimizing the write away, and therefore compiler cannot remove the read loop either.
Add a volatile 'value_sink' into resctrl_tests.c and make fill_buf to write into it. As a result, the error handling in fill_buf.c can be simplified.
---
v3:
- Altered changelog's wording to not say "a volatile pointer"
--- tools/testing/selftests/resctrl/fill_buf.c | 26 ++++--------------- tools/testing/selftests/resctrl/resctrl.h | 7 +++++ .../testing/selftests/resctrl/resctrl_tests.c | 4 +++ 3 files changed, 16 insertions(+), 21 deletions(-)
tools/testing/selftests/resctrl/fill_buf.c +5 -21
@@ -78,10 +78,9 @@ static void fill_one_span_write(unsigned char *buf, size_t buf_size) } } -static int fill_cache_read (unsigned char *buf,size_t buf_size,bool once) +static void fill_cache_read (unsigned char *buf,size_t buf_size,bool once) {int ret =0 ; -FILE *fp;while (1 ) { ret =fill_one_span_read (buf, buf_size);
@@ -90,26 +89,16 @@ static int fill_cache_read(unsigned char *buf, size_t buf_size, bool once) }/* Consume read result so that reading memory is not optimized out. */ - fp =fopen ("/dev/null" ,"w" ); -if (!fp) { -ksft_perror ("Unable to write to /dev/null" ); -return -1 ; - } -fprintf (fp,"Sum: %d " , ret); -fclose (fp); - -return 0 ; + *value_sink = ret; } -static int fill_cache_write (unsigned char *buf,size_t buf_size,bool once) +static void fill_cache_write (unsigned char *buf,size_t buf_size,bool once) {while (1 ) {fill_one_span_write (buf, buf_size);if (once)break ; } - -return 0 ; }static unsigned char *alloc_buffer (size_t buf_size,int memflush)
@@ -143,21 +132,16 @@ static unsigned char *alloc_buffer(size_t buf_size, int memflush)int run_fill_buf (size_t buf_size,int memflush,int op,bool once) {unsigned char *buf; -int ret; buf =alloc_buffer (buf_size, memflush);if (!buf)return -1 ;if (op ==0 ) - ret =fill_cache_read (buf, buf_size, once); +fill_cache_read (buf, buf_size, once);else - ret =fill_cache_write (buf, buf_size, once); +fill_cache_write (buf, buf_size, once);free (buf); -if (ret) { -printf ("\n Error in fill cache\n" ); -return -1 ; - }return 0 ; }
tools/testing/selftests/resctrl/resctrl.h +7 -0
@@ -78,6 +78,13 @@ struct perf_event_read {#define CMT_STR "cmt"#define CAT_STR "cat" +/* +* Memory location that consumes values compiler must not optimize away. +* Volatile ensures writes to this location cannot be optimized away by +* compiler. +*/ +extern volatile int *value_sink; +extern pid_t bm_pid, ppid;extern char llc_occup_path[1024 ];
tools/testing/selftests/resctrl/resctrl_tests.c +4 -0
@@ -10,6 +10,10 @@*/ #include "resctrl.h" +/* Volatile memory sink to prevent compiler optimizations */ +static volatile int sink_target; +volatile int *value_sink = &sink_target; +static int detect_vendor (void ) {FILE *inf =fopen ("/proc/cpuinfo" ,"r" );
Signature · 1 line
2.30.2
Re: [PATCH v3 20/29] selftests/resctrl: Replace file write with volatile variable
Hi Ilpo,
Quoted 10 lines · Ilpo Järvinen
The
fill_bufcode prevents compiler optimizating the entire read loop away by writing the final value of the variable into a file. While it achieves the goal, writing into a file requires significant amount of work within the innermost test loop and also error handling.A simpler approach is to take advantage of volatile. Writing through a pointer to a volatile variable is enough to prevent compiler from optimizing the write away, and therefore compiler cannot remove the read loop either.
Quoted 6 lines
Add a volatile '
value_sink' intoresctrl_tests.cand makefill_bufto write into it. As a result, the error handling infill_buf.ccan be simplified.Signed-off-by Ilpo Järvinen <[email protected]>---
Reinette
PATCH v3 21/29 selftests/resctrl: Read in less obvious order to defeat prefetch optimizations
In reply to Ilpo JärvinenWhen reading memory in order, HW prefetching optimizations will interfere with measuring how caches and memory are being accessed. This adds noise into the results.
Change the fill_buf reading loop to not use an obvious in-order access using multiply by a prime and modulo.
Using a prime multiplier with modulo ensures the entire buffer is eventually read. 23 is small enough that the reads are spread out but wrapping does not occur very frequently (wrapping too often can trigger L2 hits more frequently which causes noise to the test because getting the data from LLC is not required).
It was discovered that not all primes work equally well and some can cause wildly unstable results (e.g., in an earlier version of this patch, the reads were done in reversed order and 59 was used as the prime resulting in unacceptably high and unstable results in MBA and MBM test on some architectures).
--- tools/testing/selftests/resctrl/fill_buf.c | 38 +++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-)
tools/testing/selftests/resctrl/fill_buf.c +30 -8
@@ -51,16 +51,38 @@ static void mem_flush(unsigned char *buf, size_t buf_size)sb (); } +/* +* Buffer index step advance to workaround HW prefetching interfering with +* the measurements. +* +* Must be a prime to step through all indexes of the buffer. +* +* Some primes work better than others on some architectures (from MBA/MBM +* result stability point of view). +*/ +#define FILL_IDX_MULT 23 +static int fill_one_span_read (unsigned char *buf,size_t buf_size) { -unsigned char *end_ptr = buf + buf_size; -unsigned char sum, *p; - - sum =0 ; - p = buf; -while (p < end_ptr) { - sum += *p; - p += (CL_SIZE /2 ); +unsigned int size = buf_size / (CL_SIZE /2 ); +unsigned int i, idx =0 ; +unsigned char sum =0 ; + +/* +* Read the buffer in an order that is unexpected by HW prefetching +* optimizations to prevent them interfering with the caching pattern. +* +* The read order is (in terms of halves of cachelines): +* i * FILL_IDX_MULT % size +* The formula is open-coded below to avoiding modulo inside the loop +* as it improves MBA/MBM result stability on some architectures. +*/ +for (i =0 ; i < size; i++) { + sum += buf[idx * (CL_SIZE /2 )]; + + idx +=FILL_IDX_MULT ; +while (idx >= size) + idx -= size; }return sum;
Signature · 1 line
2.30.2
PATCH v3 22/29 selftests/resctrl: Rewrite Cache Allocation Technology (CAT) test
In reply to Ilpo JärvinenCAT test spawns two processes into two different control groups with exclusive schemata. Both the processes alloc a buffer from memory matching their allocated LLC block size and flush the entire buffer out of caches. Since the processes are reading through the buffer only once during the measurement and initially all the buffer was flushed, the test isn't testing CAT.
Rewrite the CAT test to allocate a buffer sized to half of LLC. Then perform a sequence of tests with different LLC alloc sizes starting from half of the CBM bits down to 1-bit CBM. Flush the buffer before each test and read the buffer twice. Observe the LLC misses on the second read through the buffer. As the allocated LLC block gets smaller and smaller, the LLC misses will become larger and larger giving a strong signal on CAT working properly.
The new CAT test is using only a single process because it relies on measured effect against another run of itself rather than another process adding noise. The rest of the system is set to use the CBM bits not used by the CAT test to keep the test isolated.
Replace count_bits() with count_contiguous_bits() to get the first bit position in order to be able to calculate masks based on it.
This change has been tested with a number of systems from different generations.
---
v3:
- Improve function comment
- Make min_diff_percent and MIN_DIFF_PERCENT_PER_BIT unsigned long
--- tools/testing/selftests/resctrl/cat_test.c | 283 +++++++++----------- tools/testing/selftests/resctrl/fill_buf.c | 6 +- tools/testing/selftests/resctrl/resctrl.h | 5 +- tools/testing/selftests/resctrl/resctrlfs.c | 44 +-- 4 files changed, 139 insertions(+), 199 deletions(-)
tools/testing/selftests/resctrl/cat_test.c +131 -152
@@ -11,65 +11,70 @@#include "resctrl.h" #include <unistd.h> -#define RESULT_FILE_NAME1 "result_cat1" -#define RESULT_FILE_NAME2 "result_cat2" +#define RESULT_FILE_NAME "result_cat"#define NUM_OF_RUNS 5 -#define MAX_DIFF_PERCENT 4 -#define MAX_DIFF 1000000/* -* Change schemata. Write schemata to specified -* con_mon grp, mon_grp in resctrl FS. -* Run 5 times in order to get average values. +* Minimum difference in LLC misses between a test with n+1 bits CBM to the +* test with n bits is MIN_DIFF_PERCENT_PER_BIT * (n - 1). With e.g. 5 vs 4 +* bits in the CBM mask, the minimum difference must be at least +* MIN_DIFF_PERCENT_PER_BIT * (4 - 1) = 3 percent. +* +* The relationship between number of used CBM bits and difference in LLC +* misses is not expected to be linear. With a small number of bits, the +* margin is smaller than with larger number of bits. For selftest purposes, +* however, linear approach is enough because ultimately only pass/fail +* decision has to be made and distinction between strong and stronger +* signal is irrelevant. */ -static int cat_setup (struct resctrl_val_param *p) -{ -char schemata[64 ]; -int ret =0 ; - -/* Run NUM_OF_RUNS times */ -if (p->num_of_runs >=NUM_OF_RUNS ) -return END_OF_TESTS ; - -if (p->num_of_runs ==0 ) { -sprintf (schemata,"%lx" , p->mask); - ret =write_schemata (p->ctrlgrp, schemata, p->cpu_no, - p->resctrl_val); - } - p->num_of_runs++; - -return ret; -} +#define MIN_DIFF_PERCENT_PER_BIT 1ULstatic int show_results_info (__u64 sum_llc_val,int no_of_bits, -unsigned long cache_span,unsigned long max_diff, -unsigned long max_diff_percent,unsigned long num_of_runs, -bool platform) +unsigned long cache_span, +unsigned long min_diff_percent, +unsigned long num_of_runs,bool platform, +__s64 *prev_avg_llc_val) {__u64 avg_llc_val =0 ; -float diff_percent; -int ret; +float avg_diff; +int ret =0 ; avg_llc_val = sum_llc_val / num_of_runs; - diff_percent = ((float )cache_span - avg_llc_val) / cache_span *100 ; +if (*prev_avg_llc_val) { +float delta = (__s64)(avg_llc_val - *prev_avg_llc_val); - ret = platform &&abs ((int )diff_percent) > max_diff_percent; + avg_diff = delta / *prev_avg_llc_val; + ret = platform && (avg_diff *100 ) < (float )min_diff_percent; -ksft_print_msg ("%s Check cache miss rate within %lu%%\n" , - ret ?"Fail:" :"Pass:" , max_diff_percent); +ksft_print_msg ("%s Check cache miss rate changed more than %.1f%%\n" , + ret ?"Fail:" :"Pass:" , (float )min_diff_percent); -ksft_print_msg ("Percent diff=%d\n" ,abs ((int )diff_percent)); +ksft_print_msg ("Percent diff=%.1f\n" , avg_diff *100 ); + } + *prev_avg_llc_val = avg_llc_val;show_cache_info (no_of_bits, avg_llc_val, cache_span, true);return ret; } -static int check_results (struct resctrl_val_param *param,size_t span) +/* Remove the highest bit from CBM */ +static unsigned long next_mask (unsigned long current_mask) +{ +return current_mask & (current_mask >>1 ); +} + +static int check_results (struct resctrl_val_param *param,const char *cache_type, +unsigned long cache_total_size,unsigned long full_cache_mask, +unsigned long current_mask) {char *token_array[8 ], temp[512 ]; -int runs =0 , no_of_bits =0 ;__u64 sum_llc_perf_miss =0 ; +__s64 prev_avg_llc_val =0 ; +unsigned long alloc_size; +int runs =0 ; +int fail =0 ; +int ret;FILE *fp;ksft_print_msg ("Checking for pass/fail\n" );
@@ -83,49 +88,78 @@ static int check_results(struct resctrl_val_param *param, size_t span)while (fgets (temp,sizeof (temp), fp)) {char *token =strtok (temp,":\t" );int fields =0 ; +int bits;while (token) { token_array[fields++] = token; token =strtok (NULL ,":\t" ); } -/* -* Discard the first value which is inaccurate due to monitoring -* setup transition phase. -*/ -if (runs >0 ) - sum_llc_perf_miss +=strtoull (token_array[3 ],NULL ,0 ); + + sum_llc_perf_miss +=strtoull (token_array[3 ],NULL ,0 ); runs++; + +if (runs <NUM_OF_RUNS ) +continue ; + +if (!current_mask) { +ksft_print_msg ("Unexpected empty cache mask\n" ); +break ; + } + + alloc_size =cache_portion_size (cache_total_size, current_mask, full_cache_mask); + + bits =count_bits (current_mask); + + ret =show_results_info (sum_llc_perf_miss, bits, + alloc_size /64 , +MIN_DIFF_PERCENT_PER_BIT * (bits -1 ), + runs,get_vendor () ==ARCH_INTEL , + &prev_avg_llc_val); +if (ret) + fail =1 ; + + runs =0 ; + sum_llc_perf_miss =0 ; + current_mask =next_mask (current_mask); }fclose (fp); - no_of_bits =count_bits (param->mask); -return show_results_info (sum_llc_perf_miss, no_of_bits, span /64 , -MAX_DIFF ,MAX_DIFF_PERCENT , runs -1 , -get_vendor () ==ARCH_INTEL ); +return fail; }void cat_test_cleanup (void ) { -remove (RESULT_FILE_NAME1 ); -remove (RESULT_FILE_NAME2 ); +remove (RESULT_FILE_NAME ); }/* * cat_test - Execute CAT benchmark and measure cache misses * @param: Parameters passed to cat_test() * @span: Buffer size for the benchmark +* @current_mask Start mask for the first iteration +* +* Run CAT selftest by varying the allocated cache portion and comparing the +* impact on cache misses (the result analysis is done in check_results() +* and show_results_info(), not in this function). +* +* One bit is removed from the CAT allocation bit mask (in current_mask) for +* each subsequent test which keeps reducing the size of the allocated cache +* portion. A single test flushes the buffer, reads it to warm up the cache, +* and reads the buffer again. The cache misses are measured during the last +* read pass. * * Return: 0 when the test was run, < 0 on error. */ -static int cat_test (struct resctrl_val_param *param,size_t span) +static int cat_test (struct resctrl_val_param *param,size_t span,unsigned long current_mask) { -int memflush =1 , operation =0 , ret =0 ;char *resctrl_val = param->resctrl_val;struct perf_event_read pe_read;struct perf_event_attr pea; +unsigned char *buf; +char schemata[64 ]; +int ret, i, pe_fd;pid_t bm_pid; -int pe_fd;if (strcmp (param->filename,"" ) ==0 )sprintf (param->filename,"stdio" );
@@ -149,48 +183,55 @@ static int cat_test(struct resctrl_val_param *param, size_t span)if (pe_fd <0 )return pe_fd; -/* Test runs until the callback setup() tells the test to stop. */ -while (1 ) { - ret = param->setup (param); -if (ret ==END_OF_TESTS ) { - ret =0 ; -break ; - } -if (ret <0 ) -break ; + buf =alloc_buffer (span,1 ); +if (!buf) { + ret =-1 ; + goto pe_close; + } - ret =perf_event_reset_enable (pe_fd); +while (current_mask) { +snprintf (schemata,sizeof (schemata),"%lx" , param->mask & ~current_mask); + ret =write_schemata ("" , schemata, param->cpu_no, param->resctrl_val);if (ret) - goto pe_close; + goto free_buf; +snprintf (schemata,sizeof (schemata),"%lx" , current_mask); + ret =write_schemata (param->ctrlgrp, schemata, param->cpu_no, param->resctrl_val); +if (ret) + goto free_buf; -if (run_fill_buf (span, memflush, operation, true)) { -fprintf (stderr,"Error-running fill buffer\n" ); - ret =-1 ; - goto pe_close; - } +for (i =0 ; i <NUM_OF_RUNS ; i++) { +mem_flush (buf, span); +fill_cache_read (buf, span, true); -sleep (1 ); - ret =perf_event_measure (pe_fd, &pe_read, param->filename, bm_pid); -if (ret) - goto pe_close; - } + ret =perf_event_reset_enable (pe_fd); +if (ret) + goto free_buf; -return ret; +fill_cache_read (buf, span, true); + ret =perf_event_measure (pe_fd, &pe_read, param->filename, bm_pid); +if (ret) + goto free_buf; + } + current_mask =next_mask (current_mask); + } + +free_buf: +free (buf); pe_close:close (pe_fd); +return ret; }int cat_perf_miss_val (int cpu_no,int n,char *cache_type) { -unsigned long full_cache_mask, long_mask; -unsigned long l_mask, l_mask_1; -int ret, pipefd[2 ], sibling_cpu_no; +unsigned long long_mask, start_mask, full_cache_mask;unsigned long cache_total_size =0 ; +unsigned int start;int count_of_bits; -char pipe_message;size_t span; +int ret; ret =get_full_cbm (cache_type, &full_cache_mask);if (ret)
@@ -206,7 +247,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)return ret;ksft_print_msg ("Cache size :%lu\n" , cache_total_size); - count_of_bits =count_bits (long_mask); + count_of_bits =count_contiguous_bits (long_mask, &start);if (!n) n = count_of_bits /2 ;
@@ -217,88 +258,26 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) count_of_bits - 1);return -1 ; } - -/* Get core id from same socket for running another thread */ - sibling_cpu_no =get_core_sibling (cpu_no); -if (sibling_cpu_no <0 ) -return -1 ; + start_mask =create_bit_mask (start, n);struct resctrl_val_param param = { .resctrl_val =CAT_STR , .cpu_no = cpu_no, - .setup = cat_setup, + .ctrlgrp ="c1" , + .filename =RESULT_FILE_NAME , + .num_of_runs =0 , }; - - l_mask = long_mask >> n; - l_mask_1 = ~l_mask & long_mask; - -/* Set param values for parent thread which will be allocated bitmask -* with (max_bits - n) bits -*/ - span =cache_portion_size (cache_total_size, l_mask, full_cache_mask); -strcpy (param.ctrlgrp,"c2" ); -strcpy (param.mongrp,"m2" ); -strcpy (param.filename,RESULT_FILE_NAME2 ); - param.mask = l_mask; - param.num_of_runs =0 ; - -if (pipe (pipefd)) { -ksft_perror ("Unable to create pipe" ); -return -1 ; - } - -fflush (stdout); - bm_pid =fork (); - -/* Set param values for child thread which will be allocated bitmask -* with n bits -*/ -if (bm_pid ==0 ) { - param.mask = l_mask_1; -strcpy (param.ctrlgrp,"c1" ); -strcpy (param.mongrp,"m1" ); - span =cache_portion_size (cache_total_size, l_mask_1, full_cache_mask); -strcpy (param.filename,RESULT_FILE_NAME1 ); - param.num_of_runs =0 ; - param.cpu_no = sibling_cpu_no; - } + param.mask = long_mask; + span =cache_portion_size (cache_total_size, start_mask, full_cache_mask);remove (param.filename); - ret =cat_test (¶m, span); -if (ret ==0 ) - ret =check_results (¶m, span); - -if (bm_pid ==0 ) { -/* Tell parent that child is ready */ -close (pipefd[0 ]); - pipe_message =1 ; -if (write (pipefd[1 ], &pipe_message,sizeof (pipe_message)) < -sizeof (pipe_message)) -/* -* Just print the error message. -* Let while(1) run and wait for itself to be killed. -*/ -ksft_perror ("Failed signaling parent process" ); - -close (pipefd[1 ]); -while (1 ) - ; - }else { -/* Parent waits for child to be ready. */ -close (pipefd[1 ]); - pipe_message =0 ; -while (pipe_message !=1 ) { -if (read (pipefd[0 ], &pipe_message, -sizeof (pipe_message)) <sizeof (pipe_message)) { -ksft_perror ("Failed reading from child process" ); -break ; - } - } -close (pipefd[0 ]); -kill (bm_pid,SIGKILL ); - } + ret =cat_test (¶m, span, start_mask); +if (ret) + goto out; + ret =check_results (¶m, cache_type, cache_total_size, full_cache_mask, start_mask); +out:cat_test_cleanup ();return ret;
tools/testing/selftests/resctrl/fill_buf.c +3 -3
@@ -38,7 +38,7 @@ static void cl_flush(void *p)#endif } -static void mem_flush (unsigned char *buf,size_t buf_size) +void mem_flush (unsigned char *buf,size_t buf_size) {unsigned char *cp = buf;size_t i =0 ;
@@ -100,7 +100,7 @@ static void fill_one_span_write(unsigned char *buf, size_t buf_size) } } -static void fill_cache_read (unsigned char *buf,size_t buf_size,bool once) +void fill_cache_read (unsigned char *buf,size_t buf_size,bool once) {int ret =0 ;
@@ -123,7 +123,7 @@ static void fill_cache_write(unsigned char *buf, size_t buf_size, bool once) } } -static unsigned char *alloc_buffer (size_t buf_size,int memflush) +unsigned char *alloc_buffer (size_t buf_size,int memflush) {void *buf =NULL ;uint64_t *p64;
tools/testing/selftests/resctrl/resctrl.h +4 -1
@@ -105,6 +105,9 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, char *resctrl_val);int perf_event_open (struct perf_event_attr *hw_event,pid_t pid,int cpu,int group_fd,unsigned long flags); +unsigned char *alloc_buffer (size_t buf_size,int memflush); +void mem_flush (unsigned char *buf,size_t buf_size); +void fill_cache_read (unsigned char *buf,size_t buf_size,bool once);int run_fill_buf (size_t buf_size,int memflush,int op,bool once);int resctrl_val (const char *const *benchmark_cmd,struct resctrl_val_param *param);int mbm_bw_change (int cpu_no,const char *const *benchmark_cmd);
@@ -113,6 +116,7 @@ void mbm_test_cleanup(void);int mba_schemata_change (int cpu_no,const char *const *benchmark_cmd);void mba_test_cleanup (void );unsigned long create_bit_mask (unsigned int start,unsigned int len); +unsigned int count_contiguous_bits (unsigned long val,unsigned int *start);int get_full_cbm (const char *cache_type,unsigned long *mask);int get_mask_no_shareable (const char *cache_type,unsigned long *mask);int get_cache_size (int cpu_no,const char *cache_type,unsigned long *cache_size);
@@ -124,7 +128,6 @@ int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type);int cmt_resctrl_val (int cpu_no,int n,const char *const *benchmark_cmd);unsigned int count_bits (unsigned long n);void cmt_test_cleanup (void ); -int get_core_sibling (int cpu_no);void perf_event_attr_initialize (struct perf_event_attr *pea,__u64 config);void perf_event_initialize_read_format (struct perf_event_read *pe_read);
tools/testing/selftests/resctrl/resctrlfs.c +1 -43
56 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH v3 22/29] selftests/resctrl: Rewrite Cache Allocation Technology (CAT) test
Hi Ilpo,
Quoted 23 lines · Ilpo Järvinen
CAT test spawns two processes into two different control groups with exclusive schemata. Both the processes alloc a buffer from memory matching their allocated LLC block size and flush the entire buffer out of caches. Since the processes are reading through the buffer only once during the measurement and initially all the buffer was flushed, the test isn't testing CAT.
Rewrite the CAT test to allocate a buffer sized to half of LLC. Then perform a sequence of tests with different LLC alloc sizes starting from half of the CBM bits down to 1-bit CBM. Flush the buffer before each test and read the buffer twice. Observe the LLC misses on the second read through the buffer. As the allocated LLC block gets smaller and smaller, the LLC misses will become larger and larger giving a strong signal on CAT working properly.
The new CAT test is using only a single process because it relies on measured effect against another run of itself rather than another process adding noise. The rest of the system is set to use the CBM bits not used by the CAT test to keep the test isolated.
Replace
count_bits()withcount_contiguous_bits()to get the first bit position in order to be able to calculate masks based on it.
Quoted 6 lines
This change has been tested with a number of systems from different generations.
Suggested-by Reinette Chatre <[email protected]>Signed-off-by Ilpo Järvinen <[email protected]>---
Thank you!
Reinette
PATCH v3 23/29 selftests/resctrl: Restore the CPU affinity after CAT test
In reply to Ilpo JärvinenCAT test does not reset the CPU affinity after the benchmark. This is relatively harmless as is because CAT test is the last benchmark to run, however, more tests may be added later.
Store the CPU affinity the first time taskset_benchmark() is run and add taskset_restore() which the test can call to reset the CPU mask to its original value.
---
v3:
- New patch
--- tools/testing/selftests/resctrl/cat_test.c | 13 +++++--- tools/testing/selftests/resctrl/resctrl.h | 3 +- tools/testing/selftests/resctrl/resctrl_val.c | 2 +- tools/testing/selftests/resctrl/resctrlfs.c | 33 +++++++++++++++++-- 4 files changed, 42 insertions(+), 9 deletions(-)
tools/testing/selftests/resctrl/cat_test.c +9 -4
@@ -156,6 +156,7 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned longchar *resctrl_val = param->resctrl_val;struct perf_event_read pe_read;struct perf_event_attr pea; +cpu_set_t old_affinity;unsigned char *buf;char schemata[64 ];int ret, i, pe_fd;
@@ -167,7 +168,7 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long bm_pid =getpid ();/* Taskset benchmark to specified cpu */ - ret =taskset_benchmark (bm_pid, param->cpu_no); + ret =taskset_benchmark (bm_pid, param->cpu_no, &old_affinity);if (ret)return ret;
@@ -175,13 +176,15 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long ret =write_bm_pid_to_resctrl (bm_pid, param->ctrlgrp, param->mongrp, resctrl_val);if (ret) -return ret; + goto reset_affinity;perf_event_attr_initialize (&pea,PERF_COUNT_HW_CACHE_MISSES );perf_event_initialize_read_format (&pe_read); pe_fd =perf_open (&pea, bm_pid, param->cpu_no); -if (pe_fd <0 ) -return pe_fd; +if (pe_fd <0 ) { + ret =-1 ; + goto reset_affinity; + } buf =alloc_buffer (span,1 );if (!buf) {
@@ -220,6 +223,8 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned longfree (buf); pe_close:close (pe_fd); +reset_affinity: +taskset_restore (bm_pid, &old_affinity);return ret; }
tools/testing/selftests/resctrl/resctrl.h +2 -1
@@ -98,7 +98,8 @@ int umount_resctrlfs(void);int validate_bw_report_request (char *bw_report);bool validate_resctrl_feature_request (const char *resource,const char *feature);char *fgrep (FILE *inf,const char *str); -int taskset_benchmark (pid_t bm_pid,int cpu_no); +int taskset_benchmark (pid_t bm_pid,int cpu_no,cpu_set_t *old_affinity); +int taskset_restore (pid_t bm_pid,cpu_set_t *old_affinity);int write_schemata (char *ctrlgrp,char *schemata,int cpu_no,char *resctrl_val); int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,
tools/testing/selftests/resctrl/resctrl_val.c +1 -1
@@ -777,7 +777,7 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par value.sival_ptr = (void *)benchmark_cmd;/* Taskset benchmark to specified cpu */ - ret =taskset_benchmark (bm_pid, param->cpu_no); + ret =taskset_benchmark (bm_pid, param->cpu_no,NULL );if (ret) goto out;
tools/testing/selftests/resctrl/resctrlfs.c +30 -3
@@ -345,15 +345,25 @@ int get_mask_no_shareable(const char *cache_type, unsigned long *mask)/* * taskset_benchmark - Taskset PID (i.e. benchmark) to a specified cpu -* @bm_pid: PID that should be binded -* @cpu_no: CPU number at which the PID would be binded +* @bm_pid: PID that should be binded +* @cpu_no: CPU number at which the PID would be binded +* @old_affinity: When not NULL, set to old CPU affinity * * Return: 0 on success, < 0 on error. */ -int taskset_benchmark (pid_t bm_pid,int cpu_no) +int taskset_benchmark (pid_t bm_pid,int cpu_no,cpu_set_t *old_affinity) {cpu_set_t my_set; +if (old_affinity) { +CPU_ZERO (old_affinity); +if (sched_getaffinity (bm_pid,sizeof (*old_affinity), + old_affinity)) { +ksft_perror ("Unable to read previous CPU affinity" ); +return -1 ; + } + } +CPU_ZERO (&my_set);CPU_SET (cpu_no, &my_set);
@@ -366,6 +376,23 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no)return 0 ; } +/* +* taskset_restore - Taskset PID to the earlier CPU affinity +* @bm_pid: PID that should be reset +* @old_affinity: The old CPU affinity to restore +* +* Return: 0 on success, < 0 on error. +*/ +int taskset_restore (pid_t bm_pid,cpu_set_t *old_affinity) +{ +if (sched_setaffinity (bm_pid,sizeof (*old_affinity), old_affinity)) { +ksft_perror ("Unable to restore taskset" ); +return -1 ; + } + +return 0 ; +} +/* * create_grp - Create a group only if one doesn't exist * @grp_name: Name of the group
Signature · 1 line
2.30.2
Re: [PATCH v3 23/29] selftests/resctrl: Restore the CPU affinity after CAT test
Hi Ilpo,
Quoted 112 lines · Ilpo Järvinen
CAT test does not reset the CPU affinity after the benchmark. This is relatively harmless as is because CAT test is the last benchmark to run, however, more tests may be added later.
Store the CPU affinity the first time
taskset_benchmark()is run and addtaskset_restore()which the test can call to reset the CPU mask to its original value.Signed-off-by Ilpo Järvinen <[email protected]>---
v3:
- New patch--- tools/testing/selftests/resctrl/cat_test.c | 13 +++++--- tools/testing/selftests/resctrl/resctrl.h | 3 +- tools/testing/selftests/resctrl/resctrl_val.c | 2 +- tools/testing/selftests/resctrl/resctrlfs.c | 33 +++++++++++++++++-- 4 files changed, 42 insertions(+), 9 deletions(-)tools/testing/selftests/resctrl/cat_test.c +9
-4@@ -156,6 +156,7 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned longchar *resctrl_val = param->resctrl_val;struct perf_event_read pe_read;struct perf_event_attr pea; +cpu_set_t old_affinity;unsigned char *buf;char schemata[64 ];int ret, i, pe_fd;@@ -167,7 +168,7 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long bm_pid =getpid ();/* Taskset benchmark to specified cpu */ - ret =taskset_benchmark (bm_pid, param->cpu_no); + ret =taskset_benchmark (bm_pid, param->cpu_no, &old_affinity);if (ret)return ret;@@ -175,13 +176,15 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long ret =write_bm_pid_to_resctrl (bm_pid, param->ctrlgrp, param->mongrp, resctrl_val);if (ret) -return ret; + goto reset_affinity;perf_event_attr_initialize (&pea,PERF_COUNT_HW_CACHE_MISSES );perf_event_initialize_read_format (&pe_read); pe_fd =perf_open (&pea, bm_pid, param->cpu_no); -if (pe_fd <0 ) -return pe_fd; +if (pe_fd <0 ) { + ret =-1 ; + goto reset_affinity; + } buf =alloc_buffer (span,1 );if (!buf) {@@ -220,6 +223,8 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned longfree (buf); pe_close:close (pe_fd); +reset_affinity: +taskset_restore (bm_pid, &old_affinity);return ret; }tools/testing/selftests/resctrl/resctrl.h +2
-1@@ -98,7 +98,8 @@ int umount_resctrlfs(void);int validate_bw_report_request (char *bw_report);bool validate_resctrl_feature_request (const char *resource,const char *feature);char *fgrep (FILE *inf,const char *str); -int taskset_benchmark (pid_t bm_pid,int cpu_no); +int taskset_benchmark (pid_t bm_pid,int cpu_no,cpu_set_t *old_affinity); +int taskset_restore (pid_t bm_pid,cpu_set_t *old_affinity);int write_schemata (char *ctrlgrp,char *schemata,int cpu_no,char *resctrl_val); int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,tools/testing/selftests/resctrl/resctrl_val.c +1
-1@@ -777,7 +777,7 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par value.sival_ptr = (void *)benchmark_cmd;/* Taskset benchmark to specified cpu */ - ret =taskset_benchmark (bm_pid, param->cpu_no); + ret =taskset_benchmark (bm_pid, param->cpu_no,NULL );if (ret) goto out;tools/testing/selftests/resctrl/resctrlfs.c +3
-2@@ -345,15 +345,25 @@ int get_mask_no_shareable(const char *cache_type, unsigned long *mask)/* * taskset_benchmark - Taskset PID (i.e. benchmark) to a specified cpu -* @bm_pid: PID that should be binded -* @cpu_no: CPU number at which the PID would be binded +* @bm_pid: PID that should be binded +* @cpu_no: CPU number at which the PID would be binded +* @old_affinity: When not NULL, set to old CPU affinity * * Return: 0 on success, < 0 on error. */
tools/testing/selftests/resctrl/resctrlfs.c int get_mask_no_shareable(const char *cache_type, unsigned long *mask) · line 362
Quoted 10 lines
tools/testing/selftests/resctrl/resctrlfs.c +6
-1-int taskset_benchmark (pid_t bm_pid,int cpu_no) +int taskset_benchmark (pid_t bm_pid,int cpu_no,cpu_set_t *old_affinity) {cpu_set_t my_set; +if (old_affinity) { +CPU_ZERO (old_affinity); +if (sched_getaffinity (bm_pid,sizeof (*old_affinity), + old_affinity)) { +ksft_perror ("Unable to read previous CPU affinity" );
"previous" can be confusing here (it is not trying to determine something from the past but instead the current state). It can just be "Unable to read CPU affinity"
Quoted 12 lines
tools/testing/selftests/resctrl/resctrlfs.c +5
-0+return -1 ; + } + } +CPU_ZERO (&my_set);CPU_SET (cpu_no, &my_set);@@ -366,6 +376,23 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no)return 0 ; } +/*
tools/testing/selftests/resctrl/resctrlfs.c int taskset_benchmark(pid_t bm_pid, int cpu_no) · line 389
Quoted 10 lines
tools/testing/selftests/resctrl/resctrlfs.c +10
-0+* taskset_restore - Taskset PID to the earlier CPU affinity +* @bm_pid: PID that should be reset +* @old_affinity: The old CPU affinity to restore +* +* Return: 0 on success, < 0 on error. +*/ +int taskset_restore (pid_t bm_pid,cpu_set_t *old_affinity) +{ +if (sched_setaffinity (bm_pid,sizeof (*old_affinity), old_affinity)) { +ksft_perror ("Unable to restore taskset" );
This message is not clear to me. How about "Unable to restore CPU affinity"?
tools/testing/selftests/resctrl/resctrlfs.c int taskset_benchmark(pid_t bm_pid, int cpu_no) · line 398
Quoted 9 lines
tools/testing/selftests/resctrl/resctrlfs.c +6
-0+return -1 ; + } + +return 0 ; +} +/* * create_grp - Create a group only if one doesn't exist * @grp_name: Name of the group
Reinette
Re: [PATCH v3 23/29] selftests/resctrl: Restore the CPU affinity after CAT test
Quoted 12 lines · Reinette Chatre
Quoted 10 lines · Ilpo Järvinen
CAT test does not reset the CPU affinity after the benchmark. This is relatively harmless as is because CAT test is the last benchmark to run, however, more tests may be added later.
Store the CPU affinity the first time
taskset_benchmark()is run and addtaskset_restore()which the test can call to reset the CPU mask to its original value.Signed-off-by Ilpo Järvinen <[email protected]>---
Quoted 13 lines
tools/testing/selftests/resctrl/resctrlfs.c int taskset_benchmark(pid_t bm_pid, int cpu_no) · line 389
Quoted 11 lines
tools/testing/selftests/resctrl/resctrlfs.c +11
-0+/* +* taskset_restore - Taskset PID to the earlier CPU affinity +* @bm_pid: PID that should be reset +* @old_affinity: The old CPU affinity to restore +* +* Return: 0 on success, < 0 on error. +*/ +int taskset_restore (pid_t bm_pid,cpu_set_t *old_affinity) +{ +if (sched_setaffinity (bm_pid,sizeof (*old_affinity), old_affinity)) { +ksft_perror ("Unable to restore taskset" );This message is not clear to me. How about "Unable to restore CPU affinity"?
Okay, I can change that. I actually was on the edge what to with these because I was just trying to be consistent with the existing error message in taskset_benchmark(). I reasoned that because "taskset" is the userspace tool which the user might be familiar the original idea of using "taskset" might be helpful.
And now rereading what I wrote in that message, "restore taskset" does not sound very sensical grammarwise. :-)
Signature · 1 line
i.
PATCH v3 24/29 selftests/resctrl: Create struct for input parameters
In reply to Ilpo Järvinenresctrl_tests reads a set of parameters and passes them individually for each tests which causes variations in the call signature between the tests.
Add struct input_params to hold all input parameters. It can be easily passed to every test without varying the call signature.
---
v3:
- Move uparams clear into init function
--- tools/testing/selftests/resctrl/cat_test.c | 20 +++--- tools/testing/selftests/resctrl/cmt_test.c | 16 ++--- tools/testing/selftests/resctrl/mba_test.c | 9 ++- tools/testing/selftests/resctrl/mbm_test.c | 9 ++- tools/testing/selftests/resctrl/resctrl.h | 28 ++++++--- .../testing/selftests/resctrl/resctrl_tests.c | 63 +++++++++++-------- tools/testing/selftests/resctrl/resctrl_val.c | 21 ++++--- 7 files changed, 95 insertions(+), 71 deletions(-)
tools/testing/selftests/resctrl/cat_test.c +11 -9
@@ -135,6 +135,7 @@ void cat_test_cleanup(void)/* * cat_test - Execute CAT benchmark and measure cache misses +* @uparams: User supplied parameters * @param: Parameters passed to cat_test() * @span: Buffer size for the benchmark * @current_mask Start mask for the first iteration
@@ -151,7 +152,8 @@ void cat_test_cleanup(void)* * Return: 0 when the test was run, < 0 on error. */ -static int cat_test (struct resctrl_val_param *param,size_t span,unsigned long current_mask) +static int cat_test (const struct user_params *uparams,struct resctrl_val_param *param, +size_t span,unsigned long current_mask) {char *resctrl_val = param->resctrl_val;struct perf_event_read pe_read;
@@ -168,7 +170,7 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long bm_pid =getpid ();/* Taskset benchmark to specified cpu */ - ret =taskset_benchmark (bm_pid, param->cpu_no, &old_affinity); + ret =taskset_benchmark (bm_pid, uparams->cpu, &old_affinity);if (ret)return ret;
@@ -180,7 +182,7 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned longperf_event_attr_initialize (&pea,PERF_COUNT_HW_CACHE_MISSES );perf_event_initialize_read_format (&pe_read); - pe_fd =perf_open (&pea, bm_pid, param->cpu_no); + pe_fd =perf_open (&pea, bm_pid, uparams->cpu);if (pe_fd <0 ) { ret =-1 ; goto reset_affinity;
@@ -194,11 +196,11 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned longwhile (current_mask) {snprintf (schemata,sizeof (schemata),"%lx" , param->mask & ~current_mask); - ret =write_schemata ("" , schemata, param->cpu_no, param->resctrl_val); + ret =write_schemata ("" , schemata, uparams->cpu, param->resctrl_val);if (ret) goto free_buf;snprintf (schemata,sizeof (schemata),"%lx" , current_mask); - ret =write_schemata (param->ctrlgrp, schemata, param->cpu_no, param->resctrl_val); + ret =write_schemata (param->ctrlgrp, schemata, uparams->cpu, param->resctrl_val);if (ret) goto free_buf;
@@ -229,10 +231,11 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned longreturn ret; } -int cat_perf_miss_val (int cpu_no,int n,char *cache_type) +int cat_perf_miss_val (const struct user_params *uparams,char *cache_type) {unsigned long long_mask, start_mask, full_cache_mask;unsigned long cache_total_size =0 ; +int n = uparams->bits;unsigned int start;int count_of_bits;size_t span;
@@ -247,7 +250,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)return ret;/* Get L3/L2 cache size */ - ret =get_cache_size (cpu_no, cache_type, &cache_total_size); + ret =get_cache_size (uparams->cpu, cache_type, &cache_total_size);if (ret)return ret;ksft_print_msg ("Cache size :%lu\n" , cache_total_size);
@@ -267,7 +270,6 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)struct resctrl_val_param param = { .resctrl_val =CAT_STR , - .cpu_no = cpu_no, .ctrlgrp ="c1" , .filename =RESULT_FILE_NAME , .num_of_runs =0 ,
@@ -277,7 +279,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)remove (param.filename); - ret =cat_test (¶m, span, start_mask); + ret =cat_test (uparams, ¶m, span, start_mask);if (ret) goto out;
tools/testing/selftests/resctrl/cmt_test.c +8 -8
@@ -16,7 +16,7 @@#define MAX_DIFF 2000000#define MAX_DIFF_PERCENT 15 -static int cmt_setup (struct resctrl_val_param *p) +static int cmt_setup (const struct user_params *uparams,struct resctrl_val_param *p) {/* Run NUM_OF_RUNS times */ if (p->num_of_runs >=NUM_OF_RUNS )
@@ -94,11 +94,12 @@ void cmt_test_cleanup(void)remove (RESULT_FILE_NAME ); } -int cmt_resctrl_val (int cpu_no,int n,const char *const *benchmark_cmd) +int cmt_resctrl_val (const struct user_params *uparams) { -const char *const *cmd = benchmark_cmd; +const char *const *cmd = uparams->benchmark_cmd;const char *new_cmd[BENCHMARK_ARGS ];unsigned long cache_total_size =0 ; +int n = uparams->bits ? :5 ;unsigned long long_mask;char *span_str =NULL ;int count_of_bits;
@@ -109,7 +110,7 @@ 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_total_size); + ret =get_cache_size (uparams->cpu,"L3" , &cache_total_size);if (ret)return ret;ksft_print_msg ("Cache size :%lu\n" , cache_total_size);
@@ -126,7 +127,6 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd) .resctrl_val = CMT_STR, .ctrlgrp = "c1", .mongrp = "m1", - .cpu_no = cpu_no, .filename = RESULT_FILE_NAME, .mask = ~(long_mask << n) & long_mask, .num_of_runs = 0,
@@ -137,8 +137,8 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd)if (strcmp (cmd[0 ],"fill_buf" ) ==0 ) {/* Duplicate the command to be able to replace span in it */ -for (i =0 ; benchmark_cmd[i]; i++) - new_cmd[i] = benchmark_cmd[i]; +for (i =0 ; uparams->benchmark_cmd[i]; i++) + new_cmd[i] = uparams->benchmark_cmd[i]; new_cmd[i] =NULL ; ret =asprintf (&span_str,"%zu" , span);
@@ -150,7 +150,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd)remove (RESULT_FILE_NAME ); - ret =resctrl_val (cmd, ¶m); + ret =resctrl_val (uparams, cmd, ¶m);if (ret) goto out;
tools/testing/selftests/resctrl/mba_test.c +4 -5
@@ -22,7 +22,7 @@* con_mon grp, mon_grp in resctrl FS. * For each allocation, run 5 times in order to get average values. */ -static int mba_setup (struct resctrl_val_param *p) +static int mba_setup (const struct user_params *uparams,struct resctrl_val_param *p) {static int runs_per_allocation, allocation =100 ;char allocation_str[64 ];
@@ -40,7 +40,7 @@ static int mba_setup(struct resctrl_val_param *p)sprintf (allocation_str,"%d" , allocation); - ret =write_schemata (p->ctrlgrp, allocation_str, p->cpu_no, + ret =write_schemata (p->ctrlgrp, allocation_str, uparams->cpu, p->resctrl_val);if (ret <0 )return ret;
@@ -141,13 +141,12 @@ void mba_test_cleanup(void)remove (RESULT_FILE_NAME ); } -int mba_schemata_change (int cpu_no,const char *const *benchmark_cmd) +int mba_schemata_change (const struct user_params *uparams) {struct resctrl_val_param param = { .resctrl_val =MBA_STR , .ctrlgrp ="c1" , .mongrp ="m1" , - .cpu_no = cpu_no, .filename =RESULT_FILE_NAME , .bw_report ="reads" , .setup = mba_setup
@@ -156,7 +155,7 @@ int mba_schemata_change(int cpu_no, const char * const *benchmark_cmd)remove (RESULT_FILE_NAME ); - ret =resctrl_val (benchmark_cmd, ¶m); + ret =resctrl_val (uparams, uparams->benchmark_cmd, ¶m);if (ret) goto out;
tools/testing/selftests/resctrl/mbm_test.c +4 -5
@@ -86,7 +86,7 @@ static int check_results(size_t span)return ret; } -static int mbm_setup (struct resctrl_val_param *p) +static int mbm_setup (const struct user_params *uparams,struct resctrl_val_param *p) {int ret =0 ;
@@ -96,7 +96,7 @@ static int mbm_setup(struct resctrl_val_param *p)/* Set up shemata with 100% allocation on the first run. */ if (p->num_of_runs ==0 &&validate_resctrl_feature_request ("MB" ,NULL )) - ret =write_schemata (p->ctrlgrp,"100" , p->cpu_no, + ret =write_schemata (p->ctrlgrp,"100" , uparams->cpu, p->resctrl_val); p->num_of_runs++;
@@ -109,13 +109,12 @@ void mbm_test_cleanup(void)remove (RESULT_FILE_NAME ); } -int mbm_bw_change (int cpu_no,const char *const *benchmark_cmd) +int mbm_bw_change (const struct user_params *uparams) {struct resctrl_val_param param = { .resctrl_val =MBM_STR , .ctrlgrp ="c1" , .mongrp ="m1" , - .cpu_no = cpu_no, .filename =RESULT_FILE_NAME , .bw_report ="reads" , .setup = mbm_setup
@@ -124,7 +123,7 @@ int mbm_bw_change(int cpu_no, const char * const *benchmark_cmd)remove (RESULT_FILE_NAME ); - ret =resctrl_val (benchmark_cmd, ¶m); + ret =resctrl_val (uparams, uparams->benchmark_cmd, ¶m);if (ret) goto out;
tools/testing/selftests/resctrl/resctrl.h +20 -8
@@ -44,12 +44,23 @@exit (EXIT_FAILURE ); \ }while (0 ) +/* +* user_params: User supplied parameters +* @cpu: CPU number to which the benchmark will be bound to +* @bits: Number of bits used for cache allocation size +* @benchmark_cmd: Benchmark command to run during (some of the) tests +*/ +struct user_params { +int cpu; +int bits; +const char *benchmark_cmd[BENCHMARK_ARGS ]; +}; +/* * resctrl_val_param: resctrl test parameters * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) * @ctrlgrp: Name of the control monitor group (con_mon grp) * @mongrp: Name of the monitor group (mon grp) -* @cpu_no: CPU number to which the benchmark would be binded * @filename: Name of file to which the o/p should be written * @bw_report: Bandwidth report type (reads vs writes) * @setup: Call back function to setup test environment
@@ -58,12 +69,12 @@ struct resctrl_val_param {char *resctrl_val;char ctrlgrp[64 ];char mongrp[64 ]; -int cpu_no;char filename[64 ];char *bw_report;unsigned long mask;int num_of_runs; -int (*setup)(struct resctrl_val_param *param); +int (*setup)(const struct user_params *uparams, +struct resctrl_val_param *param); };struct perf_event_read {
@@ -110,11 +121,12 @@ unsigned char *alloc_buffer(size_t buf_size, int memflush);void mem_flush (unsigned char *buf,size_t buf_size);void fill_cache_read (unsigned char *buf,size_t buf_size,bool once);int run_fill_buf (size_t buf_size,int memflush,int op,bool once); -int resctrl_val (const char *const *benchmark_cmd,struct resctrl_val_param *param); -int mbm_bw_change (int cpu_no,const char *const *benchmark_cmd); +int resctrl_val (const struct user_params *uparams,const char *const *benchmark_cmd, +struct resctrl_val_param *param); +int mbm_bw_change (const struct user_params *uparams);void tests_cleanup (void );void mbm_test_cleanup (void ); -int mba_schemata_change (int cpu_no,const char *const *benchmark_cmd); +int mba_schemata_change (const struct user_params *uparams);void mba_test_cleanup (void );unsigned long create_bit_mask (unsigned int start,unsigned int len);unsigned int count_contiguous_bits (unsigned long val,unsigned int *start);
@@ -125,8 +137,8 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr);int signal_handler_register (void );void signal_handler_unregister (void );void cat_test_cleanup (void ); -int cat_perf_miss_val (int cpu_no,int no_of_bits,char *cache_type); -int cmt_resctrl_val (int cpu_no,int n,const char *const *benchmark_cmd); +int cat_perf_miss_val (const struct user_params *uparams,char *cache_type); +int cmt_resctrl_val (const struct user_params *uparams);unsigned int count_bits (unsigned long n);void cmt_test_cleanup (void );
tools/testing/selftests/resctrl/resctrl_tests.c +36 -27
158 lines not on this page · raw message
tools/testing/selftests/resctrl/resctrl_val.c +12 -9
@@ -593,8 +593,9 @@ static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp,set_cmt_path (ctrlgrp, mongrp, resource_id); } -static int -measure_vals (struct resctrl_val_param *param,unsigned long *bw_resc_start) +static int measure_vals (const struct user_params *uparams, +struct resctrl_val_param *param, +unsigned long *bw_resc_start) {unsigned long bw_resc, bw_resc_end;float bw_imc;
@@ -607,7 +608,7 @@ measure_vals(struct resctrl_val_param *param, unsigned long *bw_resc_start)* Compare the two values to validate resctrl value. * It takes 1sec to measure the data. */ - ret =get_mem_bw_imc (param->cpu_no, param->bw_report, &bw_imc); + ret =get_mem_bw_imc (uparams->cpu, param->bw_report, &bw_imc);if (ret <0 )return ret;
@@ -683,12 +684,14 @@ static void run_benchmark(int signum, siginfo_t *info, void *ucontext)/* * resctrl_val: execute benchmark and measure memory bandwidth on * the benchmark +* @uparams: user supplied parameters * @benchmark_cmd: benchmark command and its arguments * @param: parameters passed to resctrl_val() * * Return: 0 when the test was run, < 0 on error. */ -int resctrl_val (const char *const *benchmark_cmd,struct resctrl_val_param *param) +int resctrl_val (const struct user_params *uparams,const char *const *benchmark_cmd, +struct resctrl_val_param *param) {char *resctrl_val = param->resctrl_val;unsigned long bw_resc_start =0 ;
@@ -777,7 +780,7 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par value.sival_ptr = (void *)benchmark_cmd;/* Taskset benchmark to specified cpu */ - ret =taskset_benchmark (bm_pid, param->cpu_no,NULL ); + ret =taskset_benchmark (bm_pid, uparams->cpu,NULL );if (ret) goto out;
@@ -794,10 +797,10 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par goto out;initialize_mem_bw_resctrl (param->ctrlgrp, param->mongrp, - param->cpu_no, resctrl_val); + uparams->cpu, resctrl_val); }else if (!strncmp (resctrl_val,CMT_STR ,sizeof (CMT_STR )))initialize_llc_occu_resctrl (param->ctrlgrp, param->mongrp, - param->cpu_no, resctrl_val); + uparams->cpu, resctrl_val);/* Parent waits for child to be ready. */ close (pipefd[1 ]);
@@ -823,7 +826,7 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par/* Test runs until the callback setup() tells the test to stop. */ while (1 ) { - ret = param->setup (param); + ret = param->setup (uparams, param);if (ret ==END_OF_TESTS ) { ret =0 ;break ;
@@ -833,7 +836,7 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *parif (!strncmp (resctrl_val,MBM_STR ,sizeof (MBM_STR )) || !strncmp (resctrl_val,MBA_STR ,sizeof (MBA_STR ))) { - ret =measure_vals (param, &bw_resc_start); + ret =measure_vals (uparams, param, &bw_resc_start);if (ret)break ; }else if (!strncmp (resctrl_val,CMT_STR ,sizeof (CMT_STR ))) {
Signature · 1 line
2.30.2
Re: [PATCH v3 24/29] selftests/resctrl: Create struct for input parameters
Hi Ilpo,
Quoted 9 lines · Ilpo Järvinen
resctrl_testsreads a set of parameters and passes them individually for each tests which causes variations in the call signature between the tests.Add struct
input_paramsto hold all input parameters. It can be easily passed to every test without varying the call signature.Signed-off-by Ilpo Järvinen <[email protected]>---
Reinette
PATCH v3 25/29 selftests/resctrl: Introduce generalized test framework
In reply to Ilpo JärvinenEach test currently has a "run test" function in per test file and another resctrl_tests.c. The functions in resctrl_tests.c are almost identical.
Generalize the one in resctrl_tests.c such that it can be shared between all of the tests. It makes adding new tests easier and removes the per test if () forests.
Also add comment to CPU vendor IDs that they must be defined as bits for a bitmask.
---
v3:
- Add CPU vendor ID bitmask comment
- Use test_resource_feature_check(test) in CMT
--- tools/testing/selftests/resctrl/cat_test.c | 18 +- tools/testing/selftests/resctrl/cmt_test.c | 17 +- tools/testing/selftests/resctrl/mba_test.c | 16 +- tools/testing/selftests/resctrl/mbm_test.c | 18 +- tools/testing/selftests/resctrl/resctrl.h | 35 +++- .../testing/selftests/resctrl/resctrl_tests.c | 160 ++++++------------ tools/testing/selftests/resctrl/resctrlfs.c | 5 + 7 files changed, 148 insertions(+), 121 deletions(-)
tools/testing/selftests/resctrl/cat_test.c +13 -5
@@ -231,7 +231,7 @@ static int cat_test(const struct user_params *uparams, struct resctrl_val_paramreturn ret; } -int cat_perf_miss_val (const struct user_params *uparams,char *cache_type) +static int cat_run_test (const struct resctrl_test *test,const struct user_params *uparams) {unsigned long long_mask, start_mask, full_cache_mask;unsigned long cache_total_size =0 ;
@@ -241,16 +241,16 @@ int cat_perf_miss_val(const struct user_params *uparams, char *cache_type)size_t span;int ret; - ret =get_full_cbm (cache_type, &full_cache_mask); + ret =get_full_cbm (test->resource, &full_cache_mask);if (ret)return ret;/* Get the largest contiguous exclusive portion of the cache */ - ret =get_mask_no_shareable (cache_type, &long_mask); + ret =get_mask_no_shareable (test->resource, &long_mask);if (ret)return ret;/* Get L3/L2 cache size */ - ret =get_cache_size (uparams->cpu, cache_type, &cache_total_size); + ret =get_cache_size (uparams->cpu, test->resource, &cache_total_size);if (ret)return ret;ksft_print_msg ("Cache size :%lu\n" , cache_total_size);
@@ -283,9 +283,17 @@ int cat_perf_miss_val(const struct user_params *uparams, char *cache_type)if (ret) goto out; - ret =check_results (¶m, cache_type, cache_total_size, full_cache_mask, start_mask); + ret =check_results (¶m, test->resource, + cache_total_size, full_cache_mask, start_mask); out:cat_test_cleanup ();return ret; } + +struct resctrl_test l3_cat_test = { + .name ="CAT" , + .resource ="L3" , + .feature_check = test_resource_feature_check, + .run_test = cat_run_test, +};
tools/testing/selftests/resctrl/cmt_test.c +16 -1
@@ -94,7 +94,7 @@ void cmt_test_cleanup(void)remove (RESULT_FILE_NAME ); } -int cmt_resctrl_val (const struct user_params *uparams) +static int cmt_run_test (const struct resctrl_test *test,const struct user_params *uparams) {const char *const *cmd = uparams->benchmark_cmd;const char *new_cmd[BENCHMARK_ARGS ];
@@ -155,6 +155,8 @@ int cmt_resctrl_val(const struct user_params *uparams) goto out; ret =check_results (¶m, span, n); +if (ret && (get_vendor () ==ARCH_INTEL )) +ksft_print_msg ("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n" ); out:cmt_test_cleanup ();
@@ -162,3 +164,16 @@ int cmt_resctrl_val(const struct user_params *uparams)return ret; } + +static bool cmt_feature_check (const struct resctrl_test *test) +{ +return test_resource_feature_check (test) && +validate_resctrl_feature_request ("L3_MON" ,"llc_occupancy" ); +} + +struct resctrl_test cmt_test = { + .name ="CMT" , + .resource ="L3" , + .feature_check = cmt_feature_check, + .run_test = cmt_run_test, +};
tools/testing/selftests/resctrl/mba_test.c +15 -1
@@ -141,7 +141,7 @@ void mba_test_cleanup(void)remove (RESULT_FILE_NAME ); } -int mba_schemata_change (const struct user_params *uparams) +static int mba_run_test (const struct resctrl_test *test,const struct user_params *uparams) {struct resctrl_val_param param = { .resctrl_val =MBA_STR ,
@@ -166,3 +166,17 @@ int mba_schemata_change(const struct user_params *uparams)return ret; } + +static bool mba_feature_check (const struct resctrl_test *test) +{ +return test_resource_feature_check (test) && +validate_resctrl_feature_request ("L3_MON" ,"mbm_local_bytes" ); +} + +struct resctrl_test mba_test = { + .name ="MBA" , + .resource ="MB" , + .vendor_specific =ARCH_INTEL , + .feature_check = mba_feature_check, + .run_test = mba_run_test, +};
tools/testing/selftests/resctrl/mbm_test.c +17 -1
@@ -109,7 +109,7 @@ void mbm_test_cleanup(void)remove (RESULT_FILE_NAME ); } -int mbm_bw_change (const struct user_params *uparams) +static int mbm_run_test (const struct resctrl_test *test,const struct user_params *uparams) {struct resctrl_val_param param = { .resctrl_val =MBM_STR ,
@@ -128,9 +128,25 @@ int mbm_bw_change(const struct user_params *uparams) goto out; ret =check_results (DEFAULT_SPAN ); +if (ret && (get_vendor () ==ARCH_INTEL )) +ksft_print_msg ("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n" ); out:mbm_test_cleanup ();return ret; } + +static bool mbm_feature_check (const struct resctrl_test *test) +{ +return validate_resctrl_feature_request ("L3_MON" ,"mbm_total_bytes" ) && +validate_resctrl_feature_request ("L3_MON" ,"mbm_local_bytes" ); +} + +struct resctrl_test mbm_test = { + .name ="MBM" , + .resource ="MB" , + .vendor_specific =ARCH_INTEL , + .feature_check = mbm_feature_check, + .run_test = mbm_run_test, +};
tools/testing/selftests/resctrl/resctrl.h +31 -4
@@ -28,6 +28,12 @@#define PHYS_ID_PATH "/sys/devices/system/cpu/cpu"#define INFO_PATH "/sys/fs/resctrl/info" +/* +* CPU vendor IDs +* +* Define as bits because they're used for vendor_specific bitmask in +* the struct resctrl_test. +*/ #define ARCH_INTEL 1#define ARCH_AMD 2
@@ -56,6 +62,25 @@ struct user_params {const char *benchmark_cmd[BENCHMARK_ARGS ]; }; +/* +* resctrl_test: resctrl test definition +* @name: Test name +* @resource: Resource to test (e.g., MB, L3, L2, etc.) +* @vendor_specific: Bitmask for vendor-specific tests (can be 0 for universal tests) +* @disabled: Test is disabled +* @feature_check: Callback to check required resctrl features +* @run_test: Callback to run the test +*/ +struct resctrl_test { +const char *name; +const char *resource; +unsigned int vendor_specific; +bool disabled; +bool (*feature_check)(const struct resctrl_test *test); +int (*run_test)(const struct resctrl_test *test, +const struct user_params *uparams); +}; +/* * resctrl_val_param: resctrl test parameters * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc)
@@ -108,6 +133,7 @@ int mount_resctrlfs(void);int umount_resctrlfs (void );int validate_bw_report_request (char *bw_report);bool validate_resctrl_feature_request (const char *resource,const char *feature); +bool test_resource_feature_check (const struct resctrl_test *test);char *fgrep (FILE *inf,const char *str);int taskset_benchmark (pid_t bm_pid,int cpu_no,cpu_set_t *old_affinity);int taskset_restore (pid_t bm_pid,cpu_set_t *old_affinity);
@@ -123,10 +149,8 @@ void fill_cache_read(unsigned char *buf, size_t buf_size, bool once);int run_fill_buf (size_t buf_size,int memflush,int op,bool once);int resctrl_val (const struct user_params *uparams,const char *const *benchmark_cmd,struct resctrl_val_param *param); -int mbm_bw_change (const struct user_params *uparams);void tests_cleanup (void );void mbm_test_cleanup (void ); -int mba_schemata_change (const struct user_params *uparams);void mba_test_cleanup (void );unsigned long create_bit_mask (unsigned int start,unsigned int len);unsigned int count_contiguous_bits (unsigned long val,unsigned int *start);
@@ -137,8 +161,6 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr);int signal_handler_register (void );void signal_handler_unregister (void );void cat_test_cleanup (void ); -int cat_perf_miss_val (const struct user_params *uparams,char *cache_type); -int cmt_resctrl_val (const struct user_params *uparams);unsigned int count_bits (unsigned long n);void cmt_test_cleanup (void );
@@ -166,4 +188,9 @@ static inline int cache_portion_size(unsigned long cache_size, return cache_size * count_bits(portion_mask) / count_bits(full_cache_mask); } +extern struct resctrl_test mbm_test; +extern struct resctrl_test mba_test; +extern struct resctrl_test cmt_test; +extern struct resctrl_test l3_cat_test; +#endif /* RESCTRL_H */
tools/testing/selftests/resctrl/resctrl_tests.c +51 -109
225 lines not on this page · raw message
tools/testing/selftests/resctrl/resctrlfs.c +5 -0
@@ -706,6 +706,11 @@ bool validate_resctrl_feature_request(const char *resource, const char *feature)return !!res; } +bool test_resource_feature_check (const struct resctrl_test *test) +{ +return validate_resctrl_feature_request (test->resource,NULL ); +} +int filter_dmesg (void ) {char line[1024 ];
Signature · 1 line
2.30.2
Re: [PATCH v3 25/29] selftests/resctrl: Introduce generalized test framework
Hi Ilpo,
Quoted 8 lines · Ilpo Järvinen
Each test currently has a "run test" function in per test file and another
resctrl_tests.c. The functions inresctrl_tests.care almost identical.Generalize the one in
resctrl_tests.csuch that it can be shared between all of the tests. It makes adding new tests easier and removes the per test if () forests.
Quoted 5 lines
Also add comment to CPU vendor IDs that they must be defined as bits for a bitmask.
Signed-off-by Ilpo Järvinen <[email protected]>---
Reinette
PATCH v3 26/29 selftests/resctrl: Pass write_schemata() resource instead of test name
In reply to Ilpo Järvinenwrite_schemata() takes the test name as an argument and determines the relevant resource based on the test name. Such mapping from name to resource does not really belong to resctrlfs.c that should provide only generic, test-independent functions.
Pass the resource stored in the test information structure to write_schemata() instead of the test name. The new API is also more flexible as it enables to use write_schemata() for more than one resource within a test.
While touching the sprintf(), move the unnecessary %c that is always '=' directly into the format string.
---
v3:
- "feature" -> "resource" in function comment
--- tools/testing/selftests/resctrl/cat_test.c | 11 +++++---- tools/testing/selftests/resctrl/cmt_test.c | 6 +++-- tools/testing/selftests/resctrl/mba_test.c | 9 +++---- tools/testing/selftests/resctrl/mbm_test.c | 9 +++---- tools/testing/selftests/resctrl/resctrl.h | 10 ++++---- tools/testing/selftests/resctrl/resctrl_val.c | 7 ++++-- tools/testing/selftests/resctrl/resctrlfs.c | 24 +++++-------------- 7 files changed, 38 insertions(+), 38 deletions(-)
tools/testing/selftests/resctrl/cat_test.c +7 -4
@@ -135,6 +135,7 @@ void cat_test_cleanup(void)/* * cat_test - Execute CAT benchmark and measure cache misses +* @test: Test information structure * @uparams: User supplied parameters * @param: Parameters passed to cat_test() * @span: Buffer size for the benchmark
@@ -152,7 +153,9 @@ void cat_test_cleanup(void)* * Return: 0 when the test was run, < 0 on error. */ -static int cat_test (const struct user_params *uparams,struct resctrl_val_param *param, +static int cat_test (const struct resctrl_test *test, +const struct user_params *uparams, +struct resctrl_val_param *param,size_t span,unsigned long current_mask) {char *resctrl_val = param->resctrl_val;
@@ -196,11 +199,11 @@ static int cat_test(const struct user_params *uparams, struct resctrl_val_paramwhile (current_mask) {snprintf (schemata,sizeof (schemata),"%lx" , param->mask & ~current_mask); - ret =write_schemata ("" , schemata, uparams->cpu, param->resctrl_val); + ret =write_schemata ("" , schemata, uparams->cpu, test->resource);if (ret) goto free_buf;snprintf (schemata,sizeof (schemata),"%lx" , current_mask); - ret =write_schemata (param->ctrlgrp, schemata, uparams->cpu, param->resctrl_val); + ret =write_schemata (param->ctrlgrp, schemata, uparams->cpu, test->resource);if (ret) goto free_buf;
@@ -279,7 +282,7 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_paramremove (param.filename); - ret =cat_test (uparams, ¶m, span, start_mask); + ret =cat_test (test, uparams, ¶m, span, start_mask);if (ret) goto out;
tools/testing/selftests/resctrl/cmt_test.c +4 -2
@@ -16,7 +16,9 @@#define MAX_DIFF 2000000#define MAX_DIFF_PERCENT 15 -static int cmt_setup (const struct user_params *uparams,struct resctrl_val_param *p) +static int cmt_setup (const struct resctrl_test *test, +const struct user_params *uparams, +struct resctrl_val_param *p) {/* Run NUM_OF_RUNS times */ if (p->num_of_runs >=NUM_OF_RUNS )
@@ -150,7 +152,7 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_paramremove (RESULT_FILE_NAME ); - ret =resctrl_val (uparams, cmd, ¶m); + ret =resctrl_val (test, uparams, cmd, ¶m);if (ret) goto out;
tools/testing/selftests/resctrl/mba_test.c +5 -4
@@ -22,7 +22,9 @@* con_mon grp, mon_grp in resctrl FS. * For each allocation, run 5 times in order to get average values. */ -static int mba_setup (const struct user_params *uparams,struct resctrl_val_param *p) +static int mba_setup (const struct resctrl_test *test, +const struct user_params *uparams, +struct resctrl_val_param *p) {static int runs_per_allocation, allocation =100 ;char allocation_str[64 ];
@@ -40,8 +42,7 @@ static int mba_setup(const struct user_params *uparams, struct resctrl_val_paramsprintf (allocation_str,"%d" , allocation); - ret =write_schemata (p->ctrlgrp, allocation_str, uparams->cpu, - p->resctrl_val); + ret =write_schemata (p->ctrlgrp, allocation_str, uparams->cpu, test->resource);if (ret <0 )return ret;
@@ -155,7 +156,7 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_paramremove (RESULT_FILE_NAME ); - ret =resctrl_val (uparams, uparams->benchmark_cmd, ¶m); + ret =resctrl_val (test, uparams, uparams->benchmark_cmd, ¶m);if (ret) goto out;
tools/testing/selftests/resctrl/mbm_test.c +5 -4
@@ -86,7 +86,9 @@ static int check_results(size_t span)return ret; } -static int mbm_setup (const struct user_params *uparams,struct resctrl_val_param *p) +static int mbm_setup (const struct resctrl_test *test, +const struct user_params *uparams, +struct resctrl_val_param *p) {int ret =0 ;
@@ -96,8 +98,7 @@ static int mbm_setup(const struct user_params *uparams, struct resctrl_val_param/* Set up shemata with 100% allocation on the first run. */ if (p->num_of_runs ==0 &&validate_resctrl_feature_request ("MB" ,NULL )) - ret =write_schemata (p->ctrlgrp,"100" , uparams->cpu, - p->resctrl_val); + ret =write_schemata (p->ctrlgrp,"100" , uparams->cpu, test->resource); p->num_of_runs++;
@@ -123,7 +124,7 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_paramremove (RESULT_FILE_NAME ); - ret =resctrl_val (uparams, uparams->benchmark_cmd, ¶m); + ret =resctrl_val (test, uparams, uparams->benchmark_cmd, ¶m);if (ret) goto out;
tools/testing/selftests/resctrl/resctrl.h +6 -4
@@ -98,7 +98,8 @@ struct resctrl_val_param {char *bw_report;unsigned long mask;int num_of_runs; -int (*setup)(const struct user_params *uparams, +int (*setup)(const struct resctrl_test *test, +const struct user_params *uparams,struct resctrl_val_param *param); };
@@ -137,8 +138,7 @@ bool test_resource_feature_check(const struct resctrl_test *test);char *fgrep (FILE *inf,const char *str);int taskset_benchmark (pid_t bm_pid,int cpu_no,cpu_set_t *old_affinity);int taskset_restore (pid_t bm_pid,cpu_set_t *old_affinity); -int write_schemata (char *ctrlgrp,char *schemata,int cpu_no, -char *resctrl_val); +int write_schemata (char *ctrlgrp,char *schemata,int cpu_no,const char *resource);int write_bm_pid_to_resctrl (pid_t bm_pid,char *ctrlgrp,char *mongrp,char *resctrl_val); int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu,
@@ -147,7 +147,9 @@ unsigned char *alloc_buffer(size_t buf_size, int memflush);void mem_flush (unsigned char *buf,size_t buf_size);void fill_cache_read (unsigned char *buf,size_t buf_size,bool once);int run_fill_buf (size_t buf_size,int memflush,int op,bool once); -int resctrl_val (const struct user_params *uparams,const char *const *benchmark_cmd, +int resctrl_val (const struct resctrl_test *test, +const struct user_params *uparams, +const char *const *benchmark_cmd,struct resctrl_val_param *param);void tests_cleanup (void );void mbm_test_cleanup (void );
tools/testing/selftests/resctrl/resctrl_val.c +5 -2
@@ -684,13 +684,16 @@ static void run_benchmark(int signum, siginfo_t *info, void *ucontext)/* * resctrl_val: execute benchmark and measure memory bandwidth on * the benchmark +* @test: test information structure * @uparams: user supplied parameters * @benchmark_cmd: benchmark command and its arguments * @param: parameters passed to resctrl_val() * * Return: 0 when the test was run, < 0 on error. */ -int resctrl_val (const struct user_params *uparams,const char *const *benchmark_cmd, +int resctrl_val (const struct resctrl_test *test, +const struct user_params *uparams, +const char *const *benchmark_cmd,struct resctrl_val_param *param) {char *resctrl_val = param->resctrl_val;
@@ -826,7 +829,7 @@ int resctrl_val(const struct user_params *uparams, const char * const *benchmark/* Test runs until the callback setup() tells the test to stop. */ while (1 ) { - ret = param->setup (uparams, param); + ret = param->setup (test, uparams, param);if (ret ==END_OF_TESTS ) { ret =0 ;break ;
tools/testing/selftests/resctrl/resctrlfs.c +6 -18
@@ -529,23 +529,17 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,* @ctrlgrp: Name of the con_mon grp * @schemata: Schemata that should be updated to * @cpu_no: CPU number that the benchmark PID is binded to -* @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) +* @resource: Resctrl resource (Eg: MB, L3, L2, etc.) * -* Update schemata of a con_mon grp *only* if requested resctrl feature is +* Update schemata of a con_mon grp *only* if requested resctrl resource is * allocation type * * Return: 0 on success, < 0 on error. */ -int write_schemata (char *ctrlgrp,char *schemata,int cpu_no,char *resctrl_val) +int write_schemata (char *ctrlgrp,char *schemata,int cpu_no,const char *resource) {char controlgroup[1024 ], reason[128 ], schema[1024 ] = {}; -int resource_id, fd, schema_len =-1 , ret =0 ; - -if (strncmp (resctrl_val,MBA_STR ,sizeof (MBA_STR )) && -strncmp (resctrl_val,MBM_STR ,sizeof (MBM_STR )) && -strncmp (resctrl_val,CAT_STR ,sizeof (CAT_STR )) && -strncmp (resctrl_val,CMT_STR ,sizeof (CMT_STR ))) -return -ENOENT ; +int resource_id, fd, schema_len, ret =0 ;if (!schemata) {ksft_print_msg ("Skipping empty schemata update\n" );
@@ -565,14 +559,8 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val)else sprintf (controlgroup,"%s/schemata" ,RESCTRL_PATH ); -if (!strncmp (resctrl_val,CAT_STR ,sizeof (CAT_STR )) || - !strncmp (resctrl_val,CMT_STR ,sizeof (CMT_STR ))) - schema_len =snprintf (schema,sizeof (schema),"%s%d%c%s\n" , -"L3:" , resource_id,'=' , schemata); -if (!strncmp (resctrl_val,MBA_STR ,sizeof (MBA_STR )) || - !strncmp (resctrl_val,MBM_STR ,sizeof (MBM_STR ))) - schema_len =snprintf (schema,sizeof (schema),"%s%d%c%s\n" , -"MB:" , resource_id,'=' , schemata); + schema_len =snprintf (schema,sizeof (schema),"%s:%d=%s\n" , + resource, resource_id, schemata);if (schema_len <0 || schema_len >=sizeof (schema)) {snprintf (reason,sizeof (reason),"snprintf() failed with return value : %d" , schema_len);
Signature · 1 line
2.30.2
PATCH v3 27/29 selftests/resctrl: Add helper to convert L2/3 to integer
In reply to Ilpo Järvinen"L2"/"L3" conversion to integer is embedded into get_cache_size() which prevents reuse.
Create a helper for the cache string to integer conversion to make it reusable.
--- tools/testing/selftests/resctrl/resctrlfs.c | 28 +++++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-)
tools/testing/selftests/resctrl/resctrlfs.c +20 -8
@@ -94,6 +94,23 @@ int umount_resctrlfs(void)return 0 ; } +/* +* get_cache_level - Convert cache level from string to integer +* @cache_type: Cache level as string +* +* Return: cache level as integer or -1 if @cache_type is invalid. +*/ +static int get_cache_level (const char *cache_type) +{ +if (!strcmp (cache_type,"L3" )) +return 3 ; +if (!strcmp (cache_type,"L2" )) +return 2 ; + +ksft_print_msg ("Invalid cache level\n" ); +return -1 ; +} +/* * get_resource_id - Get socket number/l3 id for a specified CPU * @cpu_no: CPU number
@@ -144,14 +161,9 @@ int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_sizeint length, i, cache_num;FILE *fp; -if (!strcmp (cache_type,"L3" )) { - cache_num =3 ; - }else if (!strcmp (cache_type,"L2" )) { - cache_num =2 ; - }else { -ksft_print_msg ("Invalid cache level\n" ); -return -1 ; - } + cache_num =get_cache_level (cache_type); +if (cache_num <0 ) +return cache_num;sprintf (cache_path,"/sys/bus/cpu/devices/cpu%d/cache/index%d/size" , cpu_no, cache_num);
Signature · 1 line
2.30.2
Re: [PATCH v3 27/29] selftests/resctrl: Add helper to convert L2/3 to integer
Hi Ilpo,
Quoted 8 lines · Ilpo Järvinen
"L2"/"L3" conversion to integer is embedded into
get_cache_size()which prevents reuse.Create a helper for the cache string to integer conversion to make it reusable.
Signed-off-by Ilpo Järvinen <[email protected]>---
Reinette
PATCH v3 28/29 selftests/resctrl: Rename resource ID to domain ID
In reply to Ilpo JärvinenKernel-side calls the instances of a resource domains.
Change the resource_id naming in the selftest code to domain_id to match the kernel side better.
--- tools/testing/selftests/resctrl/resctrl.h | 2 +- tools/testing/selftests/resctrl/resctrl_val.c | 30 +++++++++---------- tools/testing/selftests/resctrl/resctrlfs.c | 18 +++++------ 3 files changed, 25 insertions(+), 25 deletions(-)
tools/testing/selftests/resctrl/resctrl.h +1 -1
@@ -129,7 +129,7 @@ extern char llc_occup_path[1024];int get_vendor (void );bool check_resctrlfs_support (void );int filter_dmesg (void ); -int get_resource_id (int cpu_no,int *resource_id); +int get_domain_id (int cpu_no,int *domain_id);int mount_resctrlfs (void );int umount_resctrlfs (void );int validate_bw_report_request (char *bw_report);
tools/testing/selftests/resctrl/resctrl_val.c +15 -15
@@ -387,20 +387,20 @@ static int get_mem_bw_imc(int cpu_no, char *bw_report, float *bw_imc)return 0 ; } -void set_mbm_path (const char *ctrlgrp,const char *mongrp,int resource_id) +void set_mbm_path (const char *ctrlgrp,const char *mongrp,int domain_id) {if (ctrlgrp && mongrp)sprintf (mbm_total_path,CON_MON_MBM_LOCAL_BYTES_PATH , -RESCTRL_PATH , ctrlgrp, mongrp, resource_id); +RESCTRL_PATH , ctrlgrp, mongrp, domain_id);else if (!ctrlgrp && mongrp)sprintf (mbm_total_path,MON_MBM_LOCAL_BYTES_PATH ,RESCTRL_PATH , - mongrp, resource_id); + mongrp, domain_id);else if (ctrlgrp && !mongrp)sprintf (mbm_total_path,CON_MBM_LOCAL_BYTES_PATH ,RESCTRL_PATH , - ctrlgrp, resource_id); + ctrlgrp, domain_id);else if (!ctrlgrp && !mongrp)sprintf (mbm_total_path,MBM_LOCAL_BYTES_PATH ,RESCTRL_PATH , - resource_id); + domain_id); }/*
@@ -413,23 +413,23 @@ void set_mbm_path(const char *ctrlgrp, const char *mongrp, int resource_id)static void initialize_mem_bw_resctrl (const char *ctrlgrp,const char *mongrp,int cpu_no,char *resctrl_val) { -int resource_id; +int domain_id; -if (get_resource_id (cpu_no, &resource_id) <0 ) { -ksft_print_msg ("Could not get resource_id\n" ); +if (get_domain_id (cpu_no, &domain_id) <0 ) { +ksft_print_msg ("Could not get domain ID\n" );return ; }if (!strncmp (resctrl_val,MBM_STR ,sizeof (MBM_STR ))) -set_mbm_path (ctrlgrp, mongrp, resource_id); +set_mbm_path (ctrlgrp, mongrp, domain_id);if (!strncmp (resctrl_val,MBA_STR ,sizeof (MBA_STR ))) {if (ctrlgrp)sprintf (mbm_total_path,CON_MBM_LOCAL_BYTES_PATH , -RESCTRL_PATH , ctrlgrp, resource_id); +RESCTRL_PATH , ctrlgrp, domain_id);else sprintf (mbm_total_path,MBM_LOCAL_BYTES_PATH , -RESCTRL_PATH , resource_id); +RESCTRL_PATH , domain_id); } }
@@ -582,15 +582,15 @@ static void set_cmt_path(const char *ctrlgrp, const char *mongrp, char sock_num)static void initialize_llc_occu_resctrl (const char *ctrlgrp,const char *mongrp,int cpu_no,char *resctrl_val) { -int resource_id; +int domain_id; -if (get_resource_id (cpu_no, &resource_id) <0 ) { -ksft_print_msg ("Could not get resource_id\n" ); +if (get_domain_id (cpu_no, &domain_id) <0 ) { +ksft_print_msg ("Could not get domain ID\n" );return ; }if (!strncmp (resctrl_val,CMT_STR ,sizeof (CMT_STR ))) -set_cmt_path (ctrlgrp, mongrp, resource_id); +set_cmt_path (ctrlgrp, mongrp, domain_id); } static int measure_vals(const struct user_params *uparams,
tools/testing/selftests/resctrl/resctrlfs.c +9 -9
@@ -112,13 +112,13 @@ static int get_cache_level(const char *cache_type) }/* -* get_resource_id - Get socket number/l3 id for a specified CPU +* get_domain_id - Get resctrl domain ID for a specified CPU * @cpu_no: CPU number -* @resource_id: Socket number or l3_id +* @domain_id: domain ID (cache ID; for MB, L3 cache ID) * * Return: >= 0 on success, < 0 on failure. */ -int get_resource_id (int cpu_no,int *resource_id) +int get_domain_id (int cpu_no,int *domain_id) {char phys_pkg_path[1024 ];FILE *fp;
@@ -136,8 +136,8 @@ int get_resource_id(int cpu_no, int *resource_id)return -1 ; } -if (fscanf (fp,"%d" , resource_id) <=0 ) { -ksft_perror ("Could not get socket number or l3 id" ); +if (fscanf (fp,"%d" , domain_id) <=0 ) { +ksft_perror ("Could not get domain ID" );fclose (fp);return -1 ;
@@ -551,7 +551,7 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,int write_schemata (char *ctrlgrp,char *schemata,int cpu_no,const char *resource) {char controlgroup[1024 ], reason[128 ], schema[1024 ] = {}; -int resource_id, fd, schema_len, ret =0 ; +int domain_id, fd, schema_len, ret =0 ;if (!schemata) {ksft_print_msg ("Skipping empty schemata update\n" );
@@ -559,8 +559,8 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, const char *resourreturn -1 ; } -if (get_resource_id (cpu_no, &resource_id) <0 ) { -sprintf (reason,"Failed to get resource id" ); +if (get_domain_id (cpu_no, &domain_id) <0 ) { +sprintf (reason,"Failed to get domain ID" ); ret =-1 ; goto out;
@@ -572,7 +572,7 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, const char *resoursprintf (controlgroup,"%s/schemata" ,RESCTRL_PATH ); schema_len =snprintf (schema,sizeof (schema),"%s:%d=%s\n" , - resource, resource_id, schemata); + resource, domain_id, schemata);if (schema_len <0 || schema_len >=sizeof (schema)) {snprintf (reason,sizeof (reason),"snprintf() failed with return value : %d" , schema_len);
Signature · 1 line
2.30.2
Re: [PATCH v3 28/29] selftests/resctrl: Rename resource ID to domain ID
Hi Ilpo,
Quoted 8 lines · Ilpo Järvinen
Kernel-side calls the instances of a resource domains.
Change the
resource_idnaming in the selftest code todomain_idto match the kernel side better.Suggested-by Maciej Wieczór-Retman <[email protected]>Signed-off-by Ilpo Järvinen <[email protected]>---
Reinette
PATCH v3 29/29 selftests/resctrl: Get domain id from cache id
In reply to Ilpo JärvinenDomain id is acquired differently depending on CPU. AMD tests use id from L3 cache, whereas CPUs from other vendors base the id on topology package id. In order to support L2 CAT test, this has to be generalized.
The driver side code seems to get the domain ids from cache ids so the approach used by the AMD branch seems to match the kernel-side code. It will also work with L2 domain IDs as long as the cache level is generalized.
Using the topology id was always fragile due to mismatch with the kernel-side way to acquire the domain id. It got incorrect domain id, e.g., when Cluster-on-Die (CoD) is enabled for CPU (but CoD is not well suited for resctrl in the first place so it has not been a big issue if tests don't work correctly with it).
Taking all the above into account, generalize acquiring the domain id by taking it from the cache id and do not hard-code the cache level.
--- tools/testing/selftests/resctrl/resctrl.h | 2 +- tools/testing/selftests/resctrl/resctrl_val.c | 4 +-- tools/testing/selftests/resctrl/resctrlfs.c | 27 ++++++++++++------- 3 files changed, 21 insertions(+), 12 deletions(-)
tools/testing/selftests/resctrl/resctrl.h +1 -1
@@ -129,7 +129,7 @@ extern char llc_occup_path[1024];int get_vendor (void );bool check_resctrlfs_support (void );int filter_dmesg (void ); -int get_domain_id (int cpu_no,int *domain_id); +int get_domain_id (const char *resource,int cpu_no,int *domain_id);int mount_resctrlfs (void );int umount_resctrlfs (void );int validate_bw_report_request (char *bw_report);
tools/testing/selftests/resctrl/resctrl_val.c +2 -2
@@ -415,7 +415,7 @@ static void initialize_mem_bw_resctrl(const char *ctrlgrp, const char *mongrp, {int domain_id; -if (get_domain_id (cpu_no, &domain_id) <0 ) { +if (get_domain_id ("MB" , cpu_no, &domain_id) <0 ) {ksft_print_msg ("Could not get domain ID\n" );return ; }
@@ -584,7 +584,7 @@ static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp, {int domain_id; -if (get_domain_id (cpu_no, &domain_id) <0 ) { +if (get_domain_id ("L3" , cpu_no, &domain_id) <0 ) {ksft_print_msg ("Could not get domain ID\n" );return ; }
tools/testing/selftests/resctrl/resctrlfs.c +18 -9
@@ -111,28 +111,37 @@ static int get_cache_level(const char *cache_type)return -1 ; } +static int get_resource_cache_level (const char *resource) +{ +/* "MB" use L3 (LLC) as resource */ +if (!strcmp (resource,"MB" )) +return 3 ; +return get_cache_level (resource); +} +/* * get_domain_id - Get resctrl domain ID for a specified CPU +* @resource: resource name * @cpu_no: CPU number * @domain_id: domain ID (cache ID; for MB, L3 cache ID) * * Return: >= 0 on success, < 0 on failure. */ -int get_domain_id (int cpu_no,int *domain_id) +int get_domain_id (const char *resource,int cpu_no,int *domain_id) {char phys_pkg_path[1024 ]; +int cache_num;FILE *fp; -if (get_vendor () ==ARCH_AMD ) -sprintf (phys_pkg_path,"%s%d/cache/index3/id" , -PHYS_ID_PATH , cpu_no); -else -sprintf (phys_pkg_path,"%s%d/topology/physical_package_id" , -PHYS_ID_PATH , cpu_no); + cache_num =get_resource_cache_level (resource); +if (cache_num <0 ) +return cache_num; + +sprintf (phys_pkg_path,"%s%d/cache/index%d/id" ,PHYS_ID_PATH , cpu_no, cache_num); fp =fopen (phys_pkg_path,"r" );if (!fp) { -ksft_perror ("Failed to open physical_package_id" ); +ksft_perror ("Failed to open cache id file" );return -1 ; }
@@ -559,7 +568,7 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, const char *resourreturn -1 ; } -if (get_domain_id (cpu_no, &domain_id) <0 ) { +if (get_domain_id (resource, cpu_no, &domain_id) <0 ) {sprintf (reason,"Failed to get domain ID" ); ret =-1 ;
Signature · 1 line
2.30.2