[PATCH 2/2] rtems: Add rtems_scheduler_map_from_posix_priority()
Sebastian Huber
sebastian.huber at embedded-brains.de
Mon Feb 24 13:07:44 UTC 2020
Update #3881.
---
cpukit/Makefile.am | 1 +
cpukit/include/rtems/rtems/tasks.h | 18 ++++++++
cpukit/rtems/src/schedulermapfromposix.c | 70 ++++++++++++++++++++++++++++++++
testsuites/sptests/spscheduler01/init.c | 44 ++++++++++++++++++++
4 files changed, 133 insertions(+)
create mode 100644 cpukit/rtems/src/schedulermapfromposix.c
diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
index f5374efab7..9ed260addb 100644
--- a/cpukit/Makefile.am
+++ b/cpukit/Makefile.am
@@ -769,6 +769,7 @@ librtemscpu_a_SOURCES += rtems/src/schedulergetprocessorset.c
librtemscpu_a_SOURCES += rtems/src/scheduleridentbyprocessor.c
librtemscpu_a_SOURCES += rtems/src/scheduleridentbyprocessorset.c
librtemscpu_a_SOURCES += rtems/src/schedulerident.c
+librtemscpu_a_SOURCES += rtems/src/schedulermapfromposix.c
librtemscpu_a_SOURCES += rtems/src/schedulermaptoposix.c
librtemscpu_a_SOURCES += rtems/src/schedulerremoveprocessor.c
librtemscpu_a_SOURCES += rtems/src/sem.c
diff --git a/cpukit/include/rtems/rtems/tasks.h b/cpukit/include/rtems/rtems/tasks.h
index 9f4d918149..3ee7946df2 100644
--- a/cpukit/include/rtems/rtems/tasks.h
+++ b/cpukit/include/rtems/rtems/tasks.h
@@ -754,6 +754,24 @@ rtems_status_code rtems_scheduler_map_to_posix_priority(
int *posix_priority
);
+/**
+ * @brief Map a POSIX thread priority to the corresonding task priority.
+ *
+ * @param scheduler_id Identifier of the scheduler instance.
+ * @param posix_priority The POSIX thread priority to map.
+ * @param[out] priority Pointer to a task priority value.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_INVALID_ADDRESS The @a priority parameter is @c NULL.
+ * @retval RTEMS_INVALID_ID Invalid scheduler instance identifier.
+ * @retval RTEMS_INVALID_PRIORITY Invalid POSIX thread priority.
+ */
+rtems_status_code rtems_scheduler_map_from_posix_priority(
+ rtems_id scheduler_id,
+ int posix_priority,
+ rtems_task_priority *priority
+);
+
/**@}*/
#ifdef __cplusplus
diff --git a/cpukit/rtems/src/schedulermapfromposix.c b/cpukit/rtems/src/schedulermapfromposix.c
new file mode 100644
index 0000000000..ccf56e1465
--- /dev/null
+++ b/cpukit/rtems/src/schedulermapfromposix.c
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup ClassicTasks
+ *
+ * @brief Implementation of rtems_scheduler_map_from_posix_priority().
+ */
+
+/*
+ * Copyright (C) 2020 embedded brains GmbH (http://www.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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/rtems/tasksimpl.h>
+#include <rtems/posix/priorityimpl.h>
+#include <rtems/score/schedulerimpl.h>
+
+rtems_status_code rtems_scheduler_map_from_posix_priority(
+ rtems_id scheduler_id,
+ int posix_priority,
+ rtems_task_priority *priority
+)
+{
+ const Scheduler_Control *scheduler;
+ Priority_Control core_priority;
+ bool valid;
+
+ if ( priority == NULL ) {
+ return RTEMS_INVALID_ADDRESS;
+ }
+
+ scheduler = _Scheduler_Get_by_id( scheduler_id );
+ if ( scheduler == NULL ) {
+ return RTEMS_INVALID_ID;
+ }
+
+ core_priority = _POSIX_Priority_To_core( scheduler, posix_priority, &valid );
+ if ( !valid ) {
+ return RTEMS_INVALID_PRIORITY;
+ }
+
+ *priority = _RTEMS_Priority_From_core( scheduler, core_priority );
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/testsuites/sptests/spscheduler01/init.c b/testsuites/sptests/spscheduler01/init.c
index 3b94adf36f..f086cb05c0 100644
--- a/testsuites/sptests/spscheduler01/init.c
+++ b/testsuites/sptests/spscheduler01/init.c
@@ -534,6 +534,49 @@ static void test_scheduler_map_to_posix(void)
rtems_test_assert(posix_priority == 1);
}
+static void test_scheduler_map_from_posix(void)
+{
+ rtems_status_code sc;
+ rtems_task_priority priority;
+ rtems_id scheduler_id;
+
+ priority = 123;
+ sc = rtems_scheduler_map_from_posix_priority(invalid_id, 1, &priority);
+ rtems_test_assert(sc == RTEMS_INVALID_ID);
+ rtems_test_assert(priority == 123);
+
+ sc = rtems_task_get_scheduler(RTEMS_SELF, &scheduler_id);
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+ sc = rtems_scheduler_map_from_posix_priority(scheduler_id, 1, NULL);
+ rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
+
+ priority = 123;
+ sc = rtems_scheduler_map_from_posix_priority(scheduler_id, -1, &priority);
+ rtems_test_assert(sc == RTEMS_INVALID_PRIORITY);
+ rtems_test_assert(priority == 123);
+
+ priority = 123;
+ sc = rtems_scheduler_map_from_posix_priority(scheduler_id, 0, &priority);
+ rtems_test_assert(sc == RTEMS_INVALID_PRIORITY);
+ rtems_test_assert(priority == 123);
+
+ priority = 123;
+ sc = rtems_scheduler_map_from_posix_priority(scheduler_id, 255, &priority);
+ rtems_test_assert(sc == RTEMS_INVALID_PRIORITY);
+ rtems_test_assert(priority == 123);
+
+ priority = 123;
+ sc = rtems_scheduler_map_from_posix_priority(scheduler_id, 1, &priority);
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+ rtems_test_assert(priority == 254);
+
+ priority = 123;
+ sc = rtems_scheduler_map_from_posix_priority(scheduler_id, 254, &priority);
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+ rtems_test_assert(priority == 1);
+}
+
static void test_scheduler_get_processors(void)
{
rtems_status_code sc;
@@ -663,6 +706,7 @@ static void Init(rtems_task_argument arg)
test_scheduler_ident();
test_scheduler_get_max_prio();
test_scheduler_map_to_posix();
+ test_scheduler_map_from_posix();
test_scheduler_get_processors();
test_scheduler_add_remove_processors();
test_task_get_priority();
--
2.16.4
More information about the devel
mailing list