Skip to contentSkip to conversation

perf: Add persistent event facilities

RFC PATCH In review Borislav Petkov 4 participants 32 messages Mar 21, 2012 – May 31, 2012

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover perf: Add persistent event facilities

From: Borislav Petkov <[email protected]>

Hi guys,

this is yet another version of the persistent events patch incorporating all comments from last time. Highlights in this version are the switch to the other ring buffer, making the facility generic for usage by other subsystems not only RAS (patch 2/2 shows an exemplary usage) and a couple of minor simplifications.

Any comments and suggestions are welcome,
thanks.

#1 lore raw

PATCH 1/2 perf: Add persistent event facilities

From: 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; also, we map them read-only so that multiple agents can access them.

---
 include/linux/perf_event.h |   24 ++++++++++-
 kernel/events/Makefile     |    2 +-
 kernel/events/core.c       |   25 +++++++++--
 kernel/events/internal.h   |    2 +
 kernel/events/persistent.c |   98 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 145 insertions(+), 6 deletions(-)
 create mode 100644 kernel/events/persistent.c
include/linux/perf_event.h +23 -1
index abb2776be1ba..9743ba46e12d 100644
@@ -223,8 +223,9 @@ struct perf_event_attr {
 
 				exclude_host   :  1, /* don't count in host   */
 				exclude_guest  :  1, /* don't count in guest  */
+				persistent     :  1, /* always-on event */
 
-				__reserved_1   : 43;
+				__reserved_1   : 42;
 
 	union {
 		__u32		wakeup_events;	  /* wakeup every n events */
@@ -944,6 +945,14 @@ struct perf_output_handle {
 	int				page;
 };
 
+/* Persistent events descriptor */
+struct pers_event_desc {
+	struct perf_event_attr *pattr;
+	struct perf_event *event;
+	const char *dfs_name;
+	struct dentry *dfs_entry;
+};
+
 #ifdef CONFIG_PERF_EVENTS
 
 extern int perf_pmu_register(struct pmu *pmu, char *name, int type);
@@ -1149,6 +1158,11 @@ 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 int perf_add_persistent_on_cpu(int cpu, struct pers_event_desc *desc,
+				      struct dentry *dfs_dr, unsigned nr_pages);
+extern void perf_rm_persistent_on_cpu(int cpu, struct pers_event_desc *desc);
+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 *prev,
@@ -1187,6 +1201,14 @@ 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)				{ }
+extern int perf_add_persistent_on_cpu(int cpu, struct pers_event_desc *desc,
+					 struct perf_event_attr *pattr,
+					 struct dentry *dfs_dir,
+					 unsigned nr_pages);		{ return -EINVAL; }
+extern void perf_rm_persistent_on_cpu(int cpu,
+				      struct pers_event_desc *desc)	{ }
+static inline int
+perf_persistent_open(struct inode *inode, struct file *file)		{ return -1; }
 #endif
 
 #define perf_output_put(handle, x) perf_output_copy((handle), &(x), sizeof(x))
kernel/events/Makefile +1 -1
index 22d901f9caf4..0d2267fb4336 100644
@@ -2,5 +2,5 @@ ifdef CONFIG_FUNCTION_TRACER
 CFLAGS_REMOVE_core.o = -pg
 endif
 
-obj-y := core.o ring_buffer.o callchain.o
+obj-y := core.o ring_buffer.o callchain.o persistent.o
 obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
kernel/events/core.c +21 -4
index 1b5c081d8b9f..9a39dc6755f4 100644
@@ -2770,8 +2770,6 @@ static void free_event_rcu(struct rcu_head *head)
 	kfree(event);
 }
 
-static void ring_buffer_put(struct ring_buffer *rb);
-
 static void free_event(struct perf_event *event)
 {
 	irq_work_sync(&event->pending);
@@ -3423,7 +3421,7 @@ static struct ring_buffer *ring_buffer_get(struct perf_event *event)
 	return rb;
 }
 
-static void ring_buffer_put(struct ring_buffer *rb)
+void ring_buffer_put(struct ring_buffer *rb)
 {
 	struct perf_event *event, *n;
 	unsigned long flags;
@@ -3452,6 +3450,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->rb);
 		struct user_struct *user = event->mmap_user;
@@ -3495,7 +3498,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;
@@ -3606,6 +3609,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
  *
@@ -6319,6 +6332,10 @@ __perf_event_exit_task(struct perf_event *child_event,
 		raw_spin_unlock_irq(&child_ctx->lock);
 	}
 
+	/* do not remove persistent events on task exit */
+	if (child_event->attr.persistent)
+		return;
+
 	perf_remove_from_context(child_event);
 
 	/*
kernel/events/internal.h +2 -0
index b0b107f90afc..d4e6181d5faf 100644
@@ -37,6 +37,8 @@ struct ring_buffer {
 extern void rb_free(struct ring_buffer *rb);
 extern struct ring_buffer *
 rb_alloc(int nr_pages, long watermark, int cpu, int flags);
+extern void ring_buffer_put(struct ring_buffer *rb);
+
 extern void perf_event_wakeup(struct perf_event *event);
 
 extern void
kernel/events/persistent.c new file +98 -0

98 lines not on this page · raw message

Signature · 1 line
1.7.9.3.362.g71319
maintainer
#2 lore raw
Quoted 3 lines · Borislav Petkov

Add a barebones implementation for registering persistent events with perf. For that, we don't destroy the buffers when they're unmapped; also, we map them read-only so that multiple agents can access them.

Yet you don't fail mmap() for VM_WRITE && ->persistent.

#3 lore raw
Quoted 6 lines · Peter Zijlstra
Quoted 3 lines · Borislav Petkov

Add a barebones implementation for registering persistent events with perf. For that, we don't destroy the buffers when they're unmapped; also, we map them read-only so that multiple agents can access them.

Yet you don't fail mmap() for VM_WRITE && ->persistent.

I better go fix that after we've agreed on the overall design.

Thanks Peter.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
maintainer
#4 lore raw
In reply to Borislav Petkov

kernel/events/core.c __perf_event_exit_task(struct perf_event *child_event, · line 6340

Quoted 10 lines · Borislav Petkov
kernel/events/core.c +4 -0
@@ -6319,6 +6332,10 @@ __perf_event_exit_task(struct perf_event *child_event,
                raw_spin_unlock_irq(&child_ctx->lock);
        }
 
+       /* do not remove persistent events on task exit */
+       if (child_event->attr.persistent)
+               return;
+
        perf_remove_from_context(child_event);
 

