Skip to contentSkip to conversation

Rusty's back...restarting logging interface discussions

PATCH Larry Kessler 1 participant 1 message Oct 17, 2002

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

Welcome back, Rusty :0)

Sep 23 I posted patches with a new "problem() logging" interface. The subject line contained "logging macros".

In response to the LKML discussion, Alan wrote...

Quoted 15 lines

A lot of it can be tidied up by very very few changes that can be done over time and make the job easier. Why not just start with

		 dev_printk(dev, KERN_ERR "Exploded mysteriously");

and a few notification type things people can add eg

		 dev_failed(dev);
		 dev_offline(dev);

[SNIP]

dev_printk(dev, ...) is printk that formats up the device info for you. Its also easy to use and happens to pass a device pointer into the places you want it for more detailed logging

Quoted 5 lines

[SNIP]

I don't *care* what you do with it after it gets thrown at you. If I have to care what you are doing with the data the interface is wrong.
--Alan

I agree with Alan, but at the same time you don't want to define an interface that _limits_ alternative post processing of the data.

Also, Greg KH and Jeff Garzik pointed out that defining what should be logged is as important as the interface. I agree, but that's outside of the scope of this note.

The patch below defines a new interface that's a marriage between Alan's proposal and Rusty's macro + event logging. In summary...

* The goal here is to define an interface around printk() that allows an alternative logging facility to be added as needed without expecting device driver writers to move to a new interface now, and yet another one later. Another goal is compatibility with the device model (Pat Mochel and Greg KH).

* With dev_printk(), etc. you *can* define attribute names in the fmt string, but attribute names are _not_ required. Attribute names appear as part of the message in printk messages, when written as "foo_name=%s". However,
if written as "{foo_name}%s", "{foo_name} is stripped out for the printk
message, but used as an attribute name in event logging (if CONFIG_EVLOG=y).

If an attribute name is not specified using either method, attribute names can still be added to the event logging template.

* With Rusty's macro, static details (format string, source file name, function name and line number) are stored in a .log section in the .o file.

A userspace utility can then extract data from the .log section to create a template for re-combining the formatting details with the event data. This allows for alternative presentation and translations, etc. of kernel event data, and queries of events by attribute name by modifying the template, but without having to modify device driver source code.

A unique reference code ties the event record to its template.

* The attached patch for 2.5.43 works fine with printk() only, but includes Rusty's macro now named "printkat". The rest of event logging, with userspace library and utilities, is located at...

https://sourceforge.net/project/showfiles.php?group_id=34226

Click on "dev_printk" under evlog-2.5_kernel, and follow instructions.

----------------------------------------------------------------------

Rules.make +1 -1
diff -Naur linux.org/Rules.make linux.printkat.patched/Rules.make
@@ -238,7 +238,7 @@
 
 quiet_cmd_modules_install = INSTALL $(obj-m)
 cmd_modules_install = mkdir -p $(MODLIB)/kernel/$(obj); \
-		      cp $(obj-m) $(MODLIB)/kernel/$(obj)
+		      (for o in $(obj-m); do objcopy -R .log $$o $(MODLIB)/kernel/$$o; done)
 
 .PHONY: modules_install
 
arch/i386/vmlinux.lds.S +1 -0
diff -Naur linux.org/arch/i386/vmlinux.lds.S linux.printkat.patched/arch/i386/vmlinux.lds.S
@@ -92,6 +92,7 @@
 	*(.text.exit)
 	*(.data.exit)
 	*(.exitcall.exit)
+	*(.log)
 	}
 
   /* Stabs debugging sections.  */
drivers/misc/Makefile +2 -0
diff -Naur linux.org/drivers/misc/Makefile linux.printkat.patched/drivers/misc/Makefile
@@ -2,4 +2,6 @@
 # Makefile for misc devices that really don't fit anywhere else.
 #
 
+obj-m	+= dev_dummy.o
+
 include $(TOPDIR)/Rules.make
drivers/misc/dev_dummy.c +77 -0

77 lines not on this page · raw message

include/linux/device.h +14 -8
diff -Naur linux.org/include/linux/device.h linux.printkat.patched/include/linux/device.h
@@ -29,6 +29,7 @@
 #include <linux/list.h>
 #include <linux/sched.h>
 #include <linux/driverfs_fs.h>
+#include <linux/printkat.h>
 
 #define DEVICE_NAME_SIZE	80
 #define DEVICE_ID_SIZE		32
@@ -426,22 +427,27 @@
 extern void device_shutdown(void);
 
 /* debugging and troubleshooting/diagnostic helpers. */
+#define dev_printk(sev, dev, format, arg...) \
+	printkat(sev "{driver}%s {bus_id}%s: " format,	\
+		(dev).driver->name, (dev).bus_id, ## arg)
+
 #ifdef DEBUG
 #define dev_dbg(dev, format, arg...)		\
-	printk (KERN_DEBUG "%s %s: " format ,	\
-		dev.driver->name , dev.bus_id , ## arg)
+	dev_printk(KERN_DEBUG, (dev), format, ## arg)
 #else
 #define dev_dbg(dev, format, arg...) do {} while (0)
 #endif
 
 #define dev_err(dev, format, arg...)		\
-	printk (KERN_ERR "%s %s: " format ,	\
-		dev.driver->name , dev.bus_id , ## arg)
+	dev_printk(KERN_ERR, (dev), format, ## arg)
 #define dev_info(dev, format, arg...)		\
-	printk (KERN_INFO "%s %s: " format ,	\
-		dev.driver->name , dev.bus_id , ## arg)
+	dev_printk(KERN_INFO, (dev), format, ## arg)
 #define dev_warn(dev, format, arg...)		\
-	printk (KERN_WARN "%s %s: " format ,	\
-		dev.driver->name , dev.bus_id , ## arg)
+	dev_printk(KERN_WARNING, (dev), format, ## arg)
+
+#define dev_failed(dev) dev_err((dev), "Device {status}%s\n", "failed")
+#define dev_offline(dev) dev_info((dev), "Device {status}%s\n", "offline")
+#define dev_online(dev)	\
+	dev_info((dev), "Device {status}%s: {name}%s\n", "online", (dev).name)
 
 #endif /* _DEVICE_H_ */
include/linux/printkat.h +96 -0

96 lines not on this page · raw message

kernel/printk.c +103 -2

133 lines not on this page · raw message