Skip to contentSkip to conversation

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

PATCH Superseded Athira Rajeev 2 participants 3 messages Apr 6, 2022 – Apr 7, 2022 Kselftest

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 by adding CPU_FREE after its usage is done.

---
 tools/testing/selftests/mqueue/mq_perf_tests.c | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/mqueue/mq_perf_tests.c +1 -0
index b019e0b8221c..17c41f216bef 100644
@@ -732,6 +732,7 @@ int main(int argc, char *argv[])
 		pthread_attr_destroy(&thread_attr);
 	}
 
+	CPU_FREE(cpu_set);
 	if (!continuous_mode) {
 		pthread_join(cpu_threads[0], &retval);
 		shutdown((long)retval, "perf_test_thread()", __LINE__);
Signature · 1 line
2.35.1
maintainer
#1 lore raw
Quoted 6 lines · Athira Rajeev

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 by adding CPU_FREE after its usage is done.

Good find.

Quoted 11 lines
---
  tools/testing/selftests/mqueue/mq_perf_tests.c | 1 +
  1 file changed, 1 insertion(+)
tools/testing/selftests/mqueue/mq_perf_tests.c +0 -0
index b019e0b8221c..17c41f216bef 100644

tools/testing/selftests/mqueue/mq_perf_tests.c int main(int argc, char *argv[]) · line 738

Quoted 7 lines
tools/testing/selftests/mqueue/mq_perf_tests.c +1 -0
@@ -732,6 +732,7 @@ int main(int argc, char *argv[])
  		pthread_attr_destroy(&thread_attr);
  	}
 
+	CPU_FREE(cpu_set);
  	if (!continuous_mode) {
  		pthread_join(cpu_threads[0], &retval);
  		shutdown((long)retval, "perf_test_thread()", __LINE__);

CPU_ALLOC() is called very early on in main() and there are a few error paths that exit without calling CPU_FREE. This change doesn't fully fix the problem.

Review the other exit paths where CPU_FREE is needed.

thanks,
-- Shuah

#2 lore raw
Quoted 33 lines · Shuah Khan
Quoted 5 lines · Athira Rajeev

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 by adding CPU_FREE after its usage is done.

Good find.

Quoted 9 lines
---
 tools/testing/selftests/mqueue/mq_perf_tests.c | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/mqueue/mq_perf_tests.c +0 -0
index b019e0b8221c..17c41f216bef 100644

tools/testing/selftests/mqueue/mq_perf_tests.c int main(int argc, char *argv[]) · line 737

Quoted 6 lines
tools/testing/selftests/mqueue/mq_perf_tests.c +0 -0
@@ -732,6 +732,7 @@ int main(int argc, char *argv[])
 		pthread_attr_destroy(&thread_attr);
 	}
 +	CPU_FREE(cpu_set);
 	if (!continuous_mode) {
 		pthread_join(cpu_threads[0], &retval);
 		shutdown((long)retval, "perf_test_thread()", __LINE__);

CPU_ALLOC() is called very early on in main() and there are a few error paths that exit without calling CPU_FREE. This change doesn't fully fix the problem.

Quoted 1 line

Review the other exit paths where CPU_FREE is needed.

Sure, Thanks for the review.
I will check and post a V2

thanks
Athira

Quoted 3 lines

thanks,
-- Shuah