Huh, the task it dying, why would you let the event stay in the task context?

maintainer
#5 lore raw
In reply to Borislav Petkov
Quoted 7 lines · Borislav Petkov

From: 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; also, we map them read-only so that multiple agents can access them.

kernel/events/persistent.c new file +1 -0
+static struct perf_event *perf_add_persistent(struct perf_event_attr *attr,

kernel/events/persistent.c line 28

Quoted 10 lines
kernel/events/persistent.c new file +10 -0
+					      int cpu, unsigned nr_pages)
+{
+	struct ring_buffer *buffer;
+	struct perf_event *event;
+
+	event = perf_event_create_kernel_counter(attr, cpu, NULL, NULL, NULL);
+	if (IS_ERR(event))
+		return event;
+
+	buffer = rb_alloc(nr_pages, 0, cpu, RING_BUFFER_WRITABLE);

Uh what?

maintainer
#6 lore raw
In reply to Borislav Petkov
Quoted 1 line · Borislav Petkov

+ persistent : 1, /* always-on event */

Should creating something like that be privileged?

And it looks like you allow creating persistent per-task events; is that useful, if so why? And like already pointed out, your cleanup seems broken in that case.

#7 lore raw
Quoted 4 lines · Peter Zijlstra
Quoted 1 line · Borislav Petkov

+ persistent : 1, /* always-on event */

Should creating something like that be privileged?

Yeah, I dunno, do we want that? Well, what it is when we enable an event during boot, i.e. say "boot_trace=<event>..." on the kernel command line and this event is enabled until we finish booting. Then we disable it with perf or over debugfs. Is that privileged or can any user boot-trace the system?

All good questions.

Quoted 3 lines

And it looks like you allow creating persistent per-task events; is that useful, if so why? And like already pointed out, your cleanup seems broken in that case.

This was dumb - I wanted to have task-agnostic events which get enabled for the whole system and there's a buffer on each CPU which collects their output. It was a first attempt and it is a good thing you gave it a look so that I can address the issues properly.

Thanks.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
maintainer
#8 lore raw
In reply to Borislav Petkov

kernel/events/persistent.c line 65

Quoted 2 lines · Borislav Petkov
kernel/events/persistent.c new file +2 -0
+int perf_add_persistent_on_cpu(int cpu, struct pers_event_desc *desc,
+                              struct dentry *dir, unsigned nr_pages) 

OK, so this creates an even and registers it somewhere in debugfs.

- you allow an arbitrary place in debugfs; this might make finding them
'interesting'. Should we put them all in the same place?

- persistent events created from userspace don't seem to get a debugfs
entry and will be lost forever?

In general I think a little more exploring of the semantics and ramifications might be in order.

#9 lore raw
Quoted 5 lines · Peter Zijlstra

kernel/events/persistent.c line 65

Quoted 2 lines · Borislav Petkov
kernel/events/persistent.c new file +2 -0
+int perf_add_persistent_on_cpu(int cpu, struct pers_event_desc *desc,
+                              struct dentry *dir, unsigned nr_pages) 

OK, so this creates an even and registers it somewhere in debugfs.

(debugfs)/mce/

Quoted 2 lines

- you allow an arbitrary place in debugfs; this might make finding
them 'interesting'. Should we put them all in the same place?

My take on this is that we want to be able to make the same events we have now, persistent. Basically not trace for the duration of a child process but in a process-agnostic way, system-wide.

In that case, we probably want to be able to mark events as persistent, maybe add another node in debugfs:

(debugfs)/tracing/events/mce/mce_record/attr

which can be used for flags or whatever, or something to that effect...

Quoted 2 lines

- persistent events created from userspace don't seem to get a debugfs
entry and will be lost forever?

Yeah, see above.

Quoted 2 lines

In general I think a little more exploring of the semantics and ramifications might be in order.

Absolutely!

Thanks.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
maintainer
#10 lore raw
Quoted 6 lines · Borislav Petkov
Quoted 2 lines

- you allow an arbitrary place in debugfs; this might make finding
them 'interesting'. Should we put them all in the same place?

My take on this is that we want to be able to make the same events we have now, persistent. Basically not trace for the duration of a child process but in a process-agnostic way, system-wide.

This would argue against per-task persistent events..

Quoted 6 lines

In that case, we probably want to be able to mark events as persistent, maybe add another node in debugfs:

(debugfs)/tracing/events/mce/mce_record/attr

which can be used for flags or whatever, or something to that effect...

( while mce is a user of persistent events, it seems to me in general persistent events should not be related to mce )

However you raise a valid point about keeping track of what events are spooled into that buffer.

Note the plural there, it might be very desirable to allow multiple events into a single persistent buffer.

#11 lore raw
Quoted 9 lines · Peter Zijlstra
Quoted 6 lines · Borislav Petkov
Quoted 2 lines

- you allow an arbitrary place in debugfs; this might make finding
them 'interesting'. Should we put them all in the same place?

My take on this is that we want to be able to make the same events we have now, persistent. Basically not trace for the duration of a child process but in a process-agnostic way, system-wide.

This would argue against per-task persistent events..

Yeah, 'persistency' is something that's per CPU at minimum.

Quoted 2 lines

Note the plural there, it might be very desirable to allow multiple events into a single persistent buffer.

very, very, very much so. One (per CPU) buffer, with many events multiplexed into it.

Thanks,

Ingo

#12 lore raw
Quoted 7 lines · Ingo Molnar
Quoted 4 lines · Peter Zijlstra
Quoted 3 lines · Borislav Petkov
Quoted 2 lines

- you allow an arbitrary place in debugfs; this might make finding
them 'interesting'. Should we put them all in the same place?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

My take on this is that we want to be able to make the same events we have now, persistent. Basically not trace for the duration of a child process but in a process-agnostic way, system-wide.

This would argue against per-task persistent events..

Yeah, 'persistency' is something that's per CPU at minimum.

Yeah, forget the per-task thing - that's me not understanding the code fully. They need to be per CPU and "taskless."

Quoted 5 lines
Quoted 2 lines

Note the plural there, it might be very desirable to allow multiple events into a single persistent buffer.

very, very, very much so. One (per CPU) buffer, with many events multiplexed into it.

Which begs the other question: mce could use buffers which are RO - at least, I don't see a usecase where we want to delete entries from them - but other persistent events users might want to delete those events to free up the buffers.

It is an interesting question how we handle that RO/RW thing? Maybe per event and do something of a kernel-side filtering which Peter didn't like in Robert's IBS stuff.

Hmmm...

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
maintainer
#13 lore raw
Quoted 1 line · Borislav Petkov

It is an interesting question how we handle that RO/RW thing?

RO buffers overwrite, RW buffers loose events.

We could allow both for persistent under the constraints:

VM_SHARED - must imply !VM_WRITE since multiple people writing to the
control page will get 'interesting' very fast.

!VM_SHARED - must fail mmap() of the debugfs file if there's already
an existing user.

Note that even RW buffers only allows writes to the control page, a write to the actual data itself will generate a fault.

#14 lore raw
Quoted 9 lines · Peter Zijlstra
Quoted 1 line · Borislav Petkov

It is an interesting question how we handle that RO/RW thing?

RO buffers overwrite, RW buffers loose events.

We could allow both for persistent under the constraints:

VM_SHARED - must imply !VM_WRITE since multiple people writing to the
control page will get 'interesting' very fast.

Ok, I get that one.

Quoted 2 lines

!VM_SHARED - must fail mmap() of the debugfs file if there's already
an existing user.

What happens here if a second user wants to enable a second set of persistent events, allocate a second set of per-CPU buffers?

Quoted 2 lines

Note that even RW buffers only allows writes to the control page, a write to the actual data itself will generate a fault.

Ok.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
maintainer
#15 lore raw
Quoted 2 lines · Borislav Petkov

What happens here if a second user wants to enable a second set of persistent events, allocate a second set of per-CPU buffers?

I'm not seeing the relation to VM_SHARED here. But yeah, if you want a second set of buffers with either the same or other events, you create another set..

#16 lore raw
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Borislav Petkov

What happens here if a second user wants to enable a second set of persistent events, allocate a second set of per-CPU buffers?

I'm not seeing the relation to VM_SHARED here.

Well, in the sense that if mmap fails in the !VM_SHARED case, I can't enable any persistent events except the ones which are enabled and so I need to allocate another set of resources for that second persistent events user.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
maintainer
#17 lore raw
Quoted 11 lines · Borislav Petkov
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Borislav Petkov

What happens here if a second user wants to enable a second set of persistent events, allocate a second set of per-CPU buffers?

I'm not seeing the relation to VM_SHARED here.

Well, in the sense that if mmap fails in the !VM_SHARED case, I can't enable any persistent events except the ones which are enabled and so I need to allocate another set of resources for that second persistent events user.

Right, well, you could actually allow operations on the fd, just not a second mapping :-)

