Re: Instructions for Networking with Xilinx BSP and Qemu

2016-06-17 Thread Chris Johns

On 18/06/2016 01:40, Joel Sherrill wrote:

Are there instructions for doing this?  Or even the realview BSP?


I am not sure. It has been a while since I ran this. Last time I used 
qemu and the Xilinx BSP I used VDE with a 32 port VDE switch connected 
to a bridge between my test network port and the tap the VDE switch 
connected too. This meant I could run qemu sessions in parallel and as a 
user not root. This set up is easy on FreeBSD as it is just a few lines 
in the /etc/rc.conf file however I am not sure how this would translate 
to Linux. If there is interest I can look at documenting it.


Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: Error Running HelloWorld on new BSP

2016-06-17 Thread Gedare Bloom
Break at get_baud_div() or initialize(), since they appear in your
printout of the *frame, which is the interrupted thread context at the
point of the unhandled exception.

On Fri, Jun 17, 2016 at 1:44 PM, Olufowobi, Habeeb
 wrote:
> Hi Joel,
>
> When I set the breakpoint at boot_card, this how far I could get;
>
> (gdb) step
> _Terminate (the_source=RTEMS_FATAL_SOURCE_EXCEPTION,
> is_internal=false, the_error=536874976)
> at
> ../../../../../../../rtems.git/c/src/../../cpukit/score/src/interr.c:52
> 52  _CPU_Fatal_halt( the_source, the_error );
> (gdb) step
> arm_interrupt_disable ()
> at ../../cpukit/../../../tm4c129e/lib/include/rtems/score/cpu.h:345
> 345  uint32_t basepri = 0x80;
> (gdb) step
> 347  __asm__ volatile (
> (gdb) step
> 357  return level;
> (gdb) step
> 358}
> (gdb) step
>
>
>
>
> And the backtrace is below
>
> Program received signal SIGINT, Interrupt.
> 0xa6ac in _Terminate (
> the_source=RTEMS_FATAL_SOURCE_EXCEPTION, is_internal=false,
> the_error=536874976)
> at
> ../../../../../../../rtems.git/c/src/../../cpukit/score/src/interr.c:52
> 52  _CPU_Fatal_halt( the_source, the_error );
> (gdb) bt
> #0  0xa6ac in _Terminate (
> the_source=RTEMS_FATAL_SOURCE_EXCEPTION, is_internal=false,
> the_error=536874976)
> at
> ../../../../../../../rtems.git/c/src/../../cpukit/score/src/interr.c:52
> #1  0x85b0 in rtems_fatal (
> source=RTEMS_FATAL_SOURCE_EXCEPTION, error=536874976)
> at
> ../../../../../../../rtems.git/c/src/../../cpukit/sapi/src/fatal2.c:34
> #2  0x00013bfc in _ARM_Exception_default (frame=0x2fe0)
> at
> ../../../../../../../../../rtems.git/c/src/../../cpukit/score/cpu/arm/arm-exception-default.c:24
> #3  
> #4  0x in bsp_start_vector_table_begin ()
> Backtrace stopped: previous frame identical to this frame (corrupt stack?)
> (gdb)
>
>
> Regards,
> Habeeb
>
>
> On Fri, Jun 17, 2016 at 12:51 PM, Joel Sherrill  wrote:
>>
>>
>>
>> On Fri, Jun 17, 2016 at 11:33 AM, Olufowobi, Habeeb
>>  wrote:
>>>
>>> Hi,
>>>
>>> I was able to print the frame and below is the result. Also, I realised
>>> the problem is from the uart. Any ideas on how to resolve this?
>>>
>>>
>>> (gdb) print *frame
>>> $1 = {register_r0 = 115200, register_r1 = 1, register_r2 = 0,
>>>   register_r3 = 1073790976, register_r4 = 0, register_r5 = 0,
>>>   register_r6 = 0, register_r7 = 536875096, register_r8 = 0,
>>>   register_r9 = 0, register_r10 = 0, register_r11 = 0,
>>>   register_r12 = 536894384, register_sp = 120,
>>>   register_lr = 0x138d ,
>>>   register_pc = 0x1290 ,
>>>   register_xpsr = 1090519040, vector = 3,
>>>   vfp_context = 0x0 ,
>>>   reserved_for_stack_alignment = 536875056}
>>>
>>>
>>
>> Not knowing this particular BSP, can you set a breakpoint at various
>> points in
>> the assembly startup? At boot_card? How far do you get?
>>
>> Does the code in memory look like it is supposed to versus
>> arm-rtems4.12-objdump?
>>
>>
>>
>>>
>>> On Wed, Jun 15, 2016 at 12:04 PM, Olufowobi, Habeeb
>>>  wrote:

 Hi,

 I have been working on getting the console running for the past few days
 but I am still getting some errors.
 I realized that the system control configuration of the board family
 (LM3S69XX) was different so I had to rewrite the bspstart.c and the
 lm3s69xx.h to suit the TM4C129E I am working on.
 Presently, HelloWorld halt at "CPU_FATAL_HALT(the_source, the_error)"
 and I am getting RTEMS_FATAL_SOURCE_EXCEPTION in the_source and an error
 code. I am not sure how to debug this but reading about it.

 Below is the backtrace of the error message.
 Kindly assist.

 ^C
 Program received signal SIGINT, Interrupt.
 0x4b22 in _Terminate (
 the_source=the_source@entry=RTEMS_FATAL_SOURCE_EXCEPTION,
 is_internal=is_internal@entry=false, the_error=536875064)
 at
 ../../../../../../../rtems.git/c/src/../../cpukit/score/src/interr.c:52
 52  _CPU_Fatal_halt( the_source, the_error );
 (gdb) bt
 #0  0x4b22 in _Terminate (
 the_source=the_source@entry=RTEMS_FATAL_SOURCE_EXCEPTION,
 is_internal=is_internal@entry=false, the_error=536875064)
 at
 ../../../../../../../rtems.git/c/src/../../cpukit/score/src/interr.c:52
 #1  0x404a in rtems_fatal (
 source=source@entry=RTEMS_FATAL_SOURCE_EXCEPTION,
 error=)
 at
 ../../../../../../../rtems.git/c/src/../../cpukit/sapi/src/fatal2.c:34
 #2  0x7be2 in _ARM_Exception_default (frame=)
 at
 ../../../../../../../../../rtems.git/c/src/../../cpukit/score/cpu/arm/arm-exception-default.c:24
 #3  
 #4  0x0080 in bsp_start_vector_table_begin ()
 #5  0x in ?? ()
 (gdb)

>>>
>>>
>>> ___
>>> 

Re: Error Running HelloWorld on new BSP

2016-06-17 Thread Olufowobi, Habeeb
Hi Joel,

When I set the breakpoint at boot_card, this how far I could get;

(gdb) step
_Terminate (the_source=RTEMS_FATAL_SOURCE_EXCEPTION,
is_internal=false, the_error=536874976)
at
../../../../../../../rtems.git/c/src/../../cpukit/score/src/interr.c:52
52  _CPU_Fatal_halt( the_source, the_error );
(gdb) step
arm_interrupt_disable ()
at ../../cpukit/../../../tm4c129e/lib/include/rtems/score/cpu.h:345
345  uint32_t basepri = 0x80;
(gdb) step
347  __asm__ volatile (
(gdb) step
357  return level;
(gdb) step
358}
(gdb) step




And the backtrace is below

Program received signal SIGINT, Interrupt.
0xa6ac in _Terminate (
the_source=RTEMS_FATAL_SOURCE_EXCEPTION, is_internal=false,
the_error=536874976)
at
../../../../../../../rtems.git/c/src/../../cpukit/score/src/interr.c:52
52  _CPU_Fatal_halt( the_source, the_error );
(gdb) bt
#0  0xa6ac in _Terminate (
the_source=RTEMS_FATAL_SOURCE_EXCEPTION, is_internal=false,
the_error=536874976)
at
../../../../../../../rtems.git/c/src/../../cpukit/score/src/interr.c:52
#1  0x85b0 in rtems_fatal (
source=RTEMS_FATAL_SOURCE_EXCEPTION, error=536874976)
at
../../../../../../../rtems.git/c/src/../../cpukit/sapi/src/fatal2.c:34
#2  0x00013bfc in _ARM_Exception_default (frame=0x2fe0)
at
../../../../../../../../../rtems.git/c/src/../../cpukit/score/cpu/arm/arm-exception-default.c:24
#3  
#4  0x in bsp_start_vector_table_begin ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)


Regards,
Habeeb


On Fri, Jun 17, 2016 at 12:51 PM, Joel Sherrill  wrote:

