| 1 | /***************************************************************************** |
| 2 | * ltt-usertrace.h |
| 3 | * |
| 4 | * LTT userspace tracing header |
| 5 | * |
| 6 | * Mathieu Desnoyers, March 2006 |
| 7 | */ |
| 8 | |
| 9 | #ifndef _LTT_USERTRACE_H |
| 10 | #define _LTT_USERTRACE_H |
| 11 | |
| 12 | #include <errno.h> |
| 13 | #include <syscall.h> |
| 14 | #include <linux/unistd.h> |
| 15 | #include <string.h> |
| 16 | #include <sys/types.h> |
| 17 | #include <stdint.h> |
| 18 | #ifdef powerpc |
| 19 | #define __KERNEL__ /* Ugly hack : atomic.h is broken */ |
| 20 | #endif |
| 21 | #include <asm/atomic.h> |
| 22 | #include "ltt/ltt-usertrace-ppc.h" |
| 23 | #ifdef powerpc |
| 24 | #undef __KERNEL__ /* Ugly hack : atomic.h is broken */ |
| 25 | #endif |
| 26 | |
| 27 | #ifndef min |
| 28 | #define min(a,b) ((a)<(b)?(a):(b)) |
| 29 | #endif |
| 30 | |
| 31 | #ifdef i386 |
| 32 | #define __NR_ltt_trace_generic 311 |
| 33 | #define __NR_ltt_register_generic 312 |
| 34 | #undef NR_syscalls |
| 35 | #define NR_syscalls 313 |
| 36 | #endif |
| 37 | |
| 38 | #ifdef powerpc |
| 39 | #define __NR_ltt_trace_generic 283 |
| 40 | #define __NR_ltt_register_generic 284 |
| 41 | #undef NR_syscalls |
| 42 | #define NR_syscalls 285 |
| 43 | #endif |
| 44 | |
| 45 | //FIXME : setup for ARM |
| 46 | //FIXME : setup for MIPS |
| 47 | |
| 48 | #ifndef _LIBC |
| 49 | // Put in bits/syscall.h |
| 50 | #define SYS_ltt_trace_generic __NR_ltt_trace_generic |
| 51 | #define SYS_ltt_register_generic __NR_ltt_register_generic |
| 52 | #endif |
| 53 | |
| 54 | #define FACNAME_LEN 32 |
| 55 | |
| 56 | /* LTT userspace tracing is non blocking by default when buffers are full */ |
| 57 | #ifndef LTT_BLOCKING |
| 58 | #define LTT_BLOCKING 0 |
| 59 | #endif //LTT_BLOCKING |
| 60 | |
| 61 | typedef unsigned int ltt_facility_t; |
| 62 | |
| 63 | struct user_facility_info { |
| 64 | char name[FACNAME_LEN]; |
| 65 | unsigned int num_events; |
| 66 | size_t alignment; |
| 67 | uint32_t checksum; |
| 68 | size_t int_size; |
| 69 | size_t long_size; |
| 70 | size_t pointer_size; |
| 71 | size_t size_t_size; |
| 72 | }; |
| 73 | |
| 74 | static inline __attribute__((no_instrument_function)) |
| 75 | _syscall5(int, ltt_trace_generic, unsigned int, facility_id, |
| 76 | unsigned int, event_id, void *, data, size_t, data_size, int, blocking) |
| 77 | static inline __attribute__((no_instrument_function)) |
| 78 | _syscall2(int, ltt_register_generic, unsigned int *, facility_id, |
| 79 | const struct user_facility_info *, info) |
| 80 | |
| 81 | #ifndef LTT_PACK |
| 82 | /* Calculate the offset needed to align the type */ |
| 83 | static inline unsigned int __attribute__((no_instrument_function)) |
| 84 | ltt_align(size_t align_drift, |
| 85 | size_t size_of_type) |
| 86 | { |
| 87 | size_t alignment = min(sizeof(void*), size_of_type); |
| 88 | |
| 89 | return ((alignment - align_drift) & (alignment-1)); |
| 90 | } |
| 91 | #define LTT_ALIGN |
| 92 | #else |
| 93 | static inline unsigned int __attribute__((no_instrument_function)) |
| 94 | ltt_align(size_t align_drift, |
| 95 | size_t size_of_type) |
| 96 | { |
| 97 | return 0; |
| 98 | } |
| 99 | #define LTT_ALIGN __attribute__((packed)) |
| 100 | #endif //LTT_PACK |
| 101 | |
| 102 | #ifdef LTT_TRACE_FAST |
| 103 | #include <ltt/ltt-usertrace-fast.h> |
| 104 | #endif //LTT_TRACE_FAST |
| 105 | |
| 106 | #endif //_LTT_USERTRACE_H |
| 107 | |
| 108 | |