diff mbox series

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

Message ID 20220406175715.87937-1-atrajeev@linux.vnet.ibm.com (mailing list archive)
State Superseded
Headers show
Series testing/selftests/mqueue: Fix mq_perf_tests to free the allocated cpu set | expand

Commit Message

Athira Rajeev April 6, 2022, 5:57 p.m. UTC
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.

Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
---
 tools/testing/selftests/mqueue/mq_perf_tests.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Shuah Khan April 6, 2022, 8:05 p.m. UTC | #1
On 4/6/22 11:57 AM, Athira Rajeev wrote:
> 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.

> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
> ---
>   tools/testing/selftests/mqueue/mq_perf_tests.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/tools/testing/selftests/mqueue/mq_perf_tests.c b/tools/testing/selftests/mqueue/mq_perf_tests.c
> index b019e0b8221c..17c41f216bef 100644
> --- a/tools/testing/selftests/mqueue/mq_perf_tests.c
> +++ b/tools/testing/selftests/mqueue/mq_perf_tests.c
> @@ -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
Athira Rajeev April 7, 2022, 4:30 a.m. UTC | #2
> On 07-Apr-2022, at 1:35 AM, Shuah Khan <skhan@linuxfoundation.org> wrote:
> 
> On 4/6/22 11:57 AM, Athira Rajeev wrote:
>> 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.
> 
>> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
>> ---
>>  tools/testing/selftests/mqueue/mq_perf_tests.c | 1 +
>>  1 file changed, 1 insertion(+)
>> diff --git a/tools/testing/selftests/mqueue/mq_perf_tests.c b/tools/testing/selftests/mqueue/mq_perf_tests.c
>> index b019e0b8221c..17c41f216bef 100644
>> --- a/tools/testing/selftests/mqueue/mq_perf_tests.c
>> +++ b/tools/testing/selftests/mqueue/mq_perf_tests.c
>> @@ -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.
Sure, Thanks for the review.
I will check and post a V2

thanks
Athira
> 
> thanks,
> -- Shuah
diff mbox series

Patch

diff --git a/tools/testing/selftests/mqueue/mq_perf_tests.c b/tools/testing/selftests/mqueue/mq_perf_tests.c
index b019e0b8221c..17c41f216bef 100644
--- a/tools/testing/selftests/mqueue/mq_perf_tests.c
+++ b/tools/testing/selftests/mqueue/mq_perf_tests.c
@@ -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__);