>
>
> On Fri, Jun 17, 2016 at 11:33 AM, Olufowobi, Habeeb <
> habeeb.olufow...@bison.howard.edu> wrote:
>
>> Hi,
>>
>> I was able to print the frame and below is the result. Also, I realised
>> the problem is from the uart. Any ideas on how to resolve this?
>>
>>
>> (gdb) print *frame
>> $1 = {register_r0 = 115200, register_r1 = 1, register_r2 = 0,
>>   register_r3 = 1073790976, register_r4 = 0, register_r5 = 0,
>>   register_r6 = 0, register_r7 = 536875096, register_r8 = 0,
>>   register_r9 = 0, register_r10 = 0, register_r11 = 0,
>>   register_r12 = 536894384, register_sp = 120,
>>   register_lr = 0x138d ,
>>   register_pc = 0x1290 ,
>>   register_xpsr = 1090519040, vector = 3,
>>   vfp_context = 0x0 ,
>>   reserved_for_stack_alignment = 536875056}
>>
>>
>>
> Not knowing this particular BSP, can you set a breakpoint at various
> points in
> the assembly startup? At boot_card? How far do you get?
>
> Does the code in memory look like it is supposed to versus
> arm-rtems4.12-objdump?
>
>
>
>
>> On Wed, Jun 15, 2016 at 12:04 PM, Olufowobi, Habeeb <
>> habeeb.olufow...@bison.howard.edu> wrote:
>>
>>> Hi,
>>>
>>> I have been working on getting the console running for the past few days
>>> but I am still getting some errors.
>>> I realized that the system control configuration of the board family
>>> (LM3S69XX) was different so I had to rewrite the bspstart.c and the
>>> lm3s69xx.h to suit the TM4C129E I am working on.
>>> Presently, HelloWorld halt at "CPU_FATAL_HALT(the_source, the_error)"
>>> and I am getting RTEMS_FATAL_SOURCE_EXCEPTION in the_source and an error
>>> code. I am not sure how to debug this but reading about it.
>>>
>>> Below is the backtrace of the error message.
>>> Kindly assist.
>>>
>>> ^C
>>> Program received signal SIGINT, Interrupt.
>>> 0x4b22 in _Terminate (
>>> the_source=the_source@entry=RTEMS_FATAL_SOURCE_EXCEPTION,
>>> is_internal=is_internal@entry=false, the_error=536875064)
>>> at
>>> ../../../../../../../rtems.git/c/src/../../cpukit/score/src/interr.c:52
>>> 52  _CPU_Fatal_halt( the_source, the_error );
>>> (gdb) bt
>>> #0  0x4b22 in _Terminate (
>>> the_source=the_source@entry=RTEMS_FATAL_SOURCE_EXCEPTION,
>>> is_internal=is_internal@entry=false, the_error=536875064)
>>> at
>>> ../../../../../../../rtems.git/c/src/../../cpukit/score/src/interr.c:52
>>> #1  0x404a in rtems_fatal (
>>> source=source@entry=RTEMS_FATAL_SOURCE_EXCEPTION,
>>> error=)
>>> at
>>> ../../../../../../../rtems.git/c/src/../../cpukit/sapi/src/fatal2.c:34
>>> #2  0x7be2 in _ARM_Exception_default (frame=)
>>> at
>>> ../../../../../../../../../rtems.git/c/src/../../cpukit/score/cpu/arm/arm-exception-default.c:24
>>> #3  
>>> #4  0x0080 in bsp_start_vector_table_begin ()
>>> #5  0x in ?? ()
>>> (gdb)
>>>
>>>
>>
>> ___
>> devel mailing list
>> devel@rtems.org
>> http://lists.rtems.org/mailman/listinfo/devel
>>
>
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Raspberry pi not working with latest compiler and rtems-git

2016-06-17 Thread Alan Cudmore
I refreshed my RSB build and pulled the latest rtems git changes. ( as of
today ) and the Raspberry Pi BSPs are not working.
I built the sparc/sis RSB and BSP and my tests run fine on that.
I will troubleshoot in the next day or so and try to find the error.

What is the best ARM simulator BSP to try?
I have qemu-system-arm 2.5.0 installed, and I can run some bare metal
examples using the -M versatilepb sim.

Thanks,
Alan
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Instructions for Networking with Xilinx BSP and Qemu

2016-06-17 Thread Joel Sherrill
Hi

Are there instructions for doing this?  Or even the realview BSP?

Thanks.

--joel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Rework thread priority management and EDF scheduler

2016-06-17 Thread Sebastian Huber
The thread priority is manifest in two independent areas.  One area is
the user visible thread priority along with a potential thread queue.
The other is the scheduler.  Currently, a thread priority update via
_Thread_Change_priority() first updates the user visble thread priority
and the thread queue, then the scheduler is notified if necessary.  The
priority is passed to the scheduler via a local variable.  A generation
counter ensures that the scheduler discards out-of-date priorities.

This use of a local variable ties the update in these two areas close
together.  For later enhancements and the OMIP locking protocol
implementation we need more flexibility.  This patch set modifies the thread
priority management and finally adds a thread priority information block to
Scheduler_Node.

As a side-effect the EDF scheduler is reworked.  In a follow up patch the
Priority_Control will change to a 64-bit integer, so that uptimes of more than
49days are supported.
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 15/16] score: Move _RBTree_Find()

2016-06-17 Thread Sebastian Huber
The _RBTree_Find() is no longer used in the score.  Move it to sapi and
make it rtems_rbtree_find().  Move corresponding types and support
functions to sapi.
---
 cpukit/sapi/Makefile.am   |  1 +
 cpukit/sapi/include/rtems/rbtree.h| 72 ++-
 cpukit/sapi/src/rbtreefind.c  | 51 +++
 cpukit/sapi/src/rbtreeinsert.c| 16 +++---
 cpukit/score/Makefile.am  |  2 +-
 cpukit/score/include/rtems/score/rbtree.h | 48 --
 cpukit/score/include/rtems/score/rbtreeimpl.h | 21 
 cpukit/score/src/rbtreefind.c | 50 ---
 8 files changed, 120 insertions(+), 141 deletions(-)
 create mode 100644 cpukit/sapi/src/rbtreefind.c
 delete mode 100644 cpukit/score/src/rbtreefind.c

diff --git a/cpukit/sapi/Makefile.am b/cpukit/sapi/Makefile.am
index 58d2ce5..4e85062 100644
--- a/cpukit/sapi/Makefile.am
+++ b/cpukit/sapi/Makefile.am
@@ -40,6 +40,7 @@ libsapi_a_SOURCES += src/cpucounterconverter.c
 libsapi_a_SOURCES += src/delayticks.c
 libsapi_a_SOURCES += src/delaynano.c
 libsapi_a_SOURCES += src/rbtree.c
+libsapi_a_SOURCES += src/rbtreefind.c
 libsapi_a_SOURCES += src/rbtreeinsert.c
 libsapi_a_SOURCES += src/profilingiterate.c
 libsapi_a_SOURCES += src/profilingreportxml.c
diff --git a/cpukit/sapi/include/rtems/rbtree.h 
b/cpukit/sapi/include/rtems/rbtree.h
index 2b43eaa..57821cf 100644
--- a/cpukit/sapi/include/rtems/rbtree.h
+++ b/cpukit/sapi/include/rtems/rbtree.h
@@ -55,14 +55,31 @@ typedef RBTree_Node rtems_rbtree_node;
 typedef RBTree_Control rtems_rbtree_control;
 
 /**
- * @copydoc RBTree_Compare_result
+ * @brief Integer type for compare results.
+ *
+ * The type is large enough to represent pointers and 32-bit signed integers.
+ *
+ * @see rtems_rbtree_compare.
  */
-typedef RBTree_Compare_result rtems_rbtree_compare_result;
+typedef long rtems_rbtree_compare_result;
 
 /**
- * @copydoc RBTree_Compare
- */
-typedef RBTree_Compare rtems_rbtree_compare;
+ * @brief Compares two red-black tree nodes.
+ *
+ * @param[in] first The first node.
+ * @param[in] second The second node.
+ *
+ * @retval positive The key value of the first node is greater than the one of
+ *   the second node.
+ * @retval 0 The key value of the first node is equal to the one of the second
+ *   node.
+ * @retval negative The key value of the first node is less than the one of the
+ *   second node.
+ */
+typedef rtems_rbtree_compare_result ( *rtems_rbtree_compare )(
+  const RBTree_Node *first,
+  const RBTree_Node *second
+);
 
 /**
  * @brief RBTree initializer for an empty rbtree with designator @a name.
@@ -255,18 +272,47 @@ RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_root(
   return _RBTree_Is_root( the_node );
 }
 
+RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_equal(
+  rtems_rbtree_compare_result compare_result
+)
+{
+  return compare_result == 0;
+}
+
+RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_greater(
+  rtems_rbtree_compare_result compare_result
+)
+{
+  return compare_result > 0;
+}
+
+RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_lesser(
+  rtems_rbtree_compare_result compare_result
+)
+{
+  return compare_result < 0;
+}
+
 /**
- * @copydoc _RBTree_Find()
+ * @brief Tries to find a node for the specified key in the tree.
+ *
+ * @param[in] the_rbtree The red-black tree control.
+ * @param[in] the_node A node specifying the key.
+ * @param[in] compare The node compare function.
+ * @param[in] is_unique If true, then return the first node with a key equal to
+ *   the one of the node specified if it exits, else return the last node if it
+ *   exists.
+ *
+ * @retval node A node corresponding to the key.  If the tree is not unique
+ * and contains duplicate keys, the set of duplicate keys acts as FIFO.
+ * @retval NULL No node exists in the tree for the key.
  */
-RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_find(
+rtems_rbtree_node* rtems_rbtree_find(
   const rtems_rbtree_control *the_rbtree,
   const rtems_rbtree_node*the_node,
-  rtems_rbtree_comparecompare,
+  rtems_rbtree_compare  compare,
   boolis_unique
-)
-{
-  return _RBTree_Find( the_rbtree, the_node, compare, is_unique );
-}
+);
 
 /**
  * @copydoc _RBTree_Predecessor()
@@ -396,7 +442,7 @@ RTEMS_INLINE_ROUTINE rtems_rbtree_node 
*rtems_rbtree_peek_max(
 rtems_rbtree_node *rtems_rbtree_insert(
   RBTree_Control *the_rbtree,
   RBTree_Node*the_node,
-  RBTree_Compare  compare,
+  rtems_rbtree_compare  compare,
   boolis_unique
 );
 
diff --git a/cpukit/sapi/src/rbtreefind.c b/cpukit/sapi/src/rbtreefind.c
new file mode 100644
index 000..d3f67a6
--- /dev/null
+++ b/cpukit/sapi/src/rbtreefind.c
@@ -0,0 +1,51 @@
+/**
+ * @file
+ *
+ * @brief Find the control structure of the tree containing the given node
+ * @ingroup Scorertems_rbtree
+ */
+
+/*
+ *  Copyright (c) 2010 Gedare Bloom.
+ *
+ *  The license and distribution terms for this file may 

[PATCH 03/16] posix: Delete POSIX_API_Control::ss_high_priority

2016-06-17 Thread Sebastian Huber
This field was unused.
---
 cpukit/posix/include/rtems/posix/threadsup.h | 5 -
 cpukit/posix/src/pthreadsetschedparam.c  | 4 
 2 files changed, 9 deletions(-)

diff --git a/cpukit/posix/include/rtems/posix/threadsup.h 
b/cpukit/posix/include/rtems/posix/threadsup.h
index 51c9564..60bf0e4 100644
--- a/cpukit/posix/include/rtems/posix/threadsup.h
+++ b/cpukit/posix/include/rtems/posix/threadsup.h
@@ -52,11 +52,6 @@ typedef struct {
   /** This is the thread's current set of scheduling parameters. */
   struct sched_param  schedparam;
   /**
-   * This is the high priority to execute at when using the sporadic
-   * scheduler.
-   */
-  int ss_high_priority;
-  /**
* This is the timer which controls when the thread executes at
* high and low priority when using the sporadic scheduler.
*/
diff --git a/cpukit/posix/src/pthreadsetschedparam.c 
b/cpukit/posix/src/pthreadsetschedparam.c
index a6882b9..55019dd 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -100,10 +100,6 @@ int pthread_setschedparam(
 rtems_configuration_get_ticks_per_timeslice();
   new_priority = _POSIX_Priority_To_core( api->schedparam.sched_priority );
   break;
-
-case SCHED_SPORADIC:
-  api->ss_high_priority = api->schedparam.sched_priority;
-  break;
   }
 
   _Thread_State_release( the_thread, _context );
