Some improvements of resctrl selftest
Subsystems (2)
v6 cover Some improvements of resctrl selftest
Hello,
The aim of this patch series is to improve the resctrl selftest. Without these fixes, some unnecessary processing will be executed and test results will be confusing.
There is no behavior change in test themselves.
[patch 1] Make write_schemata() run to set up shemata with 100% allocation
on first run in MBM test.
[patch 2] The MBA test result message is always output as "ok",
make output message to be "not ok" if MBA check result is failed.
[patch 3] When a child process is created by fork(), the buffer of the
parent process is also copied. Flush the buffer before executing fork().
[patch 4] Add a signal handler to cleanup properly before exiting the
parent process if there is an error occurs after creating a child process with fork() in the CAT test, and unregister signal handler when each test finished.
[patch 5] Before exiting each test CMT/CAT/MBM/MBA, clear test result
files function cat/cmt/mbm/mba_test_cleanup() are called twice. Delete once.
This patch series is based on Linux v6.2-rc6.
Difference from v5:
[patch 4]
- If an error occurs in signal_handler_register() return -1, and if an error occurs in signal_handler_unregister() does not return any value.
- If signal_handler_register() fails, stop the running parents&child process.
- Ignore the result of signal_handler_unregister() so as not to overwrite earlier value of ret.
- Fix change log.
Shaopeng Tan (5):
selftests/resctrl: Fix set up schemata with 100% allocation on first
run in MBM test
selftests/resctrl: Return MBA check result and make it to output
message
selftests/resctrl: Flush stdout file buffer before executing fork() selftests/resctrl: Cleanup properly when an error occurs in CAT test selftests/resctrl: Remove duplicate codes that clear each test result
file
tools/testing/selftests/resctrl/cat_test.c | 29 ++++---- tools/testing/selftests/resctrl/cmt_test.c | 7 +- tools/testing/selftests/resctrl/fill_buf.c | 14 ---- tools/testing/selftests/resctrl/mba_test.c | 23 +++--- tools/testing/selftests/resctrl/mbm_test.c | 20 +++--- tools/testing/selftests/resctrl/resctrl.h | 2 + .../testing/selftests/resctrl/resctrl_tests.c | 4 -- tools/testing/selftests/resctrl/resctrl_val.c | 71 +++++++++++++------ tools/testing/selftests/resctrl/resctrlfs.c | 5 +- 9 files changed, 98 insertions(+), 77 deletions(-)
Signature · 1 line
2.27.0
PATCH v6 1/5 selftests/resctrl: Fix set up schemata with 100% allocation on first run in MBM test
There is a comment "Set up shemata with 100% allocation on the first run" in function mbm_setup(), but there is an increment bug and the condition "num_of_runs == 0" will never be met and write_schemata() will never be called to set schemata to 100%. Even if write_schemata() is called in MBM test, since it is not supported for MBM test it does not set the schemata. This is currently fine because resctrl_val_parm->mum_resctrlfs is always 1 and umount/mount will be run in each test to set the schemata to 100%.
To support the usage when MBM test does not unmount/remount resctrl filesystem before the test starts, fix to call write_schemata() and set schemata properly when the function is called for the first time.
Also, remove static local variable 'num_of_runs' because this is not needed as there is resctrl_val_param->num_of_runs which should be used instead like in cat_setup().
--- tools/testing/selftests/resctrl/mbm_test.c | 13 +++++++------ tools/testing/selftests/resctrl/resctrlfs.c | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-)
tools/testing/selftests/resctrl/mbm_test.c +7 -6
@@ -89,23 +89,24 @@ static int check_results(int span)static int mbm_setup (int num, ...) {struct resctrl_val_param *p; -static int num_of_runs;va_list param;int ret =0 ; -/* Run NUM_OF_RUNS times */ -if (num_of_runs++ >=NUM_OF_RUNS ) -return -1 ; -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 -1 ; +/* Set up shemata with 100% allocation on the first run. */ -if (num_of_runs ==0 ) +if (p->num_of_runs ==0 ) ret =write_schemata (p->ctrlgrp,"100" , p->cpu_no, p->resctrl_val); + p->num_of_runs++; +return ret; }
tools/testing/selftests/resctrl/resctrlfs.c +3 -1
@@ -498,6 +498,7 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val)FILE *fp;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 ;
@@ -523,7 +524,8 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val)if (!strncmp (resctrl_val,CAT_STR ,sizeof (CAT_STR )) || !strncmp (resctrl_val,CMT_STR ,sizeof (CMT_STR )))sprintf (schema,"%s%d%c%s" ,"L3:" , resource_id,'=' , schemata); -if (!strncmp (resctrl_val,MBA_STR ,sizeof (MBA_STR ))) +if (!strncmp (resctrl_val,MBA_STR ,sizeof (MBA_STR )) || + !strncmp (resctrl_val,MBM_STR ,sizeof (MBM_STR )))sprintf (schema,"%s%d%c%s" ,"MB:" , resource_id,'=' , schemata); fp =fopen (controlgroup,"w" );
Signature · 1 line
2.27.0
PATCH v6 2/5 selftests/resctrl: Return MBA check result and make it to output message
In reply to Shaopeng TanSince MBA check result is not returned, the MBA test result message is always output as "ok" regardless of whether the MBA check result is true or false.
Make output message to be "not ok" if MBA check result is failed.
--- tools/testing/selftests/resctrl/mba_test.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
tools/testing/selftests/resctrl/mba_test.c +8 -8
@@ -51,10 +51,10 @@ static int mba_setup(int num, ...)return 0 ; } -static void show_mba_info (unsigned long *bw_imc,unsigned long *bw_resc) +static bool show_mba_info (unsigned long *bw_imc,unsigned long *bw_resc) {int allocation, runs; -bool failed = false; +bool ret = false;ksft_print_msg ("Results are displayed in (MB)\n" );/* Memory bandwidth from 100% down to 10% */
@@ -90,13 +90,15 @@ static void show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc)ksft_print_msg ("avg_bw_imc: %lu\n" , avg_bw_imc);ksft_print_msg ("avg_bw_resc: %lu\n" , avg_bw_resc);if (avg_diff_per >MAX_DIFF_PERCENT ) - failed = true; + ret = true; }ksft_print_msg ("%s Check schemata change using MBA\n" , - failed ?"Fail:" :"Pass:" ); -if (failed) + ret ?"Fail:" :"Pass:" ); +if (ret)ksft_print_msg ("At least one test failed\n" ); + +return ret; }static int check_results (void )
@@ -132,9 +134,7 @@ static int check_results(void)fclose (fp); -show_mba_info (bw_imc, bw_resc); - -return 0 ; +return show_mba_info (bw_imc, bw_resc); }void mba_test_cleanup (void )
Signature · 1 line
2.27.0
PATCH v6 3/5 selftests/resctrl: Flush stdout file buffer before executing fork()
In reply to Shaopeng TanWhen a process has buffered output, a child process created by fork() will also copy buffered output. When using kselftest framework, the output (resctrl test result message) will be printed multiple times.
Add fflush() to flush out the buffered output before executing fork().
--- tools/testing/selftests/resctrl/cat_test.c | 1 + tools/testing/selftests/resctrl/resctrl_val.c | 1 + tools/testing/selftests/resctrl/resctrlfs.c | 1 + 3 files changed, 3 insertions(+)
tools/testing/selftests/resctrl/cat_test.c +1 -0
@@ -167,6 +167,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)return errno; } +fflush (stdout); bm_pid =fork ();/* Set param values for child thread which will be allocated bitmask
tools/testing/selftests/resctrl/resctrl_val.c +1 -0
@@ -629,6 +629,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)* Fork to start benchmark, save child's pid so that it can be killed * when needed */ +fflush (stdout); bm_pid =fork ();if (bm_pid ==-1 ) {perror ("# Unable to fork" );
tools/testing/selftests/resctrl/resctrlfs.c +1 -0
@@ -678,6 +678,7 @@ int filter_dmesg(void)perror ("pipe" );return ret; } +fflush (stdout); pid =fork ();if (pid ==0 ) {close (pipefds[0 ]);
Signature · 1 line
2.27.0
PATCH v6 4/5 selftests/resctrl: Cleanup properly when an error occurs in CAT test
In reply to Shaopeng TanAfter creating a child process with fork() in CAT test, if an error occurs or a signal such as SIGINT is received, the parent process will be terminated immediately, and therefor the child process will not be killed and also resctrlfs is not unmounted.
There is a signal handler registered in CMT/MBM/MBA tests, which kills child process, unmount resctrlfs, cleanups result files, etc., if a signal such as SIGINT is received.
Commonize the signal handler registered for CMT/MBM/MBA tests and reuse it in CAT too.
To reuse the signal handler, make the child process in CAT wait to be killed by parent process in any case (an error occurred or a signal was received), and when killing child process use global bm_pid instead of local bm_pid.
Also, since the MBA/MBA/CMT/CAT are run in order, unregister the signal handler at the end of each test so that the signal handler cannot be inherited by other tests.
--- tools/testing/selftests/resctrl/cat_test.c | 28 ++++---- tools/testing/selftests/resctrl/fill_buf.c | 14 ---- tools/testing/selftests/resctrl/resctrl.h | 2 + tools/testing/selftests/resctrl/resctrl_val.c | 70 +++++++++++++------ 4 files changed, 68 insertions(+), 46 deletions(-)
tools/testing/selftests/resctrl/cat_test.c +16 -12
@@ -103,7 +103,6 @@ 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;char pipe_message; -pid_t bm_pid; cache_size =0 ;
@@ -181,28 +180,31 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)strcpy (param.filename,RESULT_FILE_NAME1 ); param.num_of_runs =0 ; param.cpu_no = sibling_cpu_no; + }else { + ret =signal_handler_register (); +if (ret) { +kill (bm_pid,SIGKILL ); + goto out; + } }remove (param.filename); ret =cat_val (¶m); -if (ret) -return ret; - - ret =check_results (¶m); -if (ret) -return ret; +if (ret ==0 ) + ret =check_results (¶m);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)) { -close (pipefd[1 ]); +sizeof (pipe_message)) +/* +* Just print the error message. +* Let while(1) run and wait for itself to be killed. +*/ perror ("# failed signaling parent process" ); -return errno; - }close (pipefd[1 ]);while (1 )
@@ -222,9 +224,11 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)kill (bm_pid,SIGKILL ); } +signal_handler_unregister (); +out:cat_test_cleanup ();if (bm_pid)umount_resctrlfs (); -return 0 ; +return ret; }
tools/testing/selftests/resctrl/fill_buf.c +0 -14
@@ -33,14 +33,6 @@ static void sb(void)#endif } -static void ctrl_handler (int signo) -{ -free (startptr); -printf ("\nEnding\n" ); -sb (); -exit (EXIT_SUCCESS ); -} -static void cl_flush (void *p) {#if defined(__i386) || defined(__x86_64)
@@ -198,12 +190,6 @@ int run_fill_buf(unsigned long span, int malloc_and_init_memory,unsigned long long cache_size = span;int ret; -/* set up ctrl-c handler */ -if (signal (SIGINT , ctrl_handler) ==SIG_ERR ) -printf ("Failed to catch SIGINT!\n" ); -if (signal (SIGHUP , ctrl_handler) ==SIG_ERR ) -printf ("Failed to catch SIGHUP!\n" ); - ret =fill_cache (cache_size, malloc_and_init_memory, memflush, op, resctrl_val);if (ret) {
tools/testing/selftests/resctrl/resctrl.h +2 -0
@@ -107,6 +107,8 @@ void mba_test_cleanup(void);int get_cbm_mask (char *cache_type,char *cbm_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 ); +void signal_handler_unregister (void );int cat_val (struct resctrl_val_param *param);void cat_test_cleanup (void );int cat_perf_miss_val (int cpu_no,int no_of_bits,char *cache_type);
tools/testing/selftests/resctrl/resctrl_val.c +50 -20
116 lines not on this page · raw message
Signature · 1 line
2.27.0
Reinette Chatre
maintainerRe: [PATCH v6 4/5] selftests/resctrl: Cleanup properly when an error occurs in CAT test
Hi Shaopeng,
Quoted 12 lines · Shaopeng Tan
After creating a child process with
fork()in CAT test, if an error occurs or a signal such as SIGINT is received, the parent process will be terminated immediately, and therefor the child process will not be killed and also resctrlfs is not unmounted.There is a signal handler registered in CMT/MBM/MBA tests, which kills child process, unmount resctrlfs, cleanups result files, etc., if a signal such as SIGINT is received.
Commonize the signal handler registered for CMT/MBM/MBA tests and reuse it in CAT too.
Quoted 9 lines
To reuse the signal handler, make the child process in CAT wait to be killed by parent process in any case (an error occurred or a signal was received), and when killing child process use global
bm_pidinstead of localbm_pid.Also, since the MBA/MBA/CMT/CAT are run in order, unregister the signal handler at the end of each test so that the signal handler cannot be inherited by other tests.
Great changelog.
...
Quoted 43 lines
tools/testing/selftests/resctrl/cat_test.c +13
-10@@ -181,28 +180,31 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)strcpy (param.filename,RESULT_FILE_NAME1 ); param.num_of_runs =0 ; param.cpu_no = sibling_cpu_no; + }else { + ret =signal_handler_register (); +if (ret) { +kill (bm_pid,SIGKILL ); + goto out; + } }remove (param.filename); ret =cat_val (¶m); -if (ret) -return ret; - - ret =check_results (¶m); -if (ret) -return ret; +if (ret ==0 ) + ret =check_results (¶m);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)) { -close (pipefd[1 ]); +sizeof (pipe_message)) +/* +* Just print the error message. +* Let while(1) run and wait for itself to be killed. +*/ perror ("# failed signaling parent process" ); -return errno; - }close (pipefd[1 ]);while (1 )
tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char *cache_type) · line 227
Quoted 4 lines
tools/testing/selftests/resctrl/cat_test.c +1
-0@@ -222,9 +224,11 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)kill (bm_pid,SIGKILL ); } +signal_handler_unregister ();
I expected the code to be symmetrical but found that the signal handler is registered by parent, but unregistered by both the parent and the child. Could signal_handler_unregister() be moved to the parent portion of the "if" statement above?
...
Quoted 20 lines
tools/testing/selftests/resctrl/resctrl_val.c +14
-0@@ -476,6 +476,45 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr)exit (EXIT_SUCCESS ); } +/* +* Register CTRL-C handler for parent, as it has to kill +* child process before exiting +*/ +int signal_handler_register (void ) +{ +struct sigaction sigact; +int ret =0 ; + + sigact.sa_sigaction = ctrlc_handler; +sigemptyset (&sigact.sa_mask); + sigact.sa_flags =SA_SIGINFO ; + if (sigaction(SIGINT, &sigact, NULL) || + sigaction(SIGTERM, &sigact, NULL) ||
tools/testing/selftests/resctrl/resctrl_val.c void ctrlc_handler(int signum, siginfo_t *info, void *ptr) · line 502
Quoted 10 lines
tools/testing/selftests/resctrl/resctrl_val.c +10
-0+ sigaction(SIGHUP, &sigact, NULL)) { +perror ("# sigaction" ); + ret =-1 ; + } +return ret; +} + +/* +* Reset signal handler to SIG_DFL. +* Non-Vaule return because the caller should keep
Typo in "Non-Vaule"
Quoted 29 lines
tools/testing/selftests/resctrl/resctrl_val.c +15
-7+* the error code of other path even if sigaction fails. +*/ +void signal_handler_unregister (void ) +{ +struct sigaction sigact; + + sigact.sa_handler =SIG_DFL ; +sigemptyset (&sigact.sa_mask); +if (sigaction (SIGINT , &sigact,NULL ) || +sigaction (SIGTERM , &sigact,NULL ) || +sigaction (SIGHUP , &sigact,NULL )) { +perror ("# sigaction" ); + } +} +/* * print_results_bw: the memory bandwidth results are stored in a file * @filename: file that stores the results @@ -671,39 +710,28 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)ksft_print_msg ("Benchmark PID: %d\n" , bm_pid); -/* -* Register CTRL-C handler for parent, as it has to kill benchmark -* before exiting -*/ - sigact.sa_sigaction = ctrlc_handler; -sigemptyset (&sigact.sa_mask); - sigact.sa_flags =SA_SIGINFO ;
tools/testing/selftests/resctrl/resctrl_val.c int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) · line 715
Quoted 10 lines
tools/testing/selftests/resctrl/resctrl_val.c +3
-7-if (sigaction (SIGINT , &sigact,NULL ) || -sigaction (SIGTERM , &sigact,NULL ) || -sigaction (SIGHUP , &sigact,NULL )) { -perror ("# sigaction" ); - ret = errno; - goto out; - } + ret =signal_handler_register (); +if (ret) + goto out1;
Please do not use generic "out1" and "out2" goto labels. Could you please change them to reflect what is done at that exit? You could keep "out" but "out2" could be renamed to "unregister" or something more appropriate.
...
tools/testing/selftests/resctrl/resctrl_val.c int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) · line 797
Quoted 11 lines
tools/testing/selftests/resctrl/resctrl_val.c +3
-1@@ -761,7 +789,9 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) } } -out: +out2: +signal_handler_unregister (); +out1:kill (bm_pid,SIGKILL );umount_resctrlfs ();
Thank you
Reinette
Re: [PATCH v6 4/5] selftests/resctrl: Cleanup properly when an error occurs in CAT test
In reply to Shaopeng TanQuoted 55 lines · Shaopeng Tan
After creating a child process with
fork()in CAT test, if an error occurs or a signal such as SIGINT is received, the parent process will be terminated immediately, and therefor the child process will not be killed and also resctrlfs is not unmounted.There is a signal handler registered in CMT/MBM/MBA tests, which kills child process, unmount resctrlfs, cleanups result files, etc., if a signal such as SIGINT is received.
Commonize the signal handler registered for CMT/MBM/MBA tests and reuse it in CAT too.
To reuse the signal handler, make the child process in CAT wait to be killed by parent process in any case (an error occurred or a signal was received), and when killing child process use global
bm_pidinstead of localbm_pid.Also, since the MBA/MBA/CMT/CAT are run in order, unregister the signal handler at the end of each test so that the signal handler cannot be inherited by other tests.
Signed-off-by Shaopeng Tan <[email protected]>--- tools/testing/selftests/resctrl/cat_test.c | 28 ++++---- tools/testing/selftests/resctrl/fill_buf.c | 14 ---- tools/testing/selftests/resctrl/resctrl.h | 2 + tools/testing/selftests/resctrl/resctrl_val.c | 70 +++++++++++++------ 4 files changed, 68 insertions(+), 46 deletions(-)tools/testing/selftests/resctrl/cat_test.c +6
-1@@ -103,7 +103,6 @@ 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;char pipe_message; -pid_t bm_pid; cache_size =0 ;@@ -181,28 +180,31 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)strcpy (param.filename,RESULT_FILE_NAME1 ); param.num_of_runs =0 ; param.cpu_no = sibling_cpu_no; + }else { + ret =signal_handler_register (); +if (ret) { +kill (bm_pid,SIGKILL ); + goto out; + } }remove (param.filename);
tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char *cache_type) · line 196
Quoted 10 lines
tools/testing/selftests/resctrl/cat_test.c +2
-6ret =cat_val (¶m); -if (ret) -return ret; - - ret =check_results (¶m); -if (ret) -return ret; +if (ret ==0 ) + ret =check_results (¶m);
It would be take this program flow fix out of the signal handler change into a separate change.
Signature · 1 line
i.
RE: [PATCH v6 4/5] selftests/resctrl: Cleanup properly when an error occurs in CAT test
Hi Ilpo,
Quoted 62 lines · Shaopeng Tan
tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char
Quoted 37 lines
After creating a child process with
fork()in CAT test, if an error occurs or a signal such as SIGINT is received, the parent process will be terminated immediately, and therefor the child process will not be killed and also resctrlfs is not unmounted.There is a signal handler registered in CMT/MBM/MBA tests, which kills child process, unmount resctrlfs, cleanups result files, etc., if a signal such as SIGINT is received.
Commonize the signal handler registered for CMT/MBM/MBA tests and reuse it in CAT too.
To reuse the signal handler, make the child process in CAT wait to be killed by parent process in any case (an error occurred or a signal was received), and when killing child process use global
bm_pidinstead of localbm_pid.Also, since the MBA/MBA/CMT/CAT are run in order, unregister the signal handler at the end of each test so that the signal handler cannot be inherited by other tests.
Signed-off-by Shaopeng Tan <[email protected]>--- tools/testing/selftests/resctrl/cat_test.c | 28 ++++---- tools/testing/selftests/resctrl/fill_buf.c | 14 ---- tools/testing/selftests/resctrl/resctrl.h | 2 + tools/testing/selftests/resctrl/resctrl_val.c | 70 +++++++++++++------ 4 files changed, 68 insertions(+), 46 deletions(-)tools/testing/selftests/resctrl/cat_test.c +0
-0@@ -103,7 +103,6 @@ int cat_perf_miss_val(int cpu_no, int n, char
*cache_type)tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char
Quoted 8 lines
tools/testing/selftests/resctrl/cat_test.c +0
-1unsigned long l_mask, l_mask_1;int ret, pipefd[2 ], sibling_cpu_no;char pipe_message; -pid_t bm_pid; cache_size =0 ;@@ -181,28 +180,31 @@ int cat_perf_miss_val(int cpu_no, int n, char
*cache_type)Quoted 13 lines
tools/testing/selftests/resctrl/cat_test.c +6
-0strcpy (param.filename,RESULT_FILE_NAME1 ); param.num_of_runs =0 ; param.cpu_no = sibling_cpu_no; + }else { + ret =signal_handler_register (); +if (ret) { +kill (bm_pid,SIGKILL ); + goto out; + } }remove (param.filename);
Quoted 12 lines
tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char *cache_type) · line 195
Quoted 9 lines
tools/testing/selftests/resctrl/cat_test.c +2
-6ret =cat_val (¶m); -if (ret) -return ret; - - ret =check_results (¶m); -if (ret) -return ret; +if (ret ==0 ) + ret =check_results (¶m);It would be take this program flow fix out of the signal handler change into a separate change.
Do you mean this fix should be separated into two patches?
To make the child process wait to be killed by parent process in any case(an error occurred or a signal was received), I fixed it like this.
This fix was discussed here.
https://lore.kernel.org/lkml/[email protected]/
Best regards,
Shaopeng TAN
RE: [PATCH v6 4/5] selftests/resctrl: Cleanup properly when an error occurs in CAT test
Quoted 39 lines · Shaopeng Tan (Fujitsu)
Quoted 26 lines · Shaopeng Tan
Quoted 24 lines
After creating a child process with
fork()in CAT test, if an error occurs or a signal such as SIGINT is received, the parent process will be terminated immediately, and therefor the child process will not be killed and also resctrlfs is not unmounted.There is a signal handler registered in CMT/MBM/MBA tests, which kills child process, unmount resctrlfs, cleanups result files, etc., if a signal such as SIGINT is received.
Commonize the signal handler registered for CMT/MBM/MBA tests and reuse it in CAT too.
To reuse the signal handler, make the child process in CAT wait to be killed by parent process in any case (an error occurred or a signal was received), and when killing child process use global
bm_pidinstead of localbm_pid.Also, since the MBA/MBA/CMT/CAT are run in order, unregister the signal handler at the end of each test so that the signal handler cannot be inherited by other tests.
Signed-off-by Shaopeng Tan <[email protected]>---
Quoted 12 lines
tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char *cache_type) · line 195
Quoted 9 lines
tools/testing/selftests/resctrl/cat_test.c +2
-6ret =cat_val (¶m); -if (ret) -return ret; - - ret =check_results (¶m); -if (ret) -return ret; +if (ret ==0 ) + ret =check_results (¶m);It would be take this program flow fix out of the signal handler change into a separate change.
Quoted 1 line
Do you mean this fix should be separated into two patches?
Yes.
Currently, I see your patch doing (mainly) two things:
1) cleaning up the messy signal handler logic
2) fixing the early return in case of error from cat_val() or check_results()
Both are good changes and both are needed to fully fix things. But (IMHO) those are indepedent enough that it would warrant to split this change into two.
Signature · 1 line
i.
Quoted 6 lines
To make the child process wait to be killed by parent process in any case(an error occurred or a signal was received), I fixed it like this.
This fix was discussed here.
https://lore.kernel.org/lkml/[email protected]/
RE: [PATCH v6 4/5] selftests/resctrl: Cleanup properly when an error occurs in CAT test
Hi Ilpo,
Quoted 45 lines · Shaopeng Tan (Fujitsu)
Quoted 40 lines
Quoted 27 lines · Shaopeng Tan
Quoted 24 lines
After creating a child process with
fork()in CAT test, if an error occurs or a signal such as SIGINT is received, the parent process will be terminated immediately, and therefor the child process will not be killed and also resctrlfs is not unmounted.There is a signal handler registered in CMT/MBM/MBA tests, which kills child process, unmount resctrlfs, cleanups result files, etc., if a signal such as SIGINT is received.
Commonize the signal handler registered for CMT/MBM/MBA tests and reuse it in CAT too.
To reuse the signal handler, make the child process in CAT wait to be killed by parent process in any case (an error occurred or a signal was received), and when killing child process use global
bm_pidinstead of localbm_pid.Also, since the MBA/MBA/CMT/CAT are run in order, unregister the signal handler at the end of each test so that the signal handler cannot be inherited by other tests.
Signed-off-by Shaopeng Tan <[email protected]>---
Quoted 12 lines
tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char *cache_type) · line 195
Quoted 9 lines
tools/testing/selftests/resctrl/cat_test.c +2
-6ret =cat_val (¶m); -if (ret) -return ret; - - ret =check_results (¶m); -if (ret) -return ret; +if (ret ==0 ) + ret =check_results (¶m);It would be take this program flow fix out of the signal handler change into a separate change.
Quoted 1 line
Do you mean this fix should be separated into two patches?
Yes.
Quoted 7 lines
Currently, I see your patch doing (mainly) two things:
1) cleaning up the messy signal handler logic
2) fixing the early return in case of error fromcat_val()orcheck_results()Both are good changes and both are needed to fully fix things. But (IMHO) those are indepedent enough that it would warrant to split this change into two.
Thanks for your advice, I will split it in next version
Best regards,
Shaopeng TAN
Re: [PATCH v6 4/5] selftests/resctrl: Cleanup properly when an error occurs in CAT test
In reply to Shaopeng TanQuoted 27 lines · Shaopeng Tan
After creating a child process with
fork()in CAT test, if an error occurs or a signal such as SIGINT is received, the parent process will be terminated immediately, and therefor the child process will not be killed and also resctrlfs is not unmounted.There is a signal handler registered in CMT/MBM/MBA tests, which kills child process, unmount resctrlfs, cleanups result files, etc., if a signal such as SIGINT is received.
Commonize the signal handler registered for CMT/MBM/MBA tests and reuse it in CAT too.
To reuse the signal handler, make the child process in CAT wait to be killed by parent process in any case (an error occurred or a signal was received), and when killing child process use global
bm_pidinstead of localbm_pid.Also, since the MBA/MBA/CMT/CAT are run in order, unregister the signal handler at the end of each test so that the signal handler cannot be inherited by other tests.
Signed-off-by Shaopeng Tan <[email protected]>---
tools/testing/selftests/resctrl/cat_test.c +0
-0if (bm_pid ==0 ) {/* Tell parent that child is ready */ close (pipefd[0 ]);
tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char *cache_type) · line 207
Quoted 10 lines
tools/testing/selftests/resctrl/cat_test.c +5
-2pipe_message =1 ;if (write (pipefd[1 ], &pipe_message,sizeof (pipe_message)) < -sizeof (pipe_message)) { -close (pipefd[1 ]); +sizeof (pipe_message)) +/* +* Just print the error message. +* Let while(1) run and wait for itself to be killed. +*/ perror ("# failed signaling parent process" );
If the write error is ignored here, won't it just lead to parent hanging forever waiting for the child to send the message through the pipe which will never come?
Signature · 1 line
i.
RE: [PATCH v6 4/5] selftests/resctrl: Cleanup properly when an error occurs in CAT test
Hi Ilpo,
Quoted 35 lines · Shaopeng Tan
Quoted 34 lines
After creating a child process with
fork()in CAT test, if an error occurs or a signal such as SIGINT is received, the parent process will be terminated immediately, and therefor the child process will not be killed and also resctrlfs is not unmounted.There is a signal handler registered in CMT/MBM/MBA tests, which kills child process, unmount resctrlfs, cleanups result files, etc., if a signal such as SIGINT is received.
Commonize the signal handler registered for CMT/MBM/MBA tests and reuse it in CAT too.
To reuse the signal handler, make the child process in CAT wait to be killed by parent process in any case (an error occurred or a signal was received), and when killing child process use global
bm_pidinstead of localbm_pid.Also, since the MBA/MBA/CMT/CAT are run in order, unregister the signal handler at the end of each test so that the signal handler cannot be inherited by other tests.
Signed-off-by Shaopeng Tan <[email protected]>---
tools/testing/selftests/resctrl/cat_test.c +2
-2if (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)) { -close (pipefd[1 ]); +sizeof (pipe_message)) +/*
Quoted 8 lines
tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char *cache_type) · line 207
Quoted 4 lines
tools/testing/selftests/resctrl/cat_test.c +3
-0+* Just print the error message. +* Let while(1) run and wait for itself to be killed. +*/ perror ("# failed signaling parent process" );If the write error is ignored here, won't it just lead to parent hanging forever waiting for the child to send the message through the pipe which will never come?
If the write error is ignored here, the pipe will be closed by "close(pipefd[1]);" and child process will wait to be killed by "while(1)".
---
- return errno;
- }
close(pipefd[1]);
while (1)
---
If all file descriptors referring to the write end of a pipe have been closed, then an attempt to read(2) from the pipe will see end-of-file (read(2) will return 0). Then, "perror("# failed reading from child process");" occurs.
---
} 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)) {
perror("# failed reading from child process");
break;
}
}
close(pipefd[0]);
kill(bm_pid, SIGKILL);
signal_handler_unregister();
}---
Best regards,
Shaopeng TAN
RE: [PATCH v6 4/5] selftests/resctrl: Cleanup properly when an error occurs in CAT test
Quoted 57 lines · Shaopeng Tan (Fujitsu)
Quoted 35 lines · Shaopeng Tan
Quoted 34 lines
After creating a child process with
fork()in CAT test, if an error occurs or a signal such as SIGINT is received, the parent process will be terminated immediately, and therefor the child process will not be killed and also resctrlfs is not unmounted.There is a signal handler registered in CMT/MBM/MBA tests, which kills child process, unmount resctrlfs, cleanups result files, etc., if a signal such as SIGINT is received.
Commonize the signal handler registered for CMT/MBM/MBA tests and reuse it in CAT too.
To reuse the signal handler, make the child process in CAT wait to be killed by parent process in any case (an error occurred or a signal was received), and when killing child process use global
bm_pidinstead of localbm_pid.Also, since the MBA/MBA/CMT/CAT are run in order, unregister the signal handler at the end of each test so that the signal handler cannot be inherited by other tests.
Signed-off-by Shaopeng Tan <[email protected]>---
tools/testing/selftests/resctrl/cat_test.c +2
-2if (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)) { -close (pipefd[1 ]); +sizeof (pipe_message)) +/* Quoted 8 lines
tools/testing/selftests/resctrl/cat_test.c int cat_perf_miss_val(int cpu_no, int n, char *cache_type) · line 207
Quoted 4 lines
tools/testing/selftests/resctrl/cat_test.c +3
-0+* Just print the error message. +* Let while(1) run and wait for itself to be killed. +*/ perror ("# failed signaling parent process" );If the write error is ignored here, won't it just lead to parent hanging forever waiting for the child to send the message through the pipe which will never come?
If the write error is ignored here, the pipe will be closed by "
close(pipefd[1]);" and child process will wait to be killed by "while(1)".
---tools/testing/selftests/resctrl/cat_test.c +0
-3-return errno; - }close (pipefd[1 ]);while (1 ) ---If all file descriptors referring to the write end of a pipe have been closed, then an attempt to read(2) from the pipe will see end-of-file (read(2) will return 0). Then, "
perror("# failed reading from child process");" occurs.
---
Quoted 15 lines
} 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)) {
perror("# failed reading from child process");
break;
}
}
close(pipefd[0]);
kill(bm_pid, SIGKILL);
signal_handler_unregister();
}Ah, indeed read() will pick up the close event. So your code seem fine after all.
Signature · 1 line
i.
PATCH v6 5/5 selftests/resctrl: Remove duplicate codes that clear each test result file
In reply to Shaopeng TanBefore exiting each test function(run_cmt/cat/mbm/mba_test()), test results("ok","not ok") are printed by ksft_test_result() and then temporary result files are cleaned by function cmt/cat/mbm/mba_test_cleanup().
However, before running ksft_test_result(),
function cmt/cat/mbm/mba_test_cleanup()
has been run in each test function as follows:
cmt_resctrl_val()
cat_perf_miss_val()
mba_schemata_change()
mbm_bw_change()
Remove duplicate codes that clear each test result file, while ensuring cleanup properly even when errors occur in each test.
--- tools/testing/selftests/resctrl/cmt_test.c | 7 +++---- tools/testing/selftests/resctrl/mba_test.c | 7 +++---- tools/testing/selftests/resctrl/mbm_test.c | 7 +++---- tools/testing/selftests/resctrl/resctrl_tests.c | 4 ---- 4 files changed, 9 insertions(+), 16 deletions(-)
tools/testing/selftests/resctrl/cmt_test.c +3 -4
@@ -133,13 +133,12 @@ int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd) ret =resctrl_val (benchmark_cmd, ¶m);if (ret) -return ret; + goto out; ret =check_results (¶m, n); -if (ret) -return ret; +out:cmt_test_cleanup (); -return 0 ; +return ret; }
tools/testing/selftests/resctrl/mba_test.c +3 -4
@@ -160,13 +160,12 @@ int mba_schemata_change(int cpu_no, char *bw_report, char **benchmark_cmd) ret =resctrl_val (benchmark_cmd, ¶m);if (ret) -return ret; + goto out; ret =check_results (); -if (ret) -return ret; +out:mba_test_cleanup (); -return 0 ; +return ret; }
tools/testing/selftests/resctrl/mbm_test.c +3 -4
@@ -134,13 +134,12 @@ int mbm_bw_change(int span, int cpu_no, char *bw_report, char **benchmark_cmd) ret =resctrl_val (benchmark_cmd, ¶m);if (ret) -return ret; + goto out; ret =check_results (span); -if (ret) -return ret; +out:mbm_test_cleanup (); -return 0 ; +return ret; }
tools/testing/selftests/resctrl/resctrl_tests.c +0 -4
@@ -88,7 +88,6 @@ static void run_mbm_test(bool has_ben, char **benchmark_cmd, int span,ksft_test_result (!res,"MBM: bw change\n" );if ((get_vendor () ==ARCH_INTEL ) && res)ksft_print_msg ("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n" ); -mbm_test_cleanup (); } static void run_mba_test(bool has_ben, char **benchmark_cmd, int span,
@@ -107,7 +106,6 @@ static void run_mba_test(bool has_ben, char **benchmark_cmd, int span,sprintf (benchmark_cmd[1 ],"%d" , span); res =mba_schemata_change (cpu_no, bw_report, benchmark_cmd);ksft_test_result (!res,"MBA: schemata change\n" ); -mba_test_cleanup (); }static void run_cmt_test (bool has_ben,char **benchmark_cmd,int cpu_no)
@@ -126,7 +124,6 @@ static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no)ksft_test_result (!res,"CMT: test\n" );if ((get_vendor () ==ARCH_INTEL ) && res)ksft_print_msg ("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n" ); -cmt_test_cleanup (); }static void run_cat_test (int cpu_no,int no_of_bits)
@@ -142,7 +139,6 @@ static void run_cat_test(int cpu_no, int no_of_bits) res =cat_perf_miss_val (cpu_no, no_of_bits,"L3" );ksft_test_result (!res,"CAT: test\n" ); -cat_test_cleanup (); }int main (int argc,char **argv)
Signature · 1 line
2.27.0