[rtems-libbsd commit] Add and use rtems_bsd_get_task_priority()

Sebastian Huber sebh at rtems.org
Tue Jan 20 08:21:32 UTC 2015


Module:    rtems-libbsd
Branch:    master
Commit:    91ea7ea614c777595661c26cfa3e064182687f91
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=91ea7ea614c777595661c26cfa3e064182687f91

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Jan 20 08:39:06 2015 +0100

Add and use rtems_bsd_get_task_priority()

---

 Makefile                                     |  1 +
 freebsd-to-rtems.py                          |  1 +
 libbsd.txt                                   |  8 +++++
 rtemsbsd/include/machine/rtems-bsd-thread.h  |  8 -----
 rtemsbsd/include/rtems/bsd/bsd.h             | 15 +++++++-
 rtemsbsd/rtems/rtems-bsd-get-task-priority.c | 54 ++++++++++++++++++++++++++++
 rtemsbsd/rtems/rtems-bsd-init.c              |  7 ++--
 rtemsbsd/rtems/rtems-bsd-newproc.c           |  6 ++--
 rtemsbsd/rtems/rtems-bsd-nexus.c             |  5 +--
 rtemsbsd/rtems/rtems-bsd-thread.c            | 13 ++++---
 10 files changed, 96 insertions(+), 22 deletions(-)

diff --git a/Makefile b/Makefile
index db8bd24..b7d3a6f 100644
--- a/Makefile
+++ b/Makefile
@@ -71,6 +71,7 @@ LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-conf.c
 LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-delay.c
 LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-get-ethernet-addr.c
 LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-get-file.c
+LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-get-task-priority.c
 LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-init.c
 LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-jail.c
 LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-kern_synch.c
