From: Borislav Petkov <borislav.petkov@amd.com>
Hi,
I finally found some time for a second take at the ras daemon.
This one is based on Steven's trace-cmd integration into perf:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git, branch tip/perf/parse-events
which is still alpha, as are those patches too, btw. I'm sending them
now as a RFC/FYI type-thing only, work on them continues.
I've tried to incorporate and accomodate all comments from the last
round. Using debugfs files for mmaping the perf buffers makes the code
much simpler and introduces a lot less changes to the perf tool wrt to
exporting stuff into the library for external use.
The are still unresolved issues like the VM_SHARED check in perf_mmap()
which fails for read-only files in debugfs. Peter, what is your take at
this, do we want to relax that for persistent read-only events?
Also, I need this hunk otherwise I'm oopsing on exit:
---
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 8ff5292..8edb400 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -2665,7 +2665,9 @@ static void perf_mmap_close(struct vm_area_struct *vma)
struct user_struct *user = event->mmap_user;
struct perf_buffer *buffer = event->buffer;
- atomic_long_sub((size >> PAGE_SHIFT) + 1, &user->locked_vm);
+ if (user)
+ atomic_long_sub((size >> PAGE_SHIFT) + 1, &user->locked_vm);
+
vma->vm_mm->locked_vm -= event->mmap_locked;
rcu_assign_pointer(event->buffer, NULL);
mutex_unlock(&event->mmap_mutex);
--
and I'll add it as an additional patch to the series if there are no
objections. See, we add the current user when we mmap but on already
allocated event buffers we skip that by exiting early so this change
should be fine for events with preallocated buffers, right?
@Arnaldo: I think this version should take care of the build issues you
had last ...From: Borislav Petkov <borislav.petkov@amd.com> Move tracing stuff into tools/lib/trace and rewire it back into perf. Add a top-level Makefile which selects between targets depending on the tool we want to build. Also, add a Makefile.lib for common facilities used by all the Makefiles. While at it, make sure objects output directory using O= exists. Finally, rename trace/util.h to trace/trace-util.h so as not to conflict with perf's util.h. Signed-off-by: Borislav Petkov <borislav.petkov@amd.com> --- tools/Makefile | 47 + tools/lib/Makefile | 49 - tools/lib/parse-events.c | 4655 ---------------------------------------- tools/lib/parse-events.h | 719 ------- tools/lib/parse-filter.c | 2085 ------------------ tools/lib/parse-utils.c | 110 - tools/lib/trace-seq.c | 153 -- tools/lib/trace/Makefile | 54 + tools/lib/trace/parse-events.c | 4655 ++++++++++++++++++++++++++++++++++++++++ tools/lib/trace/parse-events.h | 719 +++++++ tools/lib/trace/parse-filter.c | 2085 ++++++++++++++++++ tools/lib/trace/parse-utils.c | 110 + tools/lib/trace/trace-seq.c | 153 ++ tools/lib/trace/trace-util.h | 64 + tools/lib/util.h | 64 - tools/perf/Makefile | 41 +- tools/perf/util/trace-event.h | 2 +- tools/scripts/Makefile.lib | 33 + 18 files changed, 7923 insertions(+), 7875 deletions(-) create mode 100644 tools/Makefile delete mode 100644 tools/lib/Makefile delete mode 100644 tools/lib/parse-events.c delete mode 100644 tools/lib/parse-events.h delete mode 100644 tools/lib/parse-filter.c delete mode 100644 tools/lib/parse-utils.c delete mode 100644 tools/lib/trace-seq.c create mode 100644 tools/lib/trace/Makefile create mode 100644 tools/lib/trace/parse-events.c create mode 100644 tools/lib/trace/parse-events.h create mode 100644 tools/lib/trace/parse-filter.c create mode 100644 tools/lib/trace/parse-utils.c create mode 100644 ...
I'll merge this patch into my tree, and that should make it easier for you. -- Steve --
From: Steven Rostedt <rostedt@goodmis.org> Yeah, that's cool. FYI, Arnaldo wanted to have that toplevel-Makefile thing too (tools/Makefile) so there might be some conflicts depending on how far he is. Thanks Steven. -- 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 --
OK, thanks for letting me know. I'll get into contact with Arnaldo and sort it out. -- Steve --
From: Borislav Petkov <borislav.petkov@amd.com>
Export cpu counting and cpumap manipulating utils for general use. This
pulls ctype.c along.
Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
tools/lib/lk/Makefile | 3 +
tools/lib/lk/cpumap.c | 114 +++++++++++++++++++++++++++++++++++++++++++
tools/lib/lk/cpumap.h | 7 +++
tools/lib/lk/ctype.c | 39 +++++++++++++++
tools/perf/Makefile | 3 -
tools/perf/builtin-record.c | 2 +-
tools/perf/builtin-stat.c | 2 +-
tools/perf/builtin-top.c | 2 +-
tools/perf/util/cpumap.c | 114 -------------------------------------------
tools/perf/util/cpumap.h | 7 ---
tools/perf/util/ctype.c | 39 ---------------
11 files changed, 166 insertions(+), 166 deletions(-)
create mode 100644 tools/lib/lk/cpumap.c
create mode 100644 tools/lib/lk/cpumap.h
create mode 100644 tools/lib/lk/ctype.c
delete mode 100644 tools/perf/util/cpumap.c
delete mode 100644 tools/perf/util/cpumap.h
delete mode 100644 tools/perf/util/ctype.c
diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
index 823bbb5..ff94b2e 100644
--- a/tools/lib/lk/Makefile
+++ b/tools/lib/lk/Makefile
@@ -7,9 +7,12 @@ LIB_OBJS=
LIB_H += debugfs.h
LIB_H += util.h
LIB_H += types.h
+LIB_H += cpumap.h
LIB_OBJS += debugfs.o
LIB_OBJS += usage.o
+LIB_OBJS += cpumap.o
+LIB_OBJS += ctype.o
LIBFILE = $(LIB_OUTPUT)lklib.a
diff --git a/tools/lib/lk/cpumap.c b/tools/lib/lk/cpumap.c
new file mode 100644
index 0000000..7c3008a
--- /dev/null
+++ b/tools/lib/lk/cpumap.c
@@ -0,0 +1,114 @@
+#include <lk/util.h>
+#include <perf.h>
+#include "cpumap.h"
+#include <assert.h>
+#include <stdio.h>
+
+int cpumap[MAX_NR_CPUS];
+
+static int default_cpu_map(void)
+{
+ int nr_cpus, i;
+
+ nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+ assert(nr_cpus <= MAX_NR_CPUS);
+ assert((int)nr_cpus >= 0);
+
+ for (i = 0; i < nr_cpus; ++i)
+ cpumap[i] = i;
+
+ return nr_cpus;
+}
+
+static ...Is this independent of previous patches? I.e. to be applied to current perf/core? - Arnaldo --
From: Arnaldo Carvalho de Melo <acme@infradead.org> I'm afraid not since earlier patches in the series introduce the toplevel Makefile that glues all the different tools/lib/* parts together. However, I could extract the toplevel Makefile parts and cpumap.c and ctype.c if you really need it now - I've been doing this so often lately that I could do it with my eyes closed now :o). -- 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 --
We need to get back at merging that series, so some patch series installments, with say, 3 or 4 patches each, would be great. - Arnaldo --
From: Arnaldo Carvalho de Melo <acme@infradead.org> Yeah, I just want to wait first until all the churn on the kernel side settles and we have agreed on the perf_event.c part which would also determine what needs exporting on the userspace side. But if you need stuff exported from perf/util/ for other tools too and if you tell me which ones, I could cook up something real soon... -- 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 --
I'll try to do what I once said I would, that is to have a tools/samples/ (stuff exercising tools/ library interfaces) counterpart to samples/ (stuff exercising kernel interfaces). I'll use what you have already posted that applies, tools/Makefile, trying to solve that -C isssue. Will shoot for having this merged early next week to avoid breaking the promise once more 8-) - Arnaldo --
From: Borislav Petkov <borislav.petkov@amd.com> Export the mmap_read* helpers into tools/lib/perf/mmap.[ch] Signed-off-by: Borislav Petkov <borislav.petkov@amd.com> --- tools/Makefile | 6 ++- tools/lib/perf/Makefile | 35 ++++++++++++++ tools/lib/perf/mmap.c | 95 ++++++++++++++++++++++++++++++++++++++ tools/lib/perf/mmap.h | 15 ++++++ tools/perf/Makefile | 2 +- tools/perf/builtin-record.c | 107 ++++--------------------------------------- tools/perf/builtin-top.c | 28 ++--------- 7 files changed, 166 insertions(+), 122 deletions(-) create mode 100644 tools/lib/perf/Makefile create mode 100644 tools/lib/perf/mmap.c create mode 100644 tools/lib/perf/mmap.h diff --git a/tools/Makefile b/tools/Makefile index d3b1447..691f78b 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -34,7 +34,7 @@ export BASIC_CFLAGS PERF_TOP_DIR := $(CURDIR) export PERF_TOP_DIR -perf: libparsevent lklib .FORCE +perf: libparsevent lklib lkperflib .FORCE $(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) libparsevent: .FORCE @@ -43,9 +43,13 @@ libparsevent: .FORCE lklib: .FORCE $(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1) +lkperflib: .FORCE + $(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 .PHONY: clean .FORCE diff --git a/tools/lib/perf/Makefile b/tools/lib/perf/Makefile new file mode 100644 index 0000000..9942d52 --- /dev/null +++ b/tools/lib/perf/Makefile @@ -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)lkperflib.a + +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) +EXTLIBS = -lpthread -lrt -lelf ...
From: Borislav Petkov <borislav.petkov@amd.com> Export /proc/mounts parser and other debugfs-related helpers for general use. Also, exit if a valid debugfs mountpoint cannot be found. Signed-off-by: Borislav Petkov <borislav.petkov@amd.com> --- tools/Makefile | 8 +- tools/lib/lk/Makefile | 38 +++ tools/lib/lk/debugfs.c | 256 ++++++++++++++++++ tools/lib/lk/debugfs.h | 31 +++ tools/lib/lk/types.h | 17 ++ tools/lib/lk/usage.c | 80 ++++++ tools/lib/lk/util.h | 285 ++++++++++++++++++++ tools/perf/Makefile | 11 +- tools/perf/bench/bench.h | 2 + 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 | 5 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/builtin.h | 2 +- tools/perf/perf.c ...
From: Borislav Petkov <borislav.petkov@amd.com> Signed-off-by: Borislav Petkov <borislav.petkov@amd.com> --- tools/Makefile | 4 ++ tools/ras/Makefile | 16 ++++++ tools/ras/rasd.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+), 0 deletions(-) create mode 100644 tools/ras/Makefile create mode 100644 tools/ras/rasd.c diff --git a/tools/Makefile b/tools/Makefile index 691f78b..360454c 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -37,6 +37,9 @@ export PERF_TOP_DIR perf: libparsevent lklib lkperflib .FORCE $(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) +ras: libparsevent lklib lkperflib .FORCE + $(QUIET_SUBDIR0)ras/ $(QUIET_SUBDIR1) + libparsevent: .FORCE $(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) @@ -51,5 +54,6 @@ 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 diff --git a/tools/ras/Makefile b/tools/ras/Makefile new file mode 100644 index 0000000..3aebe5a --- /dev/null +++ b/tools/ras/Makefile @@ -0,0 +1,16 @@ +include ../scripts/Makefile.lib + +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) +ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 +ALL_LDFLAGS = $(LDFLAGS) + +RASLIBS=$(LIB_OUTPUT)libparsevent.a $(LIB_OUTPUT)lklib.a $(LIB_OUTPUT)lkperflib.a + +rasd: rasd.o $(RASLIBS) + $(QUIET_CC)$(CC) $(ALL_CFLAGS) -o $@ $^ $(RASLIBS) + +%.o: %.c + $(QUIET_CC)$(CC) $(ALL_CFLAGS) -c $< + +clean: + rm -rf *.o rasd diff --git a/tools/ras/rasd.c b/tools/ras/rasd.c new file mode 100644 index 0000000..5bf76cb --- /dev/null +++ b/tools/ras/rasd.c @@ -0,0 +1,144 @@ +/* + * Linux RAS daemon. + * + * Initial code reused from Linux Daemon Writing HOWTO + */ + +#include <errno.h> +#include <fcntl.h> +#include ...
From: Borislav Petkov <borislav.petkov@amd.com>
... for other in-kernel users.
Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
include/linux/perf_event.h | 19 +++++++++++++++++++
kernel/perf_event.c | 19 +++++++++----------
2 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 937495c..ea2b91c 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -14,6 +14,7 @@
#ifndef _LINUX_PERF_EVENT_H
#define _LINUX_PERF_EVENT_H
+#include <linux/poll.h>
#include <linux/types.h>
#include <linux/ioctl.h>
#include <asm/byteorder.h>
@@ -1019,6 +1020,15 @@ extern int perf_swevent_get_recursion_context(void);
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 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 unsigned int perf_poll(struct file *file, poll_table *wait);
+extern long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
+extern int perf_mmap(struct file *file, struct vm_area_struct *vma);
+extern int perf_fasync(int fd, struct file *filp, int on);
+extern int perf_release(struct inode *inode, struct file *file);
+
#else
static inline void
perf_event_task_sched_in(struct task_struct *task) { }
@@ -1056,6 +1066,15 @@ static inline int perf_swevent_get_recursion_context(void) { return -1; }
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) { }
+extern 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 ...From: Borislav Petkov <borislav.petkov@amd.com>
Switch to reusing the mcheck core's machine check polling mechanism
instead of duplicating functionality by using the EDAC polling routine.
Correct formatting while at it.
Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
drivers/edac/amd64_edac.c | 118 -------------------------------------------
drivers/edac/edac_mce_amd.c | 16 +++---
2 files changed, 8 insertions(+), 126 deletions(-)
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index ac9f798..f9f5f1e 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -1975,107 +1975,6 @@ static int get_channel_from_ecc_syndrome(struct mem_ctl_info *mci, u16 syndrome)
}
/*
- * Check for valid error in the NB Status High register. If so, proceed to read
- * NB Status Low, NB Address Low and NB Address High registers and store data
- * into error structure.
- *
- * Returns:
- * - 1: if hardware regs contains valid error info
- * - 0: if no valid error is indicated
- */
-static int amd64_get_error_info_regs(struct mem_ctl_info *mci,
- struct err_regs *regs)
-{
- struct amd64_pvt *pvt;
- struct pci_dev *misc_f3_ctl;
-
- pvt = mci->pvt_info;
- misc_f3_ctl = pvt->misc_f3_ctl;
-
- if (amd64_read_pci_cfg(misc_f3_ctl, K8_NBSH, &regs->nbsh))
- return 0;
-
- if (!(regs->nbsh & K8_NBSH_VALID_BIT))
- return 0;
-
- /* valid error, read remaining error information registers */
- if (amd64_read_pci_cfg(misc_f3_ctl, K8_NBSL, &regs->nbsl) ||
- amd64_read_pci_cfg(misc_f3_ctl, K8_NBEAL, &regs->nbeal) ||
- amd64_read_pci_cfg(misc_f3_ctl, K8_NBEAH, &regs->nbeah) ||
- amd64_read_pci_cfg(misc_f3_ctl, K8_NBCFG, &regs->nbcfg))
- return 0;
-
- return 1;
-}
-
-/*
- * This function is called to retrieve the error data from hardware and store it
- * in the info structure.
- *
- * Returns:
- * - 1: if a valid error is found
- * - 0: if no error is found
- */
-static int amd64_get_error_info(struct ...