From: Mathieu Desnoyers Date: Mon, 28 Nov 2011 12:42:14 +0000 (-0500) Subject: lttng wrappers X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=69e1242eaab021eb6a4110a671af1e443fbf704d;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git lttng wrappers Implement wrappers for compatibility with older kernel versions and kernels with had the libringbuffer (old) patchset applied. Signed-off-by: Mathieu Desnoyers Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/lttng/wrapper/ftrace.h b/drivers/staging/lttng/wrapper/ftrace.h new file mode 100644 index 000000000000..ace33c54100d --- /dev/null +++ b/drivers/staging/lttng/wrapper/ftrace.h @@ -0,0 +1,70 @@ +#ifndef _LTT_WRAPPER_FTRACE_H +#define _LTT_WRAPPER_FTRACE_H + +/* + * Copyright (C) 2011 Mathieu Desnoyers (mathieu.desnoyers@efficios.com) + * + * wrapper around vmalloc_sync_all. Using KALLSYMS to get its address when + * available, else we need to have a kernel that exports this function to GPL + * modules. + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#include + +#ifdef CONFIG_KALLSYMS + +#include +#include "kallsyms.h" + +static inline +int wrapper_register_ftrace_function_probe(char *glob, + struct ftrace_probe_ops *ops, void *data) +{ + int (*register_ftrace_function_probe_sym)(char *glob, + struct ftrace_probe_ops *ops, void *data); + + register_ftrace_function_probe_sym = (void *) kallsyms_lookup_funcptr("register_ftrace_function_probe"); + if (register_ftrace_function_probe_sym) { + return register_ftrace_function_probe_sym(glob, ops, data); + } else { + printk(KERN_WARNING "LTTng: register_ftrace_function_probe symbol lookup failed.\n"); + return -EINVAL; + } +} + +static inline +void wrapper_unregister_ftrace_function_probe(char *glob, + struct ftrace_probe_ops *ops, void *data) +{ + void (*unregister_ftrace_function_probe_sym)(char *glob, + struct ftrace_probe_ops *ops, void *data); + + unregister_ftrace_function_probe_sym = (void *) kallsyms_lookup_funcptr("unregister_ftrace_function_probe"); + if (unregister_ftrace_function_probe_sym) { + unregister_ftrace_function_probe_sym(glob, ops, data); + } else { + printk(KERN_WARNING "LTTng: unregister_ftrace_function_probe symbol lookup failed.\n"); + WARN_ON(1); + } +} + +#else + +static inline +int wrapper_register_ftrace_function_probe(char *glob, + struct ftrace_probe_ops *ops, void *data) +{ + return register_ftrace_function_probe(glob, ops, data); +} + +static inline +void wrapper_unregister_ftrace_function_probe(char *glob, + struct ftrace_probe_ops *ops, void *data) +{ + return unregister_ftrace_function_probe(glob, ops, data); +} +#endif + +#endif /* _LTT_WRAPPER_FTRACE_H */ diff --git a/drivers/staging/lttng/wrapper/inline_memcpy.h b/drivers/staging/lttng/wrapper/inline_memcpy.h new file mode 100644 index 000000000000..33150cdb5b5e --- /dev/null +++ b/drivers/staging/lttng/wrapper/inline_memcpy.h @@ -0,0 +1,11 @@ +/* + * wrapper/inline_memcpy.h + * + * Copyright (C) 2010-2011 Mathieu Desnoyers + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#if !defined(__HAVE_ARCH_INLINE_MEMCPY) && !defined(inline_memcpy) +#define inline_memcpy memcpy +#endif diff --git a/drivers/staging/lttng/wrapper/kallsyms.h b/drivers/staging/lttng/wrapper/kallsyms.h new file mode 100644 index 000000000000..bb45f38a8982 --- /dev/null +++ b/drivers/staging/lttng/wrapper/kallsyms.h @@ -0,0 +1,28 @@ +#ifndef _LTT_WRAPPER_KALLSYMS_H +#define _LTT_WRAPPER_KALLSYMS_H + +/* + * Copyright (C) 2011 Avik Sil (avik.sil@linaro.org) + * + * wrapper around kallsyms_lookup_name. Implements arch-dependent code for + * arches where the address of the start of the function body is different + * from the pointer which can be used to call the function, e.g. ARM THUMB2. + * + * Dual LGPL v2.1/GPL v2 license. + */ + +static inline +unsigned long kallsyms_lookup_funcptr(const char *name) +{ + unsigned long addr; + + addr = kallsyms_lookup_name(name); +#ifdef CONFIG_ARM +#ifdef CONFIG_THUMB2_KERNEL + if (addr) + addr |= 1; /* set bit 0 in address for thumb mode */ +#endif +#endif + return addr; +} +#endif /* _LTT_WRAPPER_KALLSYMS_H */ diff --git a/drivers/staging/lttng/wrapper/perf.h b/drivers/staging/lttng/wrapper/perf.h new file mode 100644 index 000000000000..9a6dbfc03c26 --- /dev/null +++ b/drivers/staging/lttng/wrapper/perf.h @@ -0,0 +1,32 @@ +#ifndef _LTT_WRAPPER_PERF_H +#define _LTT_WRAPPER_PERF_H + +/* + * Copyright (C) 2011 Mathieu Desnoyers (mathieu.desnoyers@efficios.com) + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#include + +#if defined(CONFIG_PERF_EVENTS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,99)) +static inline struct perf_event * +wrapper_perf_event_create_kernel_counter(struct perf_event_attr *attr, + int cpu, + struct task_struct *task, + perf_overflow_handler_t callback) +{ + return perf_event_create_kernel_counter(attr, cpu, task, callback, NULL); +} +#else +static inline struct perf_event * +wrapper_perf_event_create_kernel_counter(struct perf_event_attr *attr, + int cpu, + struct task_struct *task, + perf_overflow_handler_t callback) +{ + return perf_event_create_kernel_counter(attr, cpu, task, callback); +} +#endif + +#endif /* _LTT_WRAPPER_PERF_H */ diff --git a/drivers/staging/lttng/wrapper/poll.h b/drivers/staging/lttng/wrapper/poll.h new file mode 100644 index 000000000000..9c2d18f4a729 --- /dev/null +++ b/drivers/staging/lttng/wrapper/poll.h @@ -0,0 +1,14 @@ +#ifndef _LTTNG_WRAPPER_POLL_H +#define _LTTNG_WRAPPER_POLL_H + +/* + * Copyright (C) 2011 Mathieu Desnoyers (mathieu.desnoyers@efficios.com) + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#include + +#define poll_wait_set_exclusive(poll_table) + +#endif /* _LTTNG_WRAPPER_POLL_H */ diff --git a/drivers/staging/lttng/wrapper/ringbuffer/api.h b/drivers/staging/lttng/wrapper/ringbuffer/api.h new file mode 100644 index 000000000000..182bee284016 --- /dev/null +++ b/drivers/staging/lttng/wrapper/ringbuffer/api.h @@ -0,0 +1 @@ +#include "../../lib/ringbuffer/api.h" diff --git a/drivers/staging/lttng/wrapper/ringbuffer/backend.h b/drivers/staging/lttng/wrapper/ringbuffer/backend.h new file mode 100644 index 000000000000..bfdd39def1a9 --- /dev/null +++ b/drivers/staging/lttng/wrapper/ringbuffer/backend.h @@ -0,0 +1 @@ +#include "../../lib/ringbuffer/backend.h" diff --git a/drivers/staging/lttng/wrapper/ringbuffer/backend_internal.h b/drivers/staging/lttng/wrapper/ringbuffer/backend_internal.h new file mode 100644 index 000000000000..00d45e42a60e --- /dev/null +++ b/drivers/staging/lttng/wrapper/ringbuffer/backend_internal.h @@ -0,0 +1,2 @@ +#include "../../wrapper/inline_memcpy.h" +#include "../../lib/ringbuffer/backend_internal.h" diff --git a/drivers/staging/lttng/wrapper/ringbuffer/backend_types.h b/drivers/staging/lttng/wrapper/ringbuffer/backend_types.h new file mode 100644 index 000000000000..c59effda7de3 --- /dev/null +++ b/drivers/staging/lttng/wrapper/ringbuffer/backend_types.h @@ -0,0 +1 @@ +#include "../../lib/ringbuffer/backend_types.h" diff --git a/drivers/staging/lttng/wrapper/ringbuffer/config.h b/drivers/staging/lttng/wrapper/ringbuffer/config.h new file mode 100644 index 000000000000..0ce7a9dac558 --- /dev/null +++ b/drivers/staging/lttng/wrapper/ringbuffer/config.h @@ -0,0 +1 @@ +#include "../../lib/ringbuffer/config.h" diff --git a/drivers/staging/lttng/wrapper/ringbuffer/frontend.h b/drivers/staging/lttng/wrapper/ringbuffer/frontend.h new file mode 100644 index 000000000000..7c6c07052afb --- /dev/null +++ b/drivers/staging/lttng/wrapper/ringbuffer/frontend.h @@ -0,0 +1 @@ +#include "../../lib/ringbuffer/frontend.h" diff --git a/drivers/staging/lttng/wrapper/ringbuffer/frontend_api.h b/drivers/staging/lttng/wrapper/ringbuffer/frontend_api.h new file mode 100644 index 000000000000..b03c501cc3f0 --- /dev/null +++ b/drivers/staging/lttng/wrapper/ringbuffer/frontend_api.h @@ -0,0 +1 @@ +#include "../../lib/ringbuffer/frontend_api.h" diff --git a/drivers/staging/lttng/wrapper/ringbuffer/frontend_internal.h b/drivers/staging/lttng/wrapper/ringbuffer/frontend_internal.h new file mode 100644 index 000000000000..18991014585d --- /dev/null +++ b/drivers/staging/lttng/wrapper/ringbuffer/frontend_internal.h @@ -0,0 +1 @@ +#include "../../lib/ringbuffer/frontend_internal.h" diff --git a/drivers/staging/lttng/wrapper/ringbuffer/frontend_types.h b/drivers/staging/lttng/wrapper/ringbuffer/frontend_types.h new file mode 100644 index 000000000000..0c23244b5a2f --- /dev/null +++ b/drivers/staging/lttng/wrapper/ringbuffer/frontend_types.h @@ -0,0 +1 @@ +#include "../../lib/ringbuffer/frontend_types.h" diff --git a/drivers/staging/lttng/wrapper/ringbuffer/iterator.h b/drivers/staging/lttng/wrapper/ringbuffer/iterator.h new file mode 100644 index 000000000000..76e9edbb321b --- /dev/null +++ b/drivers/staging/lttng/wrapper/ringbuffer/iterator.h @@ -0,0 +1 @@ +#include "../../lib/ringbuffer/iterator.h" diff --git a/drivers/staging/lttng/wrapper/ringbuffer/nohz.h b/drivers/staging/lttng/wrapper/ringbuffer/nohz.h new file mode 100644 index 000000000000..9fbb84d2370d --- /dev/null +++ b/drivers/staging/lttng/wrapper/ringbuffer/nohz.h @@ -0,0 +1 @@ +#include "../../lib/ringbuffer/nohz.h" diff --git a/drivers/staging/lttng/wrapper/ringbuffer/vatomic.h b/drivers/staging/lttng/wrapper/ringbuffer/vatomic.h new file mode 100644 index 000000000000..d57844520f62 --- /dev/null +++ b/drivers/staging/lttng/wrapper/ringbuffer/vatomic.h @@ -0,0 +1 @@ +#include "../../lib/ringbuffer/vatomic.h" diff --git a/drivers/staging/lttng/wrapper/ringbuffer/vfs.h b/drivers/staging/lttng/wrapper/ringbuffer/vfs.h new file mode 100644 index 000000000000..f8e9ed949da0 --- /dev/null +++ b/drivers/staging/lttng/wrapper/ringbuffer/vfs.h @@ -0,0 +1 @@ +#include "../../lib/ringbuffer/vfs.h" diff --git a/drivers/staging/lttng/wrapper/spinlock.h b/drivers/staging/lttng/wrapper/spinlock.h new file mode 100644 index 000000000000..8b1ad9925595 --- /dev/null +++ b/drivers/staging/lttng/wrapper/spinlock.h @@ -0,0 +1,26 @@ +#ifndef _LTT_WRAPPER_SPINLOCK_H +#define _LTT_WRAPPER_SPINLOCK_H + +/* + * Copyright (C) 2011 Mathieu Desnoyers (mathieu.desnoyers@efficios.com) + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#include + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)) + +#include + +#define raw_spin_lock_init(lock) \ + do { \ + raw_spinlock_t __lock = __RAW_SPIN_LOCK_UNLOCKED; \ + memcpy(lock, &__lock, sizeof(lock)); \ + } while (0) + +#define raw_spin_is_locked(lock) __raw_spin_is_locked(lock) + + +#endif +#endif /* _LTT_WRAPPER_SPINLOCK_H */ diff --git a/drivers/staging/lttng/wrapper/splice.c b/drivers/staging/lttng/wrapper/splice.c new file mode 100644 index 000000000000..ba224eea62fb --- /dev/null +++ b/drivers/staging/lttng/wrapper/splice.c @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2011 Mathieu Desnoyers (mathieu.desnoyers@efficios.com) + * + * wrapper around vmalloc_sync_all. Using KALLSYMS to get its address when + * available, else we need to have a kernel that exports this function to GPL + * modules. + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#ifdef CONFIG_KALLSYMS + +#include +#include +#include +#include "kallsyms.h" + +static +ssize_t (*splice_to_pipe_sym)(struct pipe_inode_info *pipe, + struct splice_pipe_desc *spd); + +ssize_t wrapper_splice_to_pipe(struct pipe_inode_info *pipe, + struct splice_pipe_desc *spd) +{ + if (!splice_to_pipe_sym) + splice_to_pipe_sym = (void *) kallsyms_lookup_funcptr("splice_to_pipe"); + if (splice_to_pipe_sym) { + return splice_to_pipe_sym(pipe, spd); + } else { + printk(KERN_WARNING "LTTng: splice_to_pipe symbol lookup failed.\n"); + return -ENOSYS; + } +} + +#else + +#include +#include + +ssize_t wrapper_splice_to_pipe(struct pipe_inode_info *pipe, + struct splice_pipe_desc *spd) +{ + return splice_to_pipe(pipe, spd); +} + +#endif diff --git a/drivers/staging/lttng/wrapper/splice.h b/drivers/staging/lttng/wrapper/splice.h new file mode 100644 index 000000000000..f75309a866fb --- /dev/null +++ b/drivers/staging/lttng/wrapper/splice.h @@ -0,0 +1,23 @@ +#ifndef _LTT_WRAPPER_SPLICE_H +#define _LTT_WRAPPER_SPLICE_H + +/* + * Copyright (C) 2011 Mathieu Desnoyers (mathieu.desnoyers@efficios.com) + * + * wrapper around vmalloc_sync_all. Using KALLSYMS to get its address when + * available, else we need to have a kernel that exports this function to GPL + * modules. + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#include + +ssize_t wrapper_splice_to_pipe(struct pipe_inode_info *pipe, + struct splice_pipe_desc *spd); + +#ifndef PIPE_DEF_BUFFERS +#define PIPE_DEF_BUFFERS 16 +#endif + +#endif /* _LTT_WRAPPER_SPLICE_H */ diff --git a/drivers/staging/lttng/wrapper/trace-clock.h b/drivers/staging/lttng/wrapper/trace-clock.h new file mode 100644 index 000000000000..8b77428a527b --- /dev/null +++ b/drivers/staging/lttng/wrapper/trace-clock.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2011 Mathieu Desnoyers (mathieu.desnoyers@efficios.com) + * + * Contains LTTng trace clock mapping to LTTng trace clock or mainline monotonic + * clock. This wrapper depends on CONFIG_HIGH_RES_TIMERS=y. + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#ifndef _LTT_TRACE_CLOCK_H +#define _LTT_TRACE_CLOCK_H + +#ifdef CONFIG_HAVE_TRACE_CLOCK +#include +#else /* CONFIG_HAVE_TRACE_CLOCK */ + +#include +#include +#include +#include + +static inline u64 trace_clock_monotonic_wrapper(void) +{ + ktime_t ktime; + + /* + * Refuse to trace from NMIs with this wrapper, because an NMI could + * nest over the xtime write seqlock and deadlock. + */ + if (in_nmi()) + return (u64) -EIO; + + ktime = ktime_get(); + return (u64) ktime.tv64; +} + +static inline u32 trace_clock_read32(void) +{ + return (u32) trace_clock_monotonic_wrapper(); +} + +static inline u64 trace_clock_read64(void) +{ + return (u64) trace_clock_monotonic_wrapper(); +} + +static inline u64 trace_clock_frequency(void) +{ + return (u64)NSEC_PER_SEC; +} + +static inline u32 trace_clock_freq_scale(void) +{ + return 1; +} + +static inline int get_trace_clock(void) +{ + printk(KERN_WARNING "LTTng: Using mainline kernel monotonic clock.\n"); + printk(KERN_WARNING " * NMIs will not be traced,\n"); + printk(KERN_WARNING " * expect significant performance degradation compared to the\n"); + printk(KERN_WARNING " LTTng trace clocks.\n"); + printk(KERN_WARNING "Integration of the LTTng 0.x trace clocks into LTTng 2.0 is planned\n"); + printk(KERN_WARNING "in a near future.\n"); + + return 0; +} + +static inline void put_trace_clock(void) +{ +} + +#endif /* CONFIG_HAVE_TRACE_CLOCK */ + +#endif /* _LTT_TRACE_CLOCK_H */ diff --git a/drivers/staging/lttng/wrapper/uuid.h b/drivers/staging/lttng/wrapper/uuid.h new file mode 100644 index 000000000000..bfa67ff3c1db --- /dev/null +++ b/drivers/staging/lttng/wrapper/uuid.h @@ -0,0 +1,29 @@ +#ifndef _LTT_WRAPPER_UUID_H +#define _LTT_WRAPPER_UUID_H + +/* + * Copyright (C) 2011 Mathieu Desnoyers (mathieu.desnoyers@efficios.com) + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#include + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) +#include +#else + +#include + +typedef struct { + __u8 b[16]; +} uuid_le; + +static inline +void uuid_le_gen(uuid_le *u) +{ + generate_random_uuid(u->b); +} + +#endif +#endif /* _LTT_WRAPPER_UUID_H */ diff --git a/drivers/staging/lttng/wrapper/vmalloc.h b/drivers/staging/lttng/wrapper/vmalloc.h new file mode 100644 index 000000000000..765f2ad9e225 --- /dev/null +++ b/drivers/staging/lttng/wrapper/vmalloc.h @@ -0,0 +1,49 @@ +#ifndef _LTT_WRAPPER_VMALLOC_H +#define _LTT_WRAPPER_VMALLOC_H + +/* + * Copyright (C) 2011 Mathieu Desnoyers (mathieu.desnoyers@efficios.com) + * + * wrapper around vmalloc_sync_all. Using KALLSYMS to get its address when + * available, else we need to have a kernel that exports this function to GPL + * modules. + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#ifdef CONFIG_KALLSYMS + +#include +#include "kallsyms.h" + +static inline +void wrapper_vmalloc_sync_all(void) +{ + void (*vmalloc_sync_all_sym)(void); + + vmalloc_sync_all_sym = (void *) kallsyms_lookup_funcptr("vmalloc_sync_all"); + if (vmalloc_sync_all_sym) { + vmalloc_sync_all_sym(); + } else { +#ifdef CONFIG_X86 + /* + * Only x86 needs vmalloc_sync_all to make sure LTTng does not + * trigger recursive page faults. + */ + printk(KERN_WARNING "LTTng: vmalloc_sync_all symbol lookup failed.\n"); + printk(KERN_WARNING "Page fault handler and NMI tracing might trigger faults.\n"); +#endif + } +} +#else + +#include + +static inline +void wrapper_vmalloc_sync_all(void) +{ + return vmalloc_sync_all(); +} +#endif + +#endif /* _LTT_WRAPPER_VMALLOC_H */