If a sigterm is raised once we have installed our own handler but threads are not already created, we deadlock in the shutdown function.
So, we don't wait anymore for thread until all threads has been created which is not a big issue because we don't really care of gathering all logs and traces before exiting rt-app in this case as the use case has not started yet.
Reported-by: Daniel Lezcano daniel.lezcano@linaro.org Signed-off-by: Vincent Guittot vincent.guittot@linaro.org --- src/rt-app.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/rt-app.c b/src/rt-app.c index f14f228..bbc8594 100644 --- a/src/rt-app.c +++ b/src/rt-app.c @@ -32,6 +32,7 @@ static int errno; static volatile int continue_running; static pthread_t *threads; static int nthreads; +static int running_threads; static int p_load; rtapp_options_t opts;
@@ -353,6 +354,10 @@ static void shutdown(int sig) { int i; + + if(!continue_running) + return; + /* notify threads, join them, then exit */ continue_running = 0;
@@ -364,7 +369,7 @@ shutdown(int sig) }
/* wait up all waiting threads */ - for (i = 0; i < nthreads; i++) + for (i = 0; i < running_threads; i++) { pthread_join(threads[i], NULL); } @@ -634,6 +639,7 @@ int main(int argc, char* argv[]) /* allocated threads */ nthreads = opts.nthreads; threads = malloc(nthreads * sizeof(pthread_t)); + running_threads = 0;
/* install a signal handler for proper shutdown */ signal(SIGQUIT, shutdown); @@ -664,6 +670,7 @@ int main(int argc, char* argv[]) log_ftrace(ft_data.marker_fd, "main creates threads\n"); }
+ /* Init global running_variable */ continue_running = 1;
/* Needs to calibrate 'calib_cpu' core */ @@ -835,6 +842,7 @@ int main(int argc, char* argv[]) (void*) tdata)) goto exit_err; } + running_threads = nthreads;
if (opts.duration > 0) { sleep(opts.duration);
Hi Daniel,
Could you check that thispatch fix your issue ?
Regards, Vincent
On 11 September 2015 at 13:54, Vincent Guittot vincent.guittot@linaro.org wrote:
If a sigterm is raised once we have installed our own handler but threads are not already created, we deadlock in the shutdown function.
So, we don't wait anymore for thread until all threads has been created which is not a big issue because we don't really care of gathering all logs and traces before exiting rt-app in this case as the use case has not started yet.
Reported-by: Daniel Lezcano daniel.lezcano@linaro.org Signed-off-by: Vincent Guittot vincent.guittot@linaro.org
src/rt-app.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/rt-app.c b/src/rt-app.c index f14f228..bbc8594 100644 --- a/src/rt-app.c +++ b/src/rt-app.c @@ -32,6 +32,7 @@ static int errno; static volatile int continue_running; static pthread_t *threads; static int nthreads; +static int running_threads; static int p_load; rtapp_options_t opts;
@@ -353,6 +354,10 @@ static void shutdown(int sig) { int i;
if(!continue_running)
return;
/* notify threads, join them, then exit */ continue_running = 0;
@@ -364,7 +369,7 @@ shutdown(int sig) }
/* wait up all waiting threads */
for (i = 0; i < nthreads; i++)
for (i = 0; i < running_threads; i++) { pthread_join(threads[i], NULL); }
@@ -634,6 +639,7 @@ int main(int argc, char* argv[]) /* allocated threads */ nthreads = opts.nthreads; threads = malloc(nthreads * sizeof(pthread_t));
running_threads = 0; /* install a signal handler for proper shutdown */ signal(SIGQUIT, shutdown);
@@ -664,6 +670,7 @@ int main(int argc, char* argv[]) log_ftrace(ft_data.marker_fd, "main creates threads\n"); }
/* Init global running_variable */ continue_running = 1; /* Needs to calibrate 'calib_cpu' core */
@@ -835,6 +842,7 @@ int main(int argc, char* argv[]) (void*) tdata)) goto exit_err; }
running_threads = nthreads; if (opts.duration > 0) { sleep(opts.duration);
-- 1.9.1
On 09/11/2015 01:54 PM, Vincent Guittot wrote:
Hi Vincent,
If a sigterm is raised once we have installed our own handler but threads are not already created, we deadlock in the shutdown function.
So, we don't wait anymore for thread until all threads has been created which is not a big issue because we don't really care of gathering all logs and traces before exiting rt-app in this case as the use case has not started yet.
Reported-by: Daniel Lezcano daniel.lezcano@linaro.org Signed-off-by: Vincent Guittot vincent.guittot@linaro.org
src/rt-app.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/rt-app.c b/src/rt-app.c index f14f228..bbc8594 100644 --- a/src/rt-app.c +++ b/src/rt-app.c @@ -32,6 +32,7 @@ static int errno; static volatile int continue_running; static pthread_t *threads; static int nthreads; +static int running_threads; static int p_load; rtapp_options_t opts;
@@ -353,6 +354,10 @@ static void shutdown(int sig) { int i;
- if(!continue_running)
return;
if you use a global variable in a signal handler you should use the type:
static volatile sig_atomic_t
On 11 September 2015 at 14:16, Daniel Lezcano daniel.lezcano@linaro.org wrote:
On 09/11/2015 01:54 PM, Vincent Guittot wrote:
Hi Vincent,
If a sigterm is raised once we have installed our own handler but threads are not already created, we deadlock in the shutdown function.
So, we don't wait anymore for thread until all threads has been created which is not a big issue because we don't really care of gathering all logs and traces before exiting rt-app in this case as the use case has not started yet.
Reported-by: Daniel Lezcano daniel.lezcano@linaro.org Signed-off-by: Vincent Guittot vincent.guittot@linaro.org
src/rt-app.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/rt-app.c b/src/rt-app.c index f14f228..bbc8594 100644 --- a/src/rt-app.c +++ b/src/rt-app.c @@ -32,6 +32,7 @@ static int errno; static volatile int continue_running; static pthread_t *threads; static int nthreads; +static int running_threads; static int p_load; rtapp_options_t opts;
@@ -353,6 +354,10 @@ static void shutdown(int sig) { int i;
if(!continue_running)
return;
if you use a global variable in a signal handler you should use the type:
static volatile sig_atomic_t
good point.
Beside that, is the sequence working for you or you still see a crash ?
-- http://www.linaro.org/ Linaro.org │ Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro Facebook | http://twitter.com/#!/linaroorg Twitter | http://www.linaro.org/linaro-blog/ Blog
On 09/11/2015 02:39 PM, Vincent Guittot wrote:
[ ... ]
@@ -353,6 +354,10 @@ static void shutdown(int sig) { int i;
if(!continue_running)
return;
if you use a global variable in a signal handler you should use the type:
static volatile sig_atomic_t
good point.
Beside that, is the sequence working for you or you still see a crash ?
The sequence is working for me now.
Thanks for fixing the bug.
-- Daniel