Skip to content

Commit e648723

Browse files
maciejwieczorretmanshuahkh
authored andcommitted
selftests/resctrl: Simplify cleanup in ctrl-c handler
Ctrl-c handler isn't aware of what test is currently running. Because of that it executes all cleanups even if they aren't necessary. Since the ctrl-c handler uses the sa_sigaction system no parameters can be passed to it as function arguments. Add a global variable to make ctrl-c handler aware of the currently run test and only execute the correct cleanup callback. Signed-off-by: Maciej Wieczor-Retman <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 8780bc8 commit e648723

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ int resctrl_val(const struct resctrl_test *test,
158158
const struct user_params *uparams,
159159
const char * const *benchmark_cmd,
160160
struct resctrl_val_param *param);
161-
void tests_cleanup(void);
162161
void mbm_test_cleanup(void);
163162
void mba_test_cleanup(void);
164163
unsigned long create_bit_mask(unsigned int start, unsigned int len);
@@ -168,7 +167,7 @@ int get_mask_no_shareable(const char *cache_type, unsigned long *mask);
168167
int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size);
169168
int resource_info_unsigned_get(const char *resource, const char *filename, unsigned int *val);
170169
void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
171-
int signal_handler_register(void);
170+
int signal_handler_register(const struct resctrl_test *test);
172171
void signal_handler_unregister(void);
173172
void cat_test_cleanup(void);
174173
unsigned int count_bits(unsigned long n);

tools/testing/selftests/resctrl/resctrl_tests.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,11 @@ static void cmd_help(void)
8181
printf("\t-h: help\n");
8282
}
8383

84-
void tests_cleanup(void)
85-
{
86-
mbm_test_cleanup();
87-
mba_test_cleanup();
88-
cmt_test_cleanup();
89-
cat_test_cleanup();
90-
}
91-
92-
static int test_prepare(void)
84+
static int test_prepare(const struct resctrl_test *test)
9385
{
9486
int res;
9587

96-
res = signal_handler_register();
88+
res = signal_handler_register(test);
9789
if (res) {
9890
ksft_print_msg("Failed to register signal handler\n");
9991
return res;
@@ -136,7 +128,7 @@ static void run_single_test(const struct resctrl_test *test, const struct user_p
136128

137129
ksft_print_msg("Starting %s test ...\n", test->name);
138130

139-
if (test_prepare()) {
131+
if (test_prepare(test)) {
140132
ksft_exit_fail_msg("Abnormal failure when preparing for the test\n");
141133
return;
142134
}

tools/testing/selftests/resctrl/resctrl_val.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct imc_counter_config {
6262
static char mbm_total_path[1024];
6363
static int imcs;
6464
static struct imc_counter_config imc_counters_config[MAX_IMCS][2];
65+
static const struct resctrl_test *current_test;
6566

6667
void membw_initialize_perf_event_attr(int i, int j)
6768
{
@@ -472,7 +473,8 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr)
472473
if (bm_pid)
473474
kill(bm_pid, SIGKILL);
474475
umount_resctrlfs();
475-
tests_cleanup();
476+
if (current_test && current_test->cleanup)
477+
current_test->cleanup();
476478
ksft_print_msg("Ending\n\n");
477479

478480
exit(EXIT_SUCCESS);
@@ -482,13 +484,14 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr)
482484
* Register CTRL-C handler for parent, as it has to kill
483485
* child process before exiting.
484486
*/
485-
int signal_handler_register(void)
487+
int signal_handler_register(const struct resctrl_test *test)
486488
{
487489
struct sigaction sigact = {};
488490
int ret = 0;
489491

490492
bm_pid = 0;
491493

494+
current_test = test;
492495
sigact.sa_sigaction = ctrlc_handler;
493496
sigemptyset(&sigact.sa_mask);
494497
sigact.sa_flags = SA_SIGINFO;
@@ -510,6 +513,7 @@ void signal_handler_unregister(void)
510513
{
511514
struct sigaction sigact = {};
512515

516+
current_test = NULL;
513517
sigact.sa_handler = SIG_DFL;
514518
sigemptyset(&sigact.sa_mask);
515519
if (sigaction(SIGINT, &sigact, NULL) ||

0 commit comments

Comments
 (0)