Skip to contentSkip to conversation

copperplate/mercury: introduce tunable to set max priority

PATCH Superseded Ronny Meeus 2 participants 2 messages Dec 6, 2016 – Dec 9, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 copperplate/mercury: introduce tunable to set max priority

This patch introduces a tunable in the mercury copperplate code that allows to put an upper limit on the priority used by the created thread objects.

Before this patch the complete OS scheduler's FIFO range was used and it was not possible to restrict it. Restricting it can be useful in case other activities (typically platform related things) need to get a higher priority than the application threads.

The following tuneable can be used to configure the max priority to be 92:
set_config_tunable(sched_max_prio, 92);

or using a command-line option:
--sched_max_prio=92

include/copperplate/threadobj.h +2 -0
@@ -136,6 +136,8 @@ void threadobj_save_timeout(struct threa
 		corespec->timeout = *timeout;
 }
 
+int threadobj_sched_get_priority_max(void);
+
 #endif /* CONFIG_XENO_MERCURY */
 
 /*
include/copperplate/tunables.h +11 -0
@@ -35,6 +35,7 @@ extern "C" {
 #endif
 
 extern struct copperplate_setup_data __copperplate_setup_data;
+extern int threadobj_sched_max_prio;
 
 define_config_tunable(session_label, const char *, label);
 
@@ -93,6 +94,16 @@ static inline read_config_tunable(sessio
 	return __copperplate_setup_data.session_gid;
 }
 
+static inline define_config_tunable(sched_max_prio, int, prio)
+{
+	threadobj_sched_max_prio = prio;
+}
+
+static inline read_config_tunable(sched_max_prio, int)
+{
+	return threadobj_sched_max_prio;
+}
+
 #ifdef __cplusplus
 }
 #endif
lib/copperplate/init.c +9 -0
@@ -77,6 +77,11 @@ static const struct option copperplate_o
 		.flag = &__copperplate_setup_data.shared_registry,
 		.val = 1,
 	},
+	{
+#define sched_max_prio	5
+		.name = "sched-max-prio",
+		.has_arg = required_argument,
+	},
 	{ /* Sentinel */ }
 };
 
@@ -264,6 +269,9 @@ static int copperplate_parse_option(int 
 		if (ret)
 			return ret;
 		break;
+	case sched_max_prio:
+		threadobj_sched_max_prio = atoi(optarg);
+		break;
 	case regroot_opt:
 		__copperplate_setup_data.registry_root = strdup(optarg);
 		break;
@@ -285,6 +293,7 @@ static void copperplate_help(void)
         fprintf(stderr, "--shared-registry		enable public access to registry\n");
         fprintf(stderr, "--registry-root=<path>		root path of registry\n");
         fprintf(stderr, "--session=<label>[/<group>]	enable shared session\n");
+        fprintf(stderr, "--sched_max_prio=<prio>	set max scheduler priority used\n");
 }
 
 static struct setup_descriptor copperplate_interface = {
lib/copperplate/threadobj.c +7 -1
@@ -488,6 +488,7 @@ int threadobj_stat(struct threadobj *tho
 #else /* CONFIG_XENO_MERCURY */
 
 static int threadobj_lock_prio;
+int threadobj_sched_max_prio;
 
 static void unblock_sighandler(int sig)
 {
@@ -542,6 +543,8 @@ static void nop_sighandler(int sig)
 static inline void pkg_init_corespec(void)
 {
 	struct sigaction sa;
+	int max_prio;
+	int max_sched_prio;
 
 	/*
 	 * We don't have builtin scheduler-lock feature over Mercury,
@@ -555,7 +558,10 @@ static inline void pkg_init_corespec(voi
 	 * holding the scheduler lock, unless the latter has to block
 	 * for some reason, defeating the purpose of such lock anyway.
 	 */
-	threadobj_irq_prio = sched_get_priority_max(SCHED_FIFO);
+	max_sched_prio = sched_get_priority_max(SCHED_FIFO);
+	max_prio = (threadobj_sched_max_prio==0) ? max_sched_prio:threadobj_sched_max_prio;
+
+	threadobj_irq_prio = ((max_prio > max_sched_prio)? max_sched_prio:max_prio);
 	threadobj_lock_prio = threadobj_irq_prio - 1;
 	threadobj_high_prio = threadobj_irq_prio - 2;
 	threadobj_agent_prio = threadobj_high_prio;
#1 lore raw
Quoted 11 lines · Ronny Meeus

This patch introduces a tunable in the mercury copperplate code that allows to put an upper limit on the priority used by the created thread objects.

Before this patch the complete OS scheduler's FIFO range was used and it was not possible to restrict it. Restricting it can be useful in case other activities (typically platform related things) need to get a higher priority than the application threads.

The following tuneable can be used to configure the max priority to be 92:
set_config_tunable(sched_max_prio, 92);

The patch should only affect Mercury, not Cobalt. We may need some CONFIG_XENO_MERCURY #ifdeffery here.

Signature · 1 line
Philippe.