RAS daemon v4
Subsystems (4)
cover RAS daemon v4
From: Borislav Petkov <[email protected]>
Hi,
here's another round of the RAS daemon patchset. This time I'd like to get some ACKs/NACKs on the perf bits and whether this is agreeable to do. To some of the patches:
* 0001-perf-Start-the-massive-restructuring.patch:
This renames perf_event.c into events/core.c, as talked about earlier. This is only a first step though, the rest should come from perf people I guess...
* 0002-perf-Add-persistent-event-facilities.patch
... and this one puts the persistent bits in persistent.c
* 0004-perf-Add-Makefile.lib.patch
* 0005-perf-Export-trace-event-utils.patch
I'm adding a toplevel tools/Makefile here which we could use for the other tools in there since we keep growing even more tools with each kernel release.
* 0007-perf-Export-debugfs-utilities.patch
This one is needed only temporary, as we're moving the perf events to /sysfs. After that work is done, the persistent fd will be read from there.
For more details, check the individual patches.
Btw, the patches are ontop of tip/master from ~two weeks ago, i.e.:cf1f6cd677a9ce8c80e5de61724a25074ad9a8cf.
In order to run this patchset, you need only this hunk:
---
drivers/edac/mce_amd.c +3 -0
@@ -1,5 +1,6 @@#include <linux/module.h> #include <linux/slab.h> +#include <trace/events/mce.h> #include "mce_amd.h"
@@ -598,6 +599,8 @@ int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)amd_decode_err_code (m->status &0xffff ); +trace_mce_record (m); +return NOTIFY_STOP ; }EXPORT_SYMBOL_GPL (amd_decode_mce);
---
so that you can inject some MCEs like so:
$ cd tools/ $ make -j ras $ ./ras/rasd $ modprobe mce_amd_inj (built by CONFIG_EDAC_MCE_INJ) $ echo 0x9c00410000010016 > /sys/devices/system/edac/mce/status $ echo 0 > /sys/devices/system/edac/mce/bank
And after 30 sec the latest, /var/log/ras.log will contain:
Got MCE, cpu: 0, status: 0x9c00410000010016, addr: 0x0000000000000000
This is still undecoded yet but I'm working on it.
Anyway, please take a look and send me all comments you'd have.
Thanks.
PATCH 1/12 perf: Start the massive restructuring
From: Borislav Petkov <[email protected]>
mv kernel/perf_event.c -> kernel/events/core.c. From there, all other sensible splitting can happen.
---
kernel/Makefile | 5 +++--
kernel/events/Makefile | 5 +++++
kernel/{perf_event.c => events/core.c} | 0
3 files changed, 8 insertions(+), 2 deletions(-)
create mode 100644 kernel/events/Makefile
rename kernel/{perf_event.c => events/core.c} (100%)kernel/Makefile +3 -2
@@ -21,7 +21,6 @@ CFLAGS_REMOVE_mutex-debug.o = -pg CFLAGS_REMOVE_rtmutex-debug.o = -pg CFLAGS_REMOVE_cgroup-debug.o = -pg CFLAGS_REMOVE_sched_clock.o = -pg -CFLAGS_REMOVE_perf_event.o = -pg CFLAGS_REMOVE_irq_work.o = -pg endif
@@ -102,7 +101,9 @@ obj-$(CONFIG_X86_DS) += trace/ obj-$(CONFIG_RING_BUFFER) += trace/ obj-$(CONFIG_SMP) += sched_cpupri.o obj-$(CONFIG_IRQ_WORK) += irq_work.o -obj-$(CONFIG_PERF_EVENTS) += perf_event.o + +obj-$(CONFIG_PERF_EVENTS) += events/ + obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o obj-$(CONFIG_PADATA) += padata.o
kernel/events/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +ifdef CONFIG_FUNCTION_TRACER +CFLAGS_REMOVE_core.o = -pg +endif + +obj-y += core.o
kernel/events/core.c renamed from kernel/perf_event.c +0 -0
Signature · 1 line
1.7.4.rc2
PATCH 2/12 perf: Add persistent event facilities
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Add a barebones implementation for registering persistent events with perf. For that, we don't destroy the buffers when they're unmapped and we map them read-only so that multiple agents can access them.
--- include/linux/perf_event.h | 22 ++++++++++++++++- kernel/events/Makefile | 2 +- kernel/events/core.c | 32 ++++++++++++++++++++---- kernel/events/persistent.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 kernel/events/persistent.c
include/linux/perf_event.h +21 -1
@@ -216,8 +216,9 @@ struct perf_event_attr { precise_ip : 2, /* skid constraint */ mmap_data : 1, /* non-exec mmap data */ sample_id_all : 1, /* sample_type all events */ + persistent : 1, /* event always on */ - __reserved_1 : 45; + __reserved_1 : 44;union {__u32 wakeup_events;/* wakeup every n events */
@@ -1121,6 +1122,15 @@ extern void perf_swevent_put_recursion_context(int rctx);extern void perf_event_enable (struct perf_event *event);extern void perf_event_disable (struct perf_event *event);extern void perf_event_task_tick (void ); +extern struct perf_buffer * +perf_buffer_alloc (int nr_pages,long watermark,int cpu,int flags); +extern void perf_buffer_put (struct perf_buffer *buffer); +extern struct perf_event * +perf_enable_persistent_event (struct perf_event_attr *attr, +int cpu,unsigned bufsz); +extern void perf_disable_persistent_event (struct perf_event *event,int cpu); +extern int perf_persistent_open (struct inode *inode,struct file *file); +extern const struct file_operations perf_pers_fops;#else static inline void perf_event_task_sched_in (struct task_struct *task) { }
@@ -1155,6 +1165,16 @@ static inline void perf_swevent_put_recursion_context(int rctx) { }static inline void perf_event_enable (struct perf_event *event) { }static inline void perf_event_disable (struct perf_event *event) { }static inline void perf_event_task_tick (void ) { } +static inline struct perf_buffer * +perf_buffer_alloc (int nr_pages,long watermark,int cpu,int flags) {return NULL ; } +static inline void perf_buffer_put (struct perf_buffer *buffer) {} +static inline struct perf_event * +perf_enable_persistent_event (struct perf_event_attr *attr,int cpu, +unsigned bufsz) {return -EINVAL ; } +static inline void +perf_disable_persistent_event (struct perf_event *event,int cpu) {} +static inline int +perf_persistent_open (struct inode *inode,struct file *file) {return -1 ; }#endif #define perf_output_put (handle, x) \
kernel/events/Makefile +1 -1
@@ -2,4 +2,4 @@ ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_core.o = -pg endif -obj-y += core.o +obj-y += core.o persistent.o
kernel/events/core.c +26 -6
@@ -2301,7 +2301,7 @@ static void free_event_rcu(struct rcu_head *head)kfree (event); } -static void perf_buffer_put (struct perf_buffer *buffer); +void perf_buffer_put (struct perf_buffer *buffer);static void free_event (struct perf_event *event) {
@@ -2854,7 +2854,7 @@ static void *perf_mmap_alloc_page(int cpu)return page_address (page); } -static struct perf_buffer * +struct perf_buffer *perf_buffer_alloc (int nr_pages,long watermark,int cpu,int flags) {struct perf_buffer *buffer;
@@ -2971,7 +2971,7 @@ static void perf_buffer_free(struct perf_buffer *buffer)schedule_work (&buffer->work); } -static struct perf_buffer * +struct perf_buffer *perf_buffer_alloc (int nr_pages,long watermark,int cpu,int flags) {struct perf_buffer *buffer;
@@ -3072,7 +3072,7 @@ static struct perf_buffer *perf_buffer_get(struct perf_event *event)return buffer; } -static void perf_buffer_put (struct perf_buffer *buffer) +void perf_buffer_put (struct perf_buffer *buffer) {if (!atomic_dec_and_test (&buffer->refcount))return ;
@@ -3091,6 +3091,11 @@ static void perf_mmap_close(struct vm_area_struct *vma) {struct perf_event *event = vma->vm_file->private_data; +if (event->attr.persistent) { +atomic_dec (&event->mmap_count); +return ; + } +if (atomic_dec_and_mutex_lock (&event->mmap_count, &event->mmap_mutex)) {unsigned long size =perf_data_size (event->buffer);struct user_struct *user = event->mmap_user;
@@ -3133,7 +3138,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)if (event->cpu ==-1 && event->attr.inherit)return -EINVAL ; -if (!(vma->vm_flags &VM_SHARED )) +if (!(vma->vm_flags &VM_SHARED ) && !event->attr.persistent)return -EINVAL ; vma_size = vma->vm_end - vma->vm_start;
@@ -3242,6 +3247,16 @@ static const struct file_operations perf_fops = { .fasync = perf_fasync, }; +const struct file_operations perf_pers_fops = { + .llseek = no_llseek, + .open = perf_persistent_open, + .poll = perf_poll, + .unlocked_ioctl = perf_ioctl, + .compat_ioctl = perf_ioctl, + .mmap = perf_mmap, + .fasync = perf_fasync, +}; +/* * Perf event wakeup *
@@ -6043,7 +6058,6 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,mutex_unlock (&ctx->mutex);return event; - err_free:free_event (event); err:
@@ -6093,6 +6107,12 @@ __perf_event_exit_task(struct perf_event *child_event, {struct perf_event *parent_event; +/* +* do not remove persistent events on task exit +*/ +if (child_event->attr.persistent) +return ; +perf_event_remove_from_context (child_event); parent_event = child_event->parent;
kernel/events/persistent.c new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
1.7.4.rc2
PATCH 3/12 x86, mce: Add persistent MCE event
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Add the necessary glue to enable the mce_record tracepoint on boot, turning it into a persistent event. This exports the MCE buffer to a userspace daemon which will hook into it through debugfs when booting is finished.
--- arch/x86/include/asm/mce.h | 8 ++++ arch/x86/kernel/cpu/mcheck/mce.c | 86 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 0 deletions(-)
arch/x86/include/asm/mce.h +8 -0
@@ -91,6 +91,14 @@ struct mce_log {struct mce entry[MCE_LOG_LEN ]; }; +/* +* a per-cpu descriptor of the persistent MCE tracepoint +*/ +struct mce_tp_desc { +struct perf_event *event; +struct dentry *debugfs_entry; +}; +#define MCE_OVERFLOW 0/* bit 0 in flags means overflow */ #define MCE_LOG_SIGNATURE "MACHINECHECK"
arch/x86/kernel/cpu/mcheck/mce.c +86 -0
104 lines not on this page · raw message
Signature · 1 line
1.7.4.rc2
PATCH 4/12 perf: Add Makefile.lib
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Put build settings which will be reused by other tools into a common .lib file.
--- tools/perf/Makefile | 63 +----------------------------------------- tools/scripts/Makefile.lib | 66 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 62 deletions(-) create mode 100644 tools/scripts/Makefile.lib
tools/perf/Makefile +1 -62
@@ -1,16 +1,8 @@ -ifeq ("$(origin O)", "command line") - OUTPUT := $(O)/ -endif +include ../scripts/Makefile.lib # The default target of this Makefile is... all:: -ifneq ($(OUTPUT),) -# check that the output directory actually exists -OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd) -$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist)) -endif - # Define V=1 to have a more verbose compile. # Define V=2 to have an even more verbose compile. #
@@ -193,33 +185,6 @@ endif # CFLAGS and LDFLAGS are for the users to override from the command line. -# -# Include saner warnings here, which can catch bugs: -# - -EXTRA_WARNINGS := -Wformat -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-security -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-y2k -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wshadow -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Winit-self -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wpacked -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wredundant-decls -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstack-protector -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-aliasing=3 -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-default -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-enum -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wno-system-headers -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wundef -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wvolatile-register-var -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wwrite-strings -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wbad-function-cast -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-declarations -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-prototypes -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wnested-externs -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-prototypes -EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wdeclaration-after-statement - ifeq ("$(origin DEBUG)", "command line") PERF_DEBUG = $(DEBUG) endif
@@ -857,32 +822,6 @@ ifeq ($(PERL_PATH),) NO_PERL=NoThanks endif -QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir -QUIET_SUBDIR1 = - -ifneq ($(findstring $(MAKEFLAGS),w),w) -PRINT_DIR = --no-print-directory -else # "make -w" -NO_SUBDIR = : -endif - -ifneq ($(findstring $(MAKEFLAGS),s),s) -ifndef V - QUIET_CC = @echo ' ' CC $@; - QUIET_AR = @echo ' ' AR $@; - QUIET_LINK = @echo ' ' LINK $@; - QUIET_MKDIR = @echo ' ' MKDIR $@; - QUIET_BUILT_IN = @echo ' ' BUILTIN $@; - QUIET_GEN = @echo ' ' GEN $@; - QUIET_SUBDIR0 = +@subdir= - QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ - $(MAKE) $(PRINT_DIR) -C $$subdir - export V - export QUIET_GEN - export QUIET_BUILT_IN -endif -endif - ifdef ASCIIDOC8 export ASCIIDOC8 endif
tools/scripts/Makefile.lib new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
1.7.4.rc2
PATCH 5/12 perf: Export trace-event utils
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Export trace-event* utils into a sub-lib for wider use. While at it, export functions for use by other entities later.
---
tools/Makefile | 24 ++++++++
tools/lib/trace/Makefile | 59 ++++++++++++++++++++
tools/{perf/util => lib/trace}/trace-event-info.c | 18 +++---
tools/{perf/util => lib/trace}/trace-event-parse.c | 16 +++---
tools/{perf/util => lib/trace}/trace-event-read.c | 4 +-
tools/{perf/util => lib/trace}/trace-event.h | 16 ++++-
tools/perf/Makefile | 10 +--
tools/perf/bench/bench.h | 2 +
tools/perf/builtin-kmem.c | 2 +-
tools/perf/builtin-kvm.c | 2 +-
tools/perf/builtin-lock.c | 2 +-
tools/perf/builtin-sched.c | 2 +-
tools/perf/builtin-script.c | 2 +-
tools/perf/scripts/perl/Perf-Trace-Util/Context.c | 2 +-
.../perf/scripts/python/Perf-Trace-Util/Context.c | 2 +-
tools/perf/util/cache.h | 1 +
tools/perf/util/header.c | 2 +-
tools/perf/util/probe-event.c | 2 +-
.../perf/util/scripting-engines/trace-event-perl.c | 2 +-
.../util/scripting-engines/trace-event-python.c | 2 +-
tools/perf/util/trace-event-scripting.c | 2 +-
21 files changed, 132 insertions(+), 42 deletions(-)
create mode 100644 tools/Makefile
create mode 100644 tools/lib/trace/Makefile
rename tools/{perf/util => lib/trace}/trace-event-info.c (97%)
rename tools/{perf/util => lib/trace}/trace-event-parse.c (99%)
rename tools/{perf/util => lib/trace}/trace-event-read.c (99%)
rename tools/{perf/util => lib/trace}/trace-event.h (93%)tools/Makefile new file +24 -0
@@ -0,0 +1,24 @@ +include scripts/Makefile.lib + +PERF_TOP_DIR := $(CURDIR) +export PERF_TOP_DIR + +BASIC_CFLAGS = -I$(CURDIR)/lib + +# temporary for lib/trace/ +BASIC_CFLAGS += -I$(CURDIR)/perf/util/include + +export BASIC_CFLAGS + +perf: libtrace .FORCE + $(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) + +libtrace: .FORCE + $(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) + +clean: + $(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) clean + $(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean + + +.PHONY: clean .FORCE
tools/lib/trace/Makefile new file +59 -0
59 lines not on this page · raw message
tools/lib/trace/trace-event-info.c renamed from tools/perf/util/trace-event-info.c +8 -10
@@ -37,10 +37,10 @@#include <linux/list.h> #include <linux/kernel.h> -#include "../perf.h" +#include "../../perf/perf.h" #include "trace-event.h" -#include "debugfs.h" -#include "evsel.h" +#include "../../perf/util/debugfs.h" +#include "../../perf/util/evsel.h" #define VERSION "0.5"
@@ -72,8 +72,6 @@ struct events {char *name; }; - -static void die (const char *fmt, ...) {va_list ap;
@@ -136,7 +134,7 @@ static const char *find_tracing_dir(void)return tracing; } -static char *get_tracing_file (const char *name) +char *get_tracing_file (const char *name) {const char *tracing;char *file;
@@ -231,7 +229,7 @@ static unsigned long get_size_fd(int fd)return size; } -static unsigned long get_size (const char *file) +unsigned long get_filesize (const char *file) {unsigned long long size =0 ;int fd;
@@ -340,7 +338,7 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps)if (ret >=0 ) {/* unfortunately, you can not stat debugfs files for size */ - size =get_size (format); + size =get_filesize (format);write_or_die (&size,8 ); check_size =copy_file (format);if (size != check_size)
@@ -438,7 +436,7 @@ static void read_proc_kallsyms(void)write_or_die (&size,4 );return ; } - size =get_size (path); + size =get_filesize (path);write_or_die (&size,4 ); check_size =copy_file (path);if (size != check_size)
@@ -461,7 +459,7 @@ static void read_ftrace_printk(void)write_or_die (&size,4 ); goto out; } - size =get_size (path); + size =get_filesize (path);write_or_die (&size,4 ); check_size =copy_file (path);if (size != check_size)
tools/lib/trace/trace-event-parse.c renamed from tools/perf/util/trace-event-parse.c +8 -8
@@ -29,8 +29,8 @@#include <errno.h> #undef _GNU_SOURCE -#include "../perf.h" -#include "util.h" +#include "../../perf/perf.h" +#include "../../perf/util/util.h" #include "trace-event.h" int header_page_ts_offset;
@@ -44,7 +44,7 @@ int header_page_data_size;bool latency_format; -static char *input_buf; +static const char *input_buf;static unsigned long long input_buf_ptr;static unsigned long long input_buf_siz;
@@ -56,7 +56,7 @@ static int is_symbolic_field;static struct format_field *find_any_field (struct event *event,const char *name); -static void init_input_buf (char *buf,unsigned long long size) +void init_input_buf (const char *buf,unsigned long long size) { input_buf = buf; input_buf_siz = size;
@@ -338,7 +338,7 @@ void print_printk(void) } } -static struct event *alloc_event (void ) +struct event *alloc_event (void ) {struct event *event;
@@ -701,7 +701,7 @@ static int read_expected_item(enum event_type expect, const char *str)return __read_expected (expect, str,0 , true); } -static char *event_read_name (void ) +char *event_read_name (void ) {char *token;
@@ -721,7 +721,7 @@ static char *event_read_name(void)return NULL ; } -static int event_read_id (void ) +int event_read_id (void ) {char *token;int id;
@@ -986,7 +986,7 @@ fail_expect:return -1 ; } -static int event_read_format (struct event *event) +int event_read_format (struct event *event) {char *token;int ret;
tools/lib/trace/trace-event-read.c renamed from tools/perf/util/trace-event-read.c +2 -2
@@ -36,8 +36,8 @@#include <ctype.h> #include <errno.h> -#include "../perf.h" -#include "util.h" +#include "../../perf/perf.h" +#include "../../perf/util/util.h" #include "trace-event.h" static int input_fd;
tools/lib/trace/trace-event.h renamed from tools/perf/util/trace-event.h +12 -4
@@ -1,8 +1,8 @@ -#ifndef __PERF_TRACE_EVENTS_H -#define __PERF_TRACE_EVENTS_H +#ifndef __LIB_TRACE_EVENTS_H +#define __LIB_TRACE_EVENTS_H#include <stdbool.h> -#include "parse-events.h" +#include "../../perf/util/parse-events.h" #define __unused __attribute__((unused))
@@ -265,6 +265,14 @@ unsigned long long eval_flag(const char *flag);int read_tracing_data (int fd,struct list_head *pattrs);ssize_t read_tracing_data_size (int fd,struct list_head *pattrs); +extern struct event *alloc_event (void ); +extern void init_input_buf (const char *buf,unsigned long long size); +extern char *event_read_name (void ); +extern int event_read_id (void ); +extern int event_read_format (struct event *event); +unsigned long get_filesize (const char *file); +char *get_tracing_file (const char *name); +/* taken from kernel/trace/trace.h */ enum trace_flag_type {TRACE_FLAG_IRQS_OFF =0x01 ,
@@ -296,4 +304,4 @@ int common_pc(struct scripting_context *context);int common_flags (struct scripting_context *context);int common_lock_depth (struct scripting_context *context); -#endif /* __PERF_TRACE_EVENTS_H */ +#endif /* __LIB_TRACE_EVENTS_H */
tools/perf/Makefile +4 -6
@@ -265,7 +265,7 @@ endif # Those must not be GNU-specific; they are shared with perl/ which may # be built by a different compiler. (Note that this is an artifact now # but it still might be nice to keep that distinction.) -BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include +BASIC_CFLAGS += -Iutil/include -Iarch/$(ARCH)/include BASIC_LDFLAGS = # Guard against environment variables
@@ -326,6 +326,8 @@ export PERL_PATH LIB_FILE=$(OUTPUT)libperf.a +EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a + LIB_H += ../../include/linux/perf_event.h LIB_H += ../../include/linux/rbtree.h LIB_H += ../../include/linux/list.h
@@ -385,7 +387,6 @@ LIB_H += util/values.h LIB_H += util/sort.h LIB_H += util/hist.h LIB_H += util/thread.h -LIB_H += util/trace-event.h LIB_H += util/probe-finder.h LIB_H += util/probe-event.h LIB_H += util/pstack.h
@@ -429,9 +430,6 @@ LIB_OBJS += $(OUTPUT)util/map.o LIB_OBJS += $(OUTPUT)util/pstack.o LIB_OBJS += $(OUTPUT)util/session.o LIB_OBJS += $(OUTPUT)util/thread.o -LIB_OBJS += $(OUTPUT)util/trace-event-parse.o -LIB_OBJS += $(OUTPUT)util/trace-event-read.o -LIB_OBJS += $(OUTPUT)util/trace-event-info.o LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o LIB_OBJS += $(OUTPUT)util/svghelper.o LIB_OBJS += $(OUTPUT)util/sort.o
@@ -472,7 +470,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o BUILTIN_OBJS += $(OUTPUT)builtin-test.o BUILTIN_OBJS += $(OUTPUT)builtin-inject.o -PERFLIBS = $(LIB_FILE) +PERFLIBS = $(LIB_FILE) $(EXTRA_LIBS) # # Platform specific tweaks
tools/perf/bench/bench.h +2 -0
@@ -1,6 +1,8 @@#ifndef BENCH_H #define BENCH_H +#include <linux/compiler.h> +extern int bench_sched_messaging (int argc,const char **argv,const char *prefix);extern int bench_sched_pipe (int argc,const char **argv,const char *prefix);extern int bench_mem_memcpy (int argc,const char **argv,const char *prefix__used );
tools/perf/builtin-kmem.c +1 -1
@@ -9,7 +9,7 @@#include "util/session.h" #include "util/parse-options.h" -#include "util/trace-event.h" +#include <trace/trace-event.h> #include "util/debug.h"
tools/perf/builtin-kvm.c +1 -1
@@ -9,7 +9,7 @@#include "util/session.h" #include "util/parse-options.h" -#include "util/trace-event.h" +#include <trace/trace-event.h> #include "util/debug.h"
tools/perf/builtin-lock.c +1 -1
@@ -8,7 +8,7 @@#include "util/header.h" #include "util/parse-options.h" -#include "util/trace-event.h" +#include <trace/trace-event.h> #include "util/debug.h" #include "util/session.h"
tools/perf/builtin-sched.c +1 -1
@@ -9,7 +9,7 @@#include "util/session.h" #include "util/parse-options.h" -#include "util/trace-event.h" +#include <trace/trace-event.h> #include "util/debug.h"
tools/perf/builtin-script.c +1 -1
@@ -9,7 +9,7 @@#include "util/session.h" #include "util/symbol.h" #include "util/thread.h" -#include "util/trace-event.h" +#include <trace/trace-event.h> #include "util/parse-options.h" #include "util/util.h"
tools/perf/scripts/perl/Perf-Trace-Util/Context.c +1 -1
@@ -32,7 +32,7 @@#include "perl.h" #include "XSUB.h" #include "../../../perf.h" -#include "../../../util/trace-event.h" +#include <trace/trace-event.h> #ifndef PERL_UNUSED_VAR # define PERL_UNUSED_VAR (var) if (0) var = var
tools/perf/scripts/python/Perf-Trace-Util/Context.c +1 -1
@@ -21,7 +21,7 @@#include <Python.h> #include "../../../perf.h" -#include "../../../util/trace-event.h" +#include <trace/trace-event.h> PyMODINIT_FUNC initperf_trace_context (void );
tools/perf/util/cache.h +1 -0
@@ -5,6 +5,7 @@#include "util.h" #include "strbuf.h" #include "../perf.h" +#include <linux/compiler.h> #define CMD_EXEC_PATH "--exec-path"#define CMD_PERF_DIR "--perf-dir="
tools/perf/util/header.c +1 -1
@@ -11,7 +11,7 @@#include "util.h" #include "header.h" #include "../perf.h" -#include "trace-event.h" +#include <trace/trace-event.h> #include "session.h" #include "symbol.h" #include "debug.h"
tools/perf/util/probe-event.c +1 -1
@@ -43,7 +43,7 @@#include "symbol.h" #include "thread.h" #include "debugfs.h" -#include "trace-event.h" /* For __unused */ +#include <linux/compiler.h> /* For __unused */ #include "probe-event.h" #include "probe-finder.h"
tools/perf/util/scripting-engines/trace-event-perl.c +1 -1
@@ -27,7 +27,7 @@#include "../../perf.h" #include "../util.h" -#include "../trace-event.h" +#include <trace/trace-event.h> #include <EXTERN.h> #include <perl.h>
tools/perf/util/scripting-engines/trace-event-python.c +1 -1
@@ -29,7 +29,7 @@#include "../../perf.h" #include "../util.h" -#include "../trace-event.h" +#include <trace/trace-event.h> PyMODINIT_FUNC initperf_trace_context (void );
tools/perf/util/trace-event-scripting.c +1 -1
@@ -27,7 +27,7 @@#include "../perf.h" #include "util.h" -#include "trace-event.h" +#include <trace/trace-event.h> struct scripting_context *scripting_context;
Signature · 1 line
1.7.4.rc2
PATCH 6/12 perf: Remove duplicate enum trace_flag_type
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Merge the two definitions.
--- tools/lib/trace/trace-event.h | 10 +++++++++- tools/perf/builtin-timechart.c | 21 ++------------------- 2 files changed, 11 insertions(+), 20 deletions(-)
tools/lib/trace/trace-event.h +9 -1
@@ -273,7 +273,15 @@ extern int event_read_format(struct event *event);unsigned long get_filesize (const char *file);char *get_tracing_file (const char *name); -/* taken from kernel/trace/trace.h */ +/* +* trace_flag_type is an enumeration that holds different +* states when a trace occurs. These are: +* IRQS_OFF - interrupts were disabled +* IRQS_NOSUPPORT - arch does not support irqs_disabled_flags +* NEED_RESCED - reschedule is requested +* HARDIRQ - inside an interrupt handler +* SOFTIRQ - inside a softirq handler +*/ enum trace_flag_type {TRACE_FLAG_IRQS_OFF =0x01 ,TRACE_FLAG_IRQS_NOSUPPORT =0x02 ,
tools/perf/builtin-timechart.c +2 -19
@@ -32,6 +32,8 @@#include "util/session.h" #include "util/svghelper.h" +#include <trace/trace-event.h> +#define SUPPORT_OLD_POWER_EVENTS 1#define PWR_EVENT_EXIT -1
@@ -330,25 +332,6 @@ struct wakeup_entry {int success; }; -/* -* trace_flag_type is an enumeration that holds different -* states when a trace occurs. These are: -* IRQS_OFF - interrupts were disabled -* IRQS_NOSUPPORT - arch does not support irqs_disabled_flags -* NEED_RESCED - reschedule is requested -* HARDIRQ - inside an interrupt handler -* SOFTIRQ - inside a softirq handler -*/ -enum trace_flag_type { -TRACE_FLAG_IRQS_OFF =0x01 , -TRACE_FLAG_IRQS_NOSUPPORT =0x02 , -TRACE_FLAG_NEED_RESCHED =0x04 , -TRACE_FLAG_HARDIRQ =0x08 , -TRACE_FLAG_SOFTIRQ =0x10 , -}; - - -struct sched_switch {struct trace_entry te;char prev_comm[TASK_COMM_LEN ];
Signature · 1 line
1.7.4.rc2
PATCH 7/12 perf: Export debugfs utilities
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Export /proc/mounts parser and other debugfs-related helpers for general use.
---
tools/Makefile | 6 +++-
tools/lib/lk/Makefile | 38 ++++++++++++++++++++
tools/{perf/util => lib/lk}/debugfs.c | 2 +-
tools/{perf/util => lib/lk}/debugfs.h | 7 ++--
tools/{perf/util => lib/lk}/types.h | 6 ++--
tools/{perf/util => lib/lk}/usage.c | 0
tools/{perf/util => lib/lk}/util.h | 0
tools/lib/perf/shared.h | 9 +++++
tools/lib/trace/trace-event-info.c | 2 +-
tools/lib/trace/trace-event-parse.c | 2 +-
tools/lib/trace/trace-event-read.c | 2 +-
tools/perf/Makefile | 7 +---
tools/perf/bench/mem-memcpy.c | 2 +-
tools/perf/bench/sched-messaging.c | 2 +-
tools/perf/bench/sched-pipe.c | 2 +-
tools/perf/builtin-annotate.c | 2 +-
tools/perf/builtin-bench.c | 2 +-
tools/perf/builtin-diff.c | 2 +-
tools/perf/builtin-kmem.c | 2 +-
tools/perf/builtin-kvm.c | 2 +-
tools/perf/builtin-lock.c | 2 +-
tools/perf/builtin-probe.c | 4 +-
tools/perf/builtin-record.c | 2 +-
tools/perf/builtin-report.c | 2 +-
tools/perf/builtin-sched.c | 2 +-
tools/perf/builtin-script.c | 2 +-
tools/perf/builtin-stat.c | 2 +-
tools/perf/builtin-timechart.c | 2 +-
tools/perf/builtin-top.c | 2 +-
tools/perf/builtin.h | 2 +-
tools/perf/perf.c | 21 +++++++----
tools/perf/perf.h | 2 +-
tools/perf/util/build-id.c | 2 +-
tools/perf/util/cache.h | 3 +-
tools/perf/util/callchain.c | 2 +-
tools/perf/util/config.c | 2 +-
tools/perf/util/cpumap.c | 2 +-
tools/perf/util/debug.c | 2 +-
tools/perf/util/evsel.c | 2 +-
tools/perf/util/evsel.h | 2 +-
tools/perf/util/header.c | 2 +-
tools/perf/util/header.h | 2 +-
tools/perf/util/hist.c | 2 +-
tools/perf/util/include/linux/ctype.h | 2 +-
tools/perf/util/map.h | 2 +-
tools/perf/util/parse-events.c | 4 +-
tools/perf/util/parse-options.c | 2 +-
tools/perf/util/probe-event.c | 4 +-
tools/perf/util/probe-finder.c | 2 +-
tools/perf/util/probe-finder.h | 2 +-
tools/perf/util/pstack.c | 2 +-
.../perf/util/scripting-engines/trace-event-perl.c | 2 +-
.../util/scripting-engines/trace-event-python.c | 2 +-
tools/perf/util/session.c | 2 +-
tools/perf/util/sort.h | 2 +-
tools/perf/util/string.c | 2 +-
tools/perf/util/svghelper.h | 2 +-
tools/perf/util/thread.c | 2 +-
tools/perf/util/trace-event-scripting.c | 2 +-
tools/perf/util/ui/browser.c | 2 +-
tools/perf/util/ui/browser.h | 2 +-
tools/perf/util/ui/browsers/hists.c | 4 +-
tools/perf/util/ui/util.c | 2 +-
tools/perf/util/util.c | 2 +-
tools/perf/util/values.c | 2 +-
tools/perf/util/values.h | 2 +-
tools/perf/util/xyarray.c | 2 +-
67 files changed, 136 insertions(+), 83 deletions(-)
create mode 100644 tools/lib/lk/Makefile
rename tools/{perf/util => lib/lk}/debugfs.c (99%)
rename tools/{perf/util => lib/lk}/debugfs.h (85%)
rename tools/{perf/util => lib/lk}/types.h (83%)
rename tools/{perf/util => lib/lk}/usage.c (100%)
rename tools/{perf/util => lib/lk}/util.h (100%)
create mode 100644 tools/lib/perf/shared.htools/Makefile +5 -1
@@ -10,14 +10,18 @@ BASIC_CFLAGS += -I$(CURDIR)/perf/util/include export BASIC_CFLAGS -perf: libtrace .FORCE +perf: libtrace liblk .FORCE $(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) libtrace: .FORCE $(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) +liblk: .FORCE + $(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1) + clean: $(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) clean + $(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1) clean $(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean
tools/lib/lk/Makefile new file +38 -0
@@ -0,0 +1,38 @@ +include ../../scripts/Makefile.lib + +# guard against environment variables +LIB_H= +LIB_OBJS= + +LIB_H += debugfs.h +LIB_H += util.h +LIB_H += types.h + +LIB_OBJS += debugfs.o +LIB_OBJS += usage.o + +LIBFILE = $(LIB_OUTPUT)liblk.a + +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) +#EXTLIBS = -lpthread -lrt -lelf -lm +ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 +ALL_LDFLAGS = $(LDFLAGS) + +RM = rm -f + +$(LIBFILE): $(LIB_OBJS) + $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS) + +$(LIB_OBJS): $(LIB_H) + +%.o: %.c + $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< +%.s: %.c + $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $< +%.o: %.S + $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< + +clean: + $(RM) $(LIB_OBJS) $(LIBFILE) + +.PHONY: clean
tools/lib/lk/debugfs.c renamed from tools/perf/util/debugfs.c +1 -1
@@ -1,6 +1,6 @@#include "util.h" #include "debugfs.h" -#include "cache.h" +#include <perf/shared.h> static int debugfs_premounted;static char debugfs_mountpoint[MAX_PATH +1 ];
tools/lib/lk/debugfs.h renamed from tools/perf/util/debugfs.h +4 -3
@@ -1,7 +1,8 @@ -#ifndef __DEBUGFS_H__ -#define __DEBUGFS_H__ +#ifndef __LK_DEBUGFS_H__ +#define __LK_DEBUGFS_H__#include <sys/mount.h> +#include <sys/types.h> #ifndef MAX_PATH # define MAX_PATH 256
@@ -22,4 +23,4 @@ extern int debugfs_read(const char *entry, char *buffer, size_t size);extern void debugfs_force_cleanup (void );extern int debugfs_make_path (const char *element,char *buffer,int size); -#endif /* __DEBUGFS_H__ */ +#endif /* __LK_DEBUGFS_H__ */
tools/lib/lk/types.h renamed from tools/perf/util/types.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef __PERF_TYPES_H -#define __PERF_TYPES_H +#ifndef __LK_TYPES_H +#define __LK_TYPES_H/* * We define u64 as unsigned long long for every architecture
@@ -14,4 +14,4 @@ typedef signed short s16;typedef unsigned char u8 ;typedef signed char s8 ; -#endif /* __PERF_TYPES_H */ +#endif /* __LK_TYPES_H */
tools/lib/lk/usage.c renamed from tools/perf/util/usage.c +0 -0
tools/lib/lk/util.h renamed from tools/perf/util/util.h +0 -0
tools/lib/perf/shared.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef __PERF_SHARED_H +#define __PERF_SHARED_H + +/* +* Common defines shared between perf and the libs +*/ +#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" + +#endif /* __PERF_SHARED_H */
tools/lib/trace/trace-event-info.c +1 -1
@@ -39,7 +39,7 @@#include "../../perf/perf.h" #include "trace-event.h" -#include "../../perf/util/debugfs.h" +#include <lk/debugfs.h> #include "../../perf/util/evsel.h" #define VERSION "0.5"
tools/lib/trace/trace-event-parse.c +1 -1
@@ -30,7 +30,7 @@#undef _GNU_SOURCE#include "../../perf/perf.h" -#include "../../perf/util/util.h" +#include <lk/util.h> #include "trace-event.h" int header_page_ts_offset;
tools/lib/trace/trace-event-read.c +1 -1
@@ -37,7 +37,7 @@#include <errno.h> #include "../../perf/perf.h" -#include "../../perf/util/util.h" +#include <lk/util.h> #include "trace-event.h" static int input_fd;
tools/perf/Makefile +1 -6
@@ -326,7 +326,7 @@ export PERL_PATH LIB_FILE=$(OUTPUT)libperf.a -EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a +EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a $(LIB_OUTPUT)liblk.a LIB_H += ../../include/linux/perf_event.h LIB_H += ../../include/linux/rbtree.h
@@ -361,17 +361,14 @@ LIB_H += util/cache.h LIB_H += util/callchain.h LIB_H += util/build-id.h LIB_H += util/debug.h -LIB_H += util/debugfs.h LIB_H += util/event.h LIB_H += util/evsel.h LIB_H += util/exec_cmd.h -LIB_H += util/types.h LIB_H += util/levenshtein.h LIB_H += util/map.h LIB_H += util/parse-options.h LIB_H += util/parse-events.h LIB_H += util/quote.h -LIB_H += util/util.h LIB_H += util/xyarray.h LIB_H += util/header.h LIB_H += util/help.h
@@ -398,7 +395,6 @@ LIB_OBJS += $(OUTPUT)util/alias.o LIB_OBJS += $(OUTPUT)util/build-id.o LIB_OBJS += $(OUTPUT)util/config.o LIB_OBJS += $(OUTPUT)util/ctype.o -LIB_OBJS += $(OUTPUT)util/debugfs.o LIB_OBJS += $(OUTPUT)util/environment.o LIB_OBJS += $(OUTPUT)util/event.o LIB_OBJS += $(OUTPUT)util/evsel.o
@@ -416,7 +412,6 @@ LIB_OBJS += $(OUTPUT)util/quote.o LIB_OBJS += $(OUTPUT)util/strbuf.o LIB_OBJS += $(OUTPUT)util/string.o LIB_OBJS += $(OUTPUT)util/strlist.o -LIB_OBJS += $(OUTPUT)util/usage.o LIB_OBJS += $(OUTPUT)util/wrapper.o LIB_OBJS += $(OUTPUT)util/sigchain.o LIB_OBJS += $(OUTPUT)util/symbol.o
tools/perf/bench/mem-memcpy.c +1 -1
@@ -8,7 +8,7 @@#include <ctype.h> #include "../perf.h" -#include "../util/util.h" +#include <lk/util.h> #include "../util/parse-options.h" #include "../util/header.h" #include "bench.h"
tools/perf/bench/sched-messaging.c +1 -1
@@ -10,7 +10,7 @@*/ #include "../perf.h" -#include "../util/util.h" +#include <lk/util.h> #include "../util/parse-options.h" #include "../builtin.h" #include "bench.h"
tools/perf/bench/sched-pipe.c +1 -1
@@ -11,7 +11,7 @@*/ #include "../perf.h" -#include "../util/util.h" +#include <lk/util.h> #include "../util/parse-options.h" #include "../builtin.h" #include "bench.h"
tools/perf/builtin-annotate.c +1 -1
@@ -7,7 +7,7 @@*/ #include "builtin.h" -#include "util/util.h" +#include <lk/util.h> #include "util/color.h" #include <linux/list.h>
tools/perf/builtin-bench.c +1 -1
@@ -17,7 +17,7 @@*/ #include "perf.h" -#include "util/util.h" +#include <lk/util.h> #include "util/parse-options.h" #include "builtin.h" #include "bench/bench.h"
tools/perf/builtin-diff.c +1 -1
@@ -12,7 +12,7 @@#include "util/session.h" #include "util/sort.h" #include "util/symbol.h" -#include "util/util.h" +#include <lk/util.h> #include <stdlib.h>
tools/perf/builtin-kmem.c +1 -1
@@ -1,7 +1,7 @@#include "builtin.h" #include "perf.h" -#include "util/util.h" +#include <lk/util.h> #include "util/cache.h" #include "util/symbol.h" #include "util/thread.h"
tools/perf/builtin-kvm.c +1 -1
@@ -1,7 +1,7 @@#include "builtin.h" #include "perf.h" -#include "util/util.h" +#include <lk/util.h> #include "util/cache.h" #include "util/symbol.h" #include "util/thread.h"
tools/perf/builtin-lock.c +1 -1
@@ -1,7 +1,7 @@#include "builtin.h" #include "perf.h" -#include "util/util.h" +#include <lk/util.h> #include "util/cache.h" #include "util/symbol.h" #include "util/thread.h"
tools/perf/builtin-probe.c +2 -2
@@ -34,11 +34,11 @@#undef _GNU_SOURCE#include "perf.h" #include "builtin.h" -#include "util/util.h" +#include <lk/util.h> #include "util/strlist.h" #include "util/symbol.h" #include "util/debug.h" -#include "util/debugfs.h" +#include <lk/debugfs.h> #include "util/parse-options.h" #include "util/probe-finder.h" #include "util/probe-event.h"
tools/perf/builtin-record.c +1 -1
@@ -12,7 +12,7 @@#include "perf.h" #include "util/build-id.h" -#include "util/util.h" +#include <lk/util.h> #include "util/parse-options.h" #include "util/parse-events.h"
tools/perf/builtin-report.c +1 -1
@@ -7,7 +7,7 @@*/ #include "builtin.h" -#include "util/util.h" +#include <lk/util.h> #include "util/color.h" #include <linux/list.h>
tools/perf/builtin-sched.c +1 -1
@@ -1,7 +1,7 @@#include "builtin.h" #include "perf.h" -#include "util/util.h" +#include <lk/util.h> #include "util/cache.h" #include "util/symbol.h" #include "util/thread.h"
tools/perf/builtin-script.c +1 -1
@@ -11,7 +11,7 @@#include "util/thread.h" #include <trace/trace-event.h> #include "util/parse-options.h" -#include "util/util.h" +#include <lk/util.h> static char const *script_name;static char const *generate_script_lang;
tools/perf/builtin-stat.c +1 -1
@@ -39,7 +39,7 @@#include "perf.h" #include "builtin.h" -#include "util/util.h" +#include <lk/util.h> #include "util/parse-options.h" #include "util/parse-events.h" #include "util/event.h"
tools/perf/builtin-timechart.c +1 -1
@@ -14,7 +14,7 @@#include "builtin.h" -#include "util/util.h" +#include <lk/util.h> #include "util/color.h" #include <linux/list.h>
tools/perf/builtin-top.c +1 -1
@@ -25,7 +25,7 @@#include "util/session.h" #include "util/symbol.h" #include "util/thread.h" -#include "util/util.h" +#include <lk/util.h> #include <linux/rbtree.h> #include "util/parse-options.h" #include "util/parse-events.h"
tools/perf/builtin.h +1 -1
@@ -1,7 +1,7 @@#ifndef BUILTIN_H #define BUILTIN_H -#include "util/util.h" +#include <lk/util.h> #include "util/strbuf.h" extern const char perf_version_string[];
tools/perf/perf.c +14 -7
@@ -13,7 +13,8 @@#include "util/quote.h" #include "util/run-command.h" #include "util/parse-events.h" -#include "util/debugfs.h" +#include <lk/debugfs.h> +#include <perf/shared.h> const char perf_usage_string[] ="perf [--version] [--help] COMMAND [ARGS]" ;
@@ -418,14 +419,17 @@ static int run_argv(int *argcp, const char ***argv) }/* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */ -static void get_debugfs_mntpt (void ) +static bool get_debugfs_mntpt (void ) {const char *path =debugfs_mount (NULL ); -if (path) +if (path) {strncpy (debugfs_mntpt, path,sizeof (debugfs_mntpt)); -else - debugfs_mntpt[0 ] ='\0' ; +return true; + } + + debugfs_mntpt[0 ] ='\0' ; +return false; }int main (int argc,const char **argv)
@@ -435,8 +439,11 @@ int main(int argc, const char **argv) cmd =perf_extract_argv0_path (argv[0 ]);if (!cmd) cmd ="perf-help" ; -/* get debugfs mount point from /proc/mounts */ -get_debugfs_mntpt (); + +/* Establish a debugfs mountpoint */ +if (!get_debugfs_mntpt ()) +die ("cannot find valid debugfs mountpoint" ); +/* * "perf-xxxx" is the same as "perf xxxx", but we obviously: *
tools/perf/perf.h +1 -1
@@ -91,7 +91,7 @@ void get_term_dimensions(struct winsize *ws);#include <sys/syscall.h> #include "../../include/linux/perf_event.h" -#include "util/types.h" +#include <lk/types.h> #include <stdbool.h> /*
tools/perf/util/build-id.c +1 -1
@@ -6,7 +6,7 @@* Copyright (C) 2009, 2010 Red Hat Inc. * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <[email protected]> */ -#include "util.h" +#include <lk/util.h> #include <stdio.h> #include "build-id.h" #include "event.h"
tools/perf/util/cache.h +1 -2
@@ -2,7 +2,7 @@#define __PERF_CACHE_H#include <stdbool.h> -#include "util.h" +#include <lk/util.h> #include "strbuf.h" #include "../perf.h" #include <linux/compiler.h>
@@ -16,7 +16,6 @@#define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"#define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf" -#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"typedef int (*config_fn_t )(const char *,const char *,void *);extern int perf_default_config (const char *,const char *,void *);
tools/perf/util/callchain.c +1 -1
@@ -15,7 +15,7 @@#include <errno.h> #include <math.h> -#include "util.h" +#include <lk/util.h> #include "callchain.h" bool ip_callchain__valid (struct ip_callchain *chain,const event_t *event)
tools/perf/util/config.c +1 -1
@@ -5,7 +5,7 @@* Copyright (C) Johannes Schindelin, 2005 * */ -#include "util.h" +#include <lk/util.h> #include "cache.h" #include "exec_cmd.h"
tools/perf/util/cpumap.c +1 -1
@@ -1,4 +1,4 @@ -#include "util.h" +#include <lk/util.h> #include "../perf.h" #include "cpumap.h" #include <assert.h>
tools/perf/util/debug.c +1 -1
@@ -10,7 +10,7 @@#include "color.h" #include "event.h" #include "debug.h" -#include "util.h" +#include <lk/util.h> int verbose;bool dump_trace = false, quiet = false;
tools/perf/util/evsel.c +1 -1
@@ -1,6 +1,6 @@#include "evsel.h" #include "../perf.h" -#include "util.h" +#include <lk/util.h> #include "cpumap.h" #include "thread.h"
tools/perf/util/evsel.h +1 -1
@@ -4,7 +4,7 @@#include <linux/list.h> #include <stdbool.h> #include "../../../include/linux/perf_event.h" -#include "types.h" +#include <lk/types.h> #include "xyarray.h" struct perf_counts_values {
tools/perf/util/header.c +1 -1
@@ -8,7 +8,7 @@#include <linux/list.h> #include <linux/kernel.h> -#include "util.h" +#include <lk/util.h> #include "header.h" #include "../perf.h" #include <trace/trace-event.h>
tools/perf/util/header.h +1 -1
@@ -4,7 +4,7 @@#include "../../../include/linux/perf_event.h" #include <sys/types.h> #include <stdbool.h> -#include "types.h" +#include <lk/types.h> #include "event.h" #include <linux/bitmap.h>
tools/perf/util/hist.c +1 -1
@@ -1,4 +1,4 @@ -#include "util.h" +#include <lk/util.h> #include "build-id.h" #include "hist.h" #include "session.h"
tools/perf/util/include/linux/ctype.h +1 -1
@@ -1 +1 @@ -#include "../util.h" +#include <lk/util.h>
tools/perf/util/map.h +1 -1
@@ -6,7 +6,7 @@#include <linux/rbtree.h> #include <stdio.h> #include <stdbool.h> -#include "types.h" +#include <lk/types.h> enum map_type {MAP__FUNCTION =0 ,
tools/perf/util/parse-events.c +2 -2
@@ -1,5 +1,5 @@#include "../../../include/linux/hw_breakpoint.h" -#include "util.h" +#include <lk/util.h> #include "../perf.h" #include "evsel.h" #include "parse-options.h"
@@ -9,7 +9,7 @@#include "symbol.h" #include "cache.h" #include "header.h" -#include "debugfs.h" +#include <lk/debugfs.h> int nr_counters;
tools/perf/util/parse-options.c +1 -1
@@ -1,4 +1,4 @@ -#include "util.h" +#include <lk/util.h> #include "parse-options.h" #include "cache.h"
tools/perf/util/probe-event.c +2 -2
@@ -33,7 +33,7 @@#include <limits.h> #undef _GNU_SOURCE -#include "util.h" +#include <lk/util.h> #include "event.h" #include "string.h" #include "strlist.h"
@@ -42,7 +42,7 @@#include "color.h" #include "symbol.h" #include "thread.h" -#include "debugfs.h" +#include <lk/debugfs.h> #include <linux/compiler.h> /* For __unused */ #include "probe-event.h" #include "probe-finder.h"
tools/perf/util/probe-finder.c +1 -1
@@ -35,7 +35,7 @@#include "event.h" #include "debug.h" -#include "util.h" +#include <lk/util.h> #include "symbol.h" #include "probe-finder.h"
tools/perf/util/probe-finder.h +1 -1
@@ -2,7 +2,7 @@#define _PROBE_FINDER_H#include <stdbool.h> -#include "util.h" +#include <lk/util.h> #include "probe-event.h" #define MAX_PATH_LEN 256
tools/perf/util/pstack.c +1 -1
@@ -4,7 +4,7 @@* (c) 2010 Arnaldo Carvalho de Melo <[email protected]> */ -#include "util.h" +#include <lk/util.h> #include "pstack.h" #include <linux/kernel.h> #include <stdlib.h>
tools/perf/util/scripting-engines/trace-event-perl.c +1 -1
@@ -26,7 +26,7 @@#include <errno.h> #include "../../perf.h" -#include "../util.h" +#include <lk/util.h> #include <trace/trace-event.h> #include <EXTERN.h>
tools/perf/util/scripting-engines/trace-event-python.c +1 -1
@@ -28,7 +28,7 @@#include <errno.h> #include "../../perf.h" -#include "../util.h" +#include <lk/util.h> #include <trace/trace-event.h> PyMODINIT_FUNC initperf_trace_context (void );
tools/perf/util/session.c +1 -1
@@ -9,7 +9,7 @@#include "session.h" #include "sort.h" -#include "util.h" +#include <lk/util.h> static int perf_session__open (struct perf_session *self,bool force) {
tools/perf/util/sort.h +1 -1
@@ -2,7 +2,7 @@#define __PERF_SORT_H#include "../builtin.h" -#include "util.h" +#include <lk/util.h> #include "color.h" #include <linux/list.h>
tools/perf/util/string.c +1 -1
@@ -1,4 +1,4 @@ -#include "util.h" +#include <lk/util.h> #include "string.h" #define K 1024LL
tools/perf/util/svghelper.h +1 -1
@@ -1,7 +1,7 @@#ifndef __PERF_SVGHELPER_H#define __PERF_SVGHELPER_H -#include "types.h" +#include <lk/types.h> extern void open_svg (const char *filename,int cpus,int rows,u64 start,u64 end);extern void svg_box (int Yslot,u64 start,u64 end,const char *type);
tools/perf/util/thread.c +1 -1
@@ -4,7 +4,7 @@#include <string.h> #include "session.h" #include "thread.h" -#include "util.h" +#include <lk/util.h> #include "debug.h" /* Skip "." and ".." directories */
tools/perf/util/trace-event-scripting.c +1 -1
@@ -26,7 +26,7 @@#include <errno.h> #include "../perf.h" -#include "util.h" +#include <lk/util.h> #include <trace/trace-event.h> struct scripting_context *scripting_context;
tools/perf/util/ui/browser.c +1 -1
@@ -7,7 +7,7 @@#include "browser.h" #include "helpline.h" #include "../color.h" -#include "../util.h" +#include <lk/util.h> #include <stdio.h> static int ui_browser__percent_color (double percent,bool current)
tools/perf/util/ui/browser.h +1 -1
@@ -4,7 +4,7 @@#include <stdbool.h> #include <newt.h> #include <sys/types.h> -#include "../types.h" +#include <lk/types.h> #define HE_COLORSET_TOP 50#define HE_COLORSET_MEDIUM 51
tools/perf/util/ui/browsers/hists.c +2 -2
@@ -10,11 +10,11 @@#include "../../hist.h" #include "../../pstack.h" #include "../../sort.h" -#include "../../util.h" +#include <lk/util.h> #include "../browser.h" #include "../helpline.h" -#include "../util.h" +#include <lk/util.h> #include "map.h" struct hist_browser {
tools/perf/util/ui/util.c +1 -1
@@ -9,7 +9,7 @@#include "../debug.h" #include "browser.h" #include "helpline.h" -#include "util.h" +#include <lk/util.h> static void newt_form__set_exit_keys (newtComponent self) {
tools/perf/util/util.c +1 -1
@@ -1,4 +1,4 @@ -#include "util.h" +#include <lk/util.h> #include <sys/mman.h> int mkdir_p (char *path,mode_t mode)
tools/perf/util/values.c +1 -1
@@ -1,6 +1,6 @@#include <stdlib.h> -#include "util.h" +#include <lk/util.h> #include "values.h" void perf_read_values_init (struct perf_read_values *values)
tools/perf/util/values.h +1 -1
@@ -1,7 +1,7 @@ #ifndef __PERF_VALUES_H #define __PERF_VALUES_H -#include "types.h" +#include <lk/types.h> struct perf_read_values { int threads;
tools/perf/util/xyarray.c +1 -1
@@ -1,5 +1,5 @@#include "xyarray.h" -#include "util.h" +#include <lk/util.h> struct xyarray *xyarray__new (int xlen,int ylen,size_t entry_size) {
Signature · 1 line
1.7.4.rc2
PATCH 8/12 perf: Carve out mmap helpers for general use
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Export the mmap_read* helpers into tools/lib/perf/mmap.[ch]
--- tools/Makefile | 8 +++- tools/lib/perf/Makefile | 35 +++++++++++++++ tools/lib/perf/mmap.c | 91 ++++++++++++++++++++++++++++++++++++++ tools/lib/perf/mmap.h | 13 +++++ tools/perf/Makefile | 2 +- tools/perf/builtin-record.c | 103 ++++--------------------------------------- tools/perf/builtin-top.c | 25 ++-------- 7 files changed, 160 insertions(+), 117 deletions(-) create mode 100644 tools/lib/perf/Makefile create mode 100644 tools/lib/perf/mmap.c create mode 100644 tools/lib/perf/mmap.h
tools/Makefile +6 -2
@@ -3,14 +3,14 @@ include scripts/Makefile.lib PERF_TOP_DIR := $(CURDIR) export PERF_TOP_DIR -BASIC_CFLAGS = -I$(CURDIR)/lib +BASIC_CFLAGS = -I$(CURDIR)/lib -I$(CURDIR)/perf # temporary for lib/trace/ BASIC_CFLAGS += -I$(CURDIR)/perf/util/include export BASIC_CFLAGS -perf: libtrace liblk .FORCE +perf: libtrace liblk liblkperf .FORCE $(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) libtrace: .FORCE
@@ -19,9 +19,13 @@ libtrace: .FORCE liblk: .FORCE $(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1) +liblkperf: + $(QUIET_SUBDIR0)lib/perf/ $(QUIET_SUBDIR1) + clean: $(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) clean $(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1) clean + $(QUIET_SUBDIR0)lib/perf/ $(QUIET_SUBDIR1) clean $(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean
tools/lib/perf/Makefile new file +35 -0
@@ -0,0 +1,35 @@ +include ../../scripts/Makefile.lib + +# guard against environment variables +LIB_H= +LIB_OBJS= + +LIB_H += mmap.h + +LIB_OBJS += mmap.o + +LIBFILE = $(LIB_OUTPUT)liblkperf.a + +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) +EXTLIBS = -lpthread -lrt -lelf -lm +ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 +ALL_LDFLAGS = $(LDFLAGS) + +RM = rm -f + +$(LIBFILE): $(LIB_OBJS) + $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS) + +$(LIB_OBJS): $(LIB_H) + +%.o: %.c + $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< +%.s: %.c + $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $< +%.o: %.S + $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< + +clean: + $(RM) $(LIB_OBJS) $(LIBFILE) + +.PHONY: clean
tools/lib/perf/mmap.c new file +91 -0
91 lines not on this page · raw message
tools/lib/perf/mmap.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef __PERF_MMAP_H +#define __PERF_MMAP_H + +struct mmap_data { +void *base; +unsigned int mask; +unsigned int prev; +}; + +unsigned long mmap_read_head (struct mmap_data *); +unsigned long mmap_read_all (struct mmap_data *,int , +void (*write_output)(void *,size_t )); +#endif /* __PERF_MMAP_H */
tools/perf/Makefile +1 -1
@@ -326,7 +326,7 @@ export PERL_PATH LIB_FILE=$(OUTPUT)libperf.a -EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a $(LIB_OUTPUT)liblk.a +EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a $(LIB_OUTPUT)liblk.a $(LIB_OUTPUT)liblkperf.a LIB_H += ../../include/linux/perf_event.h LIB_H += ../../include/linux/rbtree.h
tools/perf/builtin-record.c +9 -94
149 lines not on this page · raw message
tools/perf/builtin-top.c +5 -20
@@ -25,8 +25,6 @@#include "util/session.h" #include "util/symbol.h" #include "util/thread.h" -#include <lk/util.h> -#include <linux/rbtree.h> #include "util/parse-options.h" #include "util/parse-events.h" #include "util/cpumap.h"
@@ -34,6 +32,10 @@#include "util/debug.h" +#include <linux/rbtree.h> +#include <lk/util.h> +#include <perf/mmap.h> +#include <assert.h> #include <fcntl.h>
@@ -1091,12 +1093,6 @@ static void event__process_sample(const event_t *self, } } -struct mmap_data { -void *base; -int mask; -unsigned int prev; -}; -static int perf_evsel__alloc_mmap_per_thread (struct perf_evsel *evsel,int ncpus,int nthreads) {
@@ -1110,17 +1106,6 @@ static void perf_evsel__free_mmap(struct perf_evsel *evsel) evsel->priv =NULL ; } -static unsigned int mmap_read_head (struct mmap_data *md) -{ -struct perf_event_mmap_page *pc = md->base; -int head; - - head = pc->data_head; -rmb (); - -return head; -} -static void perf_session__mmap_read_counter (struct perf_session *self,struct perf_evsel *evsel,int cpu,int thread_idx)
@@ -1142,7 +1127,7 @@ static void perf_session__mmap_read_counter(struct perf_session *self,* In either case, truncate and restart at head. */ diff = head - old; -if (diff > md->mask /2 || diff <0 ) { +if ((unsigned int )diff > md->mask /2 || diff <0 ) {fprintf (stderr,"WARNING: failed to keep up with mmap data.\n" );/*
Signature · 1 line
1.7.4.rc2
Re: [PATCH 08/12] perf: Carve out mmap helpers for general use
Em Fri, Jan 21, 2011 at 04:09:31PM +0100, Borislav Petkov escreveu:
Quoted 3 lines
From: Borislav Petkov <[email protected]>
Export the mmap_read* helpers into tools/lib/perf/mmap.[ch]
Borislav, can you take a look at:
http://git.kernel.org/?p=linux/kernel/git/acme/linux-2.6.git;a=shortlog;h=refs/heads/perf/core
More specifically take a look at the function test__basic_mmap in:
434 /*
435 * This test will generate random numbers of calls to some getpid syscalls, 436 * then establish an mmap for a group of events that are created to monitor 437 * the syscalls. 438 * 439 * It will receive the events, using mmap, use its PERF_SAMPLE_ID generated 440 * sample.id field to map back to its respective perf_evsel instance. 441 * 442 * Then it checks if the number of syscalls reported as perf events by 443 * the kernel corresponds to the number of syscalls made. 444 */
I'll read the rest of your patchset to see if there are more things like this.
- Arnaldo
Re: [PATCH 08/12] perf: Carve out mmap helpers for general use
Quoted 14 lines · Arnaldo Carvalho de Melo
Em Fri, Jan 21, 2011 at 04:09:31PM +0100, Borislav Petkov escreveu:
Quoted 3 lines
From: Borislav Petkov <[email protected]>
Export the mmap_read* helpers into tools/lib/perf/mmap.[ch]
Borislav, can you take a look at:
http://git.kernel.org/?p=linux/kernel/git/acme/linux-2.6.git;a=shortlog;h=refs/heads/perf/core
More specifically take a look at the function
test__basic_mmapin:434 /*
Quoted 10 lines
435 * This test will generate random numbers of calls to some getpid syscalls, 436 * then establish an mmap for a group of events that are created to monitor 437 * the syscalls. 438 * 439 * It will receive the events, using mmap, use its PERF_SAMPLE_ID generated 440 * sample.id field to map back to its respective perf_evsel instance. 441 * 442 * Then it checks if the number of syscalls reported as perf events by 443 * the kernel corresponds to the number of syscalls made. 444 */
Ok, I see at least one problem with my patch - you've reworked the mmaping functionality in evlist.c/evsel.c and I should use it too, I guess. For that, I think you'd want me to apply my stuff ontop of your perf/core branch, right?
Am I missing something else?
Thanks.
Signature · 8 lines
Regards/Gruss, Boris. Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632
Re: [PATCH 08/12] perf: Carve out mmap helpers for general use
Em Mon, Jan 24, 2011 at 10:04:10AM +0100, Borislav Petkov escreveu:
Quoted 4 lines
Ok, I see at least one problem with my patch - you've reworked the mmaping functionality in
evlist.c/evsel.cand I should use it too, I guess. For that, I think you'd want me to apply my stuff ontop of your perf/core branch, right?
Right, I hope to have that branch merged by Ingo soon.
Quoted 1 line
Am I missing something else?
Nope, you're not. Doing that we erode your patchset a bit, reducing its size.
One related experience I'm doing now is to have a perf.so python binding, the setup.py file for it with the list of files needed for this specific binding is at:
http://userweb.kernel.org/~acme/setup.py
A simple tool using the resulting binding is a thread fork/comm/exit/sample watcher, available at:
http://userweb.kernel.org/~acme/twatch
In this process I'm moving functions around so as to reduce the number of tools/perf/util.c files to link into this perf.so python binding, untangling things as much as possible.
The binding proper is:
http://userweb.kernel.org/~acme/python.c
I'm digressing, but twatch is an example of a simple "daemon" consuming perf events where performance is not much of a problem.
And provides a prototyping ground when starting to design perf events consuming daemons :-)
- Arnaldo
Borislav Petkov
maintainerRe: [PATCH 08/12] perf: Carve out mmap helpers for general use
Quoted 6 lines · Arnaldo Carvalho de Melo
Em Mon, Jan 24, 2011 at 10:04:10AM +0100, Borislav Petkov escreveu:
Quoted 4 lines
Ok, I see at least one problem with my patch - you've reworked the mmaping functionality in
evlist.c/evsel.cand I should use it too, I guess. For that, I think you'd want me to apply my stuff ontop of your perf/core branch, right?
Quoted 6 lines
Right, I hope to have that branch merged by Ingo soon.
Quoted 1 line
Am I missing something else?
Nope, you're not. Doing that we erode your patchset a bit, reducing its size.
.. which means less work for me, heey, nice! :)
Quoted 17 lines
One related experience I'm doing now is to have a perf.so python binding, the
setup.pyfile for it with the list of files needed for this specific binding is at:http://userweb.kernel.org/~acme/setup.py
A simple tool using the resulting binding is a thread fork/comm/exit/sample watcher, available at:
http://userweb.kernel.org/~acme/twatch
In this process I'm moving functions around so as to reduce the number of
tools/perf/util.cfiles to link into this perf.so python binding, untangling things as much as possible.The binding proper is:
Quoted 7 lines
http://userweb.kernel.org/~acme/python.c
I'm digressing, but twatch is an example of a simple "daemon" consuming perf events where performance is not much of a problem.
And provides a prototyping ground when starting to design perf events consuming daemons :-)
Yaay, twatch looks almost like a child's play and even my grandma can profile her system now :).
But yeah, I thought about pythonizing the ras thingy too but the reasons against it are that we might run on systems which don't have python, have some obscure/old version of it or we simply don't want to depend on it or any other additional tool for that matter. Generally, we want to run with as low overhead as possible when handling hw error info and be as self-contained as possible.
Signature · 2 lines
Regards/Gruss,
Boris.Re: [PATCH 08/12] perf: Carve out mmap helpers for general use
Em Wed, Jan 26, 2011 at 02:00:02AM +0100, Borislav Petkov escreveu:
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 6 lines
Em Mon, Jan 24, 2011 at 10:04:10AM +0100, Borislav Petkov escreveu:
I'm digressing, but twatch is an example of a simple "daemon" consuming perf events where performance is not much of a problem.And provides a prototyping ground when starting to design perf events consuming daemons :-)
Yaay, twatch looks almost like a child's play and even my grandma can profile her system now :).
Quoted 6 lines
But yeah, I thought about pythonizing the ras thingy too but the reasons against it are that we might run on systems which don't have python, have some obscure/old version of it or we simply don't want to depend on it or any other additional tool for that matter. Generally, we want to run with as low overhead as possible when handling hw error info and be as self-contained as possible.
Right, that is why I try to have the python abstractions as close as possible to the abstractions a C program, like your RAS thingy should use.
I.e. one can go on introducing the kernel interfaces and testing them using python, where you can, for instance, from the python interpreter command line, create counters, read its values, i.e. test the kernel stuff quickly and easily.
Moving to a C version then becomes easy after the testing phase is over and the kernel bits are set in stone.
- Arnaldo
PATCH 1/1 ras: Add RAS daemon
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
--- tools/Makefile | 4 + tools/ras/Makefile | 16 +++ tools/ras/rasd.c | 311 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 331 insertions(+), 0 deletions(-) create mode 100644 tools/ras/Makefile create mode 100644 tools/ras/rasd.c
tools/Makefile +4 -0
@@ -22,11 +22,15 @@ liblk: .FORCE liblkperf: $(QUIET_SUBDIR0)lib/perf/ $(QUIET_SUBDIR1) +ras: libtrace liblk liblkperf .FORCE + $(QUIET_SUBDIR0)ras/ $(QUIET_SUBDIR1) + clean: $(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) clean $(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1) clean $(QUIET_SUBDIR0)lib/perf/ $(QUIET_SUBDIR1) clean $(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean + $(QUIET_SUBDIR0)ras/ $(QUIET_SUBDIR1) clean .PHONY: clean .FORCE
tools/ras/Makefile new file +16 -0
@@ -0,0 +1,16 @@ +include ../scripts/Makefile.lib + +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 -DNO_NEWT_SUPPORT $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) +ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 +ALL_LDFLAGS = $(LDFLAGS) + +RASLIBS=$(LIB_OUTPUT)libtrace.a $(LIB_OUTPUT)liblk.a $(LIB_OUTPUT)liblkperf.a + +rasd: rasd.o + $(QUIET_CC)$(CC) $(ALL_CFLAGS) -o $@ $^ $(RASLIBS) + +%.o: %.c + $(QUIET_CC)$(CC) $(ALL_CFLAGS) -c $< + +clean: + rm -rf *.o rasd
tools/ras/rasd.c new file +311 -0
311 lines not on this page · raw message
Signature · 1 line
1.7.4.rc2
Tony Luck
maintainerRe: [PATCH] ras: Add RAS daemon
Quoted 3 lines · Borislav Petkov
+
format_buf=malloc_or_die(fsize);
+ if (!format_buf)
+die("allocating format buffer");
You don't trust "malloc_or_die()" to make it dead enough? :-)
Will take a look through the rest of bits - looks very interesting.
-Tony
Re: [PATCH] ras: Add RAS daemon
Quoted 6 lines · Tony Luck
Quoted 3 lines · Borislav Petkov
+
format_buf=malloc_or_die(fsize);
+ if (!format_buf)
+die("allocating format buffer");You don't trust "
malloc_or_die()" to make it dead enough? :-)
Yeah, it ain't dead yet! That's me with the big hammer.
Good catch, will fix.
Quoted 1 line
Will take a look through the rest of bits - looks very interesting.
Thanks a lot sir :).
Signature · 8 lines
Regards/Gruss, Boris. Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632
PATCH 9/12 perf: Export util.ch into library
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
This is needed for shared common functionality.
---
tools/lib/lk/Makefile | 1 +
tools/{perf/util => lib/lk}/util.c | 0
tools/lib/perf/Makefile | 1 +
tools/lib/perf/util.h | 8 ++++++++
tools/perf/Makefile | 1 -
tools/perf/perf.h | 3 ---
tools/perf/util/cpumap.c | 2 +-
tools/perf/util/parse-events.h | 1 +
8 files changed, 12 insertions(+), 5 deletions(-)
rename tools/{perf/util => lib/lk}/util.c (100%)
create mode 100644 tools/lib/perf/util.htools/lib/lk/Makefile +1 -0
@@ -10,6 +10,7 @@ LIB_H += types.h LIB_OBJS += debugfs.o LIB_OBJS += usage.o +LIB_OBJS += util.o LIBFILE = $(LIB_OUTPUT)liblk.a
tools/lib/lk/util.c renamed from tools/perf/util/util.c +0 -0
tools/lib/perf/Makefile +1 -0
@@ -5,6 +5,7 @@ LIB_H= LIB_OBJS= LIB_H += mmap.h +LIB_H += util.h LIB_OBJS += mmap.o
tools/lib/perf/util.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef __PERF_UTIL_H +#define __PERF_UTIL_H + +#define MAX_COUNTERS 256 +#define MAX_NR_CPUS 256 + +#endif /* __PERF_UTIL_H */ +
tools/perf/Makefile +0 -1
@@ -430,7 +430,6 @@ LIB_OBJS += $(OUTPUT)util/svghelper.o LIB_OBJS += $(OUTPUT)util/sort.o LIB_OBJS += $(OUTPUT)util/hist.o LIB_OBJS += $(OUTPUT)util/probe-event.o -LIB_OBJS += $(OUTPUT)util/util.o LIB_OBJS += $(OUTPUT)util/xyarray.o LIB_OBJS += $(OUTPUT)util/cpumap.o
tools/perf/perf.h +0 -3
@@ -136,9 +136,6 @@ sys_perf_event_open(struct perf_event_attr *attr, group_fd, flags); } -#define MAX_COUNTERS 256 -#define MAX_NR_CPUS 256 -struct ip_callchain {u64 nr;u64 ips[0 ];
tools/perf/util/cpumap.c +1 -1
@@ -1,5 +1,5 @@#include <lk/util.h> -#include "../perf.h" +#include <perf/util.h> #include "cpumap.h" #include <assert.h> #include <stdio.h>
tools/perf/util/parse-events.h +1 -0
@@ -3,6 +3,7 @@/* * Parse symbolic events/counts passed in as options: */ +#include <perf/util.h> #include "../../../include/linux/perf_event.h"
Signature · 1 line
1.7.4.rc2
PATCH 10/12 perf: Export ctype.c
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
This is needed when linking against libtrace.a
---
tools/lib/lk/Makefile | 1 +
tools/{perf/util => lib/lk}/ctype.c | 2 +-
tools/perf/Makefile | 1 -
3 files changed, 2 insertions(+), 2 deletions(-)
rename tools/{perf/util => lib/lk}/ctype.c (98%)tools/lib/lk/Makefile +1 -0
@@ -11,6 +11,7 @@ LIB_H += types.h LIB_OBJS += debugfs.o LIB_OBJS += usage.o LIB_OBJS += util.o +LIB_OBJS += ctype.o LIBFILE = $(LIB_OUTPUT)liblk.a
tools/lib/lk/ctype.c renamed from tools/perf/util/ctype.c +1 -1
@@ -3,7 +3,7 @@* * No surprises, and works with signed and unsigned chars. */ -#include "cache.h" +#include "util.h" enum {S =GIT_SPACE ,
tools/perf/Makefile +0 -1
@@ -394,7 +394,6 @@ LIB_OBJS += $(OUTPUT)util/abspath.o LIB_OBJS += $(OUTPUT)util/alias.o LIB_OBJS += $(OUTPUT)util/build-id.o LIB_OBJS += $(OUTPUT)util/config.o -LIB_OBJS += $(OUTPUT)util/ctype.o LIB_OBJS += $(OUTPUT)util/environment.o LIB_OBJS += $(OUTPUT)util/event.o LIB_OBJS += $(OUTPUT)util/evsel.o
Signature · 1 line
1.7.4.rc2
PATCH 11/12 perf: Export tracepoint_id_to_path
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
This is needed when linking against libtrace.a so move it to <lib/trace/trace-event-info.c> and adjust all headers accordingly.
--- tools/lib/trace/trace-event-info.c | 123 ++++++++++++++++++++++++++++++----- tools/lib/trace/trace-event.h | 19 ++++++ tools/perf/util/parse-events.c | 104 +----------------------------- tools/perf/util/parse-events.h | 1 - tools/perf/util/parse-options.h | 1 + 5 files changed, 128 insertions(+), 120 deletions(-)
tools/lib/trace/trace-event-info.c +105 -18
@@ -18,7 +18,6 @@* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -#define _GNU_SOURCE#include <dirent.h> #include <mntent.h> #include <stdio.h>
@@ -26,6 +25,7 @@#include <string.h> #include <stdarg.h> #include <sys/types.h> +#include <sys/param.h> #include <sys/stat.h> #include <sys/wait.h> #include <pthread.h>
@@ -39,9 +39,11 @@#include "../../perf/perf.h" #include "trace-event.h" -#include <lk/debugfs.h> #include "../../perf/util/evsel.h" +#include <lk/util.h> +#include <lk/debugfs.h> +#define VERSION "0.5"#define _STR (x) #x
@@ -58,6 +60,7 @@unsigned int page_size;static const char *output_file ="trace.info" ; +static const char *dfs_path;static int output_fd;struct event_list {
@@ -72,7 +75,7 @@ struct events {char *name; }; -static void die (const char *fmt, ...) +static void t_die (const char *fmt, ...) {va_list ap;int ret = errno;
@@ -97,7 +100,7 @@ void *malloc_or_die(unsigned int size) data =malloc (size);if (!data) -die ("malloc" ); +t_die ("malloc" );return data; }
@@ -106,7 +109,7 @@ static const char *find_debugfs(void)const char *path =debugfs_mount (NULL );if (!path) -die ("Your kernel not support debugfs filesystem" ); +t_die ("Your kernel not support debugfs filesystem" );return path; }
@@ -167,7 +170,7 @@ static ssize_t write_or_die(const void *buf, size_t len) ret =write (output_fd, buf, len);if (ret <0 ) -die ("writing to '%s'" , output_file); +t_die ("writing to '%s'" , output_file);return ret; }
@@ -205,7 +208,7 @@ static unsigned long long copy_file(const char *file) fd =open (file,O_RDONLY );if (fd <0 ) -die ("Can't read '%s'" , file); +t_die ("Can't read '%s'" , file); size =copy_file_fd (fd);close (fd);
@@ -236,7 +239,7 @@ unsigned long get_filesize(const char *file) fd =open (file,O_RDONLY );if (fd <0 ) -die ("Can't read '%s'" , file); +t_die ("Can't read '%s'" , file); size =get_size_fd (fd);close (fd);
@@ -252,7 +255,7 @@ static void read_header_files(void) path =get_tracing_file ("events/header_page" ); fd =open (path,O_RDONLY );if (fd <0 ) -die ("can't read '%s'" , path); +t_die ("can't read '%s'" , path);/* unfortunately, you can not stat debugfs files for size */ size =get_size_fd (fd);
@@ -263,14 +266,14 @@ static void read_header_files(void)close (fd);if (size != check_size) -die ("wrong size for '%s' size=%lld read=%lld" , +t_die ("wrong size for '%s' size=%lld read=%lld" , path, size, check_size);put_tracing_file (path); path =get_tracing_file ("events/header_event" ); fd =open (path,O_RDONLY );if (fd <0 ) -die ("can't read '%s'" , path); +t_die ("can't read '%s'" , path); size =get_size_fd (fd);
@@ -278,7 +281,7 @@ static void read_header_files(void)write_or_die (&size,8 ); check_size =copy_file_fd (fd);if (size != check_size) -die ("wrong size for '%s'" , path); +t_die ("wrong size for '%s'" , path);put_tracing_file (path);close (fd); }
@@ -306,7 +309,7 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps) dir =opendir (sys);if (!dir) -die ("can't read directory '%s'" , sys); +t_die ("can't read directory '%s'" , sys);while ((dent =readdir (dir))) { if (dent->d_type != DT_DIR ||
@@ -342,7 +345,7 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps)write_or_die (&size,8 ); check_size =copy_file (format);if (size != check_size) -die ("error in size of file '%s'" , format); +t_die ("error in size of file '%s'" , format); }free (format);
@@ -386,7 +389,7 @@ static void read_event_files(struct tracepoint_path *tps) dir =opendir (path);if (!dir) -die ("can't read directory '%s'" , path); +t_die ("can't read directory '%s'" , path);while ((dent =readdir (dir))) { if (dent->d_type != DT_DIR ||
@@ -440,7 +443,7 @@ static void read_proc_kallsyms(void)write_or_die (&size,4 ); check_size =copy_file (path);if (size != check_size) -die ("error in size of file '%s'" , path); +t_die ("error in size of file '%s'" , path); }
@@ -463,11 +466,95 @@ static void read_ftrace_printk(void)write_or_die (&size,4 ); check_size =copy_file (path);if (size != check_size) -die ("error in size of file '%s'" , path); +t_die ("error in size of file '%s'" , path); out:put_tracing_file (path); } +int tp_event_has_id (struct dirent *sys_dir,struct dirent *evt_dir) +{ +char evt_path[MAXPATHLEN ]; +int fd; + +snprintf (evt_path,MAXPATHLEN ,"%s/%s/%s/id" , dfs_path, + sys_dir->d_name, evt_dir->d_name); + fd =open (evt_path,O_RDONLY ); +if (fd <0 ) +return -EINVAL ; +close (fd); + +return 0 ; +} + +struct tracepoint_path *tracepoint_id_to_path (u64 config) +{ +struct tracepoint_path *path =NULL ; +DIR *sys_dir, *evt_dir; +struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; +char id_buf[4 ]; +int fd; +u64 id; +char evt_path[MAXPATHLEN ]; +char dir_path[MAXPATHLEN ]; + + dfs_path =debugfs_mount (NULL ); +if (!dfs_path) +return NULL ; + + sys_dir =opendir (dfs_path); +if (!sys_dir) +return NULL ; + +for_each_subsystem (sys_dir, sys_dirent, sys_next) { + +snprintf (dir_path,MAXPATHLEN ,"%s/%s" , dfs_path, + sys_dirent.d_name); + evt_dir =opendir (dir_path); +if (!evt_dir) +continue ; + +for_each_event (sys_dirent, evt_dir, evt_dirent, evt_next) { + +snprintf (evt_path,MAXPATHLEN ,"%s/%s/id" , dir_path, + evt_dirent.d_name); + fd =open (evt_path,O_RDONLY ); +if (fd <0 ) +continue ; +if (read (fd, id_buf,sizeof (id_buf)) <0 ) { +close (fd); +continue ; + } +close (fd); + id =atoll (id_buf); +if (id == config) { +closedir (evt_dir); +closedir (sys_dir); + path =zalloc (sizeof (*path)); + path->system =malloc (MAX_EVENT_LENGTH ); +if (!path->system) { +free (path); +return NULL ; + } + path->name =malloc (MAX_EVENT_LENGTH ); +if (!path->name) { +free (path->system); +free (path); +return NULL ; + } +strncpy (path->system, sys_dirent.d_name, +MAX_EVENT_LENGTH ); +strncpy (path->name, evt_dirent.d_name, +MAX_EVENT_LENGTH ); +return path; + } + } +closedir (evt_dir); + } + +closedir (sys_dir); +return NULL ; +} +static struct tracepoint_path *get_tracepoints_path (struct list_head *pattrs) {
@@ -481,7 +568,7 @@ get_tracepoints_path(struct list_head *pattrs) ++nr_tracepoints; ppath->next =tracepoint_id_to_path (pos->attr.config);if (!ppath->next) -die ("%s\n" ,"No memory to alloc tracepoints list" ); +t_die ("%s\n" ,"No memory to alloc tracepoints list" ); ppath = ppath->next; }
tools/lib/trace/trace-event.h +19 -0
@@ -2,6 +2,7 @@#define __LIB_TRACE_EVENTS_H#include <stdbool.h> +#include <dirent.h> #include "../../perf/util/parse-events.h" #define __unused __attribute__((unused))
@@ -312,4 +313,22 @@ int common_pc(struct scripting_context *context);int common_flags (struct scripting_context *context);int common_lock_depth (struct scripting_context *context); +#define MAX_EVENT_LENGTH 512 +#define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1) + +#define for_each_subsystem (sys_dir, sys_dirent, sys_next) \ + while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \ + if (sys_dirent.d_type == DT_DIR && \ + (strcmp(sys_dirent.d_name, ".")) && \ + (strcmp(sys_dirent.d_name, ".."))) + +#define for_each_event (sys_dirent, evt_dir, evt_dirent, evt_next) \ + while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \ + if (evt_dirent.d_type == DT_DIR && \ + (strcmp(evt_dirent.d_name, ".")) && \ + (strcmp(evt_dirent.d_name, "..")) && \ + (!tp_event_has_id(&sys_dirent, &evt_dirent))) + +extern int tp_event_has_id (struct dirent *sys_dir,struct dirent *evt_dir); +extern struct tracepoint_path *tracepoint_id_to_path (u64 config);#endif /* __LIB_TRACE_EVENTS_H */
tools/perf/util/parse-events.c +3 -101
121 lines not on this page · raw message
tools/perf/util/parse-events.h +0 -1
@@ -23,7 +23,6 @@ struct tracepoint_path {struct tracepoint_path *next; }; -extern struct tracepoint_path *tracepoint_id_to_path (u64 config);extern bool have_tracepoints (struct list_head *evsel_list);extern int nr_counters;
tools/perf/util/parse-options.h +1 -0
@@ -3,6 +3,7 @@#include <linux/kernel.h> #include <stdbool.h> +#include <lk/util.h> enum parse_opt_type {/* special types */
Signature · 1 line
1.7.4.rc2