kmsg macros, take x+2.
Subsystems (3)
cover kmsg macros, take x+2.
Greetings,
as requested this version of the kmsg patches uses a hash over the message text instead of a manually assigned message number. There is a new kernel function kmsg_printk which calculates the hash, prints the prefix together with the hash and then the message itself. Since it is impossible to add a parameter to a va_list kmsg_printk has to do two seperate printk calls.
The kmsg tag now consists of the kmsg component and a 6 digit hexadecimal hash. The code uses the lower 24 bit of the Jenkins hash of the message text (there is a convenient inline implementation in include/linux/jhash.h). The likelyhood of a hash collision with 100 messages per component is ~0.03%, with 1000 messages ~3% and with 10000 messages ~95%. As an example the old xpam.3 message:
xpram.3: No expanded memory available
now prints as:
xpram.f6ae78: No expanded memory available
For translation purposes all messages need a unique id, that makes the special id 0 from the older kmsg patches rather useless. The replacement for id 0 are single line kmsg comments, e.g.
/*? Tag: xpram.9a3d44 Text: " size of partition %d: %u kB\n" */
This makes the script to ignore the message, the check run will print no warning and no man pages will be generated.
That leaves the question of dev_printk and friends. The dev_xxx macros prefix the message with the driver name and the device name. Both strings are dynamic, the perl script therefore can not find them which makes them unusable as part of the kmsg tag. Now there are some options how to deal with it:
1) Keep the existing dev_xxx printks, do not include a kmsg component in the printk prefix and print the hash seperately. With the hash at the start of the string an example printk would look like this:
617579: qeth: 0.0.f5f0: unknown card type
The bad: the hash prefix is out of place. The large number of dev_xxx printks makes a hash collision very likely. The only solution would be to increase the number of hash digits. The message looks like crap. The good: the message check/print script works and existing code needs no change.
2) Keep the exiting dev_xxx printks, do not include a kmsg component and sneek in the hash right after the driver name. This would look like this:
qeth.617579: 0.0.f5f0: unknown card type
The bad: the script has no chance to find the corresponding kmsg description because the driver name is not known. Automatic message checking and man page creation would be impossible.
The good: the messages look fine.
3) Keep the existing dev_xxx printks, include a kmsg component and print the hash with the component. The example from above would look like this:
qeth.617579: qeth: 0.0.f5f0: unknown card type
The bad: the driver name gets repeated and that every file that uses dev_xxx has to define a KMSG_COMPONENT. The message looks like crap. The good: the script works.
4) Define new kmsg_dev_xxx macros that are similar to dev_xxx, include a kmsg component. These new macros do not print the dynamic driver name, only the kmsg component. This is what is currently implemented. The example from above looks like this:
qeth.617579: 0.0.f5f0: unknown card type
The bad: each driver that wants to use the kmsg_dev_xxx needs to be changed. kmsg_dev_xxx in subsystems will have to do the print of the driver name in each printk as it is not included automatically. The good: the script works and the messages look fine.
I still prefer option 4). Anyone with a clever idea ?
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.
PATCH 1/4 kmsg: Kernel message catalog macros.
From: Martin Schwidefsky <[email protected]>
From: Michael Holzheu <[email protected]>
Introduce a new family of printk macros which prefixes each kmsg message with a component name and allows to tag the message with a 24 bit hash of the message text. The kmsg component name is defined per source file with the KMSG_COMPONENT macro.
If the message hash will be printed to the console / syslog at all depends on CONFIG_MSG_IDS. If it is "n" then a kmsg_xxx call is just another printk wrapper. These macros are intended to be used uniformly in the s390 architecture and the s390 device drivers.
---
arch/s390/Kconfig | 9 ++++++++ include/linux/kmsg.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/printk.c | 24 ++++++++++++++++++++++ 3 files changed, 87 insertions(+)
arch/s390/Kconfig +9 -0
@@ -571,6 +571,15 @@ bool "s390 guest support (EXPERIMENTAL)" select VIRTIO_CONSOLE help Select this option if you want to run the kernel under s390 linux + +config KMSG_IDS + bool "Kernel message numbers" + default y + help + Select this option if you want to include a message number to the + prefix for kernel messages issued by the s390 architecture and + driver code. See "Documentation/s390/kmsg.txt" for more details. + endmenu source "net/Kconfig"
include/linux/kmsg.h new file +54 -0
54 lines not on this page · raw message
kernel/printk.c +24 -0
@@ -32,6 +32,7 @@#include <linux/security.h> #include <linux/bootmem.h> #include <linux/syscalls.h> +#include <linux/jhash.h> #include <asm/uaccess.h>
@@ -1343,3 +1344,26 @@ bool printk_timed_ratelimit(unsigned lon }EXPORT_SYMBOL (printk_timed_ratelimit);#endif + +#if definedCONFIG_PRINTK && definedCONFIG_KMSG_IDS + +/** +* kmsg_printk - print a kernel message with a message id +* @fmt: format string +* @hfmt: revelant part of the format string included in the hash +*/ +asmlinkage int kmsg_printk(const char *prefix, const char *fmt, ...) +{ +va_list args; +int r; + + r =printk (prefix,jhash (fmt,strlen (fmt),0 ) &0xffffff ); +va_start (args, fmt); + r +=vprintk (fmt, args); +va_end (args); + +return r; +} +EXPORT_SYMBOL (kmsg_printk); + +#endif
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.
PATCH 2/4 kmsg: Kernel message catalog script.
In reply to Martin SchwidefskyFrom: Martin Schwidefsky <[email protected]>
From: Michael Holzheu <[email protected]>
Add a script and the calls to the make process that allows to check the kmsg printk messages and to format man pages from the message descriptions.
The kmsg message description is a comment with the following format:
/*?
* Tag: <component>.<hash>
* Text: "<kmsg message text>"
* Severity: <severity>
* Parameter:
* @1: <description of the first message parameter> * @2: <description of the second message parameter> * ...
* Description:
* <What is the kmsg message all about>
* User action:
* <What can the user do to fix the problem>
*/
The following short form of a kmsg message can be used if the message does not have a full documentation:
/*? Tag: <component>.<hash> Text: "<kmsg message text>" */
No man page will be printed for these messages.
The script looks for a kmsg comment for a kmsg printk at three places, the source file where the kmsg call is located, and in the files with the name <component> in the two directories Documentation/kmsg and Documentation/$ARCH/kmsg.
The kmsg check is invoked with "make D=1". It will read the source files for all objects that are built by the current configuration and searches for matching kmsg descriptions for the kmsg messages in the source. If a message description can not be found the script prints a blueprint and causes a make error.
The kmsg man page creation is invoked with "make D=2" and reads the source files for all built objects, looks up the message description and writes a man page to $(objtree)/man.
---
Makefile | 16 + scripts/Makefile.build | 14 + scripts/kmsg-doc | 466 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 496 insertions(+)
Makefile +16 -0
@@ -63,6 +63,20 @@ ifndef KBUILD_CHECKSRC KBUILD_CHECKSRC = 0 endif +# Call message checker as part of the C compilation +# +# Use 'make D=1' to enable checking +# Use 'make D=2' to create the message catalog + +ifdef D + ifeq ("$(origin D)", "command line") + KBUILD_KMSG_CHECK = $(D) + endif +endif +ifndef KBUILD_KMSG_CHECK + KBUILD_KMSG_CHECK = 0 +endif + # Use make M=dir to specify directory of external module to build # Old syntax make ... SUBDIRS=$PWD is still supported # Setting the environment variable KBUILD_EXTMOD take precedence
@@ -321,6 +335,7 @@ PERL = perl CHECK = sparse CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise $(CF) +KMSG_CHECK = $(srctree)/scripts/kmsg-doc MODFLAGS = -DMODULE CFLAGS_MODULE = $(MODFLAGS) AFLAGS_MODULE = $(MODFLAGS)
@@ -355,6 +370,7 @@ export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODU export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE +export KBUILD_KMSG_CHECK KMSG_CHECK # When compiling out-of-tree modules, put MODVERDIR in the module # tree rather than in the kernel tree. The kernel tree might
scripts/kmsg-doc new file +466 -0
466 lines not on this page · raw message
scripts/Makefile.build +14 -0
@@ -211,12 +211,14 @@ endef # Built-in and composite module parts $(obj)/%.o: $(src)/%.c FORCE $(call cmd,force_checksrc) + $(call cmd,force_check_kmsg) $(call if_changed_rule,cc_o_c) # Single-part modules are special since we need to mark them in $(MODVERDIR) $(single-used-m): $(obj)/%.o: $(src)/%.c FORCE $(call cmd,force_checksrc) + $(call cmd,force_check_kmsg) $(call if_changed_rule,cc_o_c) @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod)
@@ -339,6 +341,18 @@ $(multi-used-m) : %.o: $(multi-objs-m) F targets += $(multi-used-y) $(multi-used-m) +# kmsg check tool +ifneq ($(KBUILD_KMSG_CHECK),0) + ifeq ($(KBUILD_KMSG_CHECK),2) + kmsg_cmd := print + quiet_cmd_force_check_kmsg = KMSG_PRINT $< + $(shell [ -d $(objtree)/man ] || mkdir -p $(objtree)/man) + else + kmsg_cmd := check + quiet_cmd_force_check_kmsg = KMSG_CHECK $< + endif + cmd_force_check_kmsg = $(KMSG_CHECK) $(kmsg_cmd) $(CC) $(c_flags) $< ; +endif # Descending # ---------------------------------------------------------------------------
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.
PATCH 3/4 kmsg: convert xpram messages to kmsg api.
In reply to Martin SchwidefskyFrom: Martin Schwidefsky <[email protected]>
---
Documentation/kmsg/s390/xpram | 61 ++++++++++++++++++++++++++++++++++++++++++ drivers/s390/block/xpram.c | 41 +++++++++++++--------------- 2 files changed, 80 insertions(+), 22 deletions(-)
Documentation/kmsg/s390/xpram new file +61 -0
@@ -0,0 +1,61 @@ +/*? + * Tag: xpram.ab9aa4 + * Text: "%d is not a valid number of XPRAM devices\n" + * Severity: Error + * Parameter: + * @1: number of partitions + * Description: + * The number of XPRAM partitions specified for the 'devs' module parameter + * or with the 'xpram.parts' kernel parameter must be an integer in the + * range 1 to 32. The XPRAM device driver created a maximum of 32 partitions + * that are probably not configured as intended. + * User action: + * If the XPRAM device driver has been compiled as a separate module, + * unload the module and load it again with a correct value for the + * 'devs' module parameter. If the XPRAM device driver has been compiled + * into the kernel, correct the 'xpram.parts' parameter in the kernel + * command line and restart Linux. + */ + +/*? + * Tag: xpram.f004d1 + * Text: "Not enough expanded memory available\n" + * Severity: Error + * Description: + * The amount of expanded memory required to set up your XPRAM partitions + * depends on the 'sizes' parameter specified for the xpram module or on + * the specifications for the 'xpram.parts' parameter if the XPRAM device + * driver has been compiled into the kernel. Your + * current specification exceed the amount of available expanded memory. + * Your XPRAM partitions are probably not configured as intended. + * User action: + * If the XPRAM device driver has been compiled as a separate module, + * unload the xpram module and load it again with an appropriate value + * for the 'sizes' module parameter. If the XPRAM device driver has been + * compiled into the kernel, adjust the 'xpram.parts' parameter in the + * kernel command line and restart Linux. If you need more than the + * available expanded memory, increase the expanded memory allocation for + * your virtual hardware or LPAR. + */ + +/*? + * Tag: xpram.f6ae78 + * Text: "No expanded memory available\n" + * Severity: Error + * Description: + * The XPRAM device driver has been loaded in a Linux instance that runs + * in an LPAR or virtual hardware without expanded memory. + * are created. + * User action: + * Allocate expanded memory for your LPAR or virtual hardware or do not + * load the xpram module. You can ignore this message, if you do not want + * to create XPRAM partitions. + */ + +/*? Tag: xpram.fc5e30 Text: " number of devices (partitions): %d \n" */ +/*? Tag: xpram.9a3d44 Text: " size of partition %d: %u kB\n" */ +/*? Tag: xpram.d1b9da Text: " size of partition %d to be set automatically\n" */ +/*? Tag: xpram.758fd6 Text: " memory needed (for sized partitions): %lu kB\n" */ +/*? Tag: xpram.3fc92b Text: " partitions to be sized automatically: %d\n" */ +/*? Tag: xpram.6cdcc1 Text: " automatically determined partition size: %lu kB\n" */ +/*? Tag: xpram.546055 Text: " %u pages expanded memory found (%lu KB).\n" */
drivers/s390/block/xpram.c +19 -22
86 lines not on this page · raw message
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.
PATCH 4/4 kmsg: convert vmcp to kmsg api.
In reply to Martin SchwidefskyFrom: Christian Borntraeger <[email protected]>
---
drivers/s390/char/vmcp.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/s390/char/vmcp.c +19 -2
@@ -17,6 +17,7 @@#include <linux/miscdevice.h> #include <linux/module.h> #include <linux/smp_lock.h> +#include <linux/kmsg.h> #include <asm/cpcmd.h> #include <asm/debug.h> #include <asm/uaccess.h>
@@ -26,7 +27,7 @@ MODULE_LICENSE("GPL");MODULE_AUTHOR ("Christian Borntraeger <[email protected]>" );MODULE_DESCRIPTION ("z/VM CP interface" ); -#define PRINTK_HEADER "vmcp: " +#define KMSG_COMPONENT "vmcp"static debug_info_t *vmcp_debug;
@@ -193,7 +194,8 @@ static int __init vmcp_init(void)int ret;if (!MACHINE_IS_VM ) { -PRINT_WARN ("z/VM CP interface is only available under z/VM\n" ); +kmsg_warn ("The z/VM CP interface device driver cannot be " +"loaded without z/VM\n" );return -ENODEV ; }
@@ -216,6 +218,21 @@ static int __init vmcp_init(void)return 0 ; } +/*? +* Tag: vmcp.42661a +* Text: "The z/VM CP interface device driver cannot be loaded without z/VM\n" +* Severity: Warning +* Description: +* With the z/VM CP interface you can issue z/VM CP commands from a Linux +* terminal session. On Linux instances that run in environments other than +* the z/VM hypervisor, the z/VM CP interface does not provide any useful +* function and the corresponding vmcp device driver cannot be loaded. +* User action: +* Load the vmcp device driver only on Linux instances that run as guest +* operating systems of the z/VM hypervisor. If the device driver has been +* compiled into the kernel, ignore this message. +*/ + static void __exit vmcp_exit(void) {misc_deregister (&vmcp_dev);
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.