Skip to content

Commit b0bd742

Browse files
ij-intelshuahkh
authored andcommitted
selftests/resctrl: Cleanup bm_pid and ppid usage & limit scope
'bm_pid' and 'ppid' are global variables. As they are used by different processes and in signal handler, they cannot be entirely converted into local variables. The scope of those variables can still be reduced into resctrl_val.c only. As PARENT_EXIT() macro is using 'ppid', make it a function in resctrl_val.c and pass ppid to it as an argument because it is easier to understand than using the global variable directly. Pass 'bm_pid' into measure_vals() instead of relying on the global variable which helps to make the call signatures of measure_vals() and measure_llc_resctrl() more similar to each other. Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Tested-by: Babu Moger <babu.moger@amd.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 8245a70 commit b0bd742

2 files changed

Lines changed: 15 additions & 17 deletions

File tree

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@
4343

4444
#define DEFAULT_SPAN (250 * MB)
4545

46-
#define PARENT_EXIT() \
47-
do { \
48-
kill(ppid, SIGKILL); \
49-
umount_resctrlfs(); \
50-
exit(EXIT_FAILURE); \
51-
} while (0)
52-
5346
/*
5447
* user_params: User supplied parameters
5548
* @cpu: CPU number to which the benchmark will be bound to
@@ -127,8 +120,6 @@ struct perf_event_read {
127120
*/
128121
extern volatile int *value_sink;
129122

130-
extern pid_t bm_pid, ppid;
131-
132123
extern char llc_occup_path[1024];
133124

134125
int get_vendor(void);

tools/testing/selftests/resctrl/resctrl_val.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ static int get_mem_bw_resctrl(FILE *fp, unsigned long *mbm_total)
499499
return 0;
500500
}
501501

502-
pid_t bm_pid, ppid;
502+
static pid_t bm_pid, ppid;
503503

504504
void ctrlc_handler(int signum, siginfo_t *info, void *ptr)
505505
{
@@ -557,6 +557,13 @@ void signal_handler_unregister(void)
557557
}
558558
}
559559

560+
static void parent_exit(pid_t ppid)
561+
{
562+
kill(ppid, SIGKILL);
563+
umount_resctrlfs();
564+
exit(EXIT_FAILURE);
565+
}
566+
560567
/*
561568
* print_results_bw: the memory bandwidth results are stored in a file
562569
* @filename: file that stores the results
@@ -631,7 +638,7 @@ static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp,
631638
* 1 sec to measure the data.
632639
*/
633640
static int measure_vals(const struct user_params *uparams,
634-
struct resctrl_val_param *param)
641+
struct resctrl_val_param *param, pid_t bm_pid)
635642
{
636643
unsigned long bw_resc, bw_resc_start, bw_resc_end;
637644
FILE *mem_bw_fp;
@@ -700,7 +707,7 @@ static void run_benchmark(int signum, siginfo_t *info, void *ucontext)
700707
fp = freopen("/dev/null", "w", stdout);
701708
if (!fp) {
702709
ksft_perror("Unable to direct benchmark status to /dev/null");
703-
PARENT_EXIT();
710+
parent_exit(ppid);
704711
}
705712

706713
if (strcmp(benchmark_cmd[0], "fill_buf") == 0) {
@@ -714,7 +721,7 @@ static void run_benchmark(int signum, siginfo_t *info, void *ucontext)
714721
once = false;
715722
} else {
716723
ksft_print_msg("Invalid once parameter\n");
717-
PARENT_EXIT();
724+
parent_exit(ppid);
718725
}
719726

720727
if (run_fill_buf(span, memflush, operation, once))
@@ -728,7 +735,7 @@ static void run_benchmark(int signum, siginfo_t *info, void *ucontext)
728735

729736
fclose(stdout);
730737
ksft_print_msg("Unable to run specified benchmark\n");
731-
PARENT_EXIT();
738+
parent_exit(ppid);
732739
}
733740

734741
/*
@@ -807,7 +814,7 @@ int resctrl_val(const struct resctrl_test *test,
807814
/* Register for "SIGUSR1" signal from parent */
808815
if (sigaction(SIGUSR1, &sigact, NULL)) {
809816
ksft_perror("Can't register child for signal");
810-
PARENT_EXIT();
817+
parent_exit(ppid);
811818
}
812819

813820
/* Tell parent that child is ready */
@@ -825,7 +832,7 @@ int resctrl_val(const struct resctrl_test *test,
825832
sigsuspend(&sigact.sa_mask);
826833

827834
ksft_perror("Child is done");
828-
PARENT_EXIT();
835+
parent_exit(ppid);
829836
}
830837

831838
ksft_print_msg("Benchmark PID: %d\n", (int)bm_pid);
@@ -895,7 +902,7 @@ int resctrl_val(const struct resctrl_test *test,
895902

896903
if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) ||
897904
!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) {
898-
ret = measure_vals(uparams, param);
905+
ret = measure_vals(uparams, param, bm_pid);
899906
if (ret)
900907
break;
901908
} else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) {

0 commit comments

Comments
 (0)