selftests/resctrl: Fixes and cleanups
Subsystems (2)
v5 cover selftests/resctrl: Fixes and cleanups
Here is a series with some fixes and cleanups to resctrl selftests.
v5:
- Improve changelogs
- Close fd_lm only in cat_val()
- Improve unmount error handling
v4:
- Move resctrlfs (unconditional) umount after resctrl fs support check
v3:
- Don't include rewritten CAT test into this series!
- Tweak wildcard style in Makefile
- Fix many changelog typos, remove some wrong claims, and generally improve them.
- Add fix to PARENT_EXIT() to unmount resctrl FS
- Add unmounting resctrl FS before starting any tests
- Add fix for buf leak
- Add fix for perf fd closing
- Split mount/remount/umount patches differently
- Use size_t and %zu for span
- Keep MBM print as MB, only internally use span in bytes
- Drop start_buf global from fill_buf
v2 (was sent with CAT test rewrite which is no longer included in v3):
- Rebased on top of next to solve the conflicts
- Added 2 patches related to resctrl FS mount/umount (fix + cleanup)
- Consistently use "alloc" in cache_alloc_size()
- CAT test error handling tweaked
- Remove a spurious newline change from the CAT patch
- Small improvements to changelogs
Ilpo Järvinen (19):
selftests/resctrl: Add resctrl.h into build deps selftests/resctrl: Don't leak buffer in fill_cache() selftests/resctrl: Unmount resctrl FS if child fails to run benchmark selftests/resctrl: Close perf value read fd on errors selftests/resctrl: Unmount resctrl FS before starting the first test selftests/resctrl: Move resctrl FS mount/umount to higher level selftests/resctrl: Refactor remount_resctrl(bool mum_resctrlfs) to
mount_resctrl()
selftests/resctrl: Remove mum_resctrlfs from struct resctrl_val_param selftests/resctrl: Convert span to size_t selftests/resctrl: Express span internally in bytes selftests/resctrl: Remove duplicated preparation for span arg selftests/resctrl: Remove "malloc_and_init_memory" param from
run_fill_buf()
selftests/resctrl: Remove unnecessary startptr global from fill_buf selftests/resctrl: Improve parameter consistency in fill_buf selftests/resctrl: Don't pass test name to fill_buf selftests/resctrl: Don't use variable argument list for ->setup() selftests/resctrl: Move CAT/CMT test global vars to function they are
used in
selftests/resctrl: Pass the real number of tests to show_cache_info() selftests/resctrl: Remove test type checks from cat_val()
tools/testing/selftests/resctrl/Makefile | 2 +- tools/testing/selftests/resctrl/cache.c | 66 +++++++------- tools/testing/selftests/resctrl/cat_test.c | 28 ++---- tools/testing/selftests/resctrl/cmt_test.c | 29 ++----- tools/testing/selftests/resctrl/fill_buf.c | 87 +++++++------------ tools/testing/selftests/resctrl/mba_test.c | 9 +- tools/testing/selftests/resctrl/mbm_test.c | 17 ++-- tools/testing/selftests/resctrl/resctrl.h | 17 ++-- .../testing/selftests/resctrl/resctrl_tests.c | 83 ++++++++++++------ tools/testing/selftests/resctrl/resctrl_val.c | 7 +- tools/testing/selftests/resctrl/resctrlfs.c | 64 +++++++------- 11 files changed, 178 insertions(+), 231 deletions(-)
Signature · 1 line
2.30.2
PATCH v5 1/19 selftests/resctrl: Add resctrl.h into build deps
Makefile only lists *.c as build dependencies for the resctrl_tests executable which excludes resctrl.h.
Add *.h to wildcard() to include resctrl.h.
--- tools/testing/selftests/resctrl/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/resctrl/Makefile +1 -1
@@ -7,4 +7,4 @@ TEST_GEN_PROGS := resctrl_tests include ../lib.mk -$(OUTPUT)/resctrl_tests: $(wildcard *.c) +$(OUTPUT)/resctrl_tests: $(wildcard *.[ch])
Signature · 1 line
2.30.2
PATCH v5 2/19 selftests/resctrl: Don't leak buffer in fill_cache()
In reply to Ilpo JärvinenThe error path in fill_cache() does return before the allocated buffer is freed leaking the buffer.
The leak was introduced when fill_cache_read() started to return errors in commit c7b607fa9325 ("selftests/resctrl: Fix null pointer dereference on open failed"), before that both fill functions always returned 0.
Move free() earlier to prevent the mem leak.
--- tools/testing/selftests/resctrl/fill_buf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/resctrl/fill_buf.c +2 -1
@@ -177,12 +177,13 @@ fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush,else ret =fill_cache_write (start_ptr, end_ptr, resctrl_val); +free (startptr); +if (ret) {printf ("\n Error in fill cache read/write...\n" );return -1 ; } -free (startptr);return 0 ; }
Signature · 1 line
2.30.2
PATCH v5 3/19 selftests/resctrl: Unmount resctrl FS if child fails to run benchmark
In reply to Ilpo JärvinenA child calls PARENT_EXIT() when it fails to run a benchmark to kill the parent process. PARENT_EXIT() lacks unmount for the resctrl FS and the parent won't be there to unmount it either after it gets killed.
Add the resctrl FS unmount also to PARENT_EXIT().
--- tools/testing/selftests/resctrl/resctrl.h | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/resctrl/resctrl.h +1 -0
@@ -43,6 +43,7 @@do { \perror (err_msg); \kill (ppid,SIGKILL ); \ +umount_resctrlfs (); \exit (EXIT_FAILURE ); \ }while (0 )
Signature · 1 line
2.30.2
PATCH v5 4/19 selftests/resctrl: Close perf value read fd on errors
In reply to Ilpo JärvinenPerf event fd (fd_lm) is not closed when run_fill_buf() returns error.
Close fd_lm only in cat_val() to make it easier to track it is always closed.
--- tools/testing/selftests/resctrl/cache.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
tools/testing/selftests/resctrl/cache.c +11 -7
@@ -87,21 +87,19 @@ static int reset_enable_llc_perf(pid_t pid, int cpu_no)static int get_llc_perf (unsigned long *llc_perf_miss) {__u64 total_misses; +int ret;/* Stop counters after one span to get miss rate */ ioctl (fd_lm,PERF_EVENT_IOC_DISABLE ,0 ); -if (read (fd_lm, &rf_cqm,sizeof (struct read_format )) ==-1 ) { + ret =read (fd_lm, &rf_cqm,sizeof (struct read_format )); +if (ret ==-1 ) {perror ("Could not get llc misses through perf" ); -return -1 ; } total_misses = rf_cqm.values[0 ].value; - -close (fd_lm); - *llc_perf_miss = total_misses;return 0 ;
@@ -253,19 +251,25 @@ int cat_val(struct resctrl_val_param *param) memflush, operation, resctrl_val)) {fprintf (stderr,"Error-running fill buffer\n" ); ret =-1 ; -break ; + goto pe_close; }sleep (1 ); ret =measure_cache_vals (param, bm_pid);if (ret) -break ; + goto pe_close; + +close (fd_lm); }else {break ; } }return ret; + +pe_close: +close (fd_lm); +return ret; }/*
Signature · 1 line
2.30.2
Reinette Chatre
maintainerRe: [PATCH v5 04/19] selftests/resctrl: Close perf value read fd on errors
Hi Ilpo,
Quoted 22 lines · Ilpo Järvinen
Perf event fd (
fd_lm) is not closed whenrun_fill_buf()returns error.Close
fd_lmonly incat_val()to make it easier to track it is always closed.Fixes 790bf585b0ee ("selftests/resctrl: Add Cache Allocation Technology (CAT) selftest")Signed-off-by Ilpo Järvinen <[email protected]>--- tools/testing/selftests/resctrl/cache.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)tools/testing/selftests/resctrl/cache.c +1
-0@@ -87,21 +87,19 @@ static int reset_enable_llc_perf(pid_t pid, int cpu_no)static int get_llc_perf (unsigned long *llc_perf_miss) {__u64 total_misses; +int ret;/* Stop counters after one span to get miss rate */
tools/testing/selftests/resctrl/cache.c static int reset_enable_llc_perf(pid_t pid, int cpu_no) · line 100
Quoted 10 lines
tools/testing/selftests/resctrl/cache.c +2
-2ioctl (fd_lm,PERF_EVENT_IOC_DISABLE ,0 ); -if (read (fd_lm, &rf_cqm,sizeof (struct read_format )) ==-1 ) { + ret =read (fd_lm, &rf_cqm,sizeof (struct read_format )); +if (ret ==-1 ) {perror ("Could not get llc misses through perf" ); -return -1 ; }
Above changes seem to be remnant of previous version that are not needed.
Reinette
PATCH v5 5/19 selftests/resctrl: Unmount resctrl FS before starting the first test
In reply to Ilpo JärvinenResctrl FS mount/remount/umount code is hard to track. Better approach is to use mount/umount pair for each test but that assumes resctrl FS is not mounted beforehand.
Change umount_resctrlfs() so that it can unmount resctrl FS from any path, and enable further simplifications into mount/remount/umount logic by unmounting resctrl FS at the start if a pre-existing mountpoint is found.
--- tools/testing/selftests/resctrl/resctrl_tests.c | 3 +++ tools/testing/selftests/resctrl/resctrlfs.c | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
tools/testing/selftests/resctrl/resctrl_tests.c +3 -0
@@ -250,6 +250,9 @@ int main(int argc, char **argv)if (!check_resctrlfs_support ())return ksft_exit_skip ("resctrl FS does not exist. Enable X86_CPU_RESCTRL config option.\n" ); +if (umount_resctrlfs ()) +return ksft_exit_skip ("resctrl FS unmount failed.\n" ); +filter_dmesg ();ksft_set_plan (tests ? :4 );
tools/testing/selftests/resctrl/resctrlfs.c +8 -2
@@ -82,10 +82,16 @@ int remount_resctrlfs(bool mum_resctrlfs)int umount_resctrlfs (void ) { -if (find_resctrl_mount (NULL )) +char mountpoint[256 ]; +int ret; + + ret =find_resctrl_mount (mountpoint); +if (ret == -ENOENT )return 0 ; +if (ret) +return ret; -if (umount (RESCTRL_PATH )) { +if (umount (mountpoint)) {perror ("# Unable to umount resctrl" );return errno;
Signature · 1 line
2.30.2
PATCH v5 6/19 selftests/resctrl: Move resctrl FS mount/umount to higher level
In reply to Ilpo JärvinenA few places currently lack umounting resctrl FS on error paths:
- cmt_resctrl_val() has multiple error paths with direct return.
- cat_perf_miss_val() has multiple error paths with direct return.
In addition, validate_resctrl_feature_request() is called by run_mbm_test() and run_mba_test(). Neither MBA nor MBM test tries to umount resctrl FS.
Each and every test does require resctrl FS to be present already for feature check. Thus, it makes sense to just mount it on higher level in resctrl_tests.c and properly pair it with umount.
Move resctrl FS (re)mount/unmount into each test function in resctrl_tests.c. Make feature validation to simply check that resctrl FS is mounted.
As there's the final umount in main() before this change, the selftest should not leave resctrl FS behind after the tests even if one of the forementioned paths is taken (thus, no fixes tag).
--- tools/testing/selftests/resctrl/cat_test.c | 6 --- tools/testing/selftests/resctrl/cmt_test.c | 4 -- .../testing/selftests/resctrl/resctrl_tests.c | 47 ++++++++++++++++--- tools/testing/selftests/resctrl/resctrl_val.c | 5 -- tools/testing/selftests/resctrl/resctrlfs.c | 7 ++- 5 files changed, 46 insertions(+), 23 deletions(-)
tools/testing/selftests/resctrl/cat_test.c +0 -6
@@ -106,10 +106,6 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) cache_size =0 ; - ret =remount_resctrlfs (true); -if (ret) -return ret; -/* Get default cbm mask for L3/L2 cache */ ret =get_cbm_mask (cache_type, cbm_mask);if (ret)
@@ -227,8 +223,6 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) out:cat_test_cleanup (); -if (bm_pid) -umount_resctrlfs ();return ret; }
tools/testing/selftests/resctrl/cmt_test.c +0 -4
@@ -86,10 +86,6 @@ int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd) cache_size =0 ; - ret =remount_resctrlfs (true); -if (ret) -return ret; -if (!validate_resctrl_feature_request (CMT_STR ))return -1 ;
tools/testing/selftests/resctrl/resctrl_tests.c +41 -6
106 lines not on this page · raw message
tools/testing/selftests/resctrl/resctrl_val.c +0 -5
@@ -648,10 +648,6 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)return ret; } - ret =remount_resctrlfs (param->mum_resctrlfs); -if (ret) -return ret; -/* * If benchmark wasn't successfully started by child, then child should * kill parent, so save parent's pid
@@ -788,7 +784,6 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)signal_handler_unregister (); out:kill (bm_pid,SIGKILL ); -umount_resctrlfs ();return ret; }
tools/testing/selftests/resctrl/resctrlfs.c +5 -2
@@ -617,7 +617,8 @@ char *fgrep(FILE *inf, const char *str)* validate_resctrl_feature_request - Check if requested feature is valid. * @resctrl_val: Requested feature * -* Return: True if the feature is supported, else false +* Return: True if the feature is supported, else false. False is also +* returned if resctrl FS is not mounted. */ bool validate_resctrl_feature_request (const char *resctrl_val) {
@@ -625,11 +626,13 @@ bool validate_resctrl_feature_request(const char *resctrl_val)bool found = false;char *res;FILE *inf; +int ret;if (!resctrl_val)return false; -if (remount_resctrlfs (false)) + ret =find_resctrl_mount (NULL ); +if (ret)return false;if (!strncmp (resctrl_val,CAT_STR ,sizeof (CAT_STR ))) {
Signature · 1 line
2.30.2
PATCH v5 7/19 selftests/resctrl: Refactor remount_resctrl(bool mum_resctrlfs) to mount_resctrl()
In reply to Ilpo JärvinenMount/umount of the resctrl FS is now paired nicely per test.
Rename remount_resctrl(bool mum_resctrlfs) to mount_resctrl(). Make it unconditionally try to mount the resctrl FS and return error if resctrl FS was mounted already.
While at it, group the mount/umount prototypes in the header.
--- tools/testing/selftests/resctrl/resctrl.h | 2 +- .../testing/selftests/resctrl/resctrl_tests.c | 8 +++---- tools/testing/selftests/resctrl/resctrlfs.c | 23 ++++++------------- 3 files changed, 12 insertions(+), 21 deletions(-)
tools/testing/selftests/resctrl/resctrl.h +1 -1
@@ -85,8 +85,8 @@ extern char llc_occup_path[1024];int get_vendor (void );bool check_resctrlfs_support (void );int filter_dmesg (void ); -int remount_resctrlfs (bool mum_resctrlfs);int get_resource_id (int cpu_no,int *resource_id); +int mount_resctrlfs (void );int umount_resctrlfs (void );int validate_bw_report_request (char *bw_report);bool validate_resctrl_feature_request (const char *resctrl_val);
tools/testing/selftests/resctrl/resctrl_tests.c +4 -4
@@ -77,7 +77,7 @@ static void run_mbm_test(bool has_ben, char **benchmark_cmd, int span,ksft_print_msg ("Starting MBM BW change ...\n" ); - res =remount_resctrlfs (true); + res =mount_resctrlfs ();if (res) {ksft_exit_fail_msg ("Failed to mount resctrl FS\n" );return ;
@@ -106,7 +106,7 @@ static void run_mba_test(bool has_ben, char **benchmark_cmd, int span,ksft_print_msg ("Starting MBA Schemata change ...\n" ); - res =remount_resctrlfs (true); + res =mount_resctrlfs ();if (res) {ksft_exit_fail_msg ("Failed to mount resctrl FS\n" );return ;
@@ -132,7 +132,7 @@ static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no)ksft_print_msg ("Starting CMT test ...\n" ); - res =remount_resctrlfs (true); + res =mount_resctrlfs ();if (res) {ksft_exit_fail_msg ("Failed to mount resctrl FS\n" );return ;
@@ -160,7 +160,7 @@ static void run_cat_test(int cpu_no, int no_of_bits)ksft_print_msg ("Starting CAT test ...\n" ); - res =remount_resctrlfs (true); + res =mount_resctrlfs ();if (res) {ksft_exit_fail_msg ("Failed to mount resctrl FS\n" );return ;
tools/testing/selftests/resctrl/resctrlfs.c +7 -16
@@ -48,29 +48,20 @@ static int find_resctrl_mount(char *buffer) }/* -* remount_resctrlfs - Remount resctrl FS at /sys/fs/resctrl -* @mum_resctrlfs: Should the resctrl FS be remounted? +* mount_resctrlfs - Mount resctrl FS at /sys/fs/resctrl * -* If not mounted, mount it. -* If mounted and mum_resctrlfs then remount resctrl FS. -* If mounted and !mum_resctrlfs then noop +* 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 */ -int remount_resctrlfs (bool mum_resctrlfs) +int mount_resctrlfs (void ) { -char mountpoint[256 ];int ret; - ret =find_resctrl_mount (mountpoint); -if (ret) -strcpy (mountpoint,RESCTRL_PATH ); - -if (!ret && mum_resctrlfs &&umount (mountpoint)) -ksft_print_msg ("Fail: unmounting \"%s\"\n" , mountpoint); - -if (!ret && !mum_resctrlfs) -return 0 ; + ret =find_resctrl_mount (NULL ); +if (ret != -ENOENT ) +return -1 ;ksft_print_msg ("Mounting resctrl to \"%s\"\n" ,RESCTRL_PATH ); ret =mount ("resctrl" ,RESCTRL_PATH ,"resctrl" ,0 ,NULL );
Signature · 1 line
2.30.2
PATCH v5 8/19 selftests/resctrl: Remove mum_resctrlfs from struct resctrl_val_param
In reply to Ilpo JärvinenResctrl FS mount/umount are now cleanly paired leaving .mum_resctrlfs in the struct resctrl_val_param unused.
Remove .mum_resctrlfs from struct resctrl_val_param.
--- tools/testing/selftests/resctrl/cat_test.c | 1 - tools/testing/selftests/resctrl/cmt_test.c | 1 - tools/testing/selftests/resctrl/mba_test.c | 1 - tools/testing/selftests/resctrl/mbm_test.c | 1 - tools/testing/selftests/resctrl/resctrl.h | 2 -- 5 files changed, 6 deletions(-)
tools/testing/selftests/resctrl/cat_test.c +0 -1
@@ -140,7 +140,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, - .mum_resctrlfs = false, .setup = cat_setup, };
tools/testing/selftests/resctrl/cmt_test.c +0 -1
@@ -113,7 +113,6 @@ int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd) .ctrlgrp = "c1", .mongrp = "m1", .cpu_no = cpu_no, - .mum_resctrlfs = false, .filename = RESULT_FILE_NAME, .mask = ~(long_mask << n) & long_mask, .span = cache_size * n / count_of_bits,
tools/testing/selftests/resctrl/mba_test.c +0 -1
@@ -154,7 +154,6 @@ int mba_schemata_change(int cpu_no, char *bw_report, char **benchmark_cmd) .ctrlgrp = "c1", .mongrp = "m1", .cpu_no = cpu_no, - .mum_resctrlfs = true, .filename = RESULT_FILE_NAME, .bw_report = bw_report, .setup = mba_setup
tools/testing/selftests/resctrl/mbm_test.c +0 -1
@@ -123,7 +123,6 @@ int mbm_bw_change(int span, int cpu_no, char *bw_report, char **benchmark_cmd) .mongrp = "m1", .span = span, .cpu_no = cpu_no, - .mum_resctrlfs = true, .filename = RESULT_FILE_NAME, .bw_report = bw_report, .setup = mbm_setup
tools/testing/selftests/resctrl/resctrl.h +0 -2
@@ -54,7 +54,6 @@* @mongrp: Name of the monitor group (mon grp) * @cpu_no: CPU number to which the benchmark would be binded * @span: Memory bytes accessed in each benchmark iteration -* @mum_resctrlfs: Should the resctrl FS be remounted? * @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
@@ -65,7 +64,6 @@ struct resctrl_val_param {char mongrp[64 ];int cpu_no;unsigned long span; -bool mum_resctrlfs;char filename[64 ];char *bw_report;unsigned long mask;
Signature · 1 line
2.30.2
PATCH v5 9/19 selftests/resctrl: Convert span to size_t
In reply to Ilpo JärvinenSpan is defined either as unsigned long or int.
Consistently use size_t everywhere for span as it refers to size of the memory block.
--- tools/testing/selftests/resctrl/cache.c | 4 ++-- tools/testing/selftests/resctrl/cmt_test.c | 2 +- tools/testing/selftests/resctrl/fill_buf.c | 8 ++++---- tools/testing/selftests/resctrl/mbm_test.c | 8 ++++---- tools/testing/selftests/resctrl/resctrl.h | 10 +++++----- tools/testing/selftests/resctrl/resctrl_tests.c | 11 ++++++----- tools/testing/selftests/resctrl/resctrlfs.c | 2 +- 7 files changed, 23 insertions(+), 22 deletions(-)
tools/testing/selftests/resctrl/cache.c +2 -2
@@ -286,7 +286,7 @@ int cat_val(struct resctrl_val_param *param)* Return: 0 on success. non-zero on failure. */ int show_cache_info (unsigned long sum_llc_val,int no_of_bits, -unsigned long cache_span,unsigned long max_diff, +size_t cache_span,unsigned long max_diff,unsigned long max_diff_percent,unsigned long num_of_runs,bool platform,bool cmt) {
@@ -308,7 +308,7 @@ int show_cache_info(unsigned long sum_llc_val, int no_of_bits,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): %lu\n" , cmt ?"bytes" :"lines" , +ksft_print_msg ("Cache span (%s): %zu\n" , cmt ?"bytes" :"lines" , cache_span);return ret;
tools/testing/selftests/resctrl/cmt_test.c +1 -1
@@ -121,7 +121,7 @@ int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd) };if (strcmp (benchmark_cmd[0 ],"fill_buf" ) ==0 ) -sprintf (benchmark_cmd[1 ],"%lu" , param.span); +sprintf (benchmark_cmd[1 ],"%zu" , param.span);remove (RESULT_FILE_NAME );
tools/testing/selftests/resctrl/fill_buf.c +4 -4
@@ -139,7 +139,7 @@ static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr, }static int -fill_cache (unsigned long long buf_size,int malloc_and_init,int memflush, +fill_cache (size_t buf_size,int malloc_and_init,int memflush,int op,char *resctrl_val) {unsigned char *start_ptr, *end_ptr;
@@ -188,10 +188,10 @@ fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush,return 0 ; } -int run_fill_buf (unsigned long span,int malloc_and_init_memory, -int memflush,int op,char *resctrl_val) +int run_fill_buf (size_t span,int malloc_and_init_memory,int memflush,int op, +char *resctrl_val) { -unsigned long long cache_size = span; +size_t cache_size = span;int ret; ret = fill_cache(cache_size, malloc_and_init_memory, memflush, op,
tools/testing/selftests/resctrl/mbm_test.c +4 -4
@@ -15,7 +15,7 @@#define NUM_OF_RUNS 5static int -show_bw_info (unsigned long *bw_imc,unsigned long *bw_resc,int span) +show_bw_info (unsigned long *bw_imc,unsigned long *bw_resc,size_t span) {unsigned long avg_bw_imc =0 , avg_bw_resc =0 ;unsigned long sum_bw_imc =0 , sum_bw_resc =0 ;
@@ -40,14 +40,14 @@ show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, int span)ksft_print_msg ("%s Check MBM diff within %d%%\n" , ret ?"Fail:" :"Pass:" ,MAX_DIFF_PERCENT );ksft_print_msg ("avg_diff_per: %d%%\n" , avg_diff_per); -ksft_print_msg ("Span (MB): %d\n" , span); +ksft_print_msg ("Span (MB): %zu\n" , span);ksft_print_msg ("avg_bw_imc: %lu\n" , avg_bw_imc);ksft_print_msg ("avg_bw_resc: %lu\n" , avg_bw_resc);return ret; } -static int check_results (int span) +static int check_results (size_t span) {unsigned long bw_imc[NUM_OF_RUNS ], bw_resc[NUM_OF_RUNS ];char temp[1024 ], *token_array[8 ];
@@ -115,7 +115,7 @@ void mbm_test_cleanup(void)remove (RESULT_FILE_NAME ); } -int mbm_bw_change (int span,int cpu_no,char *bw_report,char **benchmark_cmd) +int mbm_bw_change (size_t span,int cpu_no,char *bw_report,char **benchmark_cmd) {struct resctrl_val_param param = { .resctrl_val =MBM_STR ,
tools/testing/selftests/resctrl/resctrl.h +5 -5
@@ -63,7 +63,7 @@ struct resctrl_val_param {char ctrlgrp[64 ];char mongrp[64 ];int cpu_no; -unsigned long span; +size_t span;char filename[64 ];char *bw_report;unsigned long mask;
@@ -97,10 +97,10 @@ 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 (unsigned long span,int malloc_and_init_memory,int memflush, -int op,char *resctrl_va); +int run_fill_buf (size_t span,int malloc_and_init_memory,int memflush,int op, +char *resctrl_va);int resctrl_val (char **benchmark_cmd,struct resctrl_val_param *param); -int mbm_bw_change (int span,int cpu_no,char *bw_report,char **benchmark_cmd); +int mbm_bw_change (size_t span,int cpu_no,char *bw_report,char **benchmark_cmd);void tests_cleanup (void );void mbm_test_cleanup (void );int mba_schemata_change (int cpu_no,char *bw_report,char **benchmark_cmd);
@@ -119,7 +119,7 @@ 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 show_cache_info (unsigned long sum_llc_val,int no_of_bits, -unsigned long cache_span,unsigned long max_diff, +size_t cache_span,unsigned long max_diff,unsigned long max_diff_percent,unsigned long num_of_runs,bool platform,bool cmt);
tools/testing/selftests/resctrl/resctrl_tests.c +6 -5
@@ -70,7 +70,7 @@ void tests_cleanup(void)cat_test_cleanup (); } -static void run_mbm_test (bool has_ben,char **benchmark_cmd,int span, +static void run_mbm_test (bool has_ben,char **benchmark_cmd,size_t span,int cpu_no,char *bw_report) {int res;
@@ -99,7 +99,7 @@ static void run_mbm_test(bool has_ben, char **benchmark_cmd, int span,umount_resctrlfs (); } -static void run_mba_test (bool has_ben,char **benchmark_cmd,int span, +static void run_mba_test (bool has_ben,char **benchmark_cmd,size_t span,int cpu_no,char *bw_report) {int res;
@@ -118,7 +118,7 @@ static void run_mba_test(bool has_ben, char **benchmark_cmd, int span, }if (!has_ben) -sprintf (benchmark_cmd[1 ],"%d" , span); +sprintf (benchmark_cmd[1 ],"%zu" , span); res =mba_schemata_change (cpu_no, bw_report, benchmark_cmd);ksft_test_result (!res,"MBA: schemata change\n" );
@@ -181,11 +181,12 @@ static void run_cat_test(int cpu_no, int no_of_bits)int main (int argc,char **argv) {bool has_ben = false, mbm_test = true, mba_test = true, cmt_test = true; -int c, cpu_no =1 , span =250 , argc_new = argc, i, no_of_bits =0 ;char *benchmark_cmd[BENCHMARK_ARGS ], bw_report[64 ], bm_type[64 ];char benchmark_cmd_area[BENCHMARK_ARGS ][BENCHMARK_ARG_SIZE ]; +int c, cpu_no =1 , argc_new = argc, i, no_of_bits =0 ;int ben_ind, ben_count, tests =0 ;bool cat_test = true; +size_t span =250 ;for (i =0 ; i < argc; i++) {if (strcmp (argv[i],"-b" ) ==0 ) {
@@ -273,7 +274,7 @@ int main(int argc, char **argv) benchmark_cmd[i] = benchmark_cmd_area[i];strcpy (benchmark_cmd[0 ],"fill_buf" ); -sprintf (benchmark_cmd[1 ],"%d" , span); +sprintf (benchmark_cmd[1 ],"%zu" , span);strcpy (benchmark_cmd[2 ],"1" );strcpy (benchmark_cmd[3 ],"1" );strcpy (benchmark_cmd[4 ],"0" );
tools/testing/selftests/resctrl/resctrlfs.c +1 -1
@@ -303,7 +303,7 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no)void run_benchmark (int signum,siginfo_t *info,void *ucontext) {int operation, ret, malloc_and_init_memory, memflush; -unsigned long span, buffer_span; +size_t span, buffer_span;char **benchmark_cmd;char resctrl_val[64 ];FILE *fp;
Signature · 1 line
2.30.2
PATCH v5 10/19 selftests/resctrl: Express span internally in bytes
In reply to Ilpo JärvinenMBA and MBM tests to use megabytes to represent span. CMT test uses bytes. The difference requires run_benchmark() to size the buffer differently based on the test name, which in turn requires passing the test name into run_benchmark().
Convert MBA and MBM tests to use span internally in bytes like CMT test to remove the internal inconsistency between the tests. Remove the test dependent buffer sizing from run_benchmark().
This change eliminates one of the reasons why the test name has to be passed around but there are still other users too so the test name passing cannot yet be removed.
--- tools/testing/selftests/resctrl/mbm_test.c | 2 +- tools/testing/selftests/resctrl/resctrl_tests.c | 2 +- tools/testing/selftests/resctrl/resctrlfs.c | 9 ++------- 3 files changed, 4 insertions(+), 9 deletions(-)
tools/testing/selftests/resctrl/mbm_test.c +1 -1
@@ -40,7 +40,7 @@ show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, size_t span)ksft_print_msg ("%s Check MBM diff within %d%%\n" , ret ?"Fail:" :"Pass:" ,MAX_DIFF_PERCENT );ksft_print_msg ("avg_diff_per: %d%%\n" , avg_diff_per); -ksft_print_msg ("Span (MB): %zu\n" , span); +ksft_print_msg ("Span (MB): %zu\n" , span /MB );ksft_print_msg ("avg_bw_imc: %lu\n" , avg_bw_imc);ksft_print_msg ("avg_bw_resc: %lu\n" , avg_bw_resc);
tools/testing/selftests/resctrl/resctrl_tests.c +1 -1
@@ -185,8 +185,8 @@ int main(int argc, char **argv)char benchmark_cmd_area[BENCHMARK_ARGS ][BENCHMARK_ARG_SIZE ];int c, cpu_no =1 , argc_new = argc, i, no_of_bits =0 ;int ben_ind, ben_count, tests =0 ; +size_t span =250 *MB ;bool cat_test = true; -size_t span =250 ;for (i =0 ; i < argc; i++) {if (strcmp (argv[i],"-b" ) ==0 ) {
tools/testing/selftests/resctrl/resctrlfs.c +2 -7
@@ -303,9 +303,9 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no)void run_benchmark (int signum,siginfo_t *info,void *ucontext) {int operation, ret, malloc_and_init_memory, memflush; -size_t span, buffer_span;char **benchmark_cmd;char resctrl_val[64 ]; +size_t span;FILE *fp; benchmark_cmd = info->si_ptr;
@@ -326,12 +326,7 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext) operation =atoi (benchmark_cmd[4 ]);sprintf (resctrl_val,"%s" , benchmark_cmd[5 ]); -if (strncmp (resctrl_val,CMT_STR ,sizeof (CMT_STR ))) - buffer_span = span *MB ; -else - buffer_span = span; - -if (run_fill_buf (buffer_span, malloc_and_init_memory, memflush, +if (run_fill_buf (span, malloc_and_init_memory, memflush, operation, resctrl_val))fprintf (stderr,"Error in running fill buffer\n" ); }else {
Signature · 1 line
2.30.2
PATCH v5 11/19 selftests/resctrl: Remove duplicated preparation for span arg
In reply to Ilpo JärvinenWhen no benchmark_cmd is given, benchmark_cmd[1] is set to span in main(). There's no need to do it again in run_mba_test().
Remove the duplicated preparation for span argument into benchmark_cmd[1] from run_mba_test(). After this, the has_ben and span arguments to run_mba_test() can be removed.
--- tools/testing/selftests/resctrl/resctrl_tests.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
tools/testing/selftests/resctrl/resctrl_tests.c +2 -5
@@ -99,8 +99,7 @@ static void run_mbm_test(bool has_ben, char **benchmark_cmd, size_t span,umount_resctrlfs (); } -static void run_mba_test (bool has_ben,char **benchmark_cmd,size_t span, -int cpu_no,char *bw_report) +static void run_mba_test (char **benchmark_cmd,int cpu_no,char *bw_report) {int res;
@@ -117,8 +116,6 @@ static void run_mba_test(bool has_ben, char **benchmark_cmd, size_t span, goto umount; } -if (!has_ben) -sprintf (benchmark_cmd[1 ],"%zu" , span); res =mba_schemata_change (cpu_no, bw_report, benchmark_cmd);ksft_test_result (!res,"MBA: schemata change\n" );
@@ -299,7 +296,7 @@ int main(int argc, char **argv)run_mbm_test (has_ben, benchmark_cmd, span, cpu_no, bw_report);if (mba_test) -run_mba_test (has_ben, benchmark_cmd, span, cpu_no, bw_report); +run_mba_test (benchmark_cmd, cpu_no, bw_report);if (cmt_test)run_cmt_test (has_ben, benchmark_cmd, cpu_no);
Signature · 1 line
2.30.2
PATCH v5 12/19 selftests/resctrl: Remove "malloc_and_init_memory" param from run_fill_buf()
In reply to Ilpo Järvinenrun_fill_buf()'s malloc_and_init_memory parameter is always 1. There's also duplicated memory init code for malloc_and_init_memory == 0 case in fill_buf() which is unused.
Remove the malloc_and_init_memory parameter and the duplicated mem init code.
While at it, fix also a typo in run_fill_buf() prototype's argument.
--- tools/testing/selftests/resctrl/cache.c | 6 ++-- tools/testing/selftests/resctrl/fill_buf.c | 28 +++---------------- tools/testing/selftests/resctrl/resctrl.h | 3 +- .../testing/selftests/resctrl/resctrl_tests.c | 13 ++++----- tools/testing/selftests/resctrl/resctrlfs.c | 12 ++++---- 5 files changed, 19 insertions(+), 43 deletions(-)
tools/testing/selftests/resctrl/cache.c +3 -3
@@ -210,7 +210,7 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid)*/ int cat_val (struct resctrl_val_param *param) { -int malloc_and_init_memory =1 , memflush =1 , operation =0 , ret =0 ; +int memflush =1 , operation =0 , ret =0 ;char *resctrl_val = param->resctrl_val;pid_t bm_pid;
@@ -247,8 +247,8 @@ int cat_val(struct resctrl_val_param *param)if (ret)break ; -if (run_fill_buf (param->span, malloc_and_init_memory, - memflush, operation, resctrl_val)) { +if (run_fill_buf (param->span, memflush, operation, + resctrl_val)) {fprintf (stderr,"Error-running fill buffer\n" ); ret =-1 ; goto pe_close;
tools/testing/selftests/resctrl/fill_buf.c +4 -24
@@ -138,36 +138,18 @@ static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr,return 0 ; } -static int -fill_cache (size_t buf_size,int malloc_and_init,int memflush, -int op,char *resctrl_val) +static int fill_cache (size_t buf_size,int memflush,int op,char *resctrl_val) {unsigned char *start_ptr, *end_ptr; -unsigned long long i;int ret; -if (malloc_and_init) - start_ptr =malloc_and_init_memory (buf_size); -else - start_ptr =malloc (buf_size); - + start_ptr =malloc_and_init_memory (buf_size);if (!start_ptr)return -1 ; startptr = start_ptr; end_ptr = start_ptr + buf_size; -/* -* It's better to touch the memory once to avoid any compiler -* optimizations -*/ -if (!malloc_and_init) { -for (i =0 ; i < buf_size; i++) - *start_ptr++ = (unsigned char )rand (); - } - - start_ptr = startptr; -/* Flush the memory before using to avoid "cache hot pages" effect */ if (memflush)mem_flush (start_ptr, buf_size);
@@ -188,14 +170,12 @@ fill_cache(size_t buf_size, int malloc_and_init, int memflush,return 0 ; } -int run_fill_buf (size_t span,int malloc_and_init_memory,int memflush,int op, -char *resctrl_val) +int run_fill_buf (size_t span,int memflush,int op,char *resctrl_val) {size_t cache_size = span;int ret; - ret =fill_cache (cache_size, malloc_and_init_memory, memflush, op, - resctrl_val); + ret =fill_cache (cache_size, memflush, op, resctrl_val);if (ret) {printf ("\n Error in fill cache\n" );return -1 ;
tools/testing/selftests/resctrl/resctrl.h +1 -2
@@ -97,8 +97,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 malloc_and_init_memory,int memflush,int op, -char *resctrl_va); +int run_fill_buf (size_t span,int memflush,int op,char *resctrl_val);int resctrl_val (char **benchmark_cmd,struct resctrl_val_param *param);int mbm_bw_change (size_t span,int cpu_no,char *bw_report,char **benchmark_cmd);void tests_cleanup (void );
tools/testing/selftests/resctrl/resctrl_tests.c +6 -7
@@ -89,7 +89,7 @@ static void run_mbm_test(bool has_ben, char **benchmark_cmd, size_t span, }if (!has_ben) -sprintf (benchmark_cmd[5 ],"%s" ,MBA_STR ); +sprintf (benchmark_cmd[4 ],"%s" ,MBA_STR ); res =mbm_bw_change (span, cpu_no, bw_report, benchmark_cmd);ksft_test_result (!res,"MBM: bw change\n" );if ((get_vendor () ==ARCH_INTEL ) && res)
@@ -141,7 +141,7 @@ static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no) }if (!has_ben) -sprintf (benchmark_cmd[5 ],"%s" ,CMT_STR ); +sprintf (benchmark_cmd[4 ],"%s" ,CMT_STR ); res =cmt_resctrl_val (cpu_no,5 , benchmark_cmd);ksft_test_result (!res,"CMT: test\n" );if ((get_vendor () ==ARCH_INTEL ) && res)
@@ -267,16 +267,15 @@ int main(int argc, char **argv) benchmark_cmd[ben_count] =NULL ; }else {/* If no benchmark is given by "-b" argument, use fill_buf. */ -for (i =0 ; i <6 ; i++) +for (i =0 ; i <5 ; i++) benchmark_cmd[i] = benchmark_cmd_area[i];strcpy (benchmark_cmd[0 ],"fill_buf" );sprintf (benchmark_cmd[1 ],"%zu" , span);strcpy (benchmark_cmd[2 ],"1" ); -strcpy (benchmark_cmd[3 ],"1" ); -strcpy (benchmark_cmd[4 ],"0" ); -strcpy (benchmark_cmd[5 ],"" ); - benchmark_cmd[6 ] =NULL ; +strcpy (benchmark_cmd[3 ],"0" ); +strcpy (benchmark_cmd[4 ],"" ); + benchmark_cmd[5 ] =NULL ; }sprintf (bw_report,"reads" );
tools/testing/selftests/resctrl/resctrlfs.c +5 -7
@@ -302,7 +302,7 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no)*/ void run_benchmark (int signum,siginfo_t *info,void *ucontext) { -int operation, ret, malloc_and_init_memory, memflush; +int operation, ret, memflush;char **benchmark_cmd;char resctrl_val[64 ];size_t span;
@@ -321,13 +321,11 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext)if (strcmp (benchmark_cmd[0 ],"fill_buf" ) ==0 ) {/* Execute default fill_buf benchmark */ span =strtoul (benchmark_cmd[1 ],NULL ,10 ); - malloc_and_init_memory =atoi (benchmark_cmd[2 ]); - memflush =atoi (benchmark_cmd[3 ]); - operation =atoi (benchmark_cmd[4 ]); -sprintf (resctrl_val,"%s" , benchmark_cmd[5 ]); + memflush =atoi (benchmark_cmd[2 ]); + operation =atoi (benchmark_cmd[3 ]); +sprintf (resctrl_val,"%s" , benchmark_cmd[4 ]); -if (run_fill_buf (span, malloc_and_init_memory, memflush, - operation, resctrl_val)) +if (run_fill_buf (span, memflush, operation, resctrl_val))fprintf (stderr,"Error in running fill buffer\n" ); }else {/* Execute specified benchmark */
Signature · 1 line
2.30.2
Shuah Khan
maintainerRe: [PATCH v5 12/19] selftests/resctrl: Remove "malloc_and_init_memory" param from run_fill_buf()
Quoted 150 lines · Ilpo Järvinen
run_fill_buf()'s
malloc_and_init_memoryparameter is always 1. There's also duplicated memory init code formalloc_and_init_memory== 0 case infill_buf()which is unused.Remove the
malloc_and_init_memoryparameter and the duplicated mem init code.While at it, fix also a typo in
run_fill_buf()prototype's argument.Co-developed-by Fenghua Yu <[email protected]>Signed-off-by Fenghua Yu <[email protected]>Signed-off-by Ilpo Järvinen <[email protected]>Reviewed-by Reinette Chatre <[email protected]>--- tools/testing/selftests/resctrl/cache.c | 6 ++-- tools/testing/selftests/resctrl/fill_buf.c | 28 +++---------------- tools/testing/selftests/resctrl/resctrl.h | 3 +- .../testing/selftests/resctrl/resctrl_tests.c | 13 ++++----- tools/testing/selftests/resctrl/resctrlfs.c | 12 ++++---- 5 files changed, 19 insertions(+), 43 deletions(-)tools/testing/selftests/resctrl/cache.c +3
-3@@ -210,7 +210,7 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid)*/ int cat_val (struct resctrl_val_param *param) { -int malloc_and_init_memory =1 , memflush =1 , operation =0 , ret =0 ; +int memflush =1 , operation =0 , ret =0 ;char *resctrl_val = param->resctrl_val;pid_t bm_pid;@@ -247,8 +247,8 @@ int cat_val(struct resctrl_val_param *param)if (ret)break ; -if (run_fill_buf (param->span, malloc_and_init_memory, - memflush, operation, resctrl_val)) { +if (run_fill_buf (param->span, memflush, operation, + resctrl_val)) {fprintf (stderr,"Error-running fill buffer\n" ); ret =-1 ; goto pe_close;tools/testing/selftests/resctrl/fill_buf.c +4
-24@@ -138,36 +138,18 @@ static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr,return 0 ; } -static int -fill_cache (size_t buf_size,int malloc_and_init,int memflush, -int op,char *resctrl_val) +static int fill_cache (size_t buf_size,int memflush,int op,char *resctrl_val) {unsigned char *start_ptr, *end_ptr; -unsigned long long i;int ret; -if (malloc_and_init) - start_ptr =malloc_and_init_memory (buf_size); -else - start_ptr =malloc (buf_size); - + start_ptr =malloc_and_init_memory (buf_size);if (!start_ptr)return -1 ; startptr = start_ptr; end_ptr = start_ptr + buf_size; -/* -* It's better to touch the memory once to avoid any compiler -* optimizations -*/ -if (!malloc_and_init) { -for (i =0 ; i < buf_size; i++) - *start_ptr++ = (unsigned char )rand (); - } - - start_ptr = startptr; -/* Flush the memory before using to avoid "cache hot pages" effect */ if (memflush)mem_flush (start_ptr, buf_size);@@ -188,14 +170,12 @@ fill_cache(size_t buf_size, int malloc_and_init, int memflush,return 0 ; } -int run_fill_buf (size_t span,int malloc_and_init_memory,int memflush,int op, -char *resctrl_val) +int run_fill_buf (size_t span,int memflush,int op,char *resctrl_val) {size_t cache_size = span;int ret; - ret =fill_cache (cache_size, malloc_and_init_memory, memflush, op, - resctrl_val); + ret =fill_cache (cache_size, memflush, op, resctrl_val);if (ret) {printf ("\n Error in fill cache\n" );return -1 ;tools/testing/selftests/resctrl/resctrl.h +1
-2@@ -97,8 +97,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 malloc_and_init_memory,int memflush,int op, -char *resctrl_va); +int run_fill_buf (size_t span,int memflush,int op,char *resctrl_val);int resctrl_val (char **benchmark_cmd,struct resctrl_val_param *param);int mbm_bw_change (size_t span,int cpu_no,char *bw_report,char **benchmark_cmd);void tests_cleanup (void );tools/testing/selftests/resctrl/resctrl_tests.c +3
-3@@ -89,7 +89,7 @@ static void run_mbm_test(bool has_ben, char **benchmark_cmd, size_t span, }if (!has_ben) -sprintf (benchmark_cmd[5 ],"%s" ,MBA_STR ); +sprintf (benchmark_cmd[4 ],"%s" ,MBA_STR ); res =mbm_bw_change (span, cpu_no, bw_report, benchmark_cmd);ksft_test_result (!res,"MBM: bw change\n" );if ((get_vendor () ==ARCH_INTEL ) && res)@@ -141,7 +141,7 @@ static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no) }if (!has_ben) -sprintf (benchmark_cmd[5 ],"%s" ,CMT_STR ); +sprintf (benchmark_cmd[4 ],"%s" ,CMT_STR ); res =cmt_resctrl_val (cpu_no,5 , benchmark_cmd);ksft_test_result (!res,"CMT: test\n" );if ((get_vendor () ==ARCH_INTEL ) && res)@@ -267,16 +267,15 @@ int main(int argc, char **argv) benchmark_cmd[ben_count] =NULL ; }else {/* If no benchmark is given by "-b" argument, use fill_buf. */ -for (i =0 ; i <6 ; i++) +for (i =0 ; i <5 ; i++) benchmark_cmd[i] = benchmark_cmd_area[i];strcpy (benchmark_cmd[0 ],"fill_buf" );
tools/testing/selftests/resctrl/resctrl_tests.c int main(int argc, char **argv) · line 279
Quoted 10 lines
tools/testing/selftests/resctrl/resctrl_tests.c +3
-4sprintf (benchmark_cmd[1 ],"%zu" , span);strcpy (benchmark_cmd[2 ],"1" ); -strcpy (benchmark_cmd[3 ],"1" ); -strcpy (benchmark_cmd[4 ],"0" ); -strcpy (benchmark_cmd[5 ],"" ); - benchmark_cmd[6 ] =NULL ; +strcpy (benchmark_cmd[3 ],"0" ); +strcpy (benchmark_cmd[4 ],"" ); + benchmark_cmd[5 ] =NULL ; }
Lots of copying - can the above be simplified. Also seeing this warning:
WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
#233: FILE: tools/testing/selftests/resctrl/resctrl_tests.c:276:
+ strcpy(benchmark_cmd[3], "0");
WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
#234: FILE: tools/testing/selftests/resctrl/resctrl_tests.c:277:
+ strcpy(benchmark_cmd[4], "");
total: 0 errors, 2 warnings, 142 lines checked
I am applying the patch set to linux-kselftest next - please fix the aboe and send a patch on top of linux-kselftest next
thanks,
-- Shuah
Reinette Chatre
maintainerRe: [PATCH v5 12/19] selftests/resctrl: Remove "malloc_and_init_memory" param from run_fill_buf()
Hi Shuah,
Quoted 4 lines · Shuah Khan
WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
#233: FILE:tools/testing/selftests/resctrl/resctrl_tests.c:276:
+strcpy(benchmark_cmd[3], "0");
Quoted 8 lines
WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
#234: FILE:tools/testing/selftests/resctrl/resctrl_tests.c:277:
+strcpy(benchmark_cmd[4], "");total: 0 errors, 2 warnings, 142 lines checked
I am applying the patch set to linux-kselftest next - please fix the aboe and send a patch on top of linux-kselftest next
Is strscpy() available to userspace? I found lib/strscpy_kunit.c that makes me think this is currently only available to kernel code.
Reinette
Re: [PATCH v5 12/19] selftests/resctrl: Remove "malloc_and_init_memory" param from run_fill_buf()
Quoted 11 lines · Reinette Chatre
Hi Shuah,
Quoted 8 lines · Shuah Khan
WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
#233: FILE:tools/testing/selftests/resctrl/resctrl_tests.c:276:
+strcpy(benchmark_cmd[3], "0");WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
#234: FILE:tools/testing/selftests/resctrl/resctrl_tests.c:277:
+strcpy(benchmark_cmd[4], "");
Quoted 7 lines
Quoted 4 lines
total: 0 errors, 2 warnings, 142 lines checked
I am applying the patch set to linux-kselftest next - please fix the aboe and send a patch on top of linux-kselftest next
Is
strscpy()available to userspace? I foundlib/strscpy_kunit.cthat makes me think this is currently only available to kernel code.
It's not available and I've done so little userspace programming in the recent years (and even less string manipulation in userspace C) I've no idea what would be the best way to replace it.
However, I've a few patches which will cleanup the benchmark command handling that include removal of these strcpy()s. Those changes looked separate enough from the rest I can send it independent of that CAT rewrite which would have been the next entry in my pending resctrl selftest patches queue.
Signature · 1 line
i.
Shuah Khan
maintainerRe: [PATCH v5 12/19] selftests/resctrl: Remove "malloc_and_init_memory" param from run_fill_buf()
In reply to Reinette ChatreQuoted 11 lines · Reinette Chatre
Hi Shuah,
Quoted 8 lines · Shuah Khan
WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
#233: FILE:tools/testing/selftests/resctrl/resctrl_tests.c:276:
+strcpy(benchmark_cmd[3], "0");WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
#234: FILE:tools/testing/selftests/resctrl/resctrl_tests.c:277:
+strcpy(benchmark_cmd[4], "");
Quoted 8 lines
Quoted 4 lines
total: 0 errors, 2 warnings, 142 lines checked
I am applying the patch set to linux-kselftest next - please fix the aboe and send a patch on top of linux-kselftest next
Is
strscpy()available to userspace? I foundlib/strscpy_kunit.cthat makes me think this is currently only available to kernel code.
Very likely. You can ignore the comment. I already applied the series anyway.
thanks,
-- Shuah
Reinette Chatre
maintainerRe: [PATCH v5 12/19] selftests/resctrl: Remove "malloc_and_init_memory" param from run_fill_buf()
Quoted 3 lines · Shuah Khan
Very likely. You can ignore the comment. I already applied the series anyway.
Thank you very much Shuah.
Reinette
PATCH v5 13/19 selftests/resctrl: Remove unnecessary startptr global from fill_buf
In reply to Ilpo Järvinenfill_buf stores buffer pointer into global variable startptr that is only used in fill_cache().
Remove startptr as global variable, the local variable in fill_cache() is enough to keep the pointer.
--- tools/testing/selftests/resctrl/fill_buf.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
tools/testing/selftests/resctrl/fill_buf.c +1 -4
@@ -22,8 +22,6 @@#define PAGE_SIZE (4 * 1024)#define MB (1024 * 1024) -static unsigned char *startptr; -static void sb (void ) {#if defined(__i386) || defined(__x86_64)
@@ -147,7 +145,6 @@ static int fill_cache(size_t buf_size, int memflush, int op, char *resctrl_val)if (!start_ptr)return -1 ; - startptr = start_ptr; end_ptr = start_ptr + buf_size;/* Flush the memory before using to avoid "cache hot pages" effect */
@@ -159,7 +156,7 @@ static int fill_cache(size_t buf_size, int memflush, int op, char *resctrl_val)else ret =fill_cache_write (start_ptr, end_ptr, resctrl_val); -free (startptr); +free (start_ptr);if (ret) {printf ("\n Error in fill cache read/write...\n" );
Signature · 1 line
2.30.2
PATCH v5 14/19 selftests/resctrl: Improve parameter consistency in fill_buf
In reply to Ilpo Järvinenfill_buf's arguments can be improved in multiple ways:
- Multiple functions in fill_buf have start_ptr as one of their argument which is a bit long and the extra "start" is pretty obvious when it comes to pointers.
- Some of the functions take end_ptr and others size_t to indicate the end of the buffer.
- Some arguments meaning buffer size are called just 's'
- mem_flush() takes void * but immediately converts it to char *
Cleanup the parameters to make things simpler and more consistent:
- Rename start_ptr to simply buf as it's shorter.
- Replace end_ptr and s parameters with buf_size and only calculate end_ptr in the functions that truly use it.
- Make mem_flush() parameters to follow the same convention as the other functions in fill_buf.
- convert mem_flush() char * to unsigned char *.
While at it, fix also a typo in a comment.
--- tools/testing/selftests/resctrl/fill_buf.c | 49 +++++++++++----------- 1 file changed, 24 insertions(+), 25 deletions(-)
tools/testing/selftests/resctrl/fill_buf.c +24 -25
@@ -38,32 +38,32 @@ static void cl_flush(void *p)#endif } -static void mem_flush (void *p,size_t s) +static void mem_flush (unsigned char *buf,size_t buf_size) { -char *cp = (char *)p; +unsigned char *cp = buf;size_t i =0 ; - s = s /CL_SIZE ;/* mem size in cache llines */ + buf_size = buf_size /CL_SIZE ;/* mem size in cache lines */ -for (i =0 ; i < s; i++) +for (i =0 ; i < buf_size; i++)cl_flush (&cp[i *CL_SIZE ]);sb (); } -static void *malloc_and_init_memory (size_t s) +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 , s); + ret =posix_memalign (&p,PAGE_SIZE , buf_size);if (ret <0 )return NULL ; p64 = (uint64_t *)p; - s64 = s /sizeof (uint64_t ); + s64 = buf_size /sizeof (uint64_t );while (s64 >0 ) { *p64 = (uint64_t )rand ();
@@ -74,12 +74,13 @@ static void *malloc_and_init_memory(size_t s)return p; } -static int fill_one_span_read (unsigned char *start_ptr,unsigned char *end_ptr) +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 = start_ptr; + p = buf;while (p < end_ptr) { sum += *p; p += (CL_SIZE /2 );
@@ -88,26 +89,26 @@ static int fill_one_span_read(unsigned char *start_ptr, unsigned char *end_ptr)return sum; } -static -void fill_one_span_write (unsigned char *start_ptr,unsigned char *end_ptr) +static void fill_one_span_write (unsigned char *buf,size_t buf_size) { +unsigned char *end_ptr = buf + buf_size;unsigned char *p; - p = start_ptr; + p = buf;while (p < end_ptr) { *p ='1' ; p += (CL_SIZE /2 ); } } -static int fill_cache_read (unsigned char *start_ptr,unsigned char *end_ptr, +static int fill_cache_read (unsigned char *buf,size_t buf_size,char *resctrl_val) {int ret =0 ;FILE *fp;while (1 ) { - ret =fill_one_span_read (start_ptr, end_ptr); + ret =fill_one_span_read (buf, buf_size);if (!strncmp (resctrl_val,CAT_STR ,sizeof (CAT_STR )))break ; }
@@ -124,11 +125,11 @@ static int fill_cache_read(unsigned char *start_ptr, unsigned char *end_ptr,return 0 ; } -static int fill_cache_write (unsigned char *start_ptr,unsigned char *end_ptr, +static int fill_cache_write (unsigned char *buf,size_t buf_size,char *resctrl_val) {while (1 ) { -fill_one_span_write (start_ptr, end_ptr); +fill_one_span_write (buf, buf_size);if (!strncmp (resctrl_val,CAT_STR ,sizeof (CAT_STR )))break ; }
@@ -138,25 +139,23 @@ static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr,static int fill_cache (size_t buf_size,int memflush,int op,char *resctrl_val) { -unsigned char *start_ptr, *end_ptr; +unsigned char *buf;int ret; - start_ptr =malloc_and_init_memory (buf_size); -if (!start_ptr) + buf =malloc_and_init_memory (buf_size); +if (!buf)return -1 ; - end_ptr = start_ptr + buf_size; -/* Flush the memory before using to avoid "cache hot pages" effect */ if (memflush) -mem_flush (start_ptr, buf_size); +mem_flush (buf, buf_size);if (op ==0 ) - ret =fill_cache_read (start_ptr, end_ptr, resctrl_val); + ret =fill_cache_read (buf, buf_size, resctrl_val);else - ret =fill_cache_write (start_ptr, end_ptr, resctrl_val); + ret =fill_cache_write (buf, buf_size, resctrl_val); -free (start_ptr); +free (buf);if (ret) {printf ("\n Error in fill cache read/write...\n" );
Signature · 1 line
2.30.2
PATCH v5 15/19 selftests/resctrl: Don't pass test name to fill_buf
In reply to Ilpo JärvinenTest name is passed to fill_buf functions so that they can loop around buffer only once. This is required for CAT test case.
To loop around buffer only once, caller doesn't need to let fill_buf know which test case it is. Instead, pass a boolean argument 'once' which makes fill_buf more generic.
As run_benchmark() no longer needs to pass the test name to run_fill_buf(), a few test running functions can be simplified to not write the test name into the default benchmark_cmd. The has_ben argument can also be removed now from those test running functions.
--- tools/testing/selftests/resctrl/cache.c | 3 +-- tools/testing/selftests/resctrl/fill_buf.c | 20 +++++++++---------- tools/testing/selftests/resctrl/resctrl.h | 2 +- .../testing/selftests/resctrl/resctrl_tests.c | 14 +++++-------- tools/testing/selftests/resctrl/resctrlfs.c | 11 +++++++--- 5 files changed, 24 insertions(+), 26 deletions(-)
tools/testing/selftests/resctrl/cache.c +1 -2
@@ -247,8 +247,7 @@ int cat_val(struct resctrl_val_param *param)if (ret)break ; -if (run_fill_buf (param->span, memflush, operation, - resctrl_val)) { +if (run_fill_buf (param->span, memflush, operation, true)) {fprintf (stderr,"Error-running fill buffer\n" ); ret =-1 ; goto pe_close;
tools/testing/selftests/resctrl/fill_buf.c +9 -11
@@ -101,15 +101,14 @@ 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, -char *resctrl_val) +static int 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); -if (!strncmp (resctrl_val,CAT_STR ,sizeof (CAT_STR ))) +if (once)break ; }
@@ -125,19 +124,18 @@ static int fill_cache_read(unsigned char *buf, size_t buf_size,return 0 ; } -static int fill_cache_write (unsigned char *buf,size_t buf_size, -char *resctrl_val) +static int fill_cache_write (unsigned char *buf,size_t buf_size,bool once) {while (1 ) {fill_one_span_write (buf, buf_size); -if (!strncmp (resctrl_val,CAT_STR ,sizeof (CAT_STR ))) +if (once)break ; }return 0 ; } -static int fill_cache (size_t buf_size,int memflush,int op,char *resctrl_val) +static int fill_cache (size_t buf_size,int memflush,int op,bool once) {unsigned char *buf;int ret;
@@ -151,9 +149,9 @@ static int fill_cache(size_t buf_size, int memflush, int op, char *resctrl_val)mem_flush (buf, buf_size);if (op ==0 ) - ret =fill_cache_read (buf, buf_size, resctrl_val); + ret =fill_cache_read (buf, buf_size, once);else - ret =fill_cache_write (buf, buf_size, resctrl_val); + ret =fill_cache_write (buf, buf_size, once);free (buf);
@@ -166,12 +164,12 @@ static int fill_cache(size_t buf_size, int memflush, int op, char *resctrl_val)return 0 ; } -int run_fill_buf (size_t span,int memflush,int op,char *resctrl_val) +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, resctrl_val); + 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
@@ -97,7 +97,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,char *resctrl_val); +int run_fill_buf (size_t span,int memflush,int op,bool once);int resctrl_val (char **benchmark_cmd,struct resctrl_val_param *param);int mbm_bw_change (size_t span,int cpu_no,char *bw_report,char **benchmark_cmd);void tests_cleanup (void );
tools/testing/selftests/resctrl/resctrl_tests.c +5 -9
@@ -70,7 +70,7 @@ void tests_cleanup(void)cat_test_cleanup (); } -static void run_mbm_test (bool has_ben,char **benchmark_cmd,size_t span, +static void run_mbm_test (char **benchmark_cmd,size_t span,int cpu_no,char *bw_report) {int res;
@@ -88,8 +88,6 @@ static void run_mbm_test(bool has_ben, char **benchmark_cmd, size_t span, goto umount; } -if (!has_ben) -sprintf (benchmark_cmd[4 ],"%s" ,MBA_STR ); res =mbm_bw_change (span, cpu_no, bw_report, benchmark_cmd);ksft_test_result (!res,"MBM: bw change\n" );if ((get_vendor () ==ARCH_INTEL ) && res)
@@ -123,7 +121,7 @@ static void run_mba_test(char **benchmark_cmd, int cpu_no, char *bw_report)umount_resctrlfs (); } -static void run_cmt_test (bool has_ben,char **benchmark_cmd,int cpu_no) +static void run_cmt_test (char **benchmark_cmd,int cpu_no) {int res;
@@ -140,8 +138,6 @@ static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no) goto umount; } -if (!has_ben) -sprintf (benchmark_cmd[4 ],"%s" ,CMT_STR ); res =cmt_resctrl_val (cpu_no,5 , benchmark_cmd);ksft_test_result (!res,"CMT: test\n" );if ((get_vendor () ==ARCH_INTEL ) && res)
@@ -274,7 +270,7 @@ int main(int argc, char **argv)sprintf (benchmark_cmd[1 ],"%zu" , span);strcpy (benchmark_cmd[2 ],"1" );strcpy (benchmark_cmd[3 ],"0" ); -strcpy (benchmark_cmd[4 ],"" ); +strcpy (benchmark_cmd[4 ],"false" ); benchmark_cmd[5 ] =NULL ; }
@@ -292,13 +288,13 @@ int main(int argc, char **argv)ksft_set_plan (tests ? :4 );if (mbm_test) -run_mbm_test (has_ben, benchmark_cmd, span, cpu_no, bw_report); +run_mbm_test (benchmark_cmd, span, cpu_no, bw_report);if (mba_test)run_mba_test (benchmark_cmd, cpu_no, bw_report);if (cmt_test) -run_cmt_test (has_ben, benchmark_cmd, cpu_no); +run_cmt_test (benchmark_cmd, cpu_no);if (cat_test)run_cat_test (cpu_no, no_of_bits);
tools/testing/selftests/resctrl/resctrlfs.c +8 -3
@@ -304,8 +304,8 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext) {int operation, ret, memflush;char **benchmark_cmd; -char resctrl_val[64 ];size_t span; +bool once;FILE *fp; benchmark_cmd = info->si_ptr;
@@ -323,9 +323,14 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext) span =strtoul (benchmark_cmd[1 ],NULL ,10 ); memflush =atoi (benchmark_cmd[2 ]); operation =atoi (benchmark_cmd[3 ]); -sprintf (resctrl_val,"%s" , benchmark_cmd[4 ]); +if (!strcmp (benchmark_cmd[4 ],"true" )) + once = true; +else if (!strcmp (benchmark_cmd[4 ],"false" )) + once = false; +else +PARENT_EXIT ("Invalid once parameter" ); -if (run_fill_buf (span, memflush, operation, resctrl_val)) +if (run_fill_buf (span, memflush, operation, once))fprintf (stderr,"Error in running fill buffer\n" ); }else {/* Execute specified benchmark */
Signature · 1 line
2.30.2
PATCH v5 16/19 selftests/resctrl: Don't use variable argument list for ->setup()
In reply to Ilpo Järvinenstruct resctrl_val_param has ->setup() function that accepts variable argument list. All test cases use only 1 argument as input and it's the struct resctrl_val_param pointer.
Instead of variable argument list, directly pass struct resctrl_val_param pointer as the only parameter to ->setup().
--- tools/testing/selftests/resctrl/cache.c | 2 +- tools/testing/selftests/resctrl/cat_test.c | 8 +------- tools/testing/selftests/resctrl/cmt_test.c | 9 +-------- tools/testing/selftests/resctrl/mba_test.c | 8 +------- tools/testing/selftests/resctrl/mbm_test.c | 8 +------- tools/testing/selftests/resctrl/resctrl.h | 3 +-- tools/testing/selftests/resctrl/resctrl_val.c | 2 +- 7 files changed, 7 insertions(+), 33 deletions(-)
tools/testing/selftests/resctrl/cache.c +1 -1
@@ -236,7 +236,7 @@ int cat_val(struct resctrl_val_param *param)/* Test runs until the callback setup() tells the test to stop. */ while (1 ) {if (!strncmp (resctrl_val,CAT_STR ,sizeof (CAT_STR ))) { - ret = param->setup (1 , param); + ret = param->setup (param);if (ret ==END_OF_TESTS ) { ret =0 ;break ;
tools/testing/selftests/resctrl/cat_test.c +1 -7
@@ -27,17 +27,11 @@ static unsigned long cache_size;* con_mon grp, mon_grp in resctrl FS. * Run 5 times in order to get average values. */ -static int cat_setup (int num, ...) +static int cat_setup (struct resctrl_val_param *p) { -struct resctrl_val_param *p;char schemata[64 ]; -va_list param;int ret =0 ; -va_start (param, num); - p = va_arg(param, struct resctrl_val_param *); -va_end (param); -/* Run NUM_OF_RUNS times */ if (p->num_of_runs >=NUM_OF_RUNS )return END_OF_TESTS ;
tools/testing/selftests/resctrl/cmt_test.c +1 -8
@@ -21,15 +21,8 @@ static char cbm_mask[256];static unsigned long long_mask;static unsigned long cache_size; -static int cmt_setup (int num, ...) +static int cmt_setup (struct resctrl_val_param *p) { -struct resctrl_val_param *p; -va_list param; - -va_start (param, num); - p = va_arg(param, struct resctrl_val_param *); -va_end (param); -/* Run NUM_OF_RUNS times */ if (p->num_of_runs >=NUM_OF_RUNS )return END_OF_TESTS ;
tools/testing/selftests/resctrl/mba_test.c +1 -7
@@ -22,18 +22,12 @@* con_mon grp, mon_grp in resctrl FS. * For each allocation, run 5 times in order to get average values. */ -static int mba_setup (int num, ...) +static int mba_setup (struct resctrl_val_param *p) {static int runs_per_allocation, allocation =100 ; -struct resctrl_val_param *p;char allocation_str[64 ]; -va_list param;int ret; -va_start (param, num); - p = va_arg(param, struct resctrl_val_param *); -va_end (param); -if (runs_per_allocation >=NUM_OF_RUNS ) runs_per_allocation =0 ;
tools/testing/selftests/resctrl/mbm_test.c +1 -7
@@ -86,16 +86,10 @@ static int check_results(size_t span)return ret; } -static int mbm_setup (int num, ...) +static int mbm_setup (struct resctrl_val_param *p) { -struct resctrl_val_param *p; -va_list param;int ret =0 ; -va_start (param, num); - p = va_arg(param, struct resctrl_val_param *); -va_end (param); -/* Run NUM_OF_RUNS times */ if (p->num_of_runs >=NUM_OF_RUNS )return END_OF_TESTS ;
tools/testing/selftests/resctrl/resctrl.h +1 -2
@@ -3,7 +3,6 @@#ifndef RESCTRL_H #define RESCTRL_H #include <stdio.h> -#include <stdarg.h> #include <math.h> #include <errno.h> #include <sched.h>
@@ -68,7 +67,7 @@ struct resctrl_val_param {char *bw_report;unsigned long mask;int num_of_runs; -int (*setup)(int num, ...); +int (*setup)(struct resctrl_val_param *param); };#define MBM_STR "mbm"
tools/testing/selftests/resctrl/resctrl_val.c +1 -1
@@ -759,7 +759,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)/* Test runs until the callback setup() tells the test to stop. */ while (1 ) { - ret = param->setup (1 , param); + ret = param->setup (param);if (ret ==END_OF_TESTS ) { ret =0 ;break ;
Signature · 1 line
2.30.2
PATCH v5 17/19 selftests/resctrl: Move CAT/CMT test global vars to function they are used in
In reply to Ilpo JärvinenCAT and CMT tests have count_of_bits, long_mask, cbm_mask, and cache_size global variables that can be moved into the sole using function.
Make the global variables local variables of the relevant function to scope them better.
While at it, move cache_size initialization into the declaration line.
--- tools/testing/selftests/resctrl/cat_test.c | 11 ++++------- tools/testing/selftests/resctrl/cmt_test.c | 11 ++++------- 2 files changed, 8 insertions(+), 14 deletions(-)
tools/testing/selftests/resctrl/cat_test.c +4 -7
@@ -17,11 +17,6 @@#define MAX_DIFF_PERCENT 4#define MAX_DIFF 1000000 -static int count_of_bits; -static char cbm_mask[256 ]; -static unsigned long long_mask; -static unsigned long cache_size; -/* * Change schemata. Write schemata to specified * con_mon grp, mon_grp in resctrl FS.
@@ -96,10 +91,12 @@ 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 long_mask; +char cbm_mask[256 ]; +int count_of_bits;char pipe_message; - cache_size =0 ; -/* Get default cbm mask for L3/L2 cache */ ret =get_cbm_mask (cache_type, cbm_mask);if (ret)
tools/testing/selftests/resctrl/cmt_test.c +4 -7
@@ -16,11 +16,6 @@#define MAX_DIFF 2000000#define MAX_DIFF_PERCENT 15 -static int count_of_bits; -static char cbm_mask[256 ]; -static unsigned long long_mask; -static unsigned long cache_size; -static int cmt_setup (struct resctrl_val_param *p) {/* Run NUM_OF_RUNS times */
@@ -75,10 +70,12 @@ void cmt_test_cleanup(void)int cmt_resctrl_val (int cpu_no,int n,char **benchmark_cmd) { +unsigned long cache_size =0 ; +unsigned long long_mask; +char cbm_mask[256 ]; +int count_of_bits;int ret; - cache_size =0 ; -if (!validate_resctrl_feature_request (CMT_STR ))return -1 ;
Signature · 1 line
2.30.2
PATCH v5 18/19 selftests/resctrl: Pass the real number of tests to show_cache_info()
In reply to Ilpo JärvinenResults include warm-up test which is discarded before passing the sum to show_cache_info(). show_cache_info() handles this by subtracting one from the number of tests in divisor. It is a trappy construct to have sum and number of tests parameters to disagree like this.
A more logical place for subtracting the skipped tests is where the sum is calculated so move it there. Pass the correct number of tests to show_cache_info() so it can be used directly as the divisor for calculating the average.
--- tools/testing/selftests/resctrl/cache.c | 2 +- tools/testing/selftests/resctrl/cat_test.c | 2 +- tools/testing/selftests/resctrl/cmt_test.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/resctrl/cache.c +1 -1
@@ -294,7 +294,7 @@ int show_cache_info(unsigned long sum_llc_val, int no_of_bits,long avg_diff =0 ;int ret; - avg_llc_val = sum_llc_val / (num_of_runs -1 ); + 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 ;
tools/testing/selftests/resctrl/cat_test.c +1 -1
@@ -77,7 +77,7 @@ static int check_results(struct resctrl_val_param *param) no_of_bits =count_bits (param->mask);return show_cache_info (sum_llc_perf_miss, no_of_bits, param->span /64 , -MAX_DIFF ,MAX_DIFF_PERCENT ,NUM_OF_RUNS , +MAX_DIFF ,MAX_DIFF_PERCENT , runs -1 ,get_vendor () ==ARCH_INTEL , false); }
tools/testing/selftests/resctrl/cmt_test.c +1 -1
@@ -59,7 +59,7 @@ static int check_results(struct resctrl_val_param *param, int no_of_bits)fclose (fp);return show_cache_info (sum_llc_occu_resc, no_of_bits, param->span, -MAX_DIFF ,MAX_DIFF_PERCENT ,NUM_OF_RUNS , +MAX_DIFF ,MAX_DIFF_PERCENT , runs -1 , true, true); }
Signature · 1 line
2.30.2
PATCH v5 19/19 selftests/resctrl: Remove test type checks from cat_val()
In reply to Ilpo Järvinencat_val() is only used during CAT test but it checks for test type.
Remove test type checks and the unused else branch from cat_val().
--- tools/testing/selftests/resctrl/cache.c | 47 +++++++++++-------------- 1 file changed, 20 insertions(+), 27 deletions(-)
tools/testing/selftests/resctrl/cache.c +20 -27
@@ -230,38 +230,31 @@ int cat_val(struct resctrl_val_param *param)if (ret)return ret; -if (!strncmp (resctrl_val,CAT_STR ,sizeof (CAT_STR ))) -initialize_llc_perf (); +initialize_llc_perf ();/* Test runs until the callback setup() tells the test to stop. */ while (1 ) { -if (!strncmp (resctrl_val,CAT_STR ,sizeof (CAT_STR ))) { - ret = param->setup (param); -if (ret ==END_OF_TESTS ) { - ret =0 ; -break ; - } -if (ret <0 ) -break ; - ret =reset_enable_llc_perf (bm_pid, param->cpu_no); -if (ret) -break ; - -if (run_fill_buf (param->span, memflush, operation, true)) { -fprintf (stderr,"Error-running fill buffer\n" ); - ret =-1 ; - goto pe_close; - } - -sleep (1 ); - ret =measure_cache_vals (param, bm_pid); -if (ret) - goto pe_close; - -close (fd_lm); - }else { + ret = param->setup (param); +if (ret ==END_OF_TESTS ) { + ret =0 ;break ; } +if (ret <0 ) +break ; + ret =reset_enable_llc_perf (bm_pid, param->cpu_no); +if (ret) +break ; + +if (run_fill_buf (param->span, memflush, operation, true)) { +fprintf (stderr,"Error-running fill buffer\n" ); + ret =-1 ; + goto pe_close; + } + +sleep (1 ); + ret =measure_cache_vals (param, bm_pid); +if (ret) + goto pe_close; }return ret;
Signature · 1 line
2.30.2
Babu Moger
reviewerv5 cover selftests/resctrl: Fixes and cleanups
In reply to Ilpo JärvinenHi Ilpo, Thanks for the patches. I did a quick test on AMD machine. There are no failures. They look good.
Some of the MBA tests are skipped for AMD. I will take that up later.
Hi Ilpo,
Quoted 7 lines
Here is a series with some fixes and cleanups to resctrl selftests.
v5:
- Improve changelogs
- Closefd_lmonly incat_val()
- Improve unmount error handling
I reviewed this patch series,
and ran resctrl selftest on Intel(R) Xeon(R) Gold 6254 CPU, they look good.
<Tested-by:[email protected]>
<Reviewed-by:[email protected]>
Shuah Khan
maintainerQuoted 7 lines · Ilpo Järvinen
Here is a series with some fixes and cleanups to resctrl selftests.
v5:
- Improve changelogs
- Closefd_lmonly incat_val()
- Improve unmount error handling
Applied to linux-kselftest next for Linux 6.6-rc1
thanks,
-- Shuah