lapi: Add TEMP_FAILURE_RETRY definition
PATCH 1/6 lapi: Add TEMP_FAILURE_RETRY definition
and use it in realtime to fix pi-tests.
This fixes build failure on libc missing it (e.g. musl, bionic):
test-skeleton.c:112:12: warning: implicit declaration of function ‘TEMP_FAILURE_RETRY’ [-Wimplicit-function-declaration]
termpid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0));
^~~~~~~~~~~~~~~~~~make[5]: *** [<builtin>: testpi-6] Error 1
--- include/lapi/unistd.h | 18 ++++++++++++++++++ .../realtime/func/pi-tests/test-skeleton.c | 1 + 2 files changed, 19 insertions(+) create mode 100644 include/lapi/unistd.h
include/lapi/unistd.h new file +18 -0
@@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2017 Petr Vorel <[email protected]> +*/ +#ifndef LAPI_UNISTD_H__ +#define LAPI_UNISTD_H__ + +/* glibc unistd.h */ +#ifndef TEMP_FAILURE_RETRY +# define TEMP_FAILURE_RETRY (expression) \ + (__extension__ \ + ({ long int __result; \ + do __result = (long int) (expression); \ + while (__result == -1L && errno == EINTR); \ + __result; })) +#endif + +#endif /* LAPI_UNISTD_H__ */
testcases/realtime/func/pi-tests/test-skeleton.c +1 -0
@@ -42,6 +42,7 @@#include <sys/wait.h> #include <time.h> #include <librttest.h> +#include "lapi/unistd.h" void usage (void ) {
Signature · 1 line
2.19.1
PATCH 2/6 realtime: Fix pthread_mutexattr_{g, s}etrobust_np detection
This fixes build failure on libc which does not have it (e.g. musl), see bellow.
Also remove _GNU_SOURCE from PTHREAD_PRIO_INHERIT check as is not needed (it requires _XOPEN_SOURCE=500 definition => POSIX 1995).
sbrk_mutex.c:112:6: warning: implicit declaration of function ‘pthread_mutexattr_setrobust_np’; did you mean ‘pthread_mutexattr_setrobust’? [-Wimplicit-function-declaration]
if (pthread_mutexattr_setrobust_np(&mutexattr, PTHREAD_MUTEX_ROBUST_NP)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pthread_mutexattr_setrobust
sbrk_mutex.c:112:49: error: ‘PTHREAD_MUTEX_ROBUST_NP’ undeclared (first use in this function); did you mean ‘PTHREAD_MUTEX_ROBUST’?
if (pthread_mutexattr_setrobust_np(&mutexattr, PTHREAD_MUTEX_ROBUST_NP)
^~~~~~~~~~~~~~~~~~~~~~~
PTHREAD_MUTEX_ROBUST
sbrk_mutex.c:112:49: note: each undeclared identifier is reported only once for each function it appears in
sbrk_mutex.c:116:6: warning: implicit declaration of function ‘pthread_mutexattr_getrobust_np’; did you mean ‘pthread_mutexattr_getrobust’? [-Wimplicit-function-declaration]
if (pthread_mutexattr_getrobust_np(&mutexattr, &robust) != 0) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pthread_mutexattr_getrobusttestpi-6.c:78:9: error: ‘PTHREAD_MUTEX_ROBUST_NP’ undeclared (first use in this function); did you mean ‘PTHREAD_MUTEX_ROBUST’?
PTHREAD_MUTEX_ROBUST_NP) != 0)
^~~~~~~~~~~~~~~~~~~~~~~
PTHREAD_MUTEX_ROBUST
testpi-6.c:78:9: note: each undeclared identifier is reported only once for each function it appears in
testpi-6.c:81:6: warning: implicit declaration of function ‘pthread_mutexattr_getrobust_np’; did you mean ‘pthread_mutexattr_getrobust’? [-Wimplicit-function-declaration]
if (pthread_mutexattr_getrobust_np(&mutexattr, &robust) != 0)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pthread_mutexattr_getrobust--- testcases/realtime/m4/check.m4 | 36 ++++------------------------------ 1 file changed, 4 insertions(+), 32 deletions(-)
testcases/realtime/m4/check.m4 +4 -32
@@ -1,9 +1,6 @@ AC_DEFUN([REALTIME_CHECK_PRIO_INHERIT],[ AC_MSG_CHECKING([for PTHREAD_PRIO_INHERIT]) AC_TRY_COMPILE([ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif #include <pthread.h>],[int main(void) { pthread_mutexattr_t attr; return pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
@@ -17,35 +14,10 @@ fi ]) AC_DEFUN([REALTIME_CHECK_ROBUST_APIS],[ -AC_MSG_CHECKING([for pthread_mutexattr_*robust* APIs]) -AC_TRY_COMPILE([ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif -#include <pthread.h>],[int main(void) { - pthread_mutexattr_t attr; - return pthread_mutexattr_setrobust_np(&attr, 0); -}],[has_robust="yes"]) -if test "x$has_robust" = "xyes" ; then - AC_DEFINE(HAS_PTHREAD_MUTEXTATTR_ROBUST_APIS,1,[Define to 1 if you have pthread_mutexattr_*robust* APIs]) - AC_MSG_RESULT(yes) -else - AC_MSG_RESULT(no) -fi -]) - -AC_DEFUN([REALTIME_CHECK_ROBUST_APIS],[ -AC_MSG_CHECKING([for pthread_mutexattr_*robust* APIs]) -AC_TRY_COMPILE([ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif -#include <pthread.h>],[int main(void) { - pthread_mutexattr_t attr; - return pthread_mutexattr_setrobust_np(&attr, 0); -}],[has_robust="yes"]) -if test "x$has_robust" = "xyes" ; then - AC_DEFINE(HAS_PTHREAD_MUTEXTATTR_ROBUST_APIS,1,[Define to 1 if you have pthread_mutexattr_*robust* APIs]) + AC_CHECK_DECLS([pthread_mutexattr_getrobust_np, pthread_mutexattr_setrobust_np],[],[has_robust="no"],[[#define _GNU_SOURCE +#include <pthread.h>]]) + AC_MSG_CHECKING([for pthread_mutexattr_*robust* APIs]) +if test "x$has_robust" != "xno"; then AC_MSG_RESULT(yes) else AC_MSG_RESULT(no)
Signature · 1 line
2.19.1
PATCH 3/6 realtime/configure.ac: Remove unused check
In reply to Petr VorelHAS_PTHREAD_MUTEXATTR_PROTOCOL_FUNCTIONS is not used anywhere.
--- testcases/realtime/configure.ac | 21 --------------------- 1 file changed, 21 deletions(-)
testcases/realtime/configure.ac +0 -21
@@ -38,27 +38,6 @@ else fi REALTIME_CHECK_PRIO_INHERIT - -if test "x$has_priority_inherit" = xyes; then - - AC_MSG_CHECKING([for pthread mutex attr protocol functions]) - AC_TRY_COMPILE([ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif -#include <pthread.h>],[int main(void) { - pthread_mutexattr_t attr; - (void) pthread_mutexattr_getprotocol(&attr, (void*) NULL); - (void) pthread_mutexattr_setprotocol(&attr, 0); - return 0; -}],[has_pthread_mutexattr_protocol_functions="yes"]) -fi -if test "x$has_pthread_mutexattr_protocol_functions" = "xyes" ; then - AC_DEFINE(HAS_PTHREAD_MUTEXATTR_PROTOCOL_FUNCTIONS,1,[Define to 1 if you have the pthread_mutexattr protocol APIs]) - AC_MSG_RESULT(yes) -else - AC_MSG_RESULT(no) -fi REALTIME_CHECK_ROBUST_APIS LTP_CHECK_EXP10
Signature · 1 line
2.19.1
PATCH 4/6 Use POSIX variants of pthread robust mutex functions
In reply to Petr VorelPOSIX added pthread_mutexattr_setrobust, pthread_mutexattr_getrobust, PTHREAD_MUTEX_ROBUST in POSIX.1-2008. There is no need to use their glibc specific (now deprecated) variants. While they're on some other libc (including uclibc-ng), they're not (at least) in musl and bionic.
--- .../open_posix_testsuite/functional/threads/pi_test/README | 4 ++-- testcases/realtime/00_Descriptions.txt | 2 +- testcases/realtime/func/pi-tests/sbrk_mutex.c | 4 ++-- testcases/realtime/func/pi-tests/testpi-6.c | 6 +++--- testcases/realtime/m4/check.m4 | 3 +-- 5 files changed, 9 insertions(+), 10 deletions(-)
testcases/open_posix_testsuite/functional/threads/pi_test/README +2 -2
@@ -33,14 +33,14 @@ Robust Mutex Tests The tests are under <rtnptl-tests>/robust_test directory. rt-nptl supports 'robust' behavior, there will be two robust modes, -one is PTHREAD_MUTEX_ROBUST_NP mode, the other is +one is PTHREAD_MUTEX_ROBUST mode, the other is PTHREAD_MUTEX_ROBUST_SUN_NP mode. When the owner of a mutex dies in the first mode, the waiter will set the mutex to ENOTRECOVERABLE state, while in the second mode, the waiter needs to call pthread_mutex_setconsistency_np to change the state manually. The tests with name robust*-sun are used to test the -PTHREAD_MUTEX_ROBUST_NP mode, other tests with name robust*-mode2 are +PTHREAD_MUTEX_ROBUST mode, other tests with name robust*-mode2 are used to test the PTHREAD_MUTEX_ROBUST_SUN_NP mode. Please refer to the description in the tests for the detailed information.
testcases/realtime/00_Descriptions.txt +1 -1
@@ -127,7 +127,7 @@ testpi-5.c: twice. testpi-6.c: -- Uses robust mutex lock (PTHREAD_MUTEX_ROBUST_NP) and uses test-skeleton for +- Uses robust mutex lock (PTHREAD_MUTEX_ROBUST) and uses test-skeleton for other things. testpi-7.c:
testcases/realtime/func/pi-tests/sbrk_mutex.c +2 -2
@@ -109,11 +109,11 @@ int main(int argc, char *argv[])if (pthread_mutexattr_init (&mutexattr) !=0 ) {printf ("Failed to init mutexattr\n" ); } -if (pthread_mutexattr_setrobust_np (&mutexattr,PTHREAD_MUTEX_ROBUST_NP ) +if (pthread_mutexattr_setrobust (&mutexattr,PTHREAD_MUTEX_ROBUST ) !=0 ) {printf ("Can't set mutexattr robust\n" ); } -if (pthread_mutexattr_getrobust_np (&mutexattr, &robust) !=0 ) { +if (pthread_mutexattr_getrobust (&mutexattr, &robust) !=0 ) {printf ("Can't get mutexattr robust\n" ); }else {printf ("robust in mutexattr is %d\n" , robust);
testcases/realtime/func/pi-tests/testpi-6.c +3 -3
@@ -74,11 +74,11 @@ int do_test(int argc, char **argv)if (pthread_mutexattr_init (&mutexattr) !=0 )printf ("Failed to init mutexattr\n" ); -if (pthread_mutexattr_setrobust_np (&mutexattr, -PTHREAD_MUTEX_ROBUST_NP ) !=0 ) +if (pthread_mutexattr_setrobust (&mutexattr, +PTHREAD_MUTEX_ROBUST ) !=0 )printf ("Can't set robust mutex\n" ); -if (pthread_mutexattr_getrobust_np (&mutexattr, &robust) !=0 ) +if (pthread_mutexattr_getrobust (&mutexattr, &robust) !=0 )printf ("Can't get mutexattr protocol\n" );else printf ("robust in mutexattr is %d\n" , robust);
testcases/realtime/m4/check.m4 +1 -2
@@ -14,8 +14,7 @@ fi ]) AC_DEFUN([REALTIME_CHECK_ROBUST_APIS],[ - AC_CHECK_DECLS([pthread_mutexattr_getrobust_np, pthread_mutexattr_setrobust_np],[],[has_robust="no"],[[#define _GNU_SOURCE -#include <pthread.h>]]) + AC_CHECK_DECLS([pthread_mutexattr_getrobust, pthread_mutexattr_setrobust],[],[has_robust="no"],[[#include <pthread.h>]]) AC_MSG_CHECKING([for pthread_mutexattr_*robust* APIs]) if test "x$has_robust" != "xno"; then AC_MSG_RESULT(yes)
Signature · 1 line
2.19.1
PATCH 5/6 kernel/pt_test: Add missing string.h header
In reply to Petr VorelFixes implicit declaration of function warnings on older compilers:
pt_test.c: In function ‘intel_pt_pmu_value’:
pt_test.c:67:6: warning: implicit declaration of function ‘strstr’ [-Wimplicit-function-declaration]
if (strstr(value, delims) == NULL) {
^~~~~~pt_test.c:67:6: warning: incompatible implicit declaration of built-in function ‘strstr’
pt_test.c:67:6: note: include ‘<string.h>’ or provide a declaration of ‘strstr’
pt_test.c:70:3: warning: implicit declaration of function ‘strsep’; did you mean ‘strlen’? [-Wimplicit-function-declaration]
strsep(&value, delims);
^~~~~~
--- testcases/kernel/tracing/pt_test/pt_test.c | 1 + 1 file changed, 1 insertion(+)
testcases/kernel/tracing/pt_test/pt_test.c +1 -0
@@ -18,6 +18,7 @@#include <sched.h> #include <stdlib.h> #include <stdio.h> +#include <string.h> #include "tst_test.h" #include "lapi/syscalls.h" #include "config.h"
Signature · 1 line
2.19.1
PATCH 6/6 posix: Update README
In reply to Petr VorelRobust Mutex Tests has been removed in a0896f695 ("Remove the robust thread posix testcases.")
--- .../functional/threads/pi_test/README | 20 ------------------- 1 file changed, 20 deletions(-)
testcases/open_posix_testsuite/functional/threads/pi_test/README +0 -20
@@ -28,26 +28,6 @@ watchdog timer to kill the pi mutex tests if they fail. For different tests, there are different result analysis methods. The following two sections will describe this in detail. -Robust Mutex Tests ------------------------- -The tests are under <rtnptl-tests>/robust_test directory. - -rt-nptl supports 'robust' behavior, there will be two robust modes, -one is PTHREAD_MUTEX_ROBUST mode, the other is -PTHREAD_MUTEX_ROBUST_SUN_NP mode. When the owner of a mutex dies in -the first mode, the waiter will set the mutex to ENOTRECOVERABLE -state, while in the second mode, the waiter needs to call -pthread_mutex_setconsistency_np to change the state manually. - -The tests with name robust*-sun are used to test the -PTHREAD_MUTEX_ROBUST mode, other tests with name robust*-mode2 are -used to test the PTHREAD_MUTEX_ROBUST_SUN_NP mode. Please refer to the -description in the tests for the detailed information. - -Using run.sh under <rtnptl-tests>/robust_test to run the robust mutex -tests automatically, the PASS or FAIL result can be obtained from the -stdout. - Priority Inheritance Mutex Tests -------------------------- The tests are under <rtnptl-tests>/pi_test directory.
Signature · 1 line
2.19.1
PATCH 6/6 posix: Update README
Hi!
And the rest of the patchset looks OK.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/6 lapi: Add TEMP_FAILURE_RETRY definition
In reply to Petr VorelHi!
Quoted 7 lines
and use it in realtime to fix pi-tests.
This fixes build failure on libc missing it (e.g. musl, bionic):test-skeleton.c:112:12: warning: implicit declaration of function ???TEMP_FAILURE_RETRY??? [-Wimplicit-function-declaration]
termpid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0)); ^~~~~~~~~~~~~~~~~~make[5]: *** [<builtin>: testpi-6] Error 1
I had no idea glibc has macro like this. I do wonder if it worth a fallback definition if we have exactly one use in the source code tree. Maybe we should just replace the macro with the while loop instead.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/6 lapi: Add TEMP_FAILURE_RETRY definition
Hi Cyril,
Quoted 4 lines
Hi!
Quoted 2 lines
and use it in realtime to fix pi-tests.
This fixes build failure on libc missing it (e.g. musl, bionic):
Quoted 8 lines
Quoted 4 lines
test-skeleton.c:112:12: warning: implicit declaration of function ???TEMP_FAILURE_RETRY??? [-Wimplicit-function-declaration]
termpid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0)); ^~~~~~~~~~~~~~~~~~make[5]: *** [<builtin>: testpi-6] Error 1
I had no idea glibc has macro like this. I do wonder if it worth a fallback definition if we have exactly one use in the source code tree. Maybe we should just replace the macro with the while loop instead.
Replaced and the rest pushed with your ack.
Thanks for your review!
Kind regards,
Petr