Skip to contentSkip to conversation

Add generic routine for parsing map-like options on kernel cmd-line

PATCH In review Remy Bohmer 2 participants 4 messages Dec 18, 2007 – Dec 19, 2007 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/3 Add generic routine for parsing map-like options on kernel cmd-line

This patch adds a generic routine to the kernel, so that a map of settings can be entered on the kernel commandline.

---

---
 include/linux/kernel.h |    1 
 lib/cmdline.c          |   58 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
include/linux/kernel.h +1 -0
Index: linux-2.6.24-rc5-rt1/include/linux/kernel.h
===================================================================
@@ -164,6 +164,7 @@ extern int vsscanf(const char *, const c
 
 extern int get_option(char **str, int *pint);
 extern char *get_options(const char *str, int nints, int *ints);
+extern int get_map_option(const char *str, const char *key, int *pint);
 extern unsigned long long memparse(char *ptr, char **retptr);
 
 extern int core_kernel_text(unsigned long addr);
lib/cmdline.c +58 -0

70 lines not on this page · raw message

#2 lore raw
Quoted 5 lines · Remy Bohmer

plain text document attachment (add-map-functionality-to-kernel-cmdline.patch)
This patch adds a generic routine to the kernel, so that a map of settings can be entered on the kernel commandline.

Hi Remy,

this might be of general interest - you should consider copying LKML for feedback.

Regards,

Sven

Quoted 97 lines

---

---
 include/linux/kernel.h |    1 
 lib/cmdline.c          |   58 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)

Index: linux-2.6.24-rc5-rt1/include/linux/kernel.h
===================================================================