Anyway.. I'd push that error back to the user. If they need a second set, let them create it.

Do you really need multiple consumers for your MCE stuff? If so, what would be the problem of using VM_SHARED?

#18 lore raw
Quoted 7 lines · Peter Zijlstra
Quoted 6 lines
Quoted 1 line

I'm not seeing the relation to VM_SHARED here.

Well, in the sense that if mmap fails in the !VM_SHARED case, I can't enable any persistent events except the ones which are enabled and so I need to allocate another set of resources for that second persistent events user.

Quoted 8 lines

Right, well, you could actually allow operations on the fd, just not a second mapping :-)

Anyway.. I'd push that error back to the user. If they need a second set, let them create it.

Do you really need multiple consumers for your MCE stuff? If so, what would be the problem of using VM_SHARED?

Nah, for MCE I'm fine with RO buffers, simple :-).

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
#19 lore raw
In reply to Peter Zijlstra
Quoted 6 lines · Peter Zijlstra

Review

Quoted 2 lines · Borislav Petkov
(quoted diff) +2 -0
+int perf_add_persistent_on_cpu(int cpu, struct pers_event_desc *desc,
+                              struct dentry *dir, unsigned nr_pages) 

OK, so this creates an even and registers it somewhere in debugfs.

Quoted 8 lines

- you allow an arbitrary place in debugfs; this might make finding them
'interesting'. Should we put them all in the same place?

- persistent events created from userspace don't seem to get a debugfs
entry and will be lost forever?

In general I think a little more exploring of the semantics and ramifications might be in order.

Ok, how about the following. This is rough and not in any way ready - it is supposed to feel out how you guys feel about it. Basically, it adds another file in (debugfs)/tracing/events/<subsys>/<event_name>/ which can be used for whatever.

In the persistent event case, I get this:

/mnt/dbg/tracing/events/mce/mce_record/

|-- enable
|-- filter
|-- format
|-- id

