From 92f441a729c923fa6e27fad038918a42a1c76ef0 Mon Sep 17 00:00:00 2001 From: compudj Date: Thu, 26 Jan 2006 14:24:48 +0000 Subject: [PATCH] tls git-svn-id: http://ltt.polymtl.ca/svn@1492 04897980-b3bd-0310-b5e0-8ef037075253 --- usertrace/Makefile | 5 +- usertrace/lttng_usertrace.c | 93 +++++++++++++++++++++++++++++++++++++ usertrace/lttng_usertrace.h | 1 + usertrace/test.c | 42 +++++++++++++++++ 4 files changed, 140 insertions(+), 1 deletion(-) diff --git a/usertrace/Makefile b/usertrace/Makefile index 049c44bf..83c3b89f 100644 --- a/usertrace/Makefile +++ b/usertrace/Makefile @@ -1,6 +1,9 @@ + +CC=gcc + test: test.c lttng_usertrace.c - $(CC) $(CFLAGS) -o $@ $^ + $(CC) $(CFLAGS) -lpthread -o $@ $^ .PHONY : clean diff --git a/usertrace/lttng_usertrace.c b/usertrace/lttng_usertrace.c index b4de2676..f989667f 100644 --- a/usertrace/lttng_usertrace.c +++ b/usertrace/lttng_usertrace.c @@ -9,19 +9,92 @@ #include #include #include +#include #include #include #include +#include +#include +#include +#include +#include #include "lttng_usertrace.h" +#define MAX_TRACES 16 + +struct ltt_buf { + void *start; + atomic_t offset; + atomic_t reserve_count; + atomic_t commit_count; + + atomic_t events_lost; +}; + +struct lttng_trace_info { + struct lttng_trace_info *next; + int active:1; + struct { + struct ltt_buf facilities; + struct ltt_buf cpu; + } channel; +}; + + +/* TLS for the trace info */ +static __thread struct lttng_trace_info *test; +static __thread struct lttng_trace_info lttng_trace_info[MAX_TRACES]; + + /* signal handler */ void __lttng_sig_trace_handler(int signo) { + int ret; + sigset_t set, oldset; + printf("LTTng Sig handler : pid : %lu\n", getpid()); + + /* Disable signals */ + ret = sigfillset(&set); + if(ret) { + printf("Error in sigfillset\n"); + exit(1); + } + + ret = sigprocmask(SIG_BLOCK, &set, &oldset); + if(ret) { + printf("Error in sigprocmask\n"); + exit(1); + } + + /* Get all the new traces */ +#if 0 + do { + /* FIXME : allocate the trace structure somewhere : thread private */ + ret = ltt_update(addr, &active, &filter); + + if(ret) { + printf("Error in ltt_update system call\n"); + exit(1); + } + } while(addr); + +#endif //0 + /* Enable signals */ + ret = sigprocmask(SIG_SETMASK, &oldset, NULL); + if(ret) { + printf("Error in sigprocmask\n"); + exit(1); + } + } +void __lttng_init_trace_info(void) +{ + memset(<tng_trace_info, 0, MAX_TRACES*sizeof(struct lttng_trace_info)); +} void __attribute__((constructor)) __lttng_user_init(void) { @@ -30,6 +103,9 @@ void __attribute__((constructor)) __lttng_user_init(void) printf("LTTng user init\n"); + /* Init trace info */ + __lttng_init_trace_info(); + /* Activate the signal */ act.sa_handler = __lttng_sig_trace_handler; err = sigemptyset(&(act.sa_mask)); @@ -39,10 +115,27 @@ void __attribute__((constructor)) __lttng_user_init(void) err = sigaction(SIGRTMIN+3, &act, NULL); if(err) perror("Error with sigaction"); + /* TEST */ + err = ltt_switch((unsigned long)NULL); + if(err) { + printf("Error in ltt_switch system call\n"); + exit(1); + } + /* Make the first ltt_update system call */ err = ltt_update(1, NULL, NULL); if(err) { printf("Error in ltt_update system call\n"); exit(1); } + + /* Make some ltt_switch syscalls */ + err = ltt_switch((unsigned long)NULL); + if(err) { + printf("Error in ltt_switch system call\n"); + exit(1); + } + + + } diff --git a/usertrace/lttng_usertrace.h b/usertrace/lttng_usertrace.h index c16aa781..b4aa8f3b 100644 --- a/usertrace/lttng_usertrace.h +++ b/usertrace/lttng_usertrace.h @@ -26,6 +26,7 @@ void __lttng_sig_trace_handler(int signo); +static inline _syscall1(int, ltt_switch, unsigned long, addr) static inline _syscall3(int, ltt_update, unsigned long, addr, int *, active, int *, filter) #endif //_LTTNG_USERTRACE_H diff --git a/usertrace/test.c b/usertrace/test.c index 0154f3ca..9c772973 100644 --- a/usertrace/test.c +++ b/usertrace/test.c @@ -1,13 +1,55 @@ +#include +#include +#include +#include + #include "lttng_usertrace.h" + + +void *thr1(void *arg) +{ + printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid()); + + while(1) {} + + return ((void*)1); + +} + +void *thr2(void *arg) +{ + while(1) { + printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid()); + sleep(2); + } + return ((void*)2); +} + + int main() { + int err; + pthread_t tid1, tid2; + void *tret; + + err = pthread_create(&tid1, NULL, thr1, NULL); + if(err!=0) exit(1); + + err = pthread_create(&tid2, NULL, thr2, NULL); + if(err!=0) exit(1); while(1) { } + + err = pthread_join(tid1, &tret); + if(err!= 0) exit(1); + + err = pthread_join(tid2, &tret); + if(err!= 0) exit(1); return 0; } -- 2.34.1