-- 
1.8.4.5

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 04/16] posix: Delete POSIX_API_Control::schedpolicy

2016-06-17 Thread Sebastian Huber
This field was redundant.
---
 cpukit/posix/include/rtems/posix/threadsup.h | 2 --
 cpukit/posix/src/pthread.c   | 3 +--
 cpukit/posix/src/pthreadcreate.c | 3 +--
 cpukit/posix/src/pthreadgetschedparam.c  | 2 +-
 cpukit/posix/src/pthreadsetschedparam.c  | 3 +--
 cpukit/score/include/rtems/score/thread.h| 1 -
 6 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/cpukit/posix/include/rtems/posix/threadsup.h 
b/cpukit/posix/include/rtems/posix/threadsup.h
index 60bf0e4..a9f36ef 100644
--- a/cpukit/posix/include/rtems/posix/threadsup.h
+++ b/cpukit/posix/include/rtems/posix/threadsup.h
@@ -47,8 +47,6 @@ typedef struct {
   Thread_Control *thread;
   /** This is the POSIX threads attribute set. */
   pthread_attr_t  Attributes;
-  /** This is the thread's current scheduling policy. */
-  int schedpolicy;
   /** This is the thread's current set of scheduling parameters. */
   struct sched_param  schedparam;
   /**
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index 432f70c..33c2830 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -193,7 +193,6 @@ static bool _POSIX_Threads_Create_extension(
   /* XXX check all fields are touched */
   api->thread = created;
   _POSIX_Threads_Initialize_attributes( >Attributes );
-  api->schedpolicy = _POSIX_Threads_Default_attributes.schedpolicy;
   api->schedparam  = _POSIX_Threads_Default_attributes.schedparam;
   api->schedparam.sched_priority =
  _POSIX_Priority_From_core( created->current_priority );
@@ -232,7 +231,7 @@ static void _POSIX_Threads_Terminate_extension( 
Thread_Control *executing )
 
   _Thread_State_acquire( executing, _context );
 
-  if ( api->schedpolicy == SCHED_SPORADIC ) {
+  if ( api->Attributes.schedpolicy == SCHED_SPORADIC ) {
 _Watchdog_Per_CPU_remove_relative( >Sporadic_timer );
   }
 
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index a120fdd..019ccc8 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -110,7 +110,7 @@ int pthread_create(
   switch ( the_attr->inheritsched ) {
 case PTHREAD_INHERIT_SCHED:
   api = executing->API_Extensions[ THREAD_API_POSIX ];
-  schedpolicy = api->schedpolicy;
+  schedpolicy = api->Attributes.schedpolicy;
   schedparam  = api->schedparam;
   break;
 
@@ -226,7 +226,6 @@ int pthread_create(
   api = the_thread->API_Extensions[ THREAD_API_POSIX ];
 
   _POSIX_Threads_Copy_attributes( >Attributes, the_attr );
-  api->schedpolicy = schedpolicy;
   api->schedparam  = schedparam;
 
   if ( schedpolicy == SCHED_SPORADIC ) {
diff --git a/cpukit/posix/src/pthreadgetschedparam.c 
b/cpukit/posix/src/pthreadgetschedparam.c
index 9b6969c..d03a8a8 100644
--- a/cpukit/posix/src/pthreadgetschedparam.c
+++ b/cpukit/posix/src/pthreadgetschedparam.c
@@ -51,7 +51,7 @@ int pthread_getschedparam(
   _Thread_State_acquire_critical( the_thread, _context );
 
   api = the_thread->API_Extensions[ THREAD_API_POSIX ];
-  *policy = api->schedpolicy;
+  *policy = api->Attributes.schedpolicy;
   *param  = api->schedparam;
   param->sched_priority = _POSIX_Priority_From_core(
 the_thread->real_priority
diff --git a/cpukit/posix/src/pthreadsetschedparam.c 
b/cpukit/posix/src/pthreadsetschedparam.c
index 55019dd..30ddd03 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -80,11 +80,10 @@ int pthread_setschedparam(
 
   api = the_thread->API_Extensions[ THREAD_API_POSIX ];
 
-  if ( api->schedpolicy == SCHED_SPORADIC ) {
+  if ( api->Attributes.schedpolicy == SCHED_SPORADIC ) {
 _Watchdog_Per_CPU_remove_relative( >Sporadic_timer );
   }
 
-  api->schedpolicy = policy;
   api->schedparam  = *param;
   api->Attributes.schedpolicy = policy;
   api->Attributes.schedparam  = *param;
diff --git a/cpukit/score/include/rtems/score/thread.h 
b/cpukit/score/include/rtems/score/thread.h
index 7491e8f..d98658c 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -712,7 +712,6 @@ struct _Thread_Control {
*
* - POSIX_API_Control::Attributes,
* - POSIX_API_Control::schedparam,
-   * - POSIX_API_Control::schedpolicy,
* - RTEMS_API_Control::Signal,
* - Thread_Control::budget_algorithm,
* - Thread_Control::budget_callout,
-- 
1.8.4.5

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 05/16] posix: Delete POSIX_API_Control::schedparam

2016-06-17 Thread Sebastian Huber
This field was redundant.
---
 cpukit/posix/include/rtems/posix/threadsup.h |  4 ++--
 cpukit/posix/src/pthread.c   | 14 +-
 cpukit/posix/src/pthreadcreate.c |  3 +--
 cpukit/posix/src/pthreadgetschedparam.c  |  2 +-
 cpukit/posix/src/pthreadsetschedparam.c  |  5 +++--
 cpukit/posix/src/pthreadsetschedprio.c   |  1 -
 cpukit/score/include/rtems/score/thread.h|  1 -
 7 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/cpukit/posix/include/rtems/posix/threadsup.h 
b/cpukit/posix/include/rtems/posix/threadsup.h
index a9f36ef..e18a429 100644
--- a/cpukit/posix/include/rtems/posix/threadsup.h
+++ b/cpukit/posix/include/rtems/posix/threadsup.h
@@ -45,10 +45,10 @@ extern "C" {
 typedef struct {
   /** Back pointer to thread of this POSIX API control. */
   Thread_Control *thread;
+
   /** This is the POSIX threads attribute set. */
   pthread_attr_t  Attributes;
-  /** This is the thread's current set of scheduling parameters. */
-  struct sched_param  schedparam;
+
   /**
* This is the timer which controls when the thread executes at
* high and low priority when using the sporadic scheduler.
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index 33c2830..ead24cf 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -116,7 +116,9 @@ void _POSIX_Threads_Sporadic_budget_TSR( Watchdog_Control 
*watchdog )
   _Watchdog_Per_CPU_remove_relative( >Sporadic_timer );
   _POSIX_Threads_Sporadic_timer_insert( the_thread, api );
 
-  new_priority = _POSIX_Priority_To_core( api->schedparam.sched_priority );
+  new_priority = _POSIX_Priority_To_core(
+api->Attributes.schedparam.sched_priority
+  );
 
   _Thread_State_release( the_thread, _context );
 
@@ -167,7 +169,9 @@ void _POSIX_Threads_Sporadic_budget_callout(
 
   _Thread_Change_priority(
 the_thread,
-_POSIX_Priority_To_core( api->schedparam.sched_ss_low_priority ),
+_POSIX_Priority_To_core(
+  api->Attributes.schedparam.sched_ss_low_priority
+),
 NULL,
 _POSIX_Threads_Sporadic_budget_callout_filter,
 true
@@ -193,9 +197,9 @@ static bool _POSIX_Threads_Create_extension(
   /* XXX check all fields are touched */
   api->thread = created;
   _POSIX_Threads_Initialize_attributes( >Attributes );
-  api->schedparam  = _POSIX_Threads_Default_attributes.schedparam;
-  api->schedparam.sched_priority =
- _POSIX_Priority_From_core( created->current_priority );
+  api->Attributes.schedparam.sched_priority = _POSIX_Priority_From_core(
+created->current_priority
+  );
 
   /*
*  If the thread is not a posix thread, then all posix signals are blocked
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 019ccc8..c7c2338 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -111,7 +111,7 @@ int pthread_create(
 case PTHREAD_INHERIT_SCHED:
   api = executing->API_Extensions[ THREAD_API_POSIX ];
   schedpolicy = api->Attributes.schedpolicy;
-  schedparam  = api->schedparam;
+  schedparam  = api->Attributes.schedparam;
   break;
 
 case PTHREAD_EXPLICIT_SCHED:
@@ -226,7 +226,6 @@ int pthread_create(
   api = the_thread->API_Extensions[ THREAD_API_POSIX ];
 
   _POSIX_Threads_Copy_attributes( >Attributes, the_attr );
-  api->schedparam  = schedparam;
 
   if ( schedpolicy == SCHED_SPORADIC ) {
 _ISR_lock_ISR_disable( _context );
diff --git a/cpukit/posix/src/pthreadgetschedparam.c 
b/cpukit/posix/src/pthreadgetschedparam.c
index d03a8a8..ed149f2 100644
--- a/cpukit/posix/src/pthreadgetschedparam.c
+++ b/cpukit/posix/src/pthreadgetschedparam.c
@@ -52,7 +52,7 @@ int pthread_getschedparam(
 
   api = the_thread->API_Extensions[ THREAD_API_POSIX ];
   *policy = api->Attributes.schedpolicy;
-  *param  = api->schedparam;
+  *param  = api->Attributes.schedparam;
   param->sched_priority = _POSIX_Priority_From_core(
 the_thread->real_priority
   );
diff --git a/cpukit/posix/src/pthreadsetschedparam.c 
b/cpukit/posix/src/pthreadsetschedparam.c
index 30ddd03..a2e13a0 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -84,7 +84,6 @@ int pthread_setschedparam(
 _Watchdog_Per_CPU_remove_relative( >Sporadic_timer );
   }
 
-  api->schedparam  = *param;
   api->Attributes.schedpolicy = policy;
   api->Attributes.schedparam  = *param;
 
@@ -97,7 +96,9 @@ int pthread_setschedparam(
 case SCHED_RR:
   the_thread->cpu_time_budget =
 rtems_configuration_get_ticks_per_timeslice();
-  new_priority = _POSIX_Priority_To_core( api->schedparam.sched_priority );
+  new_priority = _POSIX_Priority_To_core(
+api->Attributes.schedparam.sched_priority
+  );
   break;
   }
 
diff --git a/cpukit/posix/src/pthreadsetschedprio.c 
b/cpukit/posix/src/pthreadsetschedprio.c
index 856e49d..b7166bc 100644
--- a/cpukit/posix/src/pthreadsetschedprio.c

[PATCH 06/16] posix: Rework sporadic server scheduling policy

2016-06-17 Thread Sebastian Huber
Instead of lowering the priority in case the initial budget is consumed
raise the priority for each new period.  Restore the normal priority
once the initial budget is consumed.  This makes it later easier to
combine the high priority phase with temporary priority boosts (e.g. via
priority ceiling and inheritance).

Use the thread lock to protect the POSIX thread attributes instead of
the thread state lock.  This makes it easier to change the thread
priority and keep the POSIX attributes consistent.

Fixes a false positive use of uninitialized variable warning.
---
 cpukit/posix/include/rtems/posix/pthreadimpl.h |  17 +--
 cpukit/posix/include/rtems/posix/threadsup.h   |  26 +++-
 cpukit/posix/src/psxtransschedparam.c  |   8 --
 cpukit/posix/src/pthread.c | 105 +++-
 cpukit/posix/src/pthreadcreate.c   |  48 +---
 cpukit/posix/src/pthreadgetschedparam.c|   7 +-
 cpukit/posix/src/pthreadsetschedparam.c| 163 +++--
 cpukit/posix/src/pthreadsetschedprio.c |  71 ---
 cpukit/score/include/rtems/score/thread.h  |   2 +-
 9 files changed, 254 insertions(+), 193 deletions(-)

diff --git a/cpukit/posix/include/rtems/posix/pthreadimpl.h 
b/cpukit/posix/include/rtems/posix/pthreadimpl.h
index ba99392..988246e 100644
--- a/cpukit/posix/include/rtems/posix/pthreadimpl.h
+++ b/cpukit/posix/include/rtems/posix/pthreadimpl.h
@@ -62,7 +62,7 @@ RTEMS_INLINE_ROUTINE void 
_POSIX_Threads_Sporadic_timer_insert(
 _Timespec_To_ticks( >Attributes.schedparam.sched_ss_init_budget );
 
   _Watchdog_Per_CPU_insert_relative(
->Sporadic_timer,
+>Sporadic.Timer,
 _Per_CPU_Get(),
 _Timespec_To_ticks( >Attributes.schedparam.sched_ss_repl_period )
   );
@@ -81,21 +81,6 @@ void _POSIX_Threads_Sporadic_budget_callout(
 );
 
 /**
- * This routine supports the sporadic scheduling algorithm.  It
- * is scheduled to be executed at the end of each replenishment
- * period.  In sporadic scheduling a thread will execute at a
- * high priority for a user specified amount of CPU time.  When
- * it exceeds that amount of CPU time, its priority is automatically
- * lowered. This TSR is executed when it is time to replenish
- * the thread's processor budget and raise its priority.
- *
- * @param[in] id is ignored
- * @param[in] argument is a pointer to the Thread_Control structure
- *for the thread being replenished.
- */
-void _POSIX_Threads_Sporadic_budget_TSR( Watchdog_Control *watchdog );
-
-/**
  * @brief Translate sched_param into SuperCore terms.
  *
  * This method translates the POSIX API sched_param into the corresponding
diff --git a/cpukit/posix/include/rtems/posix/threadsup.h 
b/cpukit/posix/include/rtems/posix/threadsup.h
index e18a429..21977be 100644
--- a/cpukit/posix/include/rtems/posix/threadsup.h
+++ b/cpukit/posix/include/rtems/posix/threadsup.h
@@ -18,10 +18,7 @@
 #ifndef _RTEMS_POSIX_THREADSUP_H
 #define _RTEMS_POSIX_THREADSUP_H
 
-#include 
-#include 
 #include 
-#include 
 #include 
 
 #include 
@@ -50,10 +47,27 @@ typedef struct {
   pthread_attr_t  Attributes;
 
   /**
-   * This is the timer which controls when the thread executes at
-   * high and low priority when using the sporadic scheduler.
+   * @brief Control block for the sporadic server scheduling policy.
*/
-  Watchdog_ControlSporadic_timer;
+  struct {
+/**
+ * @brief This is the timer which controls when the thread executes at high
+ * and low priority when using the sporadic server scheduling policy.
+ */
+Watchdog_Control Timer;
+
+/**
+ * @brief The low priority when using the sporadic server scheduling
+ * policy.
+ */
+Priority_Control low_priority;
+
+/**
+ * @brief The high priority when using the sporadic server scheduling
+ * policy.
+ */
+Priority_Control high_priority;
+  } Sporadic;
 
   /** This is the set of signals which are currently unblocked. */
   sigset_tsignals_unblocked;
diff --git a/cpukit/posix/src/psxtransschedparam.c 
b/cpukit/posix/src/psxtransschedparam.c
index 89fadde..fb501b0 100644
--- a/cpukit/posix/src/psxtransschedparam.c
+++ b/cpukit/posix/src/psxtransschedparam.c
@@ -21,9 +21,7 @@
 #include 
 #include 
 
-#include 
 #include 
-#include 
 
 int _POSIX_Thread_Translate_sched_param(
   int  policy,
@@ -32,9 +30,6 @@ int _POSIX_Thread_Translate_sched_param(
   Thread_CPU_budget_algorithm_callout *budget_callout
 )
 {
-  if ( !_POSIX_Priority_Is_valid( param->sched_priority ) )
-return EINVAL;
-
   *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
   *budget_callout = NULL;
 
@@ -66,9 +61,6 @@ int _POSIX_Thread_Translate_sched_param(
 _Timespec_To_ticks( >sched_ss_init_budget ) )
   return EINVAL;
 
-if ( !_POSIX_Priority_Is_valid( param->sched_ss_low_priority ) )
-  return EINVAL;
-
 *budget_algorithm  = 

[PATCH 02/16] posix: _POSIX_Mutex_Default_attributes

2016-06-17 Thread Sebastian Huber
Make _POSIX_Mutex_Default_attributes constant and independent of the
scheduler instance.  Use INT_MAX to indicate the default ceiling
priority.
---
 cpukit/posix/Makefile.am|  2 +-
 cpukit/posix/include/rtems/posix/muteximpl.h|  2 +-
 cpukit/posix/include/rtems/posix/priorityimpl.h | 10 
 cpukit/posix/preinstall.am  |  8 +++---
 cpukit/posix/src/mutex.c| 33 +
 cpukit/posix/src/mutexinit.c| 14 +--
 cpukit/posix/src/psxpriorityisvalid.c   | 10 +++-
 cpukit/posix/src/sched_getprioritymax.c | 10 ++--
 8 files changed, 50 insertions(+), 39 deletions(-)

diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am
index 2442f0c..5bf11c7 100644
--- a/cpukit/posix/Makefile.am
+++ b/cpukit/posix/Makefile.am
@@ -20,6 +20,7 @@ include_rtems_posix_HEADERS += include/rtems/posix/key.h
 include_rtems_posix_HEADERS += include/rtems/posix/keyimpl.h
 include_rtems_posix_HEADERS += include/rtems/posix/config.h
 include_rtems_posix_HEADERS += include/rtems/posix/posixapi.h
+include_rtems_posix_HEADERS += include/rtems/posix/priorityimpl.h
 
 if HAS_PTHREADS
 # include
@@ -37,7 +38,6 @@ include_rtems_posix_HEADERS += include/rtems/posix/mqueue.h
 include_rtems_posix_HEADERS += include/rtems/posix/mqueueimpl.h
 include_rtems_posix_HEADERS += include/rtems/posix/mutex.h
 include_rtems_posix_HEADERS += include/rtems/posix/muteximpl.h
-include_rtems_posix_HEADERS += include/rtems/posix/priorityimpl.h
 include_rtems_posix_HEADERS += include/rtems/posix/psignal.h
 include_rtems_posix_HEADERS += include/rtems/posix/psignalimpl.h
 include_rtems_posix_HEADERS += include/rtems/posix/pthread.h
diff --git a/cpukit/posix/include/rtems/posix/muteximpl.h 
b/cpukit/posix/include/rtems/posix/muteximpl.h
index 4957e20..7d19d8c 100644
--- a/cpukit/posix/include/rtems/posix/muteximpl.h
+++ b/cpukit/posix/include/rtems/posix/muteximpl.h
@@ -50,7 +50,7 @@ extern Objects_Information _POSIX_Mutex_Information;
 /**
  *  The default mutex attributes structure.
  */
-extern pthread_mutexattr_t _POSIX_Mutex_Default_attributes;
+extern const pthread_mutexattr_t _POSIX_Mutex_Default_attributes;
 
 RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Acquire_critical(
   POSIX_Mutex_Control  *the_mutex,
diff --git a/cpukit/posix/include/rtems/posix/priorityimpl.h 
b/cpukit/posix/include/rtems/posix/priorityimpl.h
index 3835ee9..e3f23e7 100644
--- a/cpukit/posix/include/rtems/posix/priorityimpl.h
+++ b/cpukit/posix/include/rtems/posix/priorityimpl.h
@@ -60,6 +60,16 @@ extern "C" {
 #define POSIX_SCHEDULER_MINIMUM_PRIORITY (1)
 
 /**
+ * @brief Gets the maximum POSIX API priority for this scheduler instance.
+ *
+ * Such a priority is valid.  A scheduler instance may support priority values
+ * that are not representable as an integer.
+ *
+ * @return The maximum POSIX API priority for this scheduler instance.
+ */
+int _POSIX_Priority_Get_maximum( const Scheduler_Control *scheduler );
+
+/**
  * @brief Check if POSIX priority is valid.
  * 
  * 1003.1b-1993,2.2.2.80 definition of priority, p. 19
diff --git a/cpukit/posix/preinstall.am b/cpukit/posix/preinstall.am
index 6fc6b4c..1d035e7 100644
--- a/cpukit/posix/preinstall.am
+++ b/cpukit/posix/preinstall.am
@@ -43,6 +43,10 @@ $(PROJECT_INCLUDE)/rtems/posix/posixapi.h: 
include/rtems/posix/posixapi.h $(PROJ
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/posixapi.h
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/posixapi.h
 
+$(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h: 
include/rtems/posix/priorityimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+   $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
+
 if HAS_PTHREADS
 $(PROJECT_INCLUDE)/aio.h: include/aio.h $(PROJECT_INCLUDE)/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/aio.h
@@ -85,10 +89,6 @@ $(PROJECT_INCLUDE)/rtems/posix/muteximpl.h: 
include/rtems/posix/muteximpl.h $(PR
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/muteximpl.h
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/muteximpl.h
 
-$(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h: 
include/rtems/posix/priorityimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
-   $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
-PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
-
 $(PROJECT_INCLUDE)/rtems/posix/psignal.h: include/rtems/posix/psignal.h 
$(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/psignal.h
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/psignal.h
diff --git a/cpukit/posix/src/mutex.c b/cpukit/posix/src/mutex.c
index 22b14c0..3e34dff 100644
--- a/cpukit/posix/src/mutex.c
+++ b/cpukit/posix/src/mutex.c
@@ -18,21 +18,25 @@
 #include "config.h"
 #endif
 
-#include 
-#include 
 #include 
 
-#include 
 #include 
 #include 
-#include 

[PATCH 14/16] score: Move _RBTree_Insert()

2016-06-17 Thread Sebastian Huber
The _RBTree_Insert() is no longer used in the score.  Move it to sapi
and make it rtems_rbtree_insert().
---
 cpukit/sapi/Makefile.am   |  1 +
 cpukit/sapi/include/rtems/rbtree.h| 32 +++--
 cpukit/sapi/src/rbtreeinsert.c| 57 +++
 cpukit/score/include/rtems/score/rbtree.h | 23 -
 cpukit/score/src/rbtreeinsert.c   | 43 ---
 5 files changed, 79 insertions(+), 77 deletions(-)
 create mode 100644 cpukit/sapi/src/rbtreeinsert.c

diff --git a/cpukit/sapi/Makefile.am b/cpukit/sapi/Makefile.am
index 8970e3d..58d2ce5 100644
--- a/cpukit/sapi/Makefile.am
+++ b/cpukit/sapi/Makefile.am
@@ -40,6 +40,7 @@ libsapi_a_SOURCES += src/cpucounterconverter.c
 libsapi_a_SOURCES += src/delayticks.c
 libsapi_a_SOURCES += src/delaynano.c
 libsapi_a_SOURCES += src/rbtree.c
+libsapi_a_SOURCES += src/rbtreeinsert.c
 libsapi_a_SOURCES += src/profilingiterate.c
 libsapi_a_SOURCES += src/profilingreportxml.c
 libsapi_a_SOURCES += src/tcsimpleinstall.c
diff --git a/cpukit/sapi/include/rtems/rbtree.h 
b/cpukit/sapi/include/rtems/rbtree.h
index 271e4b5..2b43eaa 100644
--- a/cpukit/sapi/include/rtems/rbtree.h
+++ b/cpukit/sapi/include/rtems/rbtree.h
@@ -378,17 +378,27 @@ RTEMS_INLINE_ROUTINE rtems_rbtree_node 
*rtems_rbtree_peek_max(
 }
 
 /**
- * @copydoc _RBTree_Insert()
- */
-RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_insert(
-  rtems_rbtree_control *the_rbtree,
-  rtems_rbtree_node*the_node,
-  rtems_rbtree_compare  compare,
-  bool  is_unique
-)
-{
-  return _RBTree_Insert( the_rbtree, the_node, compare, is_unique );
-}
+ * @brief Inserts the node into the red-black tree.
+ *
+ * In case the node is already a node of a tree, then this function yields
+ * unpredictable results.
+ *
+ * @param[in] the_rbtree The red-black tree control.
+ * @param[in] the_node The node to insert.
+ * @param[in] compare The node compare function.
+ * @param[in] is_unique If true, then reject nodes with a duplicate key, else
+ *   insert nodes in FIFO order in case the key value is equal to existing 
nodes.
+ *
+ * @retval NULL Successfully inserted.
+ * @retval existing_node This is a unique insert and there exists a node with
+ *   an equal key in the tree already.
+ */
+rtems_rbtree_node *rtems_rbtree_insert(
+  RBTree_Control *the_rbtree,
+  RBTree_Node*the_node,
+  RBTree_Compare  compare,
+  boolis_unique
+);
 
 /** @} */
 
diff --git a/cpukit/sapi/src/rbtreeinsert.c b/cpukit/sapi/src/rbtreeinsert.c
new file mode 100644
index 000..a4850ff
--- /dev/null
+++ b/cpukit/sapi/src/rbtreeinsert.c
@@ -0,0 +1,57 @@
+/*
+ *  Copyright (c) 2010-2012 Gedare Bloom.
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include 
+#include 
+
+RTEMS_STATIC_ASSERT(
+  sizeof( RBTree_Compare_result ) >= sizeof( intptr_t ),
+  RBTree_Compare_result_intptr_t
+);
+
+RTEMS_STATIC_ASSERT(
+  sizeof( RBTree_Compare_result ) >= sizeof( int32_t ),
+  RBTree_Compare_result_int32_t
+);
+
+rtems_rbtree_node *rtems_rbtree_insert(
+  rtems_rbtree_control *the_rbtree,
+  rtems_rbtree_node*the_node,
+  RBTree_Comparecompare,
+  bool  is_unique
+)
+{
+  rtems_rbtree_node **which = _RBTree_Root_reference( the_rbtree );
+  rtems_rbtree_node  *parent = NULL;
+
+  while ( *which != NULL ) {
+RBTree_Compare_result compare_result;
+
+parent = *which;
+compare_result = ( *compare )( the_node, parent );
+
+if ( is_unique && _RBTree_Is_equal( compare_result ) ) {
+  return parent;
+}
+
+if ( _RBTree_Is_lesser( compare_result ) ) {
+  which = _RBTree_Left_reference( parent );
+} else {
+  which = _RBTree_Right_reference( parent );
+}
+  }
+
+  _RBTree_Add_child( the_node, parent, which );
+  _RBTree_Insert_color( the_rbtree, the_node );
+
+  return NULL;
+}
diff --git a/cpukit/score/include/rtems/score/rbtree.h 
b/cpukit/score/include/rtems/score/rbtree.h
index dd56f1b..f0590c0 100644
--- a/cpukit/score/include/rtems/score/rbtree.h
+++ b/cpukit/score/include/rtems/score/rbtree.h
@@ -117,29 +117,6 @@ RBTree_Node *_RBTree_Find(
 );
 
 /**
- * @brief Inserts the node into the red-black tree.
- *
- * In case the node is already a node of a tree, then this function yields
- * unpredictable results.
- *
- * @param[in] the_rbtree The red-black tree control.
- * @param[in] the_node The node to insert.
- * @param[in] compare The node compare function.
- * @param[in] is_unique If true, then reject nodes with a duplicate key, else
- *   insert nodes in FIFO order in case the key value is equal to existing 
nodes.
- *
- * @retval NULL Successfully inserted.
- * @retval existing_node This is a unique insert and there exists a node with
- *   an equal key in the tree already.
- */
-RBTree_Node 

[PATCH 01/16] posix: pthread_mutexattr_setprioceiling()

2016-06-17 Thread Sebastian Huber
Accept all priority values in pthread_mutexattr_setprioceiling().  This
is in line with POSIX and FreeBSD.  The priority is validated in
pthread_mutex_init().  Validate the priority only for priority ceiling
mutexes.
---
 cpukit/posix/src/mutexattrsetprioceiling.c |  9 -
 cpukit/posix/src/mutexinit.c   | 19 +++
 testsuites/psxtests/psx05/init.c   | 23 +++
 testsuites/psxtests/psx05/psx05.scn| 13 -
 4 files changed, 34 insertions(+), 30 deletions(-)

diff --git a/cpukit/posix/src/mutexattrsetprioceiling.c 
b/cpukit/posix/src/mutexattrsetprioceiling.c
index ba377a9..3411121 100644
--- a/cpukit/posix/src/mutexattrsetprioceiling.c
+++ b/cpukit/posix/src/mutexattrsetprioceiling.c
@@ -21,12 +21,6 @@
 #include 
 #include 
 
-#include 
-#include 
-#include 
-#include 
-#include 
-
 /*
  *  13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 
128
  */
@@ -39,9 +33,6 @@ int pthread_mutexattr_setprioceiling(
   if ( !attr || !attr->is_initialized )
 return EINVAL;
 
-  if ( !_POSIX_Priority_Is_valid( prioceiling ) )
-return EINVAL;
-
   attr->prio_ceiling = prioceiling;
   return 0;
 }
diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c
index 73f0544..3459df7 100644
--- a/cpukit/posix/src/mutexinit.c
+++ b/cpukit/posix/src/mutexinit.c
@@ -36,6 +36,7 @@ int pthread_mutex_init(
   POSIX_Mutex_Control   *the_mutex;
   const pthread_mutexattr_t *the_attr;
   POSIX_Mutex_Protocol   protocol;
+  Priority_Control   priority;
 
   if ( attr ) the_attr = attr;
   elsethe_attr = &_POSIX_Mutex_Default_attributes;
@@ -86,12 +87,6 @@ int pthread_mutex_init(
   return EINVAL;
   }
 
-  /*
-   *  Validate the priority ceiling field -- should always be valid.
-   */
-  if ( !_POSIX_Priority_Is_valid( the_attr->prio_ceiling ) )
-return EINVAL;
-
 #if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
   /*
*  Validate the mutex type and set appropriate SuperCore mutex
@@ -109,6 +104,14 @@ int pthread_mutex_init(
   }
 #endif
 
+  if ( protocol == POSIX_MUTEX_PRIORITY_CEILING ) {
+if ( !_POSIX_Priority_Is_valid( the_attr->prio_ceiling ) ) {
+  return EINVAL;
+}
+
+priority = _POSIX_Priority_To_core( the_attr->prio_ceiling );
+  }
+
   the_mutex = _POSIX_Mutex_Allocate();
 
   if ( !the_mutex ) {
@@ -119,11 +122,11 @@ int pthread_mutex_init(
   the_mutex->protocol = protocol;
   the_mutex->is_recursive = ( the_attr->type == PTHREAD_MUTEX_RECURSIVE );
 
-  switch ( the_mutex->protocol ) {
+  switch ( protocol ) {
 case POSIX_MUTEX_PRIORITY_CEILING:
   _CORE_ceiling_mutex_Initialize(
 _mutex->Mutex,
-_POSIX_Priority_To_core( the_attr->prio_ceiling )
+priority
   );
   break;
 default:
diff --git a/testsuites/psxtests/psx05/init.c b/testsuites/psxtests/psx05/init.c
index bbc863a..5f39b2f 100644
--- a/testsuites/psxtests/psx05/init.c
+++ b/testsuites/psxtests/psx05/init.c
@@ -16,6 +16,7 @@
 #define CONFIGURE_INIT
 #include "system.h"
 #include 
+#include 
 
 #include 
 
@@ -375,11 +376,13 @@ void *POSIX_Init(
   status = pthread_mutexattr_setprioceiling( NULL, 128 );
   rtems_test_assert( status == EINVAL );
 
-  puts( "Init: pthread_mutexattr_setprioceiling - EINVAL (invalid priority)" );
-  status = pthread_mutexattr_setprioceiling( , 512 );
-  if ( status != EINVAL )
-printf( "status = %d\n", status );
-  rtems_test_assert( status == EINVAL );
+  puts( "Init: pthread_mutexattr_setprioceiling - SUCCESSFUL (priority 
INT_MAX)" );
+  status = pthread_mutexattr_setprioceiling( , INT_MAX );
+  rtems_test_assert( status == 0 );
+
+  puts( "Init: pthread_mutexattr_setprioceiling - SUCCESSFUL (priority 
INT_MIN)" );
+  status = pthread_mutexattr_setprioceiling( , INT_MIN );
+  rtems_test_assert( status == 0 );
 
   puts( "Init: pthread_mutexattr_setprioceiling - EINVAL (not initialized)" );
   status = pthread_mutexattr_setprioceiling( _attr, -1 );
@@ -409,9 +412,13 @@ void *POSIX_Init(
   status = pthread_mutex_init( _id,  );
   rtems_test_assert( status == EINVAL );
 
-  /* must get around error checks in attribute set routines */
-  attr.protocol = PTHREAD_PRIO_INHERIT;
-  attr.prio_ceiling = -1;
+  puts( "Init: pthread_mutexattr_setprotocol - SUCCESSFUL" );
+  status = pthread_mutexattr_setprotocol( , PTHREAD_PRIO_PROTECT );
+  rtems_test_assert( !status );
+
+  puts( "Init: pthread_mutexattr_setprioceiling - SUCCESSFUL" );
+  status = pthread_mutexattr_setprioceiling( , -1 );
+  rtems_test_assert( !status );
 
   puts( "Init: pthread_mutex_init - EINVAL (bad priority ceiling)" );
   status = pthread_mutex_init( _id,  );
diff --git a/testsuites/psxtests/psx05/psx05.scn 
b/testsuites/psxtests/psx05/psx05.scn
index 8fa3e23..4e66cea 100644
--- a/testsuites/psxtests/psx05/psx05.scn
+++ b/testsuites/psxtests/psx05/psx05.scn
@@ -1,4 +1,4 @@
-*** POSIX TEST 5 ***
+*** BEGIN OF TEST PSX 5 ***
 Init's ID is 0x0b010001
 Init: 

[PATCH 10/16] score: Introduce map priority scheduler operation

2016-06-17 Thread Sebastian Huber
Introduce map/unmap priority scheduler operations to map thread priority
values from/to the user domain to/from the scheduler domain.  Use the
map priority operation to validate the thread priority.  The EDF
schedulers use this new operation to distinguish between normal
priorities and priorities obtain through a job release.
---
 cpukit/libmisc/monitor/mon-sema.c  |   6 +-
 cpukit/posix/include/rtems/posix/priorityimpl.h|  13 +-
 cpukit/posix/src/mutexgetprioceiling.c |  12 +-
 cpukit/posix/src/mutexinit.c   |   6 +-
 cpukit/posix/src/mutexsetprioceiling.c |  36 ++--
 cpukit/posix/src/psxpriorityisvalid.c  |  25 ++-
 cpukit/posix/src/pthreadcreate.c   |   3 +-
 cpukit/posix/src/pthreadgetschedparam.c|   9 +-
 cpukit/rtems/src/semcreate.c   |  59 ---
 cpukit/rtems/src/semsetpriority.c  | 105 +++-
 cpukit/rtems/src/tasksetpriority.c |  47 +++---
 cpukit/score/Makefile.am   |   2 +
 cpukit/score/include/rtems/score/coremutex.h   |   9 +
 cpukit/score/include/rtems/score/coremuteximpl.h   |  42 +
 cpukit/score/include/rtems/score/mrspimpl.h|  39 +++--
 cpukit/score/include/rtems/score/scheduler.h   |  40 +
 cpukit/score/include/rtems/score/schedulercbs.h|   2 +
 cpukit/score/include/rtems/score/scheduleredf.h|  12 ++
 cpukit/score/include/rtems/score/schedulerimpl.h   |  39 +
 .../score/include/rtems/score/schedulerpriority.h  |   2 +
 .../rtems/score/schedulerpriorityaffinitysmp.h |   2 +
 .../include/rtems/score/schedulerprioritysmp.h |   2 +
 cpukit/score/include/rtems/score/schedulersimple.h |   2 +
 .../score/include/rtems/score/schedulersimplesmp.h |   2 +
 .../score/include/rtems/score/schedulerstrongapa.h |   2 +
 cpukit/score/include/rtems/score/status.h  |   5 +
 cpukit/score/include/rtems/score/threadimpl.h  |  24 +++
 cpukit/score/src/schedulerdefaultmappriority.c |  21 +++
 cpukit/score/src/schedulerdefaultunmappriority.c   |  23 +++
 cpukit/score/src/scheduleredfchangepriority.c  |  21 +++
 cpukit/score/src/threadcreateidle.c|  11 +-
 cpukit/score/src/threadsetpriority.c   |  57 +++
 testsuites/psxtests/psxautoinit01/init.c   |   4 +
 testsuites/smptests/Makefile.am|   1 +
 testsuites/smptests/configure.ac   |   1 +
 testsuites/smptests/smppsxmutex01/Makefile.am  |  19 +++
 testsuites/smptests/smppsxmutex01/init.c   | 184 +
 .../smptests/smppsxmutex01/smppsxmutex01.doc   |  12 ++
 .../smptests/smppsxmutex01/smppsxmutex01.scn   |   2 +
 testsuites/smptests/smpscheduler02/init.c  |  35 +++-
 testsuites/sptests/sp51/init.c |  10 ++
 testsuites/sptests/sp51/sp51.scn   |   5 +-
 testsuites/sptests/spmrsp01/init.c |  13 ++
 43 files changed, 825 insertions(+), 141 deletions(-)
 create mode 100644 cpukit/score/src/schedulerdefaultmappriority.c
 create mode 100644 cpukit/score/src/schedulerdefaultunmappriority.c
 create mode 100644 testsuites/smptests/smppsxmutex01/Makefile.am
 create mode 100644 testsuites/smptests/smppsxmutex01/init.c
 create mode 100644 testsuites/smptests/smppsxmutex01/smppsxmutex01.doc
 create mode 100644 testsuites/smptests/smppsxmutex01/smppsxmutex01.scn

diff --git a/cpukit/libmisc/monitor/mon-sema.c 
b/cpukit/libmisc/monitor/mon-sema.c
index 272391f..7334611 100644
--- a/cpukit/libmisc/monitor/mon-sema.c
+++ b/cpukit/libmisc/monitor/mon-sema.c
@@ -61,8 +61,10 @@ rtems_monitor_sema_canonical(
 
 switch ( rtems_sema->variant ) {
   case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
-canonical_sema->priority_ceiling =
-  rtems_sema->Core_control.Mutex.priority_ceiling;
+canonical_sema->priority_ceiling = _Scheduler_Unmap_priority(
+  _CORE_ceiling_mutex_Get_scheduler( _sema->Core_control.Mutex ),
+  _CORE_ceiling_mutex_Get_priority( _sema->Core_control.Mutex )
+);
 /* Fall through */
   case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
   case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
diff --git a/cpukit/posix/include/rtems/posix/priorityimpl.h 
b/cpukit/posix/include/rtems/posix/priorityimpl.h
index 54f5c9c..bc59742 100644
--- a/cpukit/posix/include/rtems/posix/priorityimpl.h
+++ b/cpukit/posix/include/rtems/posix/priorityimpl.h
@@ -79,20 +79,17 @@ bool _POSIX_Priority_To_core(
 );
 
 /**
- * @brief Converts SuperCore priority to POSIX priority.
+ * @brief Converts SuperCore priority to the corresponding POSIX API priority.
  *
  * @param[in] scheduler The scheduler instance.
- * @param[in] priority The SuperCore priority.
+ * @param[in] core_priority The SuperCore priority.
  *
  * @return Returns the corresponding POSIX API priority.
  */
-RTEMS_INLINE_ROUTINE int _POSIX_Priority_From_core(

[PATCH 11/16] score: Remove hidden deadline overrule for CBS

2016-06-17 Thread Sebastian Huber
Do what the user commands.  Maybe we should add a rtems_cbs_period()
that calls rtems_rate_monotonic_period() with the right parameter.
---
 cpukit/score/src/schedulercbsreleasejob.c | 30 --
 1 file changed, 8 insertions(+), 22 deletions(-)

diff --git a/cpukit/score/src/schedulercbsreleasejob.c 
b/cpukit/score/src/schedulercbsreleasejob.c
index a9f8e33..b820829 100644
--- a/cpukit/score/src/schedulercbsreleasejob.c
+++ b/cpukit/score/src/schedulercbsreleasejob.c
@@ -20,8 +20,6 @@
 #endif
 
 #include 
-#include 
-#include 
 
 void _Scheduler_CBS_Release_job(
   const Scheduler_Control *scheduler,
@@ -29,28 +27,16 @@ void _Scheduler_CBS_Release_job(
   uint32_t deadline
 )
 {
-  Scheduler_CBS_Node   *node = _Scheduler_CBS_Thread_get_node( the_thread );
-  Scheduler_CBS_Server *serv_info = node->cbs_server;
-  Priority_Control  new_priority;
-  Priority_Control  unused;
+  Scheduler_CBS_Node   *node;
+  Scheduler_CBS_Server *serv_info;
 
-  if (deadline) {
-/* Initializing or shifting deadline. */
-if (serv_info)
-  new_priority = (_Watchdog_Ticks_since_boot + 
serv_info->parameters.deadline)
-& ~SCHEDULER_EDF_PRIO_MSB;
-else
-  new_priority = (_Watchdog_Ticks_since_boot + deadline)
-& ~SCHEDULER_EDF_PRIO_MSB;
-  }
-  else {
-/* Switch back to background priority. */
-new_priority = the_thread->Start.initial_priority;
-  }
+  _Scheduler_EDF_Release_job( scheduler, the_thread, deadline );
+
+  node = _Scheduler_CBS_Thread_get_node( the_thread );
+  serv_info = node->cbs_server;
 
   /* Budget replenishment for the next job. */
-  if (serv_info)
+  if ( serv_info != NULL ) {
 the_thread->cpu_time_budget = serv_info->parameters.budget;
-
-  _Thread_Set_priority( the_thread, new_priority, , true );
+  }
 }
-- 
1.8.4.5

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 13/16] score: Rework EDF scheduler

2016-06-17 Thread Sebastian Huber
Use inline red-black tree insert.  Do not use shifting priorities since
this is not supported by the thread queues.  Due to the 32-bit
Priority_Control this currently limits the uptime to 49days with a 1ms
clock tick.
---
 cpukit/score/include/rtems/score/scheduleredf.h|  25 ++---
 .../score/include/rtems/score/scheduleredfimpl.h   | 107 +++--
 cpukit/score/src/schedulercbsnodeinit.c|   9 +-
 cpukit/score/src/schedulercbsunblock.c |  56 +--
 cpukit/score/src/scheduleredf.c|  41 
 cpukit/score/src/scheduleredfblock.c   |   2 +-
 cpukit/score/src/scheduleredfchangepriority.c  |  28 --
 cpukit/score/src/scheduleredfnodeinit.c|   1 -
 cpukit/score/src/scheduleredfreleasejob.c  |  52 ++
 cpukit/score/src/scheduleredfunblock.c |  16 +--
 cpukit/score/src/scheduleredfupdate.c  |  15 ++-
 cpukit/score/src/scheduleredfyield.c   |  20 ++--
 12 files changed, 190 insertions(+), 182 deletions(-)

diff --git a/cpukit/score/include/rtems/score/scheduleredf.h 
b/cpukit/score/include/rtems/score/scheduleredf.h
index 562620a..e85510c 100644
--- a/cpukit/score/include/rtems/score/scheduleredf.h
+++ b/cpukit/score/include/rtems/score/scheduleredf.h
@@ -35,7 +35,7 @@ extern "C" {
  */
 /**@{*/
 
-#define SCHEDULER_EDF_MAXIMUM_PRIORITY 255
+#define SCHEDULER_EDF_MAXIMUM_PRIORITY 0x7fff
 
 /**
  *  Entry points for the Earliest Deadline First Scheduler.
@@ -82,18 +82,6 @@ typedef struct {
 } Scheduler_EDF_Context;
 
 /**
- * @typedef Scheduler_EDF_Queue_state
- *
- * This enumeration distiguishes state of a thread with respect to the
- * ready queue.
- */
-typedef enum {
-  SCHEDULER_EDF_QUEUE_STATE_NOT_PRESENTLY,
-  SCHEDULER_EDF_QUEUE_STATE_YES,
-  SCHEDULER_EDF_QUEUE_STATE_NEVER_HAS_BEEN
-} Scheduler_EDF_Queue_state;
-
-/**
  * @brief Scheduler node specialization for EDF schedulers.
  */
 typedef struct {
@@ -110,10 +98,17 @@ typedef struct {
* Rbtree node related to this thread.
*/
   RBTree_Node Node;
+
+  /**
+   * @brief The thread priority used by this scheduler instance in case no job
+   * is released.
+   */
+  Priority_Control background_priority;
+
   /**
-   * State of the thread with respect to ready queue.
+   * @brief The thread priority currently used by this scheduler instance.
*/
-  Scheduler_EDF_Queue_state queue_state;
+  Priority_Control current_priority;
 } Scheduler_EDF_Node;
 
 /**
diff --git a/cpukit/score/include/rtems/score/scheduleredfimpl.h 
b/cpukit/score/include/rtems/score/scheduleredfimpl.h
index e831caf..7ff7aa2 100644
--- a/cpukit/score/include/rtems/score/scheduleredfimpl.h
+++ b/cpukit/score/include/rtems/score/scheduleredfimpl.h
@@ -44,44 +44,92 @@ RTEMS_INLINE_ROUTINE Scheduler_EDF_Node 
*_Scheduler_EDF_Thread_get_node(
   return (Scheduler_EDF_Node *) _Scheduler_Thread_get_node( the_thread );
 }
 
-int _Scheduler_EDF_Priority_compare (
-  Priority_Control p1,
-  Priority_Control p2
-);
+RTEMS_INLINE_ROUTINE bool _Scheduler_EDF_Less(
+  const void*left,
+  const RBTree_Node *right
+)
+{
+  const Priority_Control   *the_left;
+  const Scheduler_EDF_Node *the_right;
+  Priority_Control  prio_left;
+  Priority_Control  prio_right;
+
+  the_left = left;
+  the_right = RTEMS_CONTAINER_OF( right, Scheduler_EDF_Node, Node );
+
+  prio_left = *the_left;
+  prio_right = the_right->current_priority;
+
+  return prio_left < prio_right;
+}
+
+RTEMS_INLINE_ROUTINE bool _Scheduler_EDF_Less_or_equal(
+  const void*left,
+  const RBTree_Node *right
+)
+{
+  const Priority_Control   *the_left;
+  const Scheduler_EDF_Node *the_right;
+  Priority_Control  prio_left;
+  Priority_Control  prio_right;
 
-RBTree_Compare_result _Scheduler_EDF_Compare(
-  const RBTree_Node* n1,
-  const RBTree_Node* n2
-);
+  the_left = left;
+  the_right = RTEMS_CONTAINER_OF( right, Scheduler_EDF_Node, Node );
+
+  prio_left = *the_left;
+  prio_right = the_right->current_priority;
+
+  return prio_left <= prio_right;
+}
 
 RTEMS_INLINE_ROUTINE void _Scheduler_EDF_Enqueue(
-  const Scheduler_Control *scheduler,
-  Thread_Control  *the_thread
+  Scheduler_EDF_Context *context,
+  Scheduler_EDF_Node*node,
+  Priority_Control   current_priority
 )
 {
-  Scheduler_EDF_Context *context =
-_Scheduler_EDF_Get_context( scheduler );
-  Scheduler_EDF_Node *node = _Scheduler_EDF_Thread_get_node( the_thread );
+  _RBTree_Insert_inline(
+>Ready,
+>Node,
+_priority,
+_Scheduler_EDF_Less
+  );
+}
 
-  _RBTree_Insert(
+RTEMS_INLINE_ROUTINE void _Scheduler_EDF_Enqueue_first(
+  Scheduler_EDF_Context *context,
+  Scheduler_EDF_Node*node,
+  Priority_Control   current_priority
+)
+{
+  _RBTree_Insert_inline(
 >Ready,
 >Node,
-_Scheduler_EDF_Compare,
-false
+_priority,
+_Scheduler_EDF_Less_or_equal
   );
-  node->queue_state = 

[PATCH 09/16] score: Delete unused _Scheduler_Priority_compare()

2016-06-17 Thread Sebastian Huber
By convention, thread priorities must be integers in RTEMS.  Smaller
values represent more important threads.
---
 cpukit/score/Makefile.am   |  2 -
 cpukit/score/include/rtems/score/scheduler.h   |  6 ---
 cpukit/score/include/rtems/score/schedulercbs.h|  1 -
 cpukit/score/include/rtems/score/scheduleredf.h| 14 --
 .../score/include/rtems/score/scheduleredfimpl.h   |  5 +++
 cpukit/score/include/rtems/score/schedulerimpl.h   | 51 --
 .../score/include/rtems/score/schedulerpriority.h  | 13 --
 .../rtems/score/schedulerpriorityaffinitysmp.h |  1 -
 .../include/rtems/score/schedulerpriorityimpl.h| 17 
 .../include/rtems/score/schedulerprioritysmp.h |  1 -
 cpukit/score/include/rtems/score/schedulersimple.h |  1 -
 .../score/include/rtems/score/schedulersimplesmp.h |  1 -
 .../score/include/rtems/score/schedulerstrongapa.h |  1 -
 cpukit/score/src/schedulercbsunblock.c |  9 ++--
 cpukit/score/src/scheduleredf.c| 22 ++
 cpukit/score/src/scheduleredfprioritycompare.c | 47 
 cpukit/score/src/scheduleredfunblock.c | 10 +++--
 .../score/src/schedulerpriorityprioritycompare.c   | 29 
 18 files changed, 37 insertions(+), 194 deletions(-)
 delete mode 100644 cpukit/score/src/scheduleredfprioritycompare.c
 delete mode 100644 cpukit/score/src/schedulerpriorityprioritycompare.c

diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 537cf60..7166d72 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -239,7 +239,6 @@ libscore_a_SOURCES += src/schedulerdefaultupdate.c
 libscore_a_SOURCES += src/schedulerpriority.c \
 src/schedulerpriorityblock.c \
 src/schedulerprioritychangepriority.c \
-src/schedulerpriorityprioritycompare.c \
 src/schedulerpriorityschedule.c \
 src/schedulerpriorityunblock.c \
 src/schedulerpriorityupdate.c \
@@ -258,7 +257,6 @@ libscore_a_SOURCES += src/scheduleredf.c \
 src/scheduleredfnodeinit.c \
 src/scheduleredfblock.c \
 src/scheduleredfchangepriority.c \
-src/scheduleredfprioritycompare.c \
 src/scheduleredfreleasejob.c \
 src/scheduleredfschedule.c \
 src/scheduleredfunblock.c \
diff --git a/cpukit/score/include/rtems/score/scheduler.h 
b/cpukit/score/include/rtems/score/scheduler.h
index 1e6236f..2e9aba5 100644
--- a/cpukit/score/include/rtems/score/scheduler.h
+++ b/cpukit/score/include/rtems/score/scheduler.h
@@ -129,12 +129,6 @@ typedef struct {
 Priority_Control
   );
 
-  /** @see _Scheduler_Priority_compare() */
-  int ( *priority_compare )(
-Priority_Control,
-Priority_Control
-  );
-
   /** @see _Scheduler_Release_job() */
   void ( *release_job ) (
 const Scheduler_Control *,
diff --git a/cpukit/score/include/rtems/score/schedulercbs.h 
b/cpukit/score/include/rtems/score/schedulercbs.h
index e390532..397488f 100644
--- a/cpukit/score/include/rtems/score/schedulercbs.h
+++ b/cpukit/score/include/rtems/score/schedulercbs.h
@@ -59,7 +59,6 @@ extern "C" {
 _Scheduler_CBS_Node_initialize,  /* node initialize entry point */ \
 _Scheduler_default_Node_destroy, /* node destroy entry point */ \
 _Scheduler_EDF_Update_priority,  /* update priority entry point */ \
-_Scheduler_EDF_Priority_compare, /* compares two priorities */ \
 _Scheduler_CBS_Release_job,  /* new period of task */ \
 _Scheduler_default_Tick, /* tick entry point */ \
 _Scheduler_default_Start_idle/* start idle entry point */ \
diff --git a/cpukit/score/include/rtems/score/scheduleredf.h 
b/cpukit/score/include/rtems/score/scheduleredf.h
index 137ea3a..7d513ca 100644
--- a/cpukit/score/include/rtems/score/scheduleredf.h
+++ b/cpukit/score/include/rtems/score/scheduleredf.h
@@ -52,7 +52,6 @@ extern "C" {
 _Scheduler_EDF_Node_initialize,  /* node initialize entry point */ \
 _Scheduler_default_Node_destroy, /* node destroy entry point */ \
 _Scheduler_EDF_Update_priority,  /* update priority entry point */ \
-_Scheduler_EDF_Priority_compare, /* compares two priorities */ \
 _Scheduler_EDF_Release_job,  /* new period of task */ \
 _Scheduler_default_Tick, /* tick entry point */ \
 _Scheduler_default_Start_idle/* start idle entry point */ \
@@ -226,19 +225,6 @@ Scheduler_Void_or_thread _Scheduler_EDF_Yield(
 );
 
 /**
- *  @brief Explicitly compare absolute dedlines (priorities) of threads.
- *
- * This routine explicitly compares absolute dedlines (priorities) of threads.
- * In case of EDF scheduling time overflow is taken into account.
- *
- * @retval >0 for p1 > p2; 0 for p1 == p2; <0 for p1 < p2.
- */
-int _Scheduler_EDF_Priority_compare (
-  Priority_Control p1,
-  Priority_Control p2
-);
-
-/**
  *  @brief Called when a new job of task is released.
  *
  *  This routine is called when a new job of task is released.
diff --git 

[PATCH 08/16] posix: Generalize _POSIX_Priority_To_core()

2016-06-17 Thread Sebastian Huber
Move POSIX API priority validation into _POSIX_Priority_To_core().
---
 cpukit/posix/include/rtems/posix/priorityimpl.h | 29 +++--
 cpukit/posix/src/mutexinit.c|  4 +---
 cpukit/posix/src/mutexsetprioceiling.c  |  7 ++
 cpukit/posix/src/psxpriorityisvalid.c   | 18 ++-
 cpukit/posix/src/pthreadcreate.c|  7 ++
 cpukit/posix/src/pthreadsetschedparam.c |  7 ++
 cpukit/posix/src/pthreadsetschedprio.c  |  3 +--
 7 files changed, 29 insertions(+), 46 deletions(-)

diff --git a/cpukit/posix/include/rtems/posix/priorityimpl.h 
b/cpukit/posix/include/rtems/posix/priorityimpl.h
index 7e770f7..54f5c9c 100644
--- a/cpukit/posix/include/rtems/posix/priorityimpl.h
+++ b/cpukit/posix/include/rtems/posix/priorityimpl.h
@@ -51,7 +51,8 @@ extern "C" {
 int _POSIX_Priority_Get_maximum( const Scheduler_Control *scheduler );
 
 /**
- * @brief Check if POSIX priority is valid.
+ * @brief Checks if the POSIX priority is valid and converts it to the
+ * SuperCore priority.
  * 
  * According to POSIX, numerically higher values represent higher priorities.
  * Thus, SuperCore has priorities run in the opposite sense of the POSIX API.
@@ -65,33 +66,19 @@ int _POSIX_Priority_Get_maximum( const Scheduler_Control 
*scheduler );
  * having N priorities.
  *
  * @param[in] scheduler The scheduler instance.
- * @param[in] priority The POSIX API priority to test.
+ * @param[in] posix_priority The POSIX API priority to test and convert.
+ * @param[out] core_priority_p The corresponding SuperCore API priority.
  *
- * @retval true The priority is valid.
+ * @retval true The priority is valid and the conversion was successful.
  * @retval false Otherwise.
  */
-bool _POSIX_Priority_Is_valid(
+bool _POSIX_Priority_To_core(
   const Scheduler_Control *scheduler,
-  int  priority
+  int  posix_priority,
+  Priority_Control*core_priority_p
 );
 
 /**
- * @brief Converts POSIX priority to SuperCore priority.
- *
- * @param[in] scheduler The scheduler instance.
- * @param[in] priority The POSIX API priority.
- *
- * @return Returns the corresponding SuperCore priority.
- */
-RTEMS_INLINE_ROUTINE Priority_Control _POSIX_Priority_To_core(
-  const Scheduler_Control *scheduler,
-  int  priority
-)
-{
-  return scheduler->maximum_priority - (Priority_Control) priority;
-}
-
-/**
  * @brief Converts SuperCore priority to POSIX priority.
  *
  * @param[in] scheduler The scheduler instance.
diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c
index 04c36e1..7fbb53a 100644
--- a/cpukit/posix/src/mutexinit.c
+++ b/cpukit/posix/src/mutexinit.c
@@ -116,11 +116,9 @@ int pthread_mutex_init(
   prio_ceiling = _POSIX_Priority_Get_maximum( scheduler );
 }
 
-if ( !_POSIX_Priority_Is_valid( scheduler, prio_ceiling ) ) {
+if ( !_POSIX_Priority_To_core( scheduler, prio_ceiling,  ) ) {
   return EINVAL;
 }
-
-priority = _POSIX_Priority_To_core( scheduler, prio_ceiling );
   }
 
   the_mutex = _POSIX_Mutex_Allocate();
diff --git a/cpukit/posix/src/mutexsetprioceiling.c 
b/cpukit/posix/src/mutexsetprioceiling.c
index 65b93c7..f1aa741 100644
--- a/cpukit/posix/src/mutexsetprioceiling.c
+++ b/cpukit/posix/src/mutexsetprioceiling.c
@@ -33,6 +33,7 @@ int pthread_mutex_setprioceiling(
 {
   POSIX_Mutex_Control *the_mutex;
   const Scheduler_Control *scheduler;
+  Priority_Control priority;
   int  error;
   int  unlock_error;
 
@@ -59,12 +60,8 @@ int pthread_mutex_setprioceiling(
 the_mutex->Mutex.priority_ceiling
   );
 
-  if ( _POSIX_Priority_Is_valid( scheduler, prioceiling ) ) {
-Priority_Control priority;
-
-priority = _POSIX_Priority_To_core( scheduler, prioceiling );
+  if ( _POSIX_Priority_To_core( scheduler, prioceiling,  ) ) {
 the_mutex->Mutex.priority_ceiling = priority;
-
 error = 0;
   } else {
 error = EINVAL;
diff --git a/cpukit/posix/src/psxpriorityisvalid.c 
b/cpukit/posix/src/psxpriorityisvalid.c
index ea7f6f4..2d3a0d4 100644
--- a/cpukit/posix/src/psxpriorityisvalid.c
+++ b/cpukit/posix/src/psxpriorityisvalid.c
@@ -29,12 +29,20 @@ int _POSIX_Priority_Get_maximum( const Scheduler_Control 
*scheduler )
   }
 }
 
-bool _POSIX_Priority_Is_valid(
+bool _POSIX_Priority_To_core(
   const Scheduler_Control *scheduler,
-  int  priority
+  int  posix_priority,
+  Priority_Control*core_priority_p
 )
 {
-  return priority >= POSIX_SCHEDULER_MINIMUM_PRIORITY
-&& (Priority_Control) priority < scheduler->maximum_priority;
-}
+  Priority_Control core_posix_priority;
+  Priority_Control core_priority;
+
+  core_posix_priority = (Priority_Control) posix_priority;
+  core_priority = scheduler->maximum_priority - core_posix_priority;
 
+  *core_priority_p = core_priority;
+
+  return posix_priority >=