`-- pers

and 'pers' contains the file descriptor of the perf per-cpu buffer which I can mmap in userspace. I can read that out later.

Other events can put other files in there containing other relevant stuff for them.

The interface trace_add_file() is pretty generic (it can be done even more so). It is not design-finished - it is only meant to show the intent. Oh, and don't look at bob_add_trace_file() - it is a quick'n'dirty hack for testing :-).

So, what do you guys think, Peter, Steven?

Thanks.

--

include/linux/ftrace_event.h +2 -0
index 176a939d1547..1c13fb5e9a50 100644
@@ -222,6 +222,8 @@ struct ftrace_event_call {
 #ifdef CONFIG_PERF_EVENTS
 	int				perf_refcount;
 	struct hlist_head __percpu	*perf_events;
+	/* persistent event filedes */
+	int				pers_fd;
 #endif
 };
 
kernel/trace/trace_events.c +80 -8

121 lines not on this page · raw message

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
#20 lore raw

PATCH 2/2 x86, mce: Add persistent MCE event

In reply to Borislav Petkov

From: 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 through a debugfs per-CPU file which a userspace daemon can read and then process the received error data further.

---
 arch/x86/kernel/cpu/mcheck/mce.c |   53 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
arch/x86/kernel/cpu/mcheck/mce.c +53 -0
index 5a11ae2e9e91..791c4633d771 100644
@@ -95,6 +95,13 @@ static DECLARE_WAIT_QUEUE_HEAD(mce_chrdev_wait);
 static DEFINE_PER_CPU(struct mce, mces_seen);
 static int			cpu_missing;
 
+static struct perf_event_attr pattr = {
+	.type           = PERF_TYPE_TRACEPOINT,
+	.size           = sizeof(pattr),
+	.sample_type    = PERF_SAMPLE_RAW,
+	.persistent     = 1,
+};
+
 /* MCA banks polled by the period polling timer for corrected events */
 DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = {
 	[0 ... BITS_TO_LONGS(MAX_NR_BANKS)-1] = ~0UL
@@ -102,6 +109,8 @@ DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = {
 
 static DEFINE_PER_CPU(struct work_struct, mce_work);
 
+static DEFINE_PER_CPU(struct pers_event_desc, mce_ev);
+
 /*
  * CPU/chipset specific EDAC code can register a notifier call here to print
  * MCE errors in a human-readable form.
@@ -2109,6 +2118,50 @@ static void __cpuinit mce_reenable_cpu(void *h)
 	}
 }
 
+static __init int mcheck_init_persistent_event(void)
+{
+
+#define MCE_RECORD_FNAME_SZ 14
+#define MCE_BUF_PAGES 4
+
+	int cpu, err = 0;
+	char buf[MCE_RECORD_FNAME_SZ];
+
+	pattr.config = event_mce_record.event.type;
+	pattr.sample_period = 1;
+	pattr.wakeup_events = 1;
+
+	get_online_cpus();
+
+	for_each_online_cpu(cpu) {
+		struct pers_event_desc *d = &per_cpu(mce_ev, cpu);
+
+		snprintf(buf, MCE_RECORD_FNAME_SZ, "mce_record%d", cpu);
+		d->dfs_name = buf;
+		d->pattr = &pattr;
+
+		if (perf_add_persistent_on_cpu(cpu, d, mce_get_debugfs_dir(),
+					       MCE_BUF_PAGES))
+			goto err_unwind;
+	}
+	goto unlock;
+
+err_unwind:
+	err = -EINVAL;
+	for (--cpu; cpu >= 0; cpu--)
+		perf_rm_persistent_on_cpu(cpu, &per_cpu(mce_ev, cpu));
+
+unlock:
+	put_online_cpus();
+
+	return err;
+}
+
+/*
+ * This has to run after event_trace_init()
+ */
+device_initcall(mcheck_init_persistent_event);
+
 /* Get notified when a cpu comes on/off. Be hotplug friendly. */
 static int __cpuinit
 mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
Signature · 1 line
1.7.9.3.362.g71319
#21 lore raw

Re: [PATCH 2/2] x86, mce: Add persistent MCE event

Quoted 66 lines · Borislav Petkov

From: 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 through a debugfs per-CPU file which a userspace daemon can read and then process the received error data further.

---
 arch/x86/kernel/cpu/mcheck/mce.c |   53 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
arch/x86/kernel/cpu/mcheck/mce.c +32 -0
index 5a11ae2e9e91..791c4633d771 100644
@@ -95,6 +95,13 @@ static DECLARE_WAIT_QUEUE_HEAD(mce_chrdev_wait);
 static DEFINE_PER_CPU(struct mce, mces_seen);
 static int			cpu_missing;
 
+static struct perf_event_attr pattr = {
+	.type           = PERF_TYPE_TRACEPOINT,
+	.size           = sizeof(pattr),
+	.sample_type    = PERF_SAMPLE_RAW,
+	.persistent     = 1,
+};
+
 /* MCA banks polled by the period polling timer for corrected events */
 DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = {
 	[0 ... BITS_TO_LONGS(MAX_NR_BANKS)-1] = ~0UL
@@ -102,6 +109,8 @@ DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = {
 
 static DEFINE_PER_CPU(struct work_struct, mce_work);
 
+static DEFINE_PER_CPU(struct pers_event_desc, mce_ev);
+
 /*
  * CPU/chipset specific EDAC code can register a notifier call here to print
  * MCE errors in a human-readable form.
@@ -2109,6 +2118,50 @@ static void __cpuinit mce_reenable_cpu(void *h)
 	}
 }
 
+static __init int mcheck_init_persistent_event(void)
+{
+
+#define MCE_RECORD_FNAME_SZ 14
+#define MCE_BUF_PAGES 4
+
+	int cpu, err = 0;
+	char buf[MCE_RECORD_FNAME_SZ];
+
+	pattr.config = event_mce_record.event.type;
+	pattr.sample_period = 1;
+	pattr.wakeup_events = 1;
+
+	get_online_cpus();
+
+	for_each_online_cpu(cpu) {
+		struct pers_event_desc *d = &per_cpu(mce_ev, cpu);
+
+		snprintf(buf, MCE_RECORD_FNAME_SZ, "mce_record%d", cpu);
+		d->dfs_name = buf;
+		d->pattr = &pattr;
+
+		if (perf_add_persistent_on_cpu(cpu, d, mce_get_debugfs_dir(),

arch/x86/kernel/cpu/mcheck/mce.c static void __cpuinit mce_reenable_cpu(void *h) · line 2153

Quoted 10 lines
arch/x86/kernel/cpu/mcheck/mce.c +10 -0
+					       MCE_BUF_PAGES))
+			goto err_unwind;
+	}
+	goto unlock;
+
+err_unwind:
+	err = -EINVAL;
+	for (--cpu; cpu >= 0; cpu--)
+		perf_rm_persistent_on_cpu(cpu, &per_cpu(mce_ev, cpu));
+

*Totally* theoretical question: How do you know that the cpu_online_mask isn't sparse? In other words, what if some CPUs weren't booted? Then this for-loop wouldn't be very good..

Oh, now I see that perf_rm_persistent_on_cpu() probably handles that case well.. So no issues I guess.. ?

(Moreover, we will probably have bigger issues at hand if some CPU didn't boot..)

(The code looked funny, so I thought of pointing it out, whether or not it actually is worrisome. Sorry for the noise, if any).

Quoted 4 lines
arch/x86/kernel/cpu/mcheck/mce.c +4 -0
+unlock:
+	put_online_cpus();
+
+	return err;

arch/x86/kernel/cpu/mcheck/mce.c static void __cpuinit mce_reenable_cpu(void *h) · line 2167

Quoted 10 lines
arch/x86/kernel/cpu/mcheck/mce.c +7 -0
+}
+
+/*
+ * This has to run after event_trace_init()
+ */
+device_initcall(mcheck_init_persistent_event);
+
 /* Get notified when a cpu comes on/off. Be hotplug friendly. */
 static int __cpuinit
 mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)

Regards,
Srivatsa S. Bhat

#22 lore raw

Re: [PATCH 2/2] x86, mce: Add persistent MCE event

Quoted 11 lines · Srivatsa S. Bhat

arch/x86/kernel/cpu/mcheck/mce.c static void __cpuinit mce_reenable_cpu(void *h) · line 2153

Quoted 5 lines
arch/x86/kernel/cpu/mcheck/mce.c +5 -0
+err_unwind:
+	err = -EINVAL;
+	for (--cpu; cpu >= 0; cpu--)
+		perf_rm_persistent_on_cpu(cpu, &per_cpu(mce_ev, cpu));
+

*Totally* theoretical question: How do you know that the cpu_online_mask isn't sparse? In other words, what if some CPUs weren't booted? Then this for-loop wouldn't be very good..

Quoted 2 lines

Oh, now I see that perf_rm_persistent_on_cpu() probably handles that case well.. So no issues I guess.. ?

Right, this could theoretically come around to bite us in some obscure cases, so we probably fix it from the get-go.

Quoted 5 lines

(Moreover, we will probably have bigger issues at hand if some CPU didn't boot..)

(The code looked funny, so I thought of pointing it out, whether or not it actually is worrisome. Sorry for the noise, if any).

Right, no, thanks for pointing it out.

I'll probably do something like the following:

	for (--cpu; cpu >= 0; cpu--)
		if (cpu_online(cpu))
			perf_rm_persistent_on_cpu(cpu, &per_cpu(mce_ev, cpu));

to be on the safe side from that perspective.

Thanks.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
#23 lore raw

Re: [PATCH 2/2] x86, mce: Add persistent MCE event

Quoted 26 lines · Borislav Petkov
Quoted 11 lines · Srivatsa S. Bhat

arch/x86/kernel/cpu/mcheck/mce.c static void __cpuinit mce_reenable_cpu(void *h) · line 2153

Quoted 5 lines
arch/x86/kernel/cpu/mcheck/mce.c +5 -0
+err_unwind:
+	err = -EINVAL;
+	for (--cpu; cpu >= 0; cpu--)
+		perf_rm_persistent_on_cpu(cpu, &per_cpu(mce_ev, cpu));
+

*Totally* theoretical question: How do you know that the cpu_online_mask isn't sparse? In other words, what if some CPUs weren't booted? Then this for-loop wouldn't be very good..

Quoted 2 lines

Oh, now I see that perf_rm_persistent_on_cpu() probably handles that case well.. So no issues I guess.. ?

Right, this could theoretically come around to bite us in some obscure cases, so we probably fix it from the get-go.

Quoted 5 lines

(Moreover, we will probably have bigger issues at hand if some CPU didn't boot..)

(The code looked funny, so I thought of pointing it out, whether or not it actually is worrisome. Sorry for the noise, if any).

Right, no, thanks for pointing it out.

Quoted 8 lines

I'll probably do something like the following:

	for (--cpu; cpu >= 0; cpu--)
		if (cpu_online(cpu))
			perf_rm_persistent_on_cpu(cpu, &per_cpu(mce_ev, cpu));

to be on the safe side from that perspective.

You can do that or something like the following, to make it more readable:

int cpunum;

for_each_online_cpu(cpunum) {
	if (cpunum == cpu)
		break;
	perf_rm_persistent_on_cpu(cpunum, &per_cpu(mce_ev, cpunum));
}

It is of course, up to you.. whichever form you prefer..

Regards,
Srivatsa S. Bhat

#24 lore raw

Re: [PATCH 2/2] x86, mce: Add persistent MCE event

In reply to Borislav Petkov
Quoted 70 lines · Borislav Petkov

From: 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 through a debugfs per-CPU file which a userspace daemon can read and then process the received error data further.

---
 arch/x86/kernel/cpu/mcheck/mce.c |   53 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
arch/x86/kernel/cpu/mcheck/mce.c +36 -0
index 5a11ae2e9e91..791c4633d771 100644
@@ -95,6 +95,13 @@ static DECLARE_WAIT_QUEUE_HEAD(mce_chrdev_wait);
 static DEFINE_PER_CPU(struct mce, mces_seen);
 static int			cpu_missing;
 
+static struct perf_event_attr pattr = {
+	.type           = PERF_TYPE_TRACEPOINT,
+	.size           = sizeof(pattr),
+	.sample_type    = PERF_SAMPLE_RAW,
+	.persistent     = 1,
+};
+
 /* MCA banks polled by the period polling timer for corrected events */
 DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = {
 	[0 ... BITS_TO_LONGS(MAX_NR_BANKS)-1] = ~0UL
@@ -102,6 +109,8 @@ DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = {
 
 static DEFINE_PER_CPU(struct work_struct, mce_work);
 
+static DEFINE_PER_CPU(struct pers_event_desc, mce_ev);
+
 /*
  * CPU/chipset specific EDAC code can register a notifier call here to print
  * MCE errors in a human-readable form.
@@ -2109,6 +2118,50 @@ static void __cpuinit mce_reenable_cpu(void *h)
 	}
 }
 
+static __init int mcheck_init_persistent_event(void)
+{
+
+#define MCE_RECORD_FNAME_SZ 14
+#define MCE_BUF_PAGES 4
+
+	int cpu, err = 0;
+	char buf[MCE_RECORD_FNAME_SZ];
+
+	pattr.config = event_mce_record.event.type;
+	pattr.sample_period = 1;
+	pattr.wakeup_events = 1;
+
+	get_online_cpus();
+
+	for_each_online_cpu(cpu) {
+		struct pers_event_desc *d = &per_cpu(mce_ev, cpu);
+
+		snprintf(buf, MCE_RECORD_FNAME_SZ, "mce_record%d", cpu);
+		d->dfs_name = buf;
+		d->pattr = &pattr;
+
+		if (perf_add_persistent_on_cpu(cpu, d, mce_get_debugfs_dir(),
+					       MCE_BUF_PAGES))
+			goto err_unwind;
+	}
+	goto unlock;

arch/x86/kernel/cpu/mcheck/mce.c static void __cpuinit mce_reenable_cpu(void *h) · line 2157

Quoted 10 lines
arch/x86/kernel/cpu/mcheck/mce.c +10 -0
+
+err_unwind:
+	err = -EINVAL;
+	for (--cpu; cpu >= 0; cpu--)
+		perf_rm_persistent_on_cpu(cpu, &per_cpu(mce_ev, cpu));
+
+unlock:
+	put_online_cpus();
+
+	return err;

I like it.

Have you considered making the addition of persistent events straightforward and robust, in terms of adding a TRACE_EVENT() variant for them? It could replace the above code.

Thanks,

Ingo

#25 lore raw

Re: [PATCH 2/2] x86, mce: Add persistent MCE event

Quoted 3 lines · Ingo Molnar

Have you considered making the addition of persistent events straightforward and robust, in terms of adding a TRACE_EVENT() variant for them? It could replace the above code.

Err,

are you thinking of something in TRACE_EVENT() that sets perf_event_attr.persistent to 1?

Btw, the more important question is are we going to need persistent events that much so that a generic approach is warranted? I guess maybe the black box events recording deal would be another user..

IOW, please elaborate :)

Thanks.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
#26 lore raw

Re: [PATCH 2/2] x86, mce: Add persistent MCE event

Quoted 9 lines · Borislav Petkov
Quoted 3 lines · Ingo Molnar

Have you considered making the addition of persistent events straightforward and robust, in terms of adding a TRACE_EVENT() variant for them? It could replace the above code.

Err,

are you thinking of something in TRACE_EVENT() that sets perf_event_attr.persistent to 1?

I was mainly thinking of reducing this:

 arch/x86/kernel/cpu/mcheck/mce.c |   53 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

to almost nothing. There doesn't seem to be much MCE specific in that code, right?

Quoted 4 lines

Btw, the more important question is are we going to need persistent events that much so that a generic approach is warranted? I guess maybe the black box events recording deal would be another user..

So, here's the big picture as I see it:

I think tracing could use persistent events: mark all the events we want to trace as persistent from bootup, and recover the bootup trace after the system has been booted up.

But other, runtime models of tracing could use it as well:
basically the main difference that ftrace has to perf based tracing today is a system-wide persistent buffer with no particular owning process. (The rest is mostly UI and analysis features and scope of tracing differences, and of course a lot more love and detail went into ftrace so far.)

So MCE will in the end be just a minor user of such a facility - I think you should aim for enabling *any* set of events to have persistent recording properties, and add the APIs to recover that information sanely. It should also be possible for them to record into a shared mmap page in essence - instead of having per event persistent buffers.

That way testing would be a lot easier as well: you could enable persistent tracing via something like:

perf trace on -e <events>

and turn it off via:

perf trace off

and just recover the recorded events via something like:

perf trace

... or so. That you can then also enable this during bootup for MCE events is just a very nice side effect of a much more generally useful feature.

Would you be interested in creating a clean incarnation of this without making peterz sad? The 'perf trace' perf subcommand is still unused and up for grabs for sufficiently good patches, coincidentally ;-)

Thanks,

Ingo

#27 lore raw

Re: [PATCH 2/2] x86, mce: Add persistent MCE event

Quoted 7 lines · Ingo Molnar

I was mainly thinking of reducing this:

 arch/x86/kernel/cpu/mcheck/mce.c |   53 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

to almost nothing. There doesn't seem to be much MCE specific in that code, right?

Yeah, this could be generalized even more, AFAICT.

Quoted 11 lines
Quoted 5 lines

Btw, the more important question is are we going to need persistent events that much so that a generic approach is warranted? I guess maybe the black box events recording deal would be another user..

So, here's the big picture as I see it:

I think tracing could use persistent events: mark all the events we want to trace as persistent from bootup, and recover the bootup trace after the system has been booted up.

Right, but (more nasty questions):

Why would I do this, am I tracing the boot process? If so, then I need another syntax which enables those events from the kernel command line which gets parsed the moment ftrace and ring buffer get initialized.

IOW, I'd need userspace for perf otherwise but I don't have that before booting...

Then, after having booted, do I stop the trace? If no, then I can see the persistency in there so are you saying we want a low overhead, low ressource utilization machinery which runs all the time and traces the system? What are possible real life use cases for that? Scheduler analysis probably, long-term tracing of some stuff people are interested in how it behaves over long periods of time... MCE is one use case, definitely...

Quoted 7 lines

But other, runtime models of tracing could use it as well:
basically the main difference that ftrace has to perf based tracing today is a system-wide persistent buffer with no particular owning process. (The rest is mostly UI and analysis features and scope of tracing differences, and of course a lot more love and detail went into ftrace so far.)

Quoted 6 lines

So MCE will in the end be just a minor user of such a facility - I think you should aim for enabling *any* set of events to have persistent recording properties, and add the APIs to recover that information sanely. It should also be possible for them to record into a shared mmap page in essence - instead of having per event persistent buffers.

Sounds like ftrace. But we have that already, we only need to get to using it perf-side, no...? Especially if we could get the love and detail that went in there for free :-) ...without stepping on Steve's toes, of course :-).

..

Fun.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
#28 lore raw

Re: [PATCH 2/2] x86, mce: Add persistent MCE event

Quoted 19 lines · Borislav Petkov
Quoted 7 lines · Ingo Molnar

I was mainly thinking of reducing this:

 arch/x86/kernel/cpu/mcheck/mce.c |   53 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

to almost nothing. There doesn't seem to be much MCE specific in that code, right?

Yeah, this could be generalized even more, AFAICT.

Quoted 8 lines
Quoted 5 lines

Btw, the more important question is are we going to need persistent events that much so that a generic approach is warranted? I guess maybe the black box events recording deal would be another user..

So, here's the big picture as I see it:

Quoted 7 lines
Quoted 3 lines

I think tracing could use persistent events: mark all the events we want to trace as persistent from bootup, and recover the bootup trace after the system has been booted up.

Right, but (more nasty questions):

Why would I do this, am I tracing the boot process? [...]

Correct, in essence the MCE persistent event is partially about
that: we are starting to collect events well before there's any user-space available.

Quoted 3 lines

[...] If so, then I need another syntax which enables those events from the kernel command line which gets parsed the moment ftrace and ring buffer get initialized.

Correct. Something really simple like:

boot_trace=<event1>,<event2>...

... which could be all implicit within MCE too. (So I'm not suggesting some boot command trigger to provide the MCE case - but for more general boot tracing it would be the right solution.)

Quoted 2 lines

IOW, I'd need userspace for perf otherwise but I don't have that before booting...

Correct. In the case of MCE there's no "userspace" really needed
- we just want to trace early enough. This model carries over to later as well: there's no *specific* process we want to attach the trace buffer to - we just want a persistent trace buffer that essentially never loses MCE events.

Quoted 8 lines

Then, after having booted, do I stop the trace? If no, then I can see the persistency in there so are you saying we want a low overhead, low ressource utilization machinery which runs all the time and traces the system? What are possible real life use cases for that? Scheduler analysis probably, long-term tracing of some stuff people are interested in how it behaves over long periods of time... MCE is one use case, definitely...

Boot tracing is a very real usecase, people use it to reduce boot times. Today printk timestamps are used as a substitute. (There's also a boot tracer plugin within ftrace, see the bootup_tracer.)

Quoted 14 lines
Quoted 7 lines

But other, runtime models of tracing could use it as well:
basically the main difference that ftrace has to perf based tracing today is a system-wide persistent buffer with no particular owning process. (The rest is mostly UI and analysis features and scope of tracing differences, and of course a lot more love and detail went into ftrace so far.)

Quoted 6 lines

So MCE will in the end be just a minor user of such a facility - I think you should aim for enabling *any* set of events to have persistent recording properties, and add the APIs to recover that information sanely. It should also be possible for them to record into a shared mmap page in essence - instead of having per event persistent buffers.

Quoted 2 lines

Sounds like ftrace. But we have that already, we only need to get to using it perf-side, no...? [...]

What we want is to extend the perf ring-buffer to be persistent *as well*. It's an evidently useful model of collecting events.

All the remaining perf tooling can be used after that point - if it's a bog-standard perf ring-buffer then it can be saved into a perf.data and can be analyzed in a rich fashion, etc.

Think about it: for example we could do not just boot tracing but also boot *profiling*, by using the PMU to sample into a persistent buffer which after bootup can be put into a perf.data and 'perf report' will do the right thing, etc...

Does it overlap with ftrace? Perf overlapped with ftrace from day one on and it's starting to become a maintenance problem: we want to remove that overlap not by keeping two separate entities (both of which suck and rule in their own ways) but having a unified facility.

Thanks,

Ingo

#29 lore raw

Re: [PATCH 2/2] x86, mce: Add persistent MCE event

Quoted 98 lines · Ingo Molnar
Quoted 19 lines · Borislav Petkov
Quoted 7 lines · Ingo Molnar

I was mainly thinking of reducing this:

 arch/x86/kernel/cpu/mcheck/mce.c |   53 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

to almost nothing. There doesn't seem to be much MCE specific in that code, right?

Yeah, this could be generalized even more, AFAICT.

Quoted 8 lines
Quoted 5 lines

Btw, the more important question is are we going to need persistent events that much so that a generic approach is warranted? I guess maybe the black box events recording deal would be another user..

So, here's the big picture as I see it:

Quoted 7 lines
Quoted 3 lines

I think tracing could use persistent events: mark all the events we want to trace as persistent from bootup, and recover the bootup trace after the system has been booted up.

Right, but (more nasty questions):

Why would I do this, am I tracing the boot process? [...]

Correct, in essence the MCE persistent event is partially about
that: we are starting to collect events well before there's any user-space available.

Quoted 3 lines

[...] If so, then I need another syntax which enables those events from the kernel command line which gets parsed the moment ftrace and ring buffer get initialized.

Correct. Something really simple like:

boot_trace=<event1>,<event2>...

... which could be all implicit within MCE too. (So I'm not suggesting some boot command trigger to provide the MCE case - but for more general boot tracing it would be the right solution.)

Quoted 2 lines

IOW, I'd need userspace for perf otherwise but I don't have that before booting...

Correct. In the case of MCE there's no "userspace" really needed
- we just want to trace early enough. This model carries over to later as well: there's no *specific* process we want to attach the trace buffer to - we just want a persistent trace buffer that essentially never loses MCE events.

Quoted 8 lines

Then, after having booted, do I stop the trace? If no, then I can see the persistency in there so are you saying we want a low overhead, low ressource utilization machinery which runs all the time and traces the system? What are possible real life use cases for that? Scheduler analysis probably, long-term tracing of some stuff people are interested in how it behaves over long periods of time... MCE is one use case, definitely...

Boot tracing is a very real usecase, people use it to reduce boot times. Today printk timestamps are used as a substitute. (There's also a boot tracer plugin within ftrace, see the bootup_tracer.)

Quoted 14 lines
Quoted 7 lines

But other, runtime models of tracing could use it as well:
basically the main difference that ftrace has to perf based tracing today is a system-wide persistent buffer with no particular owning process. (The rest is mostly UI and analysis features and scope of tracing differences, and of course a lot more love and detail went into ftrace so far.)

Quoted 6 lines

So MCE will in the end be just a minor user of such a facility - I think you should aim for enabling *any* set of events to have persistent recording properties, and add the APIs to recover that information sanely. It should also be possible for them to record into a shared mmap page in essence - instead of having per event persistent buffers.

Quoted 2 lines

Sounds like ftrace. But we have that already, we only need to get to using it perf-side, no...? [...]

What we want is to extend the perf ring-buffer to be persistent *as well*. It's an evidently useful model of collecting events.

All the remaining perf tooling can be used after that point - if it's a bog-standard perf ring-buffer then it can be saved into a perf.data and can be analyzed in a rich fashion, etc.

Think about it: for example we could do not just boot tracing but also boot *profiling*, by using the PMU to sample into a persistent buffer which after bootup can be put into a perf.data and 'perf report' will do the right thing, etc...

Quoted 5 lines

Does it overlap with ftrace? Perf overlapped with ftrace from day one on and it's starting to become a maintenance problem: we want to remove that overlap not by keeping two separate entities (both of which suck and rule in their own ways) but having a unified facility.

Leaving all of the above for reference.

So, I spent some more nights sleeping on it :-)

Here's what I dreamt of:

* The last thing perf_event_init() does is init the persistent, per-cpu buffers.

* there's no need for changing TRACE_EVENT: "boot_trace" parameter parsing code enables those events the moment perf is initialized. We're doing this anyway because we're enabling the trace_mce_record TP.

It sounds pretty simple to me but the devil is in the details, especially making the persistent buffers, task-agnostic and generic enough.

Ingo, Peter, thoughts?

Thanks.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
#30 lore raw

Re: [PATCH 2/2] x86, mce: Add persistent MCE event

Quoted 118 lines · Borislav Petkov
Quoted 98 lines · Ingo Molnar
Quoted 19 lines · Borislav Petkov
Quoted 7 lines · Ingo Molnar

I was mainly thinking of reducing this:

 arch/x86/kernel/cpu/mcheck/mce.c |   53 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

to almost nothing. There doesn't seem to be much MCE specific in that code, right?

Yeah, this could be generalized even more, AFAICT.

Quoted 8 lines
Quoted 5 lines

Btw, the more important question is are we going to need persistent events that much so that a generic approach is warranted? I guess maybe the black box events recording deal would be another user..

So, here's the big picture as I see it:

Quoted 7 lines
Quoted 3 lines

I think tracing could use persistent events: mark all the events we want to trace as persistent from bootup, and recover the bootup trace after the system has been booted up.

Right, but (more nasty questions):

Why would I do this, am I tracing the boot process? [...]

Correct, in essence the MCE persistent event is partially about
that: we are starting to collect events well before there's any user-space available.

Quoted 3 lines

[...] If so, then I need another syntax which enables those events from the kernel command line which gets parsed the moment ftrace and ring buffer get initialized.

Correct. Something really simple like:

boot_trace=<event1>,<event2>...

... which could be all implicit within MCE too. (So I'm not suggesting some boot command trigger to provide the MCE case - but for more general boot tracing it would be the right solution.)

Quoted 2 lines

IOW, I'd need userspace for perf otherwise but I don't have that before booting...

Correct. In the case of MCE there's no "userspace" really needed
- we just want to trace early enough. This model carries over to later as well: there's no *specific* process we want to attach the trace buffer to - we just want a persistent trace buffer that essentially never loses MCE events.

Quoted 8 lines

Then, after having booted, do I stop the trace? If no, then I can see the persistency in there so are you saying we want a low overhead, low ressource utilization machinery which runs all the time and traces the system? What are possible real life use cases for that? Scheduler analysis probably, long-term tracing of some stuff people are interested in how it behaves over long periods of time... MCE is one use case, definitely...

Boot tracing is a very real usecase, people use it to reduce boot times. Today printk timestamps are used as a substitute. (There's also a boot tracer plugin within ftrace, see the bootup_tracer.)

Quoted 14 lines
Quoted 7 lines

But other, runtime models of tracing could use it as well:
basically the main difference that ftrace has to perf based tracing today is a system-wide persistent buffer with no particular owning process. (The rest is mostly UI and analysis features and scope of tracing differences, and of course a lot more love and detail went into ftrace so far.)

Quoted 6 lines

So MCE will in the end be just a minor user of such a facility - I think you should aim for enabling *any* set of events to have persistent recording properties, and add the APIs to recover that information sanely. It should also be possible for them to record into a shared mmap page in essence - instead of having per event persistent buffers.

Quoted 2 lines

Sounds like ftrace. But we have that already, we only need to get to using it perf-side, no...? [...]

What we want is to extend the perf ring-buffer to be persistent *as well*. It's an evidently useful model of collecting events.

All the remaining perf tooling can be used after that point - if it's a bog-standard perf ring-buffer then it can be saved into a perf.data and can be analyzed in a rich fashion, etc.

Think about it: for example we could do not just boot tracing but also boot *profiling*, by using the PMU to sample into a persistent buffer which after bootup can be put into a perf.data and 'perf report' will do the right thing, etc...

Quoted 5 lines

Does it overlap with ftrace? Perf overlapped with ftrace from day one on and it's starting to become a maintenance problem: we want to remove that overlap not by keeping two separate entities (both of which suck and rule in their own ways) but having a unified facility.

Leaving all of the above for reference.

So, I spent some more nights sleeping on it :-)

Here's what I dreamt of:

* The last thing perf_event_init() does is init the persistent, per-cpu buffers.

* there's no need for changing TRACE_EVENT: "boot_trace" parameter parsing code enables those events the moment perf is initialized. We're doing this anyway because we're enabling the trace_mce_record TP.

Quoted 5 lines

It sounds pretty simple to me but the devil is in the details, especially making the persistent buffers, task-agnostic and generic enough.

Ingo, Peter, thoughts?

Sounds good to me in principle - I guess if you send something that is tested, works, and also enables boot tracing we can see the details?

Thanks,

Ingo

#31 lore raw

Re: [PATCH 2/2] x86, mce: Add persistent MCE event

Quoted 2 lines · Ingo Molnar

Sounds good to me in principle - I guess if you send something that is tested, works, and also enables boot tracing we can see the details?

Yeah, let me see what I can do.

Thanks.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551