Skip to content

Commit af2962d

Browse files
walaclenticularis39
authored andcommitted
rtla: Make stop_tracing variable volatile
The stop_tracing global variable is accessed from both the signal handler context and the main program flow without synchronization. This creates a potential race condition where compiler optimizations could cache the variable value in registers, preventing the signal handler's updates from being visible to other parts of the program. Add the volatile qualifier to stop_tracing in both common.c and common.h to ensure all accesses to this variable bypass compiler optimizations and read directly from memory. This guarantees that when the signal handler sets stop_tracing, the change is immediately visible to the main program loop, preventing potential hangs or delayed shutdown when termination signals are received. Signed-off-by: Wander Lairson Costa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Tomas Glozar <[email protected]>
1 parent 02689ae commit af2962d

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

tools/tracing/rtla/src/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "common.h"
1111

1212
struct trace_instance *trace_inst;
13-
int stop_tracing;
13+
volatile int stop_tracing;
1414

1515
static void stop_trace(int sig)
1616
{

tools/tracing/rtla/src/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct osnoise_context {
5454
};
5555

5656
extern struct trace_instance *trace_inst;
57-
extern int stop_tracing;
57+
extern volatile int stop_tracing;
5858

5959
struct hist_params {
6060
char no_irq;

0 commit comments

Comments
 (0)