[Xenomai] [PATCH] copperplate/mercury: introduce tunable to set max priority

Ronny Meeus ronny.meeus at gmail.com
Tue Dec 6 15:10:31 CET 2016


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

diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -136,6 +136,8 @@ void threadobj_save_timeout(struct threa
 		corespec->timeout = *timeout;
 }
 
+int threadobj_sched_get_priority_max(void);
+
 #endif /* CONFIG_XENO_MERCURY */
 
 /*
diff --git a/include/copperplate/tunables.h b/include/copperplate/tunables.h
--- a/include/copperplate/tunables.h
+++ b/include/copperplate/tunables.h
@@ -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
diff --git a/lib/copperplate/init.c b/lib/copperplate/init.c
--- a/lib/copperplate/init.c
+++ b/lib/copperplate/init.c
@@ -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 = {
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -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;



More information about the Xenomai mailing list