From: Pierre-Marc Fournier Date: Tue, 27 Oct 2009 22:58:15 +0000 (-0400) Subject: Merge branch 'for-pierre-marc' of git://git.infradead.org/users/jblunck/ust X-Git-Tag: v0.1~71 X-Git-Url: http://git.liburcu.org/?a=commitdiff_plain;h=aa08b4413291fabcbd1b1144377d37034ad361de;hp=-c;p=ust.git Merge branch 'for-pierre-marc' of git://git.infradead.org/users/jblunck/ust Fixed conflicts: include/ust/marker.h --- aa08b4413291fabcbd1b1144377d37034ad361de diff --combined include/ust/marker.h index 0000000,2b5a0c3..5c7d1b3 mode 000000,100644..100644 --- a/include/ust/marker.h +++ b/include/ust/marker.h @@@ -1,0 -1,311 +1,328 @@@ + /* + * Code markup for dynamic and static tracing. + * + * See Documentation/marker.txt. + * + * (C) Copyright 2006 Mathieu Desnoyers + * (C) Copyright 2009 Pierre-Marc Fournier + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + #ifndef _LINUX_MARKER_H + #define _LINUX_MARKER_H + + #include + //ust// #include + #include + //ust// #include + #include + #include ++#include "processor.h" + + //ust// struct module; + //ust// struct task_struct; + struct marker; + + /** + * marker_probe_func - Type of a marker probe function + * @mdata: marker data + * @probe_private: probe private data + * @call_private: call site private data + * @fmt: format string + * @args: variable argument list pointer. Use a pointer to overcome C's + * inability to pass this around as a pointer in a portable manner in + * the callee otherwise. + * + * Type of marker probe functions. They receive the mdata and need to parse the + * format string to recover the variable argument list. + */ + typedef void marker_probe_func(const struct marker *mdata, - void *probe_private, void *call_private, ++ void *probe_private, struct registers *regs, void *call_private, + const char *fmt, va_list *args); + + struct marker_probe_closure { + marker_probe_func *func; /* Callback */ + void *probe_private; /* Private probe data */ + }; + + struct marker { + const char *channel; /* Name of channel where to send data */ + const char *name; /* Marker name */ + const char *format; /* Marker format string, describing the + * variable argument list. + */ + DEFINE_IMV(char, state);/* Immediate value state. */ + char ptype; /* probe type : 0 : single, 1 : multi */ + /* Probe wrapper */ + u16 channel_id; /* Numeric channel identifier, dynamic */ + u16 event_id; /* Numeric event identifier, dynamic */ - void (*call)(const struct marker *mdata, void *call_private, ...); ++ void (*call)(const struct marker *mdata, void *call_private, struct registers *regs, ...); + struct marker_probe_closure single; + struct marker_probe_closure *multi; + const char *tp_name; /* Optional tracepoint name */ + void *tp_cb; /* Optional tracepoint callback */ ++ void *location; /* Address of marker in code */ + } __attribute__((aligned(8))); + + #define CONFIG_MARKERS + #ifdef CONFIG_MARKERS + + #define _DEFINE_MARKER(channel, name, tp_name_str, tp_cb, format) \ + static const char __mstrtab_##channel##_##name[] \ + __attribute__((section("__markers_strings"))) \ + = #channel "\0" #name "\0" format; \ ++ struct registers regs; \ + static struct marker __mark_##channel##_##name \ + __attribute__((section("__markers"), aligned(8))) = \ + { __mstrtab_##channel##_##name, \ + &__mstrtab_##channel##_##name[sizeof(#channel)], \ + &__mstrtab_##channel##_##name[sizeof(#channel) + \ + sizeof(#name)], \ + 0, 0, 0, 0, marker_probe_cb, \ + { __mark_empty_function, NULL}, \ - NULL, tp_name_str, tp_cb } ++ NULL, tp_name_str, tp_cb, NULL }; \ ++ asm (".section __marker_addr,\"aw\",@progbits\n\t" \ ++ _ASM_PTR "%c[marker_struct], (1f)\n\t" \ ++ ".previous\n\t" \ ++ "1:\n\t" \ ++ :: [marker_struct] "i" (&__mark_##channel##_##name));\ ++ save_registers(®s) ++ ++ + + #define DEFINE_MARKER(channel, name, format) \ + _DEFINE_MARKER(channel, name, NULL, NULL, format) + + #define DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format) \ + _DEFINE_MARKER(channel, name, #tp_name, tp_cb, format) + + /* + * Make sure the alignment of the structure in the __markers section will + * not add unwanted padding between the beginning of the section and the + * structure. Force alignment to the same alignment as the section start. + * + * The "generic" argument controls which marker enabling mechanism must be used. + * If generic is true, a variable read is used. + * If generic is false, immediate values are used. + */ + #define __trace_mark(generic, channel, name, call_private, format, args...) \ + do { \ + DEFINE_MARKER(channel, name, format); \ + __mark_check_format(format, ## args); \ + if (!generic) { \ + if (unlikely(imv_read( \ + __mark_##channel##_##name.state))) \ + (*__mark_##channel##_##name.call) \ + (&__mark_##channel##_##name, \ - call_private, ## args); \ ++ call_private, ®s, ## args); \ + } else { \ + if (unlikely(_imv_read( \ + __mark_##channel##_##name.state))) \ + (*__mark_##channel##_##name.call) \ + (&__mark_##channel##_##name, \ - call_private, ## args); \ ++ call_private, ®s, ## args); \ + } \ + } while (0) + + #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \ + format, args...) \ + do { \ + void __check_tp_type(void) \ + { \ + register_trace_##tp_name(tp_cb); \ + } \ + DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format);\ + __mark_check_format(format, ## args); \ + (*__mark_##channel##_##name.call)(&__mark_##channel##_##name, \ - call_private, ## args); \ ++ call_private, ®s, ## args); \ + } while (0) + + extern void marker_update_probe_range(struct marker *begin, + struct marker *end); + + #define GET_MARKER(channel, name) (__mark_##channel##_##name) + + #else /* !CONFIG_MARKERS */ + #define DEFINE_MARKER(channel, name, tp_name, tp_cb, format) + #define __trace_mark(generic, channel, name, call_private, format, args...) \ + __mark_check_format(format, ## args) + #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \ + format, args...) \ + do { \ + void __check_tp_type(void) \ + { \ + register_trace_##tp_name(tp_cb); \ + } \ + __mark_check_format(format, ## args); \ + } while (0) + static inline void marker_update_probe_range(struct marker *begin, + struct marker *end) + { } + #define GET_MARKER(channel, name) + #endif /* CONFIG_MARKERS */ + + /** + * trace_mark - Marker using code patching + * @channel: marker channel (where to send the data), not quoted. + * @name: marker name, not quoted. + * @format: format string + * @args...: variable argument list + * + * Places a marker using optimized code patching technique (imv_read()) + * to be enabled when immediate values are present. + */ + #define trace_mark(channel, name, format, args...) \ + __trace_mark(0, channel, name, NULL, format, ## args) + + /** + * _trace_mark - Marker using variable read + * @channel: marker channel (where to send the data), not quoted. + * @name: marker name, not quoted. + * @format: format string + * @args...: variable argument list + * + * Places a marker using a standard memory read (_imv_read()) to be + * enabled. Should be used for markers in code paths where instruction + * modification based enabling is not welcome. (__init and __exit functions, + * lockdep, some traps, printk). + */ + #define _trace_mark(channel, name, format, args...) \ + __trace_mark(1, channel, name, NULL, format, ## args) + + /** + * trace_mark_tp - Marker in a tracepoint callback + * @channel: marker channel (where to send the data), not quoted. + * @name: marker name, not quoted. + * @tp_name: tracepoint name, not quoted. + * @tp_cb: tracepoint callback. Should have an associated global symbol so it + * is not optimized away by the compiler (should not be static). + * @format: format string + * @args...: variable argument list + * + * Places a marker in a tracepoint callback. + */ + #define trace_mark_tp(channel, name, tp_name, tp_cb, format, args...) \ + __trace_mark_tp(channel, name, NULL, tp_name, tp_cb, format, ## args) + + /** + * MARK_NOARGS - Format string for a marker with no argument. + */ + #define MARK_NOARGS " " + + extern void lock_markers(void); + extern void unlock_markers(void); + + extern void markers_compact_event_ids(void); + + /* To be used for string format validity checking with gcc */ + static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...) + { + } + + #define __mark_check_format(format, args...) \ + do { \ + if (0) \ + ___mark_check_format(format, ## args); \ + } while (0) + + extern marker_probe_func __mark_empty_function; + + extern void marker_probe_cb(const struct marker *mdata, - void *call_private, ...); ++ void *call_private, struct registers *regs, ...); + + /* + * Connect a probe to a marker. + * private data pointer must be a valid allocated memory address, or NULL. + */ + extern int marker_probe_register(const char *channel, const char *name, + const char *format, marker_probe_func *probe, void *probe_private); + + /* + * Returns the private data given to marker_probe_register. + */ + extern int marker_probe_unregister(const char *channel, const char *name, + marker_probe_func *probe, void *probe_private); + /* + * Unregister a marker by providing the registered private data. + */ + extern int marker_probe_unregister_private_data(marker_probe_func *probe, + void *probe_private); + + extern void *marker_get_private_data(const char *channel, const char *name, + marker_probe_func *probe, int num); + + /* + * marker_synchronize_unregister must be called between the last marker probe + * unregistration and the first one of + * - the end of module exit function + * - the free of any resource used by the probes + * to ensure the code and data are valid for any possibly running probes. + */ + #define marker_synchronize_unregister() synchronize_sched() + + struct marker_iter { + //ust// struct module *module; + struct lib *lib; + struct marker *marker; + }; + + extern void marker_iter_start(struct marker_iter *iter); + extern void marker_iter_next(struct marker_iter *iter); + extern void marker_iter_stop(struct marker_iter *iter); + extern void marker_iter_reset(struct marker_iter *iter); + extern int marker_get_iter_range(struct marker **marker, struct marker *begin, + struct marker *end); + + extern void marker_update_process(void); + extern int is_marker_enabled(const char *channel, const char *name); + + //ust// #ifdef CONFIG_MARKERS_USERSPACE + //ust// extern void exit_user_markers(struct task_struct *p); + //ust// #else + //ust// static inline void exit_user_markers(struct task_struct *p) + //ust// { + //ust// } + //ust// #endif + ++struct marker_addr { ++ struct marker *marker; ++ void *addr; ++}; + + struct lib { + struct marker *markers_start; ++ struct marker_addr *markers_addr_start; + int markers_count; + struct list_head list; + }; + -extern int marker_register_lib(struct marker *markers_start, - int markers_count); - -#define MARKER_LIB \ -extern struct marker __start___markers[] __attribute__((visibility("hidden"))); \ -extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); \ - \ -static void __attribute__((constructor)) __markers__init(void) \ -{ \ - marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));\ ++extern int marker_register_lib(struct marker *markers_start, struct marker_addr *marker_addr_start, int markers_count); ++ ++#define MARKER_LIB \ ++extern struct marker __start___markers[] __attribute__((visibility("hidden"))); \ ++extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); \ ++extern struct marker_addr __start___marker_addr[] __attribute__((visibility("hidden"))); \ ++extern struct marker_addr __stop___marker_addr[] __attribute__((visibility("hidden"))); \ ++ \ ++static void __attribute__((constructor)) __markers__init(void) \ ++{ \ ++ marker_register_lib(__start___markers, __start___marker_addr, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); \ + } + + extern void marker_set_new_marker_cb(void (*cb)(struct marker *)); + extern void init_markers(void); + + #endif diff --combined libust/marker.c index d4514f1,8690d2b..b543b16 --- a/libust/marker.c +++ b/libust/marker.c @@@ -33,9 -33,9 +33,9 @@@ #define _LGPL_SOURCE #include - #include "kernelcompat.h" + #include - #include "marker.h" + #include #include "usterr.h" #include "channels.h" #include "tracercore.h" @@@ -43,8 -43,6 +43,8 @@@ extern struct marker __start___markers[] __attribute__((visibility("hidden"))); extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); +extern struct marker_addr __start___marker_addr[] __attribute__((visibility("hidden"))); +extern struct marker_addr __stop___marker_addr[] __attribute__((visibility("hidden"))); /* Set to 1 to enable marker debug output */ static const int marker_debug; @@@ -89,7 -87,7 +89,7 @@@ struct marker_entry char *format; char *name; /* Probe wrapper */ - void (*call)(const struct marker *mdata, void *call_private, ...); + void (*call)(const struct marker *mdata, void *call_private, struct registers *regs, ...); struct marker_probe_closure single; struct marker_probe_closure *multi; int refcount; /* Number of times armed. 0 if disarmed. */ @@@ -125,7 -123,7 +125,7 @@@ static void marker_update_processes(voi * operations that modifies the execution flow of preemptible code. */ notrace void __mark_empty_function(const struct marker *mdata, - void *probe_private, void *call_private, const char *fmt, va_list *args) + void *probe_private, struct registers *regs, void *call_private, const char *fmt, va_list *args) { } //ust// EXPORT_SYMBOL_GPL(__mark_empty_function); @@@ -141,7 -139,7 +141,7 @@@ * rcu_dereference() for the pointer read. */ notrace void marker_probe_cb(const struct marker *mdata, - void *call_private, ...) + void *call_private, struct registers *regs, ...) { va_list args; char ptype; @@@ -162,8 -160,8 +162,8 @@@ /* Must read the ptr before private data. They are not data * dependant, so we put an explicit smp_rmb() here. */ smp_rmb(); - va_start(args, call_private); - func(mdata, mdata->single.probe_private, call_private, + va_start(args, regs); + func(mdata, mdata->single.probe_private, regs, call_private, mdata->format, &args); va_end(args); } else { @@@ -183,9 -181,9 +183,9 @@@ */ smp_read_barrier_depends(); for (i = 0; multi[i].func; i++) { - va_start(args, call_private); + va_start(args, regs); multi[i].func(mdata, multi[i].probe_private, - call_private, mdata->format, &args); + regs, call_private, mdata->format, &args); va_end(args); } } @@@ -202,7 -200,7 +202,7 @@@ * Should be connected to markers "MARK_NOARGS". */ static notrace void marker_probe_cb_noarg(const struct marker *mdata, - void *call_private, ...) + void *call_private, struct registers *regs, ...) { va_list args; /* not initialized */ char ptype; @@@ -218,7 -216,7 +218,7 @@@ /* Must read the ptr before private data. They are not data * dependant, so we put an explicit smp_rmb() here. */ smp_rmb(); - func(mdata, mdata->single.probe_private, call_private, + func(mdata, mdata->single.probe_private, regs, call_private, mdata->format, &args); } else { struct marker_probe_closure *multi; @@@ -237,7 -235,7 +237,7 @@@ */ smp_read_barrier_depends(); for (i = 0; multi[i].func; i++) - multi[i].func(mdata, multi[i].probe_private, + multi[i].func(mdata, multi[i].probe_private, regs, call_private, mdata->format, &args); } //ust// rcu_read_unlock_sched_notrace(); @@@ -825,7 -823,6 +825,7 @@@ int marker_probe_register(const char *c } mutex_unlock(&markers_mutex); + /* Activate marker if necessary */ marker_update_probes(); mutex_lock(&markers_mutex); @@@ -1498,22 -1495,15 +1498,22 @@@ static void new_markers(struct marker * } } -int marker_register_lib(struct marker *markers_start, int markers_count) +int marker_register_lib(struct marker *markers_start, struct marker_addr *marker_addr_start, int markers_count) { struct lib *pl; + struct marker_addr *addr; pl = (struct lib *) malloc(sizeof(struct lib)); pl->markers_start = markers_start; + pl->markers_addr_start = marker_addr_start; pl->markers_count = markers_count; + lock_markers(); + for(addr = marker_addr_start; addr < marker_addr_start + markers_count; addr++) + addr->marker->location = addr->addr; + unlock_markers(); + /* FIXME: maybe protect this with its own mutex? */ lock_markers(); list_add(&pl->list, &libs); @@@ -1542,8 -1532,8 +1542,8 @@@ static int initialized = 0 void __attribute__((constructor)) init_markers(void) { if(!initialized) { - marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); - DBG("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers); + marker_register_lib(__start___markers, __start___marker_addr, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); + //DBG("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers); initialized = 1; } } diff --combined libust/serialize.c index f9e45b6,99d4dce..beaf639 --- a/libust/serialize.c +++ b/libust/serialize.c @@@ -32,7 -32,7 +32,7 @@@ #include #include - #include "kernelcompat.h" + #include #define _LGPL_SOURCE #include #include @@@ -583,8 -583,7 +583,8 @@@ void ltt_write_event_data(struct rchan_ notrace void ltt_vtrace(const struct marker *mdata, void *probe_data, - void *call_data, const char *fmt, va_list *args) + struct registers *regs, void *call_data, + const char *fmt, va_list *args) { int largest_align, ret; struct ltt_active_marker *pdata; @@@ -698,13 -697,12 +698,13 @@@ } notrace void ltt_trace(const struct marker *mdata, void *probe_data, - void *call_data, const char *fmt, ...) + struct registers *regs, void *call_data, + const char *fmt, ...) { va_list args; va_start(args, fmt); - ltt_vtrace(mdata, probe_data, call_data, fmt, &args); + ltt_vtrace(mdata, probe_data, regs, call_data, fmt, &args); va_end(args); } diff --combined libust/tracectl.c index ed90257,3d3bd48..e28b315 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@@ -29,9 -29,9 +29,9 @@@ #include - #include "marker.h" + #include #include "tracer.h" - #include "localerr.h" + #include "usterr.h" #include "ustcomm.h" #include "relay.h" /* FIXME: remove */ #include "marker-control.h" @@@ -117,7 -117,7 +117,7 @@@ static void print_markers(FILE *fp marker_iter_start(&iter); while(iter.marker) { - fprintf(fp, "marker: %s/%s %d \"%s\"\n", iter.marker->channel, iter.marker->name, (int)imv_read(iter.marker->state), iter.marker->format); + fprintf(fp, "marker: %s/%s %d \"%s\" %p\n", iter.marker->channel, iter.marker->name, (int)imv_read(iter.marker->state), iter.marker->format, iter.marker->location); marker_iter_next(&iter); } unlock_markers(); @@@ -837,7 -837,7 +837,7 @@@ static void auto_probe_connect(struct m if(result && result != -EEXIST) ERR("ltt_marker_connect (marker = %s/%s, errno = %d)", m->channel, m->name, -result); - DBG("auto connected marker %s %s to probe default", m->channel, m->name); + DBG("auto connected marker %s (addr: %p) %s to probe default", m->channel, m, m->name); } diff --combined libust/tracer.h index b2ac930,cb84dad..502cdcc --- a/libust/tracer.h +++ b/libust/tracer.h @@@ -27,12 -27,12 +27,12 @@@ #include #include //#include "list.h" - #include "kernelcompat.h" + #include #include "buffer.h" #include "relay.h" #include "channels.h" #include "tracercore.h" - #include "marker.h" + #include /* Number of bytes to log with a read/write event */ #define LTT_LOG_RW_SIZE 32L @@@ -110,9 -110,9 +110,9 @@@ struct ltt_active_marker struct marker; //ust// extern void ltt_vtrace(const struct marker *mdata, void *probe_data, - void *call_data, const char *fmt, va_list *args); + struct registers *regs, void *call_data, const char *fmt, va_list *args); extern void ltt_trace(const struct marker *mdata, void *probe_data, - void *call_data, const char *fmt, ...); + struct registers *regs, void *call_data, const char *fmt, ...); /* * Unique ID assigned to each registered probe. diff --combined ustd/ustd.c index 858bdf5,0026c3b..bfa6352 --- a/ustd/ustd.c +++ b/ustd/ustd.c @@@ -33,9 -33,8 +33,8 @@@ #include #include "ustd.h" - #include "localerr.h" + #include "usterr.h" #include "ustcomm.h" - #include "share.h" /* return value: 0 = subbuffer is finished, it won't produce data anymore * 1 = got subbuffer successfully @@@ -542,24 -541,6 +541,24 @@@ void sigterm_handler(int sig terminate_req = 1; } +static int write_pidfile(const char *file_name, pid_t pid) +{ + FILE *pidfp; + + pidfp = fopen(file_name, "w+"); + if(!pidfp) { + PERROR("fopen (%s)", pidfile); + WARN("killing child process"); + return -1; + } + + fprintf(pidfp, "%d\n", pid); + + fclose(pidfp); + + return 0; +} + int start_ustd(int fd) { struct ustcomm_ustd ustd; @@@ -604,15 -585,6 +603,15 @@@ return 1; } + /* Write pidfile */ + if(pidfile) { + result = write_pidfile(pidfile, getpid()); + if(result == -1) { + ERR("failed to write pidfile"); + return 1; + } + } + /* Notify parent that we are successfully started. */ if(fd != -1) { /* write any one character */ @@@ -701,6 -673,26 +700,6 @@@ int start_ustd_daemon( char buf; FILE *pidfp; - /* It's important to write the file *before* - * the parent ends, because the file may be - * read as soon as the parent ends. - */ - if(pidfile) { - pidfp = fopen(pidfile, "w+"); - if(!pidfp) { - PERROR("fopen (%s)", pidfile); - WARN("killing child process"); - result = kill(child_pid, SIGTERM); - if(result == -1) { - PERROR("kill"); - } - return -1; - } - - fprintf(pidfp, "%d\n", child_pid); - fclose(pidfp); - } - result = read(fd[0], &buf, 1); if(result == -1) { PERROR("read");