include/linux/kernel.h +1 -0
@@ -164,6 +164,7 @@ extern int vsscanf(const char *, const c
 
 extern int get_option(char **str, int *pint);
 extern char *get_options(const char *str, int nints, int *ints);
+extern int get_map_option(const char *str, const char *key, int *pint);
 extern unsigned long long memparse(char *ptr, char **retptr);
 
 extern int core_kernel_text(unsigned long addr);

Index: linux-2.6.24-rc5-rt1/lib/cmdline.c
===================================================================

lib/cmdline.c +58 -0
@@ -15,6 +15,7 @@
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
+#include <asm/setup.h>
 
 /*
  *	If a hyphen was found in get_option, this will handle the
@@ -114,6 +115,63 @@ char *get_options(const char *str, int n
 }
 
 /**
+ *	get_map_option - Parse integer from an option map
+ *
+ *	This function parses an integer from an option map like
+ *           some_map=key1:99,key2:98,...,keyN:NN,NN
+ *	Only the value of the first match is returned, or if no
+ *	key option is given (key = NULL) the value of the first
+ *	field without a ':' is returned.
+ *
+ *	@str: option string
+ *	@key: The key inside the map, can be NULL
+ *	@pint: (output) integer value parsed from the map @str
+ *
+ *	Return values:
+ *	0 - no int in string
+ *	1 - int found
+ */
+int get_map_option(const char *str, const char *key, int *pint)
+{
+	char  buf[COMMAND_LINE_SIZE];
+	char  *p, *substr;
+	int   found = 0;
+
+	/* We must copy the string to the stack, because strsep()
+	   changes it.*/
+	strncpy(buf, str, COMMAND_LINE_SIZE);
+	buf[COMMAND_LINE_SIZE-1] = '\0';
+
+	p = buf;
+	substr = strsep(&p, ",");
+	while ((!found) && (substr != NULL)) {
+		if (strlen(substr) != 0) {
+			if (key == NULL) {
+				/* Check for the absence of any ':' */
+				if (strchr(substr, ':') == NULL) {
+					sscanf(substr, "%d", pint);
+					found = 1;
+				}
+			} else {
+				/* check if the first part of the key matches */
+				if (!strncmp(substr, key, strlen(key))) {
+					substr += strlen(key);
+					/* Now the next char must be a ':',
+					   if not, search for the next match */
+					if (*substr == ':') {
+						substr++;
+						sscanf(substr, "%d", pint);
+						found = 1;
+					}
+				}
+			}
+		}
+		substr = strsep(&p, ",");
+	}
+	return found;
+}
+
+/**
  *	memparse - parse a string with mem suffixes into a number
  *	@ptr: Where parse begins
  *	@retptr: (output) Pointer to next char after parse completes
#3 lore raw

PATCH 2/3 Enable setting of IRQ-thread priorities from kernel cmdline

In reply to a message not in the archive

The RT-patch originally creates all its IRQ-threads at priority 50. Of course, this is not a usable default for many realtime systems and therefor these priorities has to be tuneable for each RT-system. But, currently there is no way within the kernel to adjust this to the needs of the user. Some scripts are floating around to do this from userspace, but for several applications the priorities should already be set properly by the kernel itself before userland is started.

This patch changes this by adding a kernel cmd-line option that can handle a map of priorities.
It is based on the name of the driver that requests an interrupt, it does NOT use the IRQ-ID to prioritize a certain IRQ thread. This is designed this way because across several hardware-boards the IRQ-IDs can change, but not necessarily the drivers (interrupt handlers) name.

Remarks:
* There is a check for conflicts added, for situations where IRQ-sharing is detected with different priorities requested on the kernel cmd-line.
* Priorities are only set at creation time of the IRQ-thread.
* If userland overrules, it is NOT restored by this code.
* if no new kernel cmdline options are given, the kernel works as before, and all IRQ-threads start at 50.
* No wildcards are supported on the cmdline.

See kernel/Documentation/kernel-parameters.txt for usage info.

---
 Documentation/kernel-parameters.txt |    7 ++
 include/linux/irq.h                 |    1 
 kernel/irq/manage.c                 |  101 ++++++++++++++++++++++++++++++++----
 3 files changed, 98 insertions(+), 11 deletions(-)
Documentation/kernel-parameters.txt +7 -0
Index: linux-2.6.24-rc5-rt1/Documentation/kernel-parameters.txt
===================================================================
@@ -799,6 +799,13 @@ and is between 256 and 4096 characters. 
 	ips=		[HW,SCSI] Adaptec / IBM ServeRAID controller
 			See header of drivers/scsi/ips.c.
 
+	irq_pmap=	[IRQ-threading] List of priorities each interrupt
+			thread must have.
+			Format: irq_pmap=megasas:90,eth0:40,50
+			The first field without ':', is the default prio.
+			If this cmdline argument is ommitted, every thread
+			runs at prio 50.
+
 	ports=		[IP_VS_FTP] IPVS ftp helper module
 			Default is 21.
 			Up to 8 (IP_VS_APP_MAX_PORTS) ports
include/linux/irq.h +1 -0
Index: linux-2.6.24-rc5-rt1/include/linux/irq.h
===================================================================
@@ -169,6 +169,7 @@ struct irq_desc {
 	unsigned int		irqs_unhandled;
 	unsigned long		last_unhandled;	/* Aging timer for unhandled count */
 	struct task_struct	*thread;
+	int                     rt_prio;
 	wait_queue_head_t	wait_for_handler;
 	cycles_t		timestamp;
 	raw_spinlock_t		lock;
kernel/irq/manage.c +90 -11

157 lines not on this page · raw message

#4 lore raw

PATCH 3/3 Enable setting of IRQ-thread priorities from kernel cmdline.

In reply to a message not in the archive

The RT-patch originally creates all its softirq-threads at priority 50. Of course, this is not a usable default for many realtime systems and therefor these priorities has to be tuneable for each RT-system. But, currently there is no way within the kernel to adjust this to the needs of the user. Some scripts are floating around to do this from userspace, but for several applications the priorities should already be set properly by the kernel itself before userland is started.

This patch changes this by adding a kernel cmd-line option that can handle a map of priorities.

Remarks:
* Priorities are only set at creation time of the softirq.
* Priorities has to be set per-cpu.
* If userland overrules, it is NOT restored by this code.
* if no new kernel cmdline options are given, the kernel works as before, and all softirqs start at 50.
* No wildcards are supported on the cmdline.

See kernel/Documentation/kernel-parameters.txt for usage info.

---
 Documentation/kernel-parameters.txt |   11 +++
 kernel/softirq.c                    |  105 ++++++++++++++++++++++++++++++------
 2 files changed, 99 insertions(+), 17 deletions(-)
Documentation/kernel-parameters.txt +11 -0
Index: linux-2.6.24-rc5-rt1/Documentation/kernel-parameters.txt
===================================================================
@@ -806,6 +806,17 @@ and is between 256 and 4096 characters. 
 			If this cmdline argument is ommitted, every thread
 			runs at prio 50.
 
+	sirq_pmap=	[IRQ-threading] List of priorities each softirq
+			thread must have.
+			Format: sirq_pmap=block/0:90,sched/0:75,50
+			The priorities have to be specified per-cpu.
+			The first field without ':', is the default prio.
+			The names have to match the softirq_names[] table in
+			kernel/softirq.c, (thus without 'softirq-' prefix) to
+			keep the cmd-line short.
+			If this cmdline argument is ommitted, every softirq
+			runs at prio 50.
+
 	ports=		[IP_VS_FTP] IPVS ftp helper module
 			Default is 21.
 			Up to 8 (IP_VS_APP_MAX_PORTS) ports
kernel/softirq.c +88 -17

136 lines not on this page · raw message