提交 ce64763c 编写于 作者: A Athira Rajeev 提交者: Shuah Khan

testing/selftests/mqueue: Fix mq_perf_tests to free the allocated cpu set

The selftest "mqueue/mq_perf_tests.c" use CPU_ALLOC to allocate
CPU set. This cpu set is used further in pthread_attr_setaffinity_np
and by pthread_create in the code. But in current code, allocated
cpu set is not freed.

Fix this issue by adding CPU_FREE in the "shutdown" function which
is called in most of the error/exit path for the cleanup. There are
few error paths which exit without using shutdown. Add a common goto
error path with CPU_FREE for these cases.

Fixes: 7820b071 ("tools/selftests: add mq_perf_tests")
Signed-off-by: NAthira Rajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: NShuah Khan <skhan@linuxfoundation.org>
上级 79ee8aa3
...@@ -180,6 +180,9 @@ void shutdown(int exit_val, char *err_cause, int line_no) ...@@ -180,6 +180,9 @@ void shutdown(int exit_val, char *err_cause, int line_no)
if (in_shutdown++) if (in_shutdown++)
return; return;
/* Free the cpu_set allocated using CPU_ALLOC in main function */
CPU_FREE(cpu_set);
for (i = 0; i < num_cpus_to_pin; i++) for (i = 0; i < num_cpus_to_pin; i++)
if (cpu_threads[i]) { if (cpu_threads[i]) {
pthread_kill(cpu_threads[i], SIGUSR1); pthread_kill(cpu_threads[i], SIGUSR1);
...@@ -551,6 +554,12 @@ int main(int argc, char *argv[]) ...@@ -551,6 +554,12 @@ int main(int argc, char *argv[])
perror("sysconf(_SC_NPROCESSORS_ONLN)"); perror("sysconf(_SC_NPROCESSORS_ONLN)");
exit(1); exit(1);
} }
if (getuid() != 0)
ksft_exit_skip("Not running as root, but almost all tests "
"require root in order to modify\nsystem settings. "
"Exiting.\n");
cpus_online = min(MAX_CPUS, sysconf(_SC_NPROCESSORS_ONLN)); cpus_online = min(MAX_CPUS, sysconf(_SC_NPROCESSORS_ONLN));
cpu_set = CPU_ALLOC(cpus_online); cpu_set = CPU_ALLOC(cpus_online);
if (cpu_set == NULL) { if (cpu_set == NULL) {
...@@ -589,7 +598,7 @@ int main(int argc, char *argv[]) ...@@ -589,7 +598,7 @@ int main(int argc, char *argv[])
cpu_set)) { cpu_set)) {
fprintf(stderr, "Any given CPU may " fprintf(stderr, "Any given CPU may "
"only be given once.\n"); "only be given once.\n");
exit(1); goto err_code;
} else } else
CPU_SET_S(cpus_to_pin[cpu], CPU_SET_S(cpus_to_pin[cpu],
cpu_set_size, cpu_set); cpu_set_size, cpu_set);
...@@ -607,7 +616,7 @@ int main(int argc, char *argv[]) ...@@ -607,7 +616,7 @@ int main(int argc, char *argv[])
queue_path = malloc(strlen(option) + 2); queue_path = malloc(strlen(option) + 2);
if (!queue_path) { if (!queue_path) {
perror("malloc()"); perror("malloc()");
exit(1); goto err_code;
} }
queue_path[0] = '/'; queue_path[0] = '/';
queue_path[1] = 0; queue_path[1] = 0;
...@@ -622,17 +631,12 @@ int main(int argc, char *argv[]) ...@@ -622,17 +631,12 @@ int main(int argc, char *argv[])
fprintf(stderr, "Must pass at least one CPU to continuous " fprintf(stderr, "Must pass at least one CPU to continuous "
"mode.\n"); "mode.\n");
poptPrintUsage(popt_context, stderr, 0); poptPrintUsage(popt_context, stderr, 0);
exit(1); goto err_code;
} else if (!continuous_mode) { } else if (!continuous_mode) {
num_cpus_to_pin = 1; num_cpus_to_pin = 1;
cpus_to_pin[0] = cpus_online - 1; cpus_to_pin[0] = cpus_online - 1;
} }
if (getuid() != 0)
ksft_exit_skip("Not running as root, but almost all tests "
"require root in order to modify\nsystem settings. "
"Exiting.\n");
max_msgs = fopen(MAX_MSGS, "r+"); max_msgs = fopen(MAX_MSGS, "r+");
max_msgsize = fopen(MAX_MSGSIZE, "r+"); max_msgsize = fopen(MAX_MSGSIZE, "r+");
if (!max_msgs) if (!max_msgs)
...@@ -740,4 +744,9 @@ int main(int argc, char *argv[]) ...@@ -740,4 +744,9 @@ int main(int argc, char *argv[])
sleep(1); sleep(1);
} }
shutdown(0, "", 0); shutdown(0, "", 0);
err_code:
CPU_FREE(cpu_set);
exit(1);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册