2 /* LTTng user-space tracing code
4 * Copyright 2006 Mathieu Desnoyers
21 #include <asm/atomic.h>
22 #include "lttng_usertrace.h"
29 atomic_t reserve_count
;
30 atomic_t commit_count
;
35 struct lttng_trace_info
{
39 struct ltt_buf facilities
;
45 /* TLS for the trace info
46 * http://www.dis.com/gnu/gcc/C--98-Thread-Local-Edits.html
48 * Add after paragraph 4
50 * The storage for an object of thread storage duration shall be statically
51 * initialized before the first statement of the thread startup function. An
52 * object of thread storage duration shall not require dynamic
54 * GCC extention permits init of a range.
57 static __thread
struct lttng_trace_info lttng_trace_info
[MAX_TRACES
] =
58 { [ 0 ... MAX_TRACES
-1 ].active
= 0,
59 [ 0 ... MAX_TRACES
-1 ].filter
= 0,
60 [ 0 ... MAX_TRACES
-1 ].channel
=
71 static void lttng_get_new_info(void)
73 unsigned long cpu_addr
, fac_addr
;
74 unsigned int i
, first_empty
;
78 /* Get all the new traces */
80 cpu_addr
= fac_addr
= 0;
82 ret
= ltt_update(&cpu_addr
, &fac_addr
, &active
, &filter
);
84 printf("LTTng : error in ltt_update\n");
88 if(!cpu_addr
|| !fac_addr
) break;
90 first_empty
= MAX_TRACES
;
91 /* Try to find the trace */
92 for(i
=0;i
<MAX_TRACES
;i
++) {
93 if(i
<first_empty
&& !lttng_trace_info
[i
].channel
.cpu
.start
)
96 (unsigned long)lttng_trace_info
[i
].channel
.cpu
.start
&&
98 (unsigned long)lttng_trace_info
[i
].channel
.facilities
.start
) {
100 lttng_trace_info
[i
].filter
= filter
;
101 lttng_trace_info
[i
].active
= active
;
105 if(i
== MAX_TRACES
) {
106 /* Not found. Must take an empty slot */
107 if(first_empty
== MAX_TRACES
) {
109 "LTTng WARNING : too many traces requested for pid %d by the kernel.\n"
110 " Compilation defined maximum is %u\n",
111 getpid(), MAX_TRACES
);
114 lttng_trace_info
[first_empty
].channel
.cpu
.start
= (void*)cpu_addr
;
115 lttng_trace_info
[first_empty
].channel
.facilities
.start
=
117 lttng_trace_info
[first_empty
].filter
= filter
;
118 lttng_trace_info
[first_empty
].active
= active
;
126 void __lttng_sig_trace_handler(int signo
)
129 sigset_t set
, oldset
;
131 printf("LTTng signal handler : thread id : %lu, pid %lu\n", pthread_self(), getpid());
133 /* Disable signals */
134 ret
= sigfillset(&set
);
136 printf("Error in sigfillset\n");
140 ret
= sigprocmask(SIG_BLOCK
, &set
, &oldset
);
142 printf("Error in sigprocmask\n");
148 ret
= sigprocmask(SIG_SETMASK
, &oldset
, NULL
);
150 printf("Error in sigprocmask\n");
157 static void thread_init(void)
159 lttng_get_new_info();
162 /* Make some ltt_switch syscalls */
163 err
= ltt_switch((unsigned long)NULL
);
165 printf("Error in ltt_switch system call\n");
170 void __attribute__((constructor
)) __lttng_user_init(void)
172 static struct sigaction act
;
175 printf("LTTng user init\n");
177 /* Activate the signal */
178 act
.sa_handler
= __lttng_sig_trace_handler
;
179 err
= sigemptyset(&(act
.sa_mask
));
180 if(err
) perror("Error with sigemptyset");
181 err
= sigaddset(&(act
.sa_mask
), SIGRTMIN
+3);
182 if(err
) perror("Error with sigaddset");
183 err
= sigaction(SIGRTMIN
+3, &act
, NULL
);
184 if(err
) perror("Error with sigaction");
190 void lttng_thread_init(void)