diff --git a/freebsd-to-rtems.py b/freebsd-to-rtems.py
index 31039b6..266c6cf 100755
--- a/freebsd-to-rtems.py
+++ b/freebsd-to-rtems.py
@@ -669,6 +669,7 @@ rtems.addRTEMSSourceFiles(
 		'rtems/rtems-bsd-delay.c',
 		'rtems/rtems-bsd-get-ethernet-addr.c',
 		'rtems/rtems-bsd-get-file.c',
+		'rtems/rtems-bsd-get-task-priority.c',
 		'rtems/rtems-bsd-init.c',
 		'rtems/rtems-bsd-jail.c',
 		'rtems/rtems-bsd-kern_synch.c',
diff --git a/libbsd.txt b/libbsd.txt
index c60bd2a..13ff893 100644
--- a/libbsd.txt
+++ b/libbsd.txt
@@ -228,6 +228,14 @@ http://www.freebsd.org/cgi/man.cgi?query=route&apropos=0&sektion=8&manpath=FreeB
 using `rtems_bsd_command_route()`.  For an example please have a look at
 `testsuite/include/rtems/bsd/test/default-network-init.h`.
 
+=== Task Priorities and Stack Size ===
+
+The default task priority is 96 for the interrupt server task (name "IRQS"), 98
+for the timer server task (name "TIME") and 100 for all other tasks.  The
+application may provide their own implementation of the
+`rtems_bsd_get_task_priority()` function (for example in the module which calls
+`rtems_bsd_initialize()`) if different values are desired.
+
 == Network Stack Features
 
 http://roy.marples.name/projects/dhcpcd/index[DHCPCD(8)]:: DHCP client
diff --git a/rtemsbsd/include/machine/rtems-bsd-thread.h b/rtemsbsd/include/machine/rtems-bsd-thread.h
index 41e08ef..64862df 100644
--- a/rtemsbsd/include/machine/rtems-bsd-thread.h
+++ b/rtemsbsd/include/machine/rtems-bsd-thread.h
@@ -50,14 +50,6 @@
 
 #define BSD_TASK_NAME rtems_build_name('_', 'B', 'S', 'D')
 
-#define BSD_TASK_PRIORITY_NORMAL 120
-
-#define BSD_TASK_PRIORITY_TIMER 110
-
-#define BSD_TASK_PRIORITY_INTERRUPT 100
-
-#define BSD_TASK_PRIORITY_RESOURCE_OWNER 100
-
 /* FIXME */
 #define BSD_MINIMUM_TASK_STACK_SIZE ((size_t) 32 * 1024)
 
diff --git a/rtemsbsd/include/rtems/bsd/bsd.h b/rtemsbsd/include/rtems/bsd/bsd.h
index a9118ec..6aea27f 100644
--- a/rtemsbsd/include/rtems/bsd/bsd.h
+++ b/rtemsbsd/include/rtems/bsd/bsd.h
@@ -7,7 +7,7 @@
  */
 
 /*
- * Copyright (c) 2009-2013 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2009-2015 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -77,6 +77,19 @@ typedef struct {
 
 rtems_status_code rtems_bsd_initialize(void);
 
+/**
+ * @brief Returns the initial priority for a task specified by its name.
+ *
+ * Applications may provide their own implementation of this function.  For
+ * example they can define their implementation in the same module which calls
+ * rtems_bsd_initialize().
+ *
+ * @param[in] name The task name.
+ *
+ * @return The desired initial task priority.
+ */
+rtems_task_priority rtems_bsd_get_task_priority(const char *name);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/rtemsbsd/rtems/rtems-bsd-get-task-priority.c b/rtemsbsd/rtems/rtems-bsd-get-task-priority.c
new file mode 100644
index 0000000..cea6210
--- /dev/null
+++ b/rtemsbsd/rtems/rtems-bsd-get-task-priority.c
@@ -0,0 +1,54 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bsd_rtems
+ *
+ * @brief TODO.
+ */
+
+/*
+ * Copyright (c) 2015 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <rtems/bsd/bsd.h>
+
+#include <string.h>
+
+rtems_task_priority
+rtems_bsd_get_task_priority(const char *name)
+{
+	if (strcmp(name, "IRQS") == 0) {
+		return (96);
+	} else if (strcmp(name, "TIME") == 0) {
+		return (98);
+	} else {
+		return (100);
+	}
+}
diff --git a/rtemsbsd/rtems/rtems-bsd-init.c b/rtemsbsd/rtems/rtems-bsd-init.c
index c9271fd..dbc2cc6 100644
--- a/rtemsbsd/rtems/rtems-bsd-init.c
+++ b/rtemsbsd/rtems/rtems-bsd-init.c
@@ -7,7 +7,7 @@
  */
 
 /*
- * Copyright (c) 2009-2013 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2009-2015 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -76,7 +76,8 @@ struct timeval boottime;
 rtems_status_code
 rtems_bsd_initialize(void)
 {
-	rtems_status_code sc = RTEMS_SUCCESSFUL;
+	static const char name[] = "TIME";
+	rtems_status_code sc;
 
 	hz = (int) rtems_clock_get_ticks_per_second();
 	tick = 1000000 / hz;
@@ -88,7 +89,7 @@ rtems_bsd_initialize(void)
 	mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO);
 
 	sc =  rtems_timer_initiate_server(
-		BSD_TASK_PRIORITY_TIMER,
+		rtems_bsd_get_task_priority(name),
 		BSD_MINIMUM_TASK_STACK_SIZE,
 		RTEMS_DEFAULT_ATTRIBUTES
 	);
diff --git a/rtemsbsd/rtems/rtems-bsd-newproc.c b/rtemsbsd/rtems/rtems-bsd-newproc.c
index b532f86..c01b41d 100644
--- a/rtemsbsd/rtems/rtems-bsd-newproc.c
+++ b/rtemsbsd/rtems/rtems-bsd-newproc.c
@@ -36,9 +36,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <rtems.h>
-
-
-static uint32_t   networkDaemonPriority = 100; /* XXX */
+#include <rtems/bsd/bsd.h>
 
 /*
  * Structure passed to task-start stub
@@ -88,7 +86,7 @@ rtems_bsdnet_newproc (char *name, int stacksize, void(*entry)(void *), void *arg
 
   strncpy (nm, name, 4);
   sc = rtems_task_create (rtems_build_name(nm[0], nm[1], nm[2], nm[3]),
-    networkDaemonPriority,
+    rtems_bsd_get_task_priority(name),
     stacksize,
     RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
     RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
diff --git a/rtemsbsd/rtems/rtems-bsd-nexus.c b/rtemsbsd/rtems/rtems-bsd-nexus.c
index 60cc8cd..a6b9925 100644
--- a/rtemsbsd/rtems/rtems-bsd-nexus.c
+++ b/rtemsbsd/rtems/rtems-bsd-nexus.c
@@ -7,7 +7,7 @@
  */
 
 /*
- * Copyright (c) 2009-2014 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2009-2015 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -69,6 +69,7 @@ static struct rman irq_rman;
 static int
 nexus_probe(device_t dev)
 {
+	static const char name[] = "IRQS";
 	rtems_status_code status;
 	int err;
 	const rtems_bsd_device *nd;
@@ -77,7 +78,7 @@ nexus_probe(device_t dev)
 
 #ifndef DISABLE_INTERRUPT_EXTENSION
 	status = rtems_interrupt_server_initialize(
-		BSD_TASK_PRIORITY_INTERRUPT,
+		rtems_bsd_get_task_priority(name),
 		BSD_MINIMUM_TASK_STACK_SIZE,
 		RTEMS_DEFAULT_MODES,
 		RTEMS_DEFAULT_ATTRIBUTES,
diff --git a/rtemsbsd/rtems/rtems-bsd-thread.c b/rtemsbsd/rtems/rtems-bsd-thread.c
index bdd9aa5..a05d743 100644
--- a/rtemsbsd/rtems/rtems-bsd-thread.c
+++ b/rtemsbsd/rtems/rtems-bsd-thread.c
@@ -7,7 +7,7 @@
  */
 
 /*
- * Copyright (c) 2009-2013 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2009-2015 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -50,6 +50,8 @@
 #include <sys/malloc.h>
 #include <sys/selinfo.h>
 
+#include <rtems/bsd/bsd.h>
+
 #include <rtems/score/objectimpl.h>
 #include <rtems/score/statesimpl.h>
 #include <rtems/score/threaddispatch.h>
@@ -246,12 +248,16 @@ rtems_bsd_thread_start(struct thread **td_ptr, void (*func)(void *), void *arg,
 	int eno = 0;
 	rtems_status_code sc;
 	rtems_id task_id;
+	struct thread *td;
+	char name[sizeof(td->td_name)];
 
 	BSD_ASSERT(pages >= 0);
 
+	vsnprintf(name, sizeof(name), fmt, ap);
+
 	sc = rtems_task_create(
 		BSD_TASK_NAME,
-		BSD_TASK_PRIORITY_NORMAL,
+		rtems_bsd_get_task_priority(name),
 		BSD_MINIMUM_TASK_STACK_SIZE + (size_t) pages * PAGE_SIZE,
 		RTEMS_DEFAULT_MODES,
 		RTEMS_DEFAULT_ATTRIBUTES,
@@ -259,14 +265,13 @@ rtems_bsd_thread_start(struct thread **td_ptr, void (*func)(void *), void *arg,
 	);
 	if (sc == RTEMS_SUCCESSFUL) {
 		Thread_Control *thread = rtems_bsd_get_thread_by_id(task_id);
-		struct thread *td;
 
 		BSD_ASSERT(thread != NULL);
 
 		td = rtems_bsd_get_thread(thread);
 		BSD_ASSERT(td != NULL);
 
-		vsnprintf(td->td_name, sizeof(td->td_name), fmt, ap);
+		memcpy(td->td_name, name, sizeof(name));
 
 		if (rtems_bsd_thread_ready_to_start) {
 			sc = rtems_task_start(task_id, (rtems_task_entry) func,




More information about the vc mailing list