fix missing check for thread creation
cover fix missing check for thread creation
There exist some thread creation function without result check.
This set of patches add result check and message print out after failure.
Chengwen Feng (2):
telemetry: fix missing check for thread creation
test: fix missing check for thread creation
app/test/process.h | 8 ++++++-- lib/librte_telemetry/telemetry.c | 30 +++++++++++++++++++++++++++--- lib/librte_telemetry/telemetry_legacy.c | 10 ++++++++-- 3 files changed, 41 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/2 telemetry: fix missing check for thread creation
From: Chengwen Feng <[email protected]>
Add result check and message print out for thread creation after failure.
--- lib/librte_telemetry/telemetry.c | 30 +++++++++++++++++++++++++++--- lib/librte_telemetry/telemetry_legacy.c | 10 ++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-)
lib/librte_telemetry/telemetry.c +27 -3
@@ -350,6 +350,7 @@ socket_listener(void *socket) {while (1 ) {pthread_t th; +int rc;struct socket *s = (struct socket *)socket;int s_accepted =accept (s->sock,NULL ,NULL );if (s_accepted <0 ) {
@@ -366,7 +367,16 @@ socket_listener(void *socket)__atomic_add_fetch (s->num_clients,1 , __ATOMIC_RELAXED); } -pthread_create (&th,NULL , s->fn, (void *)(uintptr_t )s_accepted); + rc =pthread_create (&th,NULL , s->fn, + (void *)(uintptr_t )s_accepted); +if (rc) { +snprintf (telemetry_log_error, +sizeof (telemetry_log_error), +"Error with create thread, telemetry thread " +"quitting" ); +close (s_accepted); +return NULL ; + }pthread_detach (th); }return NULL ;
@@ -425,6 +435,7 @@ static inttelemetry_legacy_init (void) {pthread_t t_old; +int rc;if (num_legacy_callbacks ==1 ) {TMTY_LOG (WARNING ,"No legacy callbacks, legacy socket not created\n" );
@@ -440,7 +451,13 @@ telemetry_legacy_init(void) v1_socket.sock =create_socket (v1_socket.path);if (v1_socket.sock <0 )return -1 ; -pthread_create (&t_old,NULL , socket_listener, &v1_socket); + rc =pthread_create (&t_old,NULL , socket_listener, &v1_socket); +if (rc) { +snprintf (telemetry_log_error,sizeof (telemetry_log_error), +"Error with create thread" ); +unlink_sockets (); +return -1 ; + }pthread_setaffinity_np (t_old,sizeof (*thread_cpuset), thread_cpuset);TMTY_LOG (DEBUG ,"Legacy telemetry socket initialized ok\n" );
@@ -451,6 +468,7 @@ static inttelemetry_v2_init (void) {pthread_t t_new; +int rc; v2_socket.num_clients = &v2_clients; rte_telemetry_register_cmd("/", list_commands,
@@ -469,7 +487,13 @@ telemetry_v2_init(void) v2_socket.sock =create_socket (v2_socket.path);if (v2_socket.sock <0 )return -1 ; -pthread_create (&t_new,NULL , socket_listener, &v2_socket); + rc =pthread_create (&t_new,NULL , socket_listener, &v2_socket); +if (rc) { +snprintf (telemetry_log_error,sizeof (telemetry_log_error), +"Error with create thread" ); +unlink_sockets (); +return -1 ; + }pthread_setaffinity_np (t_new,sizeof (*thread_cpuset), thread_cpuset);atexit (unlink_sockets);
lib/librte_telemetry/telemetry_legacy.c +8 -2
@@ -83,6 +83,7 @@ register_client(const char *cmd __rte_unused, const char *params,pthread_t th;char data[BUF_SIZE ];int fd; +int rc;struct sockaddr_un addrs;#endif /* !RTE_EXEC_ENV_WINDOWS */
@@ -112,8 +113,13 @@ register_client(const char *cmd __rte_unused, const char *params,close (fd); return -1; } -pthread_create (&th,NULL , &legacy_client_handler, - (void *)(uintptr_t )fd); + rc =pthread_create (&th,NULL , &legacy_client_handler, + (void *)(uintptr_t )fd); +if (rc) { +fprintf (stderr,"Failed to create thread\n" ); +close (fd); +return -1 ; + }#endif /* !RTE_EXEC_ENV_WINDOWS */ return 0 ; }
Signature · 1 line
2.7.4
PATCH 2/2 test: fix missing check for thread creation
In reply to Min Hu (Connor)From: Chengwen Feng <[email protected]>
There was a call for thread create function without result check. Add result check and message print out after failure.
--- app/test/process.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
app/test/process.h +6 -2
@@ -48,6 +48,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value)#ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING pthread_t thread; +int rc;#endif #endif
@@ -126,8 +127,11 @@ process_dup(const char *const argv[], int numargs, const char *env_value)/* parent process does a wait */ #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING -if ((strcmp (env_value,"run_pdump_server_tests" ) ==0 )) -pthread_create (&thread,NULL , &send_pkts,NULL ); +if ((strcmp (env_value,"run_pdump_server_tests" ) ==0 )) { + rc =pthread_create (&thread,NULL , &send_pkts,NULL ); +if (rc) +rte_panic ("Cannot start send pkts thread\n" ); + }#endif #endif
Signature · 1 line
2.7.4
v2 cover fix missing check for thread creation
In reply to Min Hu (Connor)There exist some thread creation function without result check.
This set of patches add result check and message print out after failure.
Chengwen Feng (2):
telemetry: fix missing check for thread creation
test: fix missing check for thread creation
---
v2:
* fix compiling bugs of missig value.
app/test/process.h | 8 ++++++-- lib/librte_telemetry/telemetry.c | 28 +++++++++++++++++++++++++--- lib/librte_telemetry/telemetry_legacy.c | 10 ++++++++-- 3 files changed, 39 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 1/2 telemetry: fix missing check for thread creation
From: Chengwen Feng <[email protected]>
Add result check and message print out for thread creation after failure.
--- lib/librte_telemetry/telemetry.c | 28 +++++++++++++++++++++++++--- lib/librte_telemetry/telemetry_legacy.c | 10 ++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-)
lib/librte_telemetry/telemetry.c +25 -3
@@ -350,6 +350,7 @@ socket_listener(void *socket) {while (1 ) {pthread_t th; +int rc;struct socket *s = (struct socket *)socket;int s_accepted =accept (s->sock,NULL ,NULL );if (s_accepted <0 ) {
@@ -366,7 +367,14 @@ socket_listener(void *socket)__atomic_add_fetch (s->num_clients,1 , __ATOMIC_RELAXED); } -pthread_create (&th,NULL , s->fn, (void *)(uintptr_t )s_accepted); + rc =pthread_create (&th,NULL , s->fn, + (void *)(uintptr_t )s_accepted); +if (rc) { +TMTY_LOG (ERR ,"Error with create thread, telemetry thread quitting\n" ); +close (s_accepted); +return NULL ; + } +pthread_detach (th); }return NULL ;
@@ -425,6 +433,7 @@ static inttelemetry_legacy_init (void) {pthread_t t_old; +int rc;if (num_legacy_callbacks ==1 ) {TMTY_LOG (WARNING ,"No legacy callbacks, legacy socket not created\n" );
@@ -440,7 +449,13 @@ telemetry_legacy_init(void) v1_socket.sock =create_socket (v1_socket.path);if (v1_socket.sock <0 )return -1 ; -pthread_create (&t_old,NULL , socket_listener, &v1_socket); + rc =pthread_create (&t_old,NULL , socket_listener, &v1_socket); +if (rc) { +TMTY_LOG (ERR ,"Error with create thread\n" ); +unlink_sockets (); +return -1 ; + } +pthread_setaffinity_np (t_old,sizeof (*thread_cpuset), thread_cpuset);TMTY_LOG (DEBUG ,"Legacy telemetry socket initialized ok\n" );
@@ -451,6 +466,7 @@ static inttelemetry_v2_init (void) {pthread_t t_new; +int rc; v2_socket.num_clients = &v2_clients; rte_telemetry_register_cmd("/", list_commands,
@@ -469,7 +485,13 @@ telemetry_v2_init(void) v2_socket.sock =create_socket (v2_socket.path);if (v2_socket.sock <0 )return -1 ; -pthread_create (&t_new,NULL , socket_listener, &v2_socket); + rc =pthread_create (&t_new,NULL , socket_listener, &v2_socket); +if (rc) { +TMTY_LOG (ERR ,"Error with create thread\n" ); +unlink_sockets (); +return -1 ; + } +pthread_setaffinity_np (t_new,sizeof (*thread_cpuset), thread_cpuset);atexit (unlink_sockets);
lib/librte_telemetry/telemetry_legacy.c +8 -2
@@ -83,6 +83,7 @@ register_client(const char *cmd __rte_unused, const char *params,pthread_t th;char data[BUF_SIZE ];int fd; +int rc;struct sockaddr_un addrs;#endif /* !RTE_EXEC_ENV_WINDOWS */
@@ -112,8 +113,13 @@ register_client(const char *cmd __rte_unused, const char *params,close (fd); return -1; } -pthread_create (&th,NULL , &legacy_client_handler, - (void *)(uintptr_t )fd); + rc =pthread_create (&th,NULL , &legacy_client_handler, + (void *)(uintptr_t )fd); +if (rc) { +fprintf (stderr,"Failed to create thread\n" ); +close (fd); +return -1 ; + }#endif /* !RTE_EXEC_ENV_WINDOWS */ return 0 ; }
Signature · 1 line
2.7.4
Re: [dpdk-dev] [PATCH v2 1/2] telemetry: fix missing check for thread creation
Quoted 5 lines · Min Hu (Connor)
From: Chengwen Feng <[email protected]>
Add result check and message print out for thread creation after failure.
Ah, I was looking at this code too, while looking at your other series :-).
Quoted 24 lines
Fixes b80fe1805eee ("telemetry: introduce backward compatibility")Signed-off-by Chengwen Feng <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>--- lib/librte_telemetry/telemetry.c | 28 +++++++++++++++++++++++++--- lib/librte_telemetry/telemetry_legacy.c | 10 ++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-)lib/librte_telemetry/telemetry.c +1
-0@@ -350,6 +350,7 @@ socket_listener(void *socket) {while (1 ) {pthread_t th; +int rc;struct socket *s = (struct socket *)socket;int s_accepted =accept (s->sock,NULL ,NULL );if (s_accepted <0 ) {
lib/librte_telemetry/telemetry.c socket_listener(void *socket) · line 372
Quoted 7 lines
lib/librte_telemetry/telemetry.c +3
-1@@ -366,7 +367,14 @@ socket_listener(void *socket)__atomic_add_fetch (s->num_clients,1 , __ATOMIC_RELAXED); } -pthread_create (&th,NULL , s->fn, (void *)(uintptr_t )s_accepted); + rc =pthread_create (&th,NULL , s->fn, + (void *)(uintptr_t )s_accepted); +if (rc) {
Either you use this rc variable (adding strerror(rc) in the log message below) or you can remove it.
This comment applies to others updates below.
lib/librte_telemetry/telemetry.c Fixes: 3b3757bda3c3 ("net/ice: get VF hardware index in DCF")
Quoted 17 lines
lib/librte_telemetry/telemetry.c +6
-0+TMTY_LOG (ERR ,"Error with create thread, telemetry thread quitting\n" ); +close (s_accepted); +return NULL ; + } +pthread_detach (th); }return NULL ;@@ -425,6 +433,7 @@ static inttelemetry_legacy_init (void) {pthread_t t_old; +int rc;if (num_legacy_callbacks ==1 ) {TMTY_LOG (WARNING ,"No legacy callbacks, legacy socket not created\n" );@@ -440,7 +449,13 @@ Fixes: 3b3757bda3c3 ("net/ice: get VF hardware index in DCF")
(void)
lib/librte_telemetry/telemetry.c telemetry_legacy_init(void) · line 455
Quoted 8 lines
lib/librte_telemetry/telemetry.c +4
-1v1_socket.sock =create_socket (v1_socket.path);if (v1_socket.sock <0 )return -1 ; -pthread_create (&t_old,NULL , socket_listener, &v1_socket); + rc =pthread_create (&t_old,NULL , socket_listener, &v1_socket); +if (rc) { +TMTY_LOG (ERR ,"Error with create thread\n" ); +unlink_sockets ();
Before this patch, v2 mode could be working fine with v1 ko. I think it was intended since telemetry_legacy_init return value is not checked and unlink_sockets() checks whether the v1 and v2 sockets have been created.
Plus, in this error handling, the v1 socket fd is left open.
How about:
+ ret = pthread_create(&t_old, NULL, socket_listener, &v1_socket);
+ if (ret != 0) {
+ TMTY_LOG(DEBUG, "Failed to create handler for legacy
socket: %s\n",
+ strerror(ret));
+ close(v1_socket.sock);
+ v1_socket.sock = -1;
+ if (v1_socket.path[0]) {+ unlink(v1_socket.path);
+ v1_socket.path[0] = '\0';
+ }
+ return -1;
+ }
Quoted 16 lines
lib/librte_telemetry/telemetry.c +4
-0+return -1 ; + } +pthread_setaffinity_np (t_old,sizeof (*thread_cpuset), thread_cpuset);TMTY_LOG (DEBUG ,"Legacy telemetry socket initialized ok\n" );@@ -451,6 +466,7 @@ static inttelemetry_v2_init (void) {pthread_t t_new; +int rc; v2_socket.num_clients = &v2_clients; rte_telemetry_register_cmd("/", list_commands,@@ -469,7 +485,13 @@ telemetry_v2_init(void) v2_socket.sock =create_socket (v2_socket.path);
lib/librte_telemetry/telemetry.c telemetry_v2_init(void) · line 494
Quoted 10 lines
lib/librte_telemetry/telemetry.c +7
-1if (v2_socket.sock <0 )return -1 ; -pthread_create (&t_new,NULL , socket_listener, &v2_socket); + rc =pthread_create (&t_new,NULL , socket_listener, &v2_socket); +if (rc) { +TMTY_LOG (ERR ,"Error with create thread\n" ); +unlink_sockets (); +return -1 ; + } +
Missing a close on v2 socket,
Quoted 34 lines
lib/librte_telemetry/telemetry.c +0
-0pthread_setaffinity_np (t_new,sizeof (*thread_cpuset), thread_cpuset);atexit (unlink_sockets);lib/librte_telemetry/telemetry_legacy.c +8
-3@@ -83,6 +83,7 @@ register_client(const char *cmd __rte_unused, const char *params,pthread_t th;char data[BUF_SIZE ];int fd; +int rc;struct sockaddr_un addrs;#endif /* !RTE_EXEC_ENV_WINDOWS */ @@ -112,8 +113,13 @@ register_client(const char *cmd __rte_unused, const char *params,close (fd); return -1; } -pthread_create (&th,NULL , &legacy_client_handler, - (void *)(uintptr_t )fd); + rc =pthread_create (&th,NULL , &legacy_client_handler, + (void *)(uintptr_t )fd); +if (rc) { +fprintf (stderr,"Failed to create thread\n" ); +close (fd); +return -1 ; + }#endif /* !RTE_EXEC_ENV_WINDOWS */ return 0 ; } --2.7.4
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v2 1/2] telemetry: fix missing check for thread creation
Hi, David,
ALl has been fixed in v3, please check it out, thanks.
Quoted 88 lines · David Marchand
Quoted 5 lines · Min Hu (Connor)
From: Chengwen Feng <[email protected]>
Add result check and message print out for thread creation after failure.
Ah, I was looking at this code too, while looking at your other series :-).
Quoted 24 lines
Fixes b80fe1805eee ("telemetry: introduce backward compatibility")Signed-off-by Chengwen Feng <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>--- lib/librte_telemetry/telemetry.c | 28 +++++++++++++++++++++++++--- lib/librte_telemetry/telemetry_legacy.c | 10 ++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-)lib/librte_telemetry/telemetry.c +1
-0@@ -350,6 +350,7 @@ socket_listener(void *socket) {while (1 ) {pthread_t th; +int rc;struct socket *s = (struct socket *)socket;int s_accepted =accept (s->sock,NULL ,NULL );if (s_accepted <0 ) {lib/librte_telemetry/telemetry.c socket_listener(void *socket) · line 372
Quoted 7 lines
lib/librte_telemetry/telemetry.c +3
-1@@ -366,7 +367,14 @@ socket_listener(void *socket)__atomic_add_fetch (s->num_clients,1 , __ATOMIC_RELAXED); } -pthread_create (&th,NULL , s->fn, (void *)(uintptr_t )s_accepted); + rc =pthread_create (&th,NULL , s->fn, + (void *)(uintptr_t )s_accepted); +if (rc) {Either you use this rc variable (adding strerror(rc) in the log message below) or you can remove it.
This comment applies to others updates below.lib/librte_telemetry/telemetry.c Fixes: 3b3757bda3c3 ("net/ice: get VF hardware index in DCF")
Quoted 17 lines
lib/librte_telemetry/telemetry.c +6
-0+TMTY_LOG (ERR ,"Error with create thread, telemetry thread quitting\n" ); +close (s_accepted); +return NULL ; + } +pthread_detach (th); }return NULL ;@@ -425,6 +433,7 @@ static inttelemetry_legacy_init (void) {pthread_t t_old; +int rc;if (num_legacy_callbacks ==1 ) {TMTY_LOG (WARNING ,"No legacy callbacks, legacy socket not created\n" );@@ -440,7 +449,13 @@ Fixes: 3b3757bda3c3 ("net/ice: get VF hardware index in DCF")(void)
lib/librte_telemetry/telemetry.c telemetry_legacy_init(void) · line 455
Quoted 8 lines
lib/librte_telemetry/telemetry.c +4
-1v1_socket.sock =create_socket (v1_socket.path);if (v1_socket.sock <0 )return -1 ; -pthread_create (&t_old,NULL , socket_listener, &v1_socket); + rc =pthread_create (&t_old,NULL , socket_listener, &v1_socket); +if (rc) { +TMTY_LOG (ERR ,"Error with create thread\n" ); +unlink_sockets ();Before this patch, v2 mode could be working fine with v1 ko. I think it was intended since
telemetry_legacy_initreturn value is not checked andunlink_sockets()checks whether the v1 and v2 sockets have been created.Plus, in this error handling, the v1 socket fd is left open.
How about:
(quoted diff) +3
-0+ ret = pthread_create(&t_old, NULL, socket_listener, &v1_socket); + if (ret != 0) { + TMTY_LOG(DEBUG, "Failed to create handler for legacysocket: %s\n",
Review
Quoted 9 lines
(quoted diff) +9
-0+ strerror(ret)); + close(v1_socket.sock); + v1_socket.sock = -1; + if (v1_socket.path[0]) { + unlink(v1_socket.path); + v1_socket.path[0] = '\0'; + } + return -1; + }
ok, but there is no need to judge v1_socket.path[0] because previous setup will ensure it's validation.
Quoted 68 lines
Quoted 17 lines
lib/librte_telemetry/telemetry.c +4
-0+return -1 ; + } +pthread_setaffinity_np (t_old,sizeof (*thread_cpuset), thread_cpuset);TMTY_LOG (DEBUG ,"Legacy telemetry socket initialized ok\n" );@@ -451,6 +466,7 @@ static inttelemetry_v2_init (void) {pthread_t t_new; +int rc; v2_socket.num_clients = &v2_clients; rte_telemetry_register_cmd("/", list_commands,@@ -469,7 +485,13 @@ telemetry_v2_init(void) v2_socket.sock =create_socket (v2_socket.path);lib/librte_telemetry/telemetry.c telemetry_v2_init(void) · line 494
Quoted 10 lines
lib/librte_telemetry/telemetry.c +7
-1if (v2_socket.sock <0 )return -1 ; -pthread_create (&t_new,NULL , socket_listener, &v2_socket); + rc =pthread_create (&t_new,NULL , socket_listener, &v2_socket); +if (rc) { +TMTY_LOG (ERR ,"Error with create thread\n" ); +unlink_sockets (); +return -1 ; + } +Missing a close on v2 socket,
Quoted 34 lines
lib/librte_telemetry/telemetry.c +0
-0pthread_setaffinity_np (t_new,sizeof (*thread_cpuset), thread_cpuset);atexit (unlink_sockets);lib/librte_telemetry/telemetry_legacy.c +8
-3@@ -83,6 +83,7 @@ register_client(const char *cmd __rte_unused, const char *params,pthread_t th;char data[BUF_SIZE ];int fd; +int rc;struct sockaddr_un addrs;#endif /* !RTE_EXEC_ENV_WINDOWS */ @@ -112,8 +113,13 @@ register_client(const char *cmd __rte_unused, const char *params,close (fd); return -1; } -pthread_create (&th,NULL , &legacy_client_handler, - (void *)(uintptr_t )fd); + rc =pthread_create (&th,NULL , &legacy_client_handler, + (void *)(uintptr_t )fd); +if (rc) { +fprintf (stderr,"Failed to create thread\n" ); +close (fd); +return -1 ; + }#endif /* !RTE_EXEC_ENV_WINDOWS */ return 0 ; } --2.7.4
PATCH v2 2/2 test: fix missing check for thread creation
In reply to Min Hu (Connor)From: Chengwen Feng <[email protected]>
There was a call for thread create function without result check. Add result check and message print out after failure.
--- app/test/process.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
app/test/process.h +6 -2
@@ -48,6 +48,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value)#ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING pthread_t thread; +int rc;#endif #endif
@@ -126,8 +127,11 @@ process_dup(const char *const argv[], int numargs, const char *env_value)/* parent process does a wait */ #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING -if ((strcmp (env_value,"run_pdump_server_tests" ) ==0 )) -pthread_create (&thread,NULL , &send_pkts,NULL ); +if ((strcmp (env_value,"run_pdump_server_tests" ) ==0 )) { + rc =pthread_create (&thread,NULL , &send_pkts,NULL ); +if (rc) +rte_panic ("Cannot start send pkts thread\n" ); + }#endif #endif
Signature · 1 line
2.7.4
v3 cover fix missing check for thread creation
In reply to Min Hu (Connor)There exist some thread creation function without result check.
This set of patches add result check and message print out after failure.
Chengwen Feng (2):
telemetry: fix missing check for thread creation
test: fix missing check for thread creation
---
v3:
* modify return value check and error logging.
v2:
* fix compiling bugs of missig value.
app/test/process.h | 8 ++++++-- lib/librte_telemetry/telemetry.c | 30 +++++++++++++++++++++++++++--- lib/librte_telemetry/telemetry_legacy.c | 10 ++++++++-- 3 files changed, 41 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
PATCH v3 1/2 telemetry: fix missing check for thread creation
From: Chengwen Feng <[email protected]>
Add result check and message print out for thread creation after failure.
--- lib/librte_telemetry/telemetry.c | 30 +++++++++++++++++++++++++++--- lib/librte_telemetry/telemetry_legacy.c | 10 ++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-)
lib/librte_telemetry/telemetry.c +27 -3
@@ -350,6 +350,7 @@ socket_listener(void *socket) {while (1 ) {pthread_t th; +int rc;struct socket *s = (struct socket *)socket;int s_accepted =accept (s->sock,NULL ,NULL );if (s_accepted <0 ) {
@@ -366,7 +367,12 @@ socket_listener(void *socket)__atomic_add_fetch (s->num_clients,1 , __ATOMIC_RELAXED); } -pthread_create (&th,NULL , s->fn, (void *)(uintptr_t )s_accepted); + rc =pthread_create (&th,NULL , s->fn, (void *)(uintptr_t )s_accepted); +if (rc !=0 ) { +TMTY_LOG (ERR ,"Error with create client thread\n" ); +close (s_accepted); +return NULL ; + }pthread_detach (th); }return NULL ;
@@ -425,6 +431,7 @@ static inttelemetry_legacy_init (void) {pthread_t t_old; +int rc;if (num_legacy_callbacks ==1 ) {TMTY_LOG (WARNING ,"No legacy callbacks, legacy socket not created\n" );
@@ -440,7 +447,15 @@ telemetry_legacy_init(void) v1_socket.sock =create_socket (v1_socket.path);if (v1_socket.sock <0 )return -1 ; -pthread_create (&t_old,NULL , socket_listener, &v1_socket); + rc =pthread_create (&t_old,NULL , socket_listener, &v1_socket); +if (rc !=0 ) { +TMTY_LOG (ERR ,"Error with create thread for legacy socket\n" ); +close (v1_socket.sock); + v1_socket.sock =-1 ; +unlink (v1_socket.path); + v1_socket.path[0 ] ='\0' ; +return -1 ; + }pthread_setaffinity_np (t_old,sizeof (*thread_cpuset), thread_cpuset);TMTY_LOG (DEBUG ,"Legacy telemetry socket initialized ok\n" );
@@ -451,6 +466,7 @@ static inttelemetry_v2_init (void) {pthread_t t_new; +int rc; v2_socket.num_clients = &v2_clients; rte_telemetry_register_cmd("/", list_commands,
@@ -469,7 +485,15 @@ telemetry_v2_init(void) v2_socket.sock =create_socket (v2_socket.path);if (v2_socket.sock <0 )return -1 ; -pthread_create (&t_new,NULL , socket_listener, &v2_socket); + rc =pthread_create (&t_new,NULL , socket_listener, &v2_socket); +if (rc !=0 ) { +TMTY_LOG (ERR ,"Error with create thread for socket" ); +close (v2_socket.sock); + v2_socket.sock =-1 ; +unlink (v2_socket.path); + v2_socket.path[0 ] ='\0' ; +return -1 ; + }pthread_setaffinity_np (t_new,sizeof (*thread_cpuset), thread_cpuset);atexit (unlink_sockets);
lib/librte_telemetry/telemetry_legacy.c +8 -2
@@ -83,6 +83,7 @@ register_client(const char *cmd __rte_unused, const char *params,pthread_t th;char data[BUF_SIZE ];int fd; +int rc;struct sockaddr_un addrs;#endif /* !RTE_EXEC_ENV_WINDOWS */
@@ -112,8 +113,13 @@ register_client(const char *cmd __rte_unused, const char *params,close (fd); return -1; } -pthread_create (&th,NULL , &legacy_client_handler, - (void *)(uintptr_t )fd); + rc =pthread_create (&th,NULL , &legacy_client_handler, + (void *)(uintptr_t )fd); +if (rc !=0 ) { +perror ("Failed to create legacy client thread\n" ); +close (fd); +return -1 ; + }#endif /* !RTE_EXEC_ENV_WINDOWS */ return 0 ; }
Signature · 1 line
2.7.4
Re: [dpdk-dev] [PATCH v3 1/2] telemetry: fix missing check for thread creation
Quoted 13 lines · Min Hu (Connor)
lib/librte_telemetry/telemetry.c +1
-0@@ -350,6 +350,7 @@ socket_listener(void *socket) {while (1 ) {pthread_t th; +int rc;struct socket *s = (struct socket *)socket;int s_accepted =accept (s->sock,NULL ,NULL );if (s_accepted <0 ) {
lib/librte_telemetry/telemetry.c socket_listener(void *socket) · line 375
Quoted 10 lines
lib/librte_telemetry/telemetry.c +6
-1@@ -366,7 +367,12 @@ socket_listener(void *socket)__atomic_add_fetch (s->num_clients,1 , __ATOMIC_RELAXED); } -pthread_create (&th,NULL , s->fn, (void *)(uintptr_t )s_accepted); + rc =pthread_create (&th,NULL , s->fn, (void *)(uintptr_t )s_accepted); +if (rc !=0 ) { +TMTY_LOG (ERR ,"Error with create client thread\n" ); +close (s_accepted); +return NULL ; + }
Repeating my comment:
Either you use this rc variable (adding strerror(rc) in the log message in TMTY_LOG()) or you remove the variable and simply test if (pthread_create(...) != 0).
This comment applies to other changes in this patch. And this applies to patch 2 too.
lib/librte_telemetry/telemetry.c socket_listener(void *socket) · line 378
Quoted 3 lines
lib/librte_telemetry/telemetry.c +0
-0pthread_detach (th); }return NULL ;
Thanks.
--
David Marchand
Re: [dpdk-dev] [PATCH v3 1/2] telemetry: fix missing check for thread creation
Hi, David, fixed in v4. Thanks.
Quoted 46 lines · David Marchand
Quoted 13 lines · Min Hu (Connor)
lib/librte_telemetry/telemetry.c +1
-0@@ -350,6 +350,7 @@ socket_listener(void *socket) {while (1 ) {pthread_t th; +int rc;struct socket *s = (struct socket *)socket;int s_accepted =accept (s->sock,NULL ,NULL );if (s_accepted <0 ) {lib/librte_telemetry/telemetry.c socket_listener(void *socket) · line 375
Quoted 10 lines
lib/librte_telemetry/telemetry.c +6
-1@@ -366,7 +367,12 @@ socket_listener(void *socket)__atomic_add_fetch (s->num_clients,1 , __ATOMIC_RELAXED); } -pthread_create (&th,NULL , s->fn, (void *)(uintptr_t )s_accepted); + rc =pthread_create (&th,NULL , s->fn, (void *)(uintptr_t )s_accepted); +if (rc !=0 ) { +TMTY_LOG (ERR ,"Error with create client thread\n" ); +close (s_accepted); +return NULL ; + }Repeating my comment:
Either you use this rc variable (adding strerror(rc) in the log message in
TMTY_LOG()) or you remove the variable and simply test if (pthread_create(...)!= 0).This comment applies to other changes in this patch. And this applies to patch 2 too.
lib/librte_telemetry/telemetry.c socket_listener(void *socket) · line 378
Quoted 3 lines
lib/librte_telemetry/telemetry.c +0
-0pthread_detach (th); }return NULL ;Thanks.
--
David Marchand.
Re: [dpdk-dev] [PATCH v3 1/2] telemetry: fix missing check for thread creation
In reply to Min Hu (Connor)Hi Connor,
Thanks for looking at this. Left some comments inline.
Ciara
Quoted 38 lines
-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Thursday 15 April 2021 12:50
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Power, Ciara <[email protected]>; Pattan, Reshma <[email protected]>; [email protected]
Subject: [PATCH v3 1/2] telemetry: fix missing check for thread creationFrom: Chengwen Feng <[email protected]>
Add result check and message print out for thread creation after failure.
Fixes b80fe1805eee ("telemetry: introduce backward compatibility")Signed-off-by Chengwen Feng <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
lib/librte_telemetry/telemetry.c| 30 +++++++++++++++++++++++++++-
--lib/librte_telemetry/telemetry_legacy.c| 10 ++++++++--2 files changed, 35 insertions(+), 5 deletions(-)lib/librte_telemetry/telemetry.c +1
-0@@ -350,6 +350,7 @@ socket_listener(void *socket) {while (1 ) {pthread_t th; +int rc;struct socket *s = (struct socket *)socket;int s_accepted =accept (s->sock,NULL ,NULL );if (s_accepted <0 ) {@@ -366,7 +367,12 @@ socket_listener(void *socket) __atomic_add_fetch(s->num_clients, 1,
lib/librte_telemetry/telemetry.c socket_listener(void *socket) · line 376
Quoted 10 lines
lib/librte_telemetry/telemetry.c +5
-1__ATOMIC_RELAXED); } -pthread_create (&th,NULL , s->fn, (void *)(uintptr_t)s_accepted); + rc =pthread_create (&th,NULL , s->fn, (void *)(uintptr_t )s_accepted); +if (rc !=0 ) { +TMTY_LOG (ERR ,"Error with create client thread\n" ); +close (s_accepted); +return NULL ;
I think this should be "continue" instead of "return NULL" - if one client connection thread fails, we probably want to keep listening for more clients rather than stop completely.
The "s->num_clients" counter should be decremented here too,
it gets incremented above when the connection is accepted, but if we are closing the connection, the counter should reflect that.
Quoted 90 lines
lib/librte_telemetry/telemetry.c +1
-0+ }pthread_detach (th);} return NULL;lib/librte_telemetry/telemetry.c +1
-0@@ -425,6 +431,7 @@ static inttelemetry_legacy_init (void) {pthread_t t_old; +int rc;if (num_legacy_callbacks ==1 ) { TMTY_LOG(WARNING, "No legacy callbacks, legacy socket notcreated\n"); @@ -440,7 +447,15 @@
telemetry_legacy_init(void)v1_socket.sock = create_socket(v1_socket.path); if (v1_socket.sock < 0) return -1;lib/librte_telemetry/telemetry.c +3
-1-pthread_create (&t_old,NULL , socket_listener, &v1_socket); + rc =pthread_create (&t_old,NULL , socket_listener, &v1_socket); +if (rc !=0 ) { + TMTY_LOG(ERR, "Error with create thread for legacysocket\n");
lib/librte_telemetry/telemetry.c +6
-0+close (v1_socket.sock); + v1_socket.sock =-1 ; +unlink (v1_socket.path); + v1_socket.path[0 ] ='\0' ; +return -1 ; + }pthread_setaffinity_np(t_old,
sizeof(*thread_cpuset),thread_cpuset);
TMTY_LOG(DEBUG, "Legacy telemetry socket initialized ok\n"); @@ -
451,6 +466,7 @@ static inttelemetry_v2_init(void){ pthread_t t_new;lib/librte_telemetry/telemetry.c +1
-0+int rc;v2_socket.num_clients = &v2_clients; rte_telemetry_register_cmd("/", list_commands, @@ -469,7 +485,15 @@ telemetry_v2_init(void) v2_socket.sock = create_socket(v2_socket.path); if (v2_socket.sock < 0) return -1;lib/librte_telemetry/telemetry.c +9
-1-pthread_create (&t_new,NULL , socket_listener, &v2_socket); + rc =pthread_create (&t_new,NULL , socket_listener, &v2_socket); +if (rc !=0 ) { +TMTY_LOG (ERR ,"Error with create thread for socket" ); +close (v2_socket.sock); + v2_socket.sock =-1 ; +unlink (v2_socket.path); + v2_socket.path[0 ] ='\0' ; +return -1 ; + }pthread_setaffinity_np(t_new,
sizeof(*thread_cpuset),thread_cpuset); atexit(unlink_sockets);lib/librte_telemetry/telemetry_legacy.c +8
-2@@ -83,6 +83,7 @@ register_client(const char *cmd __rte_unused, constchar *params, pthread_t th;char data[BUF_SIZE ];int fd; +int rc;struct sockaddr_un addrs;#endif /* !RTE_EXEC_ENV_WINDOWS */ @@ -112,8 +113,13 @@ register_client(const char *cmd __rte_unused, constchar *params,close (fd ); return -1; } -pthread_create (&th,NULL , &legacy_client_handler, - (void *)(uintptr_t )fd); + rc =pthread_create (&th,NULL , &legacy_client_handler, + (void *)(uintptr_t )fd); +if (rc !=0 ) { +perror ("Failed to create legacy client thread\n" ); +close (fd); +return -1 ; + }#endif /* !RTE_EXEC_ENV_WINDOWS */ return 0 ;}
--
2.7.4
Re: [dpdk-dev] [PATCH v3 1/2] telemetry: fix missing check for thread creation
Thanks Power, v4 has been sent, please check it out.
Quoted 157 lines · Ciara
Hi Connor,
Thanks for looking at this. Left some comments inline.
Ciara
Quoted 38 lines
-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Thursday 15 April 2021 12:50
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Power, Ciara <[email protected]>; Pattan, Reshma <[email protected]>; [email protected]
Subject: [PATCH v3 1/2] telemetry: fix missing check for thread creationFrom: Chengwen Feng <[email protected]>
Add result check and message print out for thread creation after failure.
Fixes b80fe1805eee ("telemetry: introduce backward compatibility")Signed-off-by Chengwen Feng <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
lib/librte_telemetry/telemetry.c| 30 +++++++++++++++++++++++++++-
--lib/librte_telemetry/telemetry_legacy.c| 10 ++++++++--2 files changed, 35 insertions(+), 5 deletions(-)lib/librte_telemetry/telemetry.c +1
-0@@ -350,6 +350,7 @@ socket_listener(void *socket) {while (1 ) {pthread_t th; +int rc;struct socket *s = (struct socket *)socket;int s_accepted =accept (s->sock,NULL ,NULL );if (s_accepted <0 ) {@@ -366,7 +367,12 @@ socket_listener(void *socket) __atomic_add_fetch(s->num_clients, 1,lib/librte_telemetry/telemetry.c socket_listener(void *socket) · line 376
Quoted 10 lines
lib/librte_telemetry/telemetry.c +5
-1__ATOMIC_RELAXED); } -pthread_create (&th,NULL , s->fn, (void *)(uintptr_t)s_accepted); + rc =pthread_create (&th,NULL , s->fn, (void *)(uintptr_t )s_accepted); +if (rc !=0 ) { +TMTY_LOG (ERR ,"Error with create client thread\n" ); +close (s_accepted); +return NULL ;I think this should be "continue" instead of "return NULL" - if one client connection thread fails, we probably want to keep listening for more clients rather than stop completely.
The "
s->num_clients" counter should be decremented here too,
it gets incremented above when the connection is accepted, but if we are closing the connection, the counter should reflect that.Quoted 87 lines
lib/librte_telemetry/telemetry.c +1
-0+ }pthread_detach (th);} return NULL;lib/librte_telemetry/telemetry.c +1
-0@@ -425,6 +431,7 @@ static inttelemetry_legacy_init (void) {pthread_t t_old; +int rc;if (num_legacy_callbacks ==1 ) { TMTY_LOG(WARNING, "No legacy callbacks, legacy socket notcreated\n"); @@ -440,7 +447,15 @@
telemetry_legacy_init(void)v1_socket.sock = create_socket(v1_socket.path); if (v1_socket.sock < 0) return -1;lib/librte_telemetry/telemetry.c +3
-1-pthread_create (&t_old,NULL , socket_listener, &v1_socket); + rc =pthread_create (&t_old,NULL , socket_listener, &v1_socket); +if (rc !=0 ) { + TMTY_LOG(ERR, "Error with create thread for legacysocket\n");
lib/librte_telemetry/telemetry.c +6
-0+close (v1_socket.sock); + v1_socket.sock =-1 ; +unlink (v1_socket.path); + v1_socket.path[0 ] ='\0' ; +return -1 ; + }pthread_setaffinity_np(t_old,
sizeof(*thread_cpuset),thread_cpuset);
TMTY_LOG(DEBUG, "Legacy telemetry socket initialized ok\n"); @@ -
451,6 +466,7 @@ static inttelemetry_v2_init(void){ pthread_t t_new;lib/librte_telemetry/telemetry.c +1
-0+int rc;v2_socket.num_clients = &v2_clients; rte_telemetry_register_cmd("/", list_commands, @@ -469,7 +485,15 @@ telemetry_v2_init(void) v2_socket.sock = create_socket(v2_socket.path); if (v2_socket.sock < 0) return -1;lib/librte_telemetry/telemetry.c +9
-1-pthread_create (&t_new,NULL , socket_listener, &v2_socket); + rc =pthread_create (&t_new,NULL , socket_listener, &v2_socket); +if (rc !=0 ) { +TMTY_LOG (ERR ,"Error with create thread for socket" ); +close (v2_socket.sock); + v2_socket.sock =-1 ; +unlink (v2_socket.path); + v2_socket.path[0 ] ='\0' ; +return -1 ; + }pthread_setaffinity_np(t_new,
sizeof(*thread_cpuset),thread_cpuset); atexit(unlink_sockets);lib/librte_telemetry/telemetry_legacy.c +8
-2@@ -83,6 +83,7 @@ register_client(const char *cmd __rte_unused, constchar *params, pthread_t th;char data[BUF_SIZE ];int fd; +int rc;struct sockaddr_un addrs;#endif /* !RTE_EXEC_ENV_WINDOWS */ @@ -112,8 +113,13 @@ register_client(const char *cmd __rte_unused, constchar *params,close (fd ); return -1; } -pthread_create (&th,NULL , &legacy_client_handler, - (void *)(uintptr_t )fd); + rc =pthread_create (&th,NULL , &legacy_client_handler, + (void *)(uintptr_t )fd); +if (rc !=0 ) { +perror ("Failed to create legacy client thread\n" ); +close (fd); +return -1 ; + }#endif /* !RTE_EXEC_ENV_WINDOWS */ return 0 ;Quoted 3 lines
}
--
2.7.4.
PATCH v3 2/2 test: fix missing check for thread creation
In reply to Min Hu (Connor)From: Chengwen Feng <[email protected]>
There was a call for thread create function without result check. Add result check and message print out after failure.
--- app/test/process.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
app/test/process.h +6 -2
@@ -48,6 +48,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value)#ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING pthread_t thread; +int rc;#endif #endif
@@ -126,8 +127,11 @@ process_dup(const char *const argv[], int numargs, const char *env_value)/* parent process does a wait */ #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING -if ((strcmp (env_value,"run_pdump_server_tests" ) ==0 )) -pthread_create (&thread,NULL , &send_pkts,NULL ); +if ((strcmp (env_value,"run_pdump_server_tests" ) ==0 )) { + rc =pthread_create (&thread,NULL , &send_pkts,NULL ); +if (rc !=0 ) +rte_panic ("Cannot start send pkts thread\n" ); + }#endif #endif
Signature · 1 line
2.7.4
Re: [dpdk-dev] [PATCH v3 2/2] test: fix missing check for thread creation
app/test/process.h process_dup(const char *const argv[], int numargs, const char *env_value) · line 134
Quoted 9 lines
-----Original Message-----
From: Min Hu (Connor) <[email protected]>app/test/process.h +5
-0+if ((strcmp (env_value,"run_pdump_server_tests" ) ==0 )) { + rc =pthread_create (&thread,NULL , &send_pkts,NULL ); +if (rc !=0 ) +rte_panic ("Cannot start send pkts thread\n" ); + }
I think you still have not addressed the David comment on previous version of the patch. So , can you change this to something like below
Option1)
rc = pthread_create(&thread, NULL, &send_pkts, NULL); If ( rc ! = 0 )
{
rte_panic("Cannot start send pkts thread : %s\n", strerror(rc));
}Or
Option2)
If ( pthread_create(&thread, NULL, &send_pkts, NULL) !=0 )
rte_panic("Cannot start send pkts thread\n");Also,
Quoted 1 line
Quoted 1 line
test: fix missing check for thread creation
Change this subject line to "test/pdump: fix missing check for thread creation"
Thanks,
Reshma
Re: [dpdk-dev] [PATCH v3 2/2] test: fix missing check for thread creation
Quoted 25 lines · Reshma
app/test/process.h process_dup(const char *const argv[], int numargs, const char *env_value) · line 134
Quoted 9 lines
-----Original Message-----
From: Min Hu (Connor) <[email protected]>app/test/process.h +5
-0+if ((strcmp (env_value,"run_pdump_server_tests" ) ==0 )) { + rc =pthread_create (&thread,NULL , &send_pkts,NULL ); +if (rc !=0 ) +rte_panic ("Cannot start send pkts thread\n" ); + }I think you still have not addressed the David comment on previous version of the patch. So , can you change this to something like below
Option1)
rc =pthread_create(&thread, NULL, &send_pkts, NULL); If ( rc ! = 0 ){ rte_panic("Cannot start send pkts thread : %s\n", strerror(rc)); }Or
Option2)
If (pthread_create(&thread, NULL, &send_pkts, NULL)!=0 )
Quoted 8 lines
rte_panic("Cannot start send pkts thread\n");Also,
Quoted 1 line
Quoted 1 line
test: fix missing check for thread creation
Change this subject line to "test/pdump: fix missing check for thread creation"
Hi, Pattan, fixed in v4, except for "test/pdump", if v4 is OK, please modify it for me, @Ferruh, thanks.
Quoted 5 lines
Thanks,
Reshma.
Re: [dpdk-dev] [PATCH v3 2/2] test: fix missing check for thread creation
Quoted 31 lines · Min Hu (Connor)
Quoted 28 lines · Reshma
Quoted 9 lines
-----Original Message-----
From: Min Hu (Connor) <[email protected]>
+ if ((strcmp(env_value, "run_pdump_server_tests")== 0)) { + rc =pthread_create(&thread, NULL, &send_pkts, NULL); + if (rc != 0)
+rte_panic("Cannot start send pkts thread\n"); + }I think you still have not addressed the David comment on previous version of the patch. So , can you change this to something like below
Option1)
rc =pthread_create(&thread, NULL, &send_pkts, NULL);
If ( rc ! = 0 )
{
rte_panic("Cannot start send pkts thread : %s\n", strerror(rc)); }Or
Option2)
If (pthread_create(&thread, NULL, &send_pkts, NULL)!=0 )rte_panic("Cannot start send pkts thread\n");
Quoted 7 lines
Quoted 5 lines
Also,
Quoted 1 line
Quoted 1 line
test: fix missing check for thread creation
Change this subject line to "test/pdump: fix missing check for thread creation"
Hi, Pattan, fixed in v4, except for "test/pdump", if v4 is OK, please modify it for me, @Ferruh, thanks.
Hi Connor, this patch is on David's domain, he will commit the patch, not me.
Re: [dpdk-dev] [PATCH v3 2/2] test: fix missing check for thread creation
Quoted 34 lines · Ferruh Yigit
Quoted 33 lines · Min Hu (Connor)
Quoted 30 lines · Reshma
Quoted 9 lines
-----Original Message-----
From: Min Hu (Connor) <[email protected]>
+ if ((strcmp(env_value, "run_pdump_server_tests")== 0)) { + rc =pthread_create(&thread, NULL, &send_pkts, NULL); + if (rc != 0)
+rte_panic("Cannot start send pkts thread\n"); + }I think you still have not addressed the David comment on previous version of the patch. So , can you change this to something like below
Option1)
rc =pthread_create(&thread, NULL, &send_pkts, NULL);
If ( rc ! = 0 )
{
rte_panic("Cannot start send pkts thread : %s\n", strerror(rc)); }Or
Option2)
If (pthread_create(&thread, NULL, &send_pkts, NULL)!=0 )rte_panic("Cannot start send pkts thread\n");Also,
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
test: fix missing check for thread creation
Change this subject line to "test/pdump: fix missing check for thread creation"
Hi, Pattan, fixed in v4, except for "test/pdump", if v4 is OK, please modify it for me, @Ferruh, thanks.
Hi Connor, this patch is on David's domain, he will commit the patch, not me.
Sorry for that, Ferruh, @David, thanks.
Quoted 1 line
.
v4 cover fix missing check for thread creation
In reply to Min Hu (Connor)There exist some thread creation function without result check.
This set of patches add result check and message print out after failure.
Chengwen Feng (2):
telemetry: fix missing check for thread creation
test: fix missing check for thread creation
---
v4:
* change error logging.
v3:
* modify return value check and error logging.
v2:
* fix compiling bugs of missig value.
app/test/process.h | 10 +++++++-- lib/librte_telemetry/telemetry.c | 37 ++++++++++++++++++++++++++++++--- lib/librte_telemetry/telemetry_legacy.c | 11 ++++++++-- 3 files changed, 51 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
PATCH v4 1/2 telemetry: fix missing check for thread creation
From: Chengwen Feng <[email protected]>
Add result check and message print out for thread creation after failure.
--- lib/librte_telemetry/telemetry.c | 37 ++++++++++++++++++++++++++++++--- lib/librte_telemetry/telemetry_legacy.c | 11 ++++++++-- 2 files changed, 43 insertions(+), 5 deletions(-)
lib/librte_telemetry/telemetry.c +34 -3
@@ -350,6 +350,7 @@ socket_listener(void *socket) {while (1 ) {pthread_t th; +int rc;struct socket *s = (struct socket *)socket;int s_accepted =accept (s->sock,NULL ,NULL );if (s_accepted <0 ) {
@@ -366,7 +367,17 @@ socket_listener(void *socket)__atomic_add_fetch (s->num_clients,1 , __ATOMIC_RELAXED); } -pthread_create (&th,NULL , s->fn, (void *)(uintptr_t )s_accepted); + rc =pthread_create (&th,NULL , s->fn, + (void *)(uintptr_t )s_accepted); +if (rc !=0 ) { +TMTY_LOG (ERR ,"Error with create client thread: %s\n" , +strerror (rc)); +close (s_accepted); +if (s->num_clients !=NULL ) +__atomic_sub_fetch (s->num_clients,1 , + __ATOMIC_RELAXED); +continue ; + }pthread_detach (th); }return NULL ;
@@ -425,6 +436,7 @@ static inttelemetry_legacy_init (void) {pthread_t t_old; +int rc;if (num_legacy_callbacks ==1 ) {TMTY_LOG (WARNING ,"No legacy callbacks, legacy socket not created\n" );
@@ -440,7 +452,16 @@ telemetry_legacy_init(void) v1_socket.sock =create_socket (v1_socket.path);if (v1_socket.sock <0 )return -1 ; -pthread_create (&t_old,NULL , socket_listener, &v1_socket); + rc =pthread_create (&t_old,NULL , socket_listener, &v1_socket); +if (rc !=0 ) { +TMTY_LOG (ERR ,"Error with create legcay socket thread: %s\n" , +strerror (rc)); +close (v1_socket.sock); + v1_socket.sock =-1 ; +unlink (v1_socket.path); + v1_socket.path[0 ] ='\0' ; +return -1 ; + }pthread_setaffinity_np (t_old,sizeof (*thread_cpuset), thread_cpuset);TMTY_LOG (DEBUG ,"Legacy telemetry socket initialized ok\n" );
@@ -451,6 +472,7 @@ static inttelemetry_v2_init (void) {pthread_t t_new; +int rc; v2_socket.num_clients = &v2_clients; rte_telemetry_register_cmd("/", list_commands,
@@ -469,7 +491,16 @@ telemetry_v2_init(void) v2_socket.sock =create_socket (v2_socket.path);if (v2_socket.sock <0 )return -1 ; -pthread_create (&t_new,NULL , socket_listener, &v2_socket); + rc =pthread_create (&t_new,NULL , socket_listener, &v2_socket); +if (rc !=0 ) { +TMTY_LOG (ERR ,"Error with create socket thread: %s\n" , +strerror (rc)); +close (v2_socket.sock); + v2_socket.sock =-1 ; +unlink (v2_socket.path); + v2_socket.path[0 ] ='\0' ; +return -1 ; + }pthread_setaffinity_np (t_new,sizeof (*thread_cpuset), thread_cpuset);atexit (unlink_sockets);
lib/librte_telemetry/telemetry_legacy.c +9 -2
@@ -83,6 +83,7 @@ register_client(const char *cmd __rte_unused, const char *params,pthread_t th;char data[BUF_SIZE ];int fd; +int rc;struct sockaddr_un addrs;#endif /* !RTE_EXEC_ENV_WINDOWS */
@@ -112,8 +113,14 @@ register_client(const char *cmd __rte_unused, const char *params,close (fd); return -1; } -pthread_create (&th,NULL , &legacy_client_handler, - (void *)(uintptr_t )fd); + rc =pthread_create (&th,NULL , &legacy_client_handler, + (void *)(uintptr_t )fd); +if (rc !=0 ) { +fprintf (stderr,"Failed to create legacy client thread: %s\n" , +strerror (rc)); +close (fd); +return -1 ; + }#endif /* !RTE_EXEC_ENV_WINDOWS */ return 0 ; }
Signature · 1 line
2.7.4
Re: [dpdk-dev] [PATCH v4 1/2] telemetry: fix missing check for thread creation
Hi Connor,
Quoted 142 lines
-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Friday 16 April 2021 09:18
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Power, Ciara <[email protected]>; Pattan, Reshma <[email protected]>; [email protected]
Subject: [PATCH v4 1/2] telemetry: fix missing check for thread creationFrom: Chengwen Feng <[email protected]>
Add result check and message print out for thread creation after failure.
Fixes b80fe1805eee ("telemetry: introduce backward compatibility")Signed-off-by Chengwen Feng <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
lib/librte_telemetry/telemetry.c| 37
++++++++++++++++++++++++++++++---lib/librte_telemetry/telemetry_legacy.c| 11 ++++++++--2 files changed, 43 insertions(+), 5 deletions(-)lib/librte_telemetry/telemetry.c +12
-1@@ -350,6 +350,7 @@ socket_listener(void *socket) {while (1 ) {pthread_t th; +int rc;struct socket *s = (struct socket *)socket;int s_accepted =accept (s->sock,NULL ,NULL );if (s_accepted <0 ) {@@ -366,7 +367,17 @@ socket_listener(void *socket)__atomic_add_fetch (s->num_clients,1 , __ATOMIC_RELAXED); } -pthread_create (&th,NULL , s->fn, (void *)(uintptr_t)s_accepted); + rc =pthread_create (&th,NULL , s->fn, + (void *)(uintptr_t )s_accepted); +if (rc !=0 ) { + TMTY_LOG(ERR, "Error with create client thread: %s\n", + strerror(rc)); +close (s_accepted); +if (s->num_clients !=NULL ) +__atomic_sub_fetch (s->num_clients,1 , + __ATOMIC_RELAXED); +continue ; + }pthread_detach (th);} return NULL;lib/librte_telemetry/telemetry.c +1
-0@@ -425,6 +436,7 @@ static inttelemetry_legacy_init (void) {pthread_t t_old; +int rc;if (num_legacy_callbacks ==1 ) { TMTY_LOG(WARNING, "No legacy callbacks, legacy socketnot created\n"); @@ -440,7 +452,16 @@
telemetry_legacy_init(void)v1_socket.sock = create_socket(v1_socket.path); if (v1_socket.sock < 0) return -1;lib/librte_telemetry/telemetry.c +3
-1-pthread_create (&t_old,NULL , socket_listener, &v1_socket); + rc =pthread_create (&t_old,NULL , socket_listener, &v1_socket); +if (rc !=0 ) { + TMTY_LOG(ERR, "Error with create legcay socket thread:%s\n",
lib/librte_telemetry/telemetry.c +7
-0+ strerror(rc)); +close (v1_socket.sock); + v1_socket.sock =-1 ; +unlink (v1_socket.path); + v1_socket.path[0 ] ='\0' ; +return -1 ; + }pthread_setaffinity_np(t_old, sizeof(*thread_cpuset), thread_cpuset); TMTY_LOG(DEBUG, "Legacy telemetry socket initialized ok\n"); @@ -451,6 +472,7 @@ static int telemetry_v2_init(void) { pthread_t t_new;lib/librte_telemetry/telemetry.c +1
-0+int rc;v2_socket.num_clients = &v2_clients; rte_telemetry_register_cmd("/", list_commands, @@ -469,7 +491,16 @@ telemetry_v2_init(void) v2_socket.sock = create_socket(v2_socket.path); if (v2_socket.sock < 0) return -1;lib/librte_telemetry/telemetry.c +10
-1-pthread_create (&t_new,NULL , socket_listener, &v2_socket); + rc =pthread_create (&t_new,NULL , socket_listener, &v2_socket); +if (rc !=0 ) { +TMTY_LOG (ERR ,"Error with create socket thread: %s\n" , +strerror (rc)); +close (v2_socket.sock); + v2_socket.sock =-1 ; +unlink (v2_socket.path); + v2_socket.path[0 ] ='\0' ; +return -1 ; + }pthread_setaffinity_np(t_new,
sizeof(*thread_cpuset),thread_cpuset); atexit(unlink_sockets);lib/librte_telemetry/telemetry_legacy.c +9
-2@@ -83,6 +83,7 @@ register_client(const char *cmd __rte_unused, constchar *params, pthread_t th;char data[BUF_SIZE ];int fd; +int rc;struct sockaddr_un addrs;#endif /* !RTE_EXEC_ENV_WINDOWS */ @@ -112,8 +113,14 @@ register_client(const char *cmd __rte_unused,const char *params,close (fd ); return -1; } -pthread_create (&th,NULL , &legacy_client_handler, - (void *)(uintptr_t )fd); + rc =pthread_create (&th,NULL , &legacy_client_handler, + (void *)(uintptr_t )fd); +if (rc !=0 ) { +fprintf (stderr,"Failed to create legacy client thread: %s\n" , +strerror (rc)); +close (fd); +return -1 ; + }#endif /* !RTE_EXEC_ENV_WINDOWS */ return 0 ;
Quoted 3 lines
}
--
2.7.4
I think there is a Fixes tag missing for commit:
With that added in, the code changes look good to me,
Thanks!
PATCH v4 2/2 test: fix missing check for thread creation
In reply to Min Hu (Connor)From: Chengwen Feng <[email protected]>
There was a call for thread create function without result check. Add result check and message print out after failure.
--- app/test/process.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
app/test/process.h +8 -2
@@ -48,6 +48,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value)#ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING pthread_t thread; +int rc;#endif #endif
@@ -126,8 +127,13 @@ process_dup(const char *const argv[], int numargs, const char *env_value)/* parent process does a wait */ #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING -if ((strcmp (env_value,"run_pdump_server_tests" ) ==0 )) -pthread_create (&thread,NULL , &send_pkts,NULL ); +if ((strcmp (env_value,"run_pdump_server_tests" ) ==0 )) { + rc =pthread_create (&thread,NULL , &send_pkts,NULL ); +if (rc !=0 ) { +rte_panic ("Cannot start send pkts thread: %s\n" , +strerror (rc)); + } + }#endif #endif
Signature · 1 line
2.7.4
Re: [dpdk-dev] [PATCH v4 2/2] test: fix missing check for thread creation
Quoted 11 lines
-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Subject: [PATCH v4 2/2] test: fix missing check for thread creationFixes 086eb64db39e ("test/pdump: add unit test for pdump library")Signed-off-by Chengwen Feng <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>
Thomas Monjalon
AppliedQuoted 3 lines
Chengwen Feng (2):
telemetry: fix missing check for thread creation
test: fix missing check for thread creation
Applied, thanks