[rtems commit] posix: Change created_with_explicit_scheduler

Sebastian Huber sebh at rtems.org
Thu Nov 9 07:13:48 UTC 2017


Module:    rtems
Branch:    master
Commit:    64ba1a9606c86f54d66d1d5cc638fb9aff7338a2
Changeset: http://git.rtems.org/rtems/commit/?id=64ba1a9606c86f54d66d1d5cc638fb9aff7338a2

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Nov  8 15:29:14 2017 +0100

posix: Change created_with_explicit_scheduler

Remove POSIX_API_Control::created_with_explicit_scheduler.  Add
Thread_Control::was_created_with_inherited_scheduler.  This fixes also
pthread_getattr_np() for Classic tasks.

Update #2514.

---

 cpukit/posix/include/rtems/posix/threadsup.h |  3 --
 cpukit/posix/src/pthreadcreate.c             |  4 +-
 cpukit/posix/src/pthreadgetattrnp.c          |  6 +--
 cpukit/score/include/rtems/score/thread.h    |  6 +++
 testsuites/psxtests/psxclassic01/init.c      | 68 +++++++++++++++++++++++++---
 5 files changed, 73 insertions(+), 14 deletions(-)

diff --git a/cpukit/posix/include/rtems/posix/threadsup.h b/cpukit/posix/include/rtems/posix/threadsup.h
index 4b62b19..d3ee5b2 100644
--- a/cpukit/posix/include/rtems/posix/threadsup.h
+++ b/cpukit/posix/include/rtems/posix/threadsup.h
@@ -40,9 +40,6 @@ extern "C" {
  * each thread in a system with POSIX configured.
  */
 typedef struct {
-  /** Created with explicit or inherited scheduler. */
-  bool created_with_explicit_scheduler;
-
   /**
    * @brief Control block for the sporadic server scheduling policy.
    */
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 348bf68..46fe1e7 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -250,8 +250,8 @@ int pthread_create(
 
   api->signals_unblocked = executing_api->signals_unblocked;
 
-  api->created_with_explicit_scheduler =
-    ( the_attr->inheritsched == PTHREAD_EXPLICIT_SCHED );
+  the_thread->was_created_with_inherited_scheduler =
+    ( the_attr->inheritsched == PTHREAD_INHERIT_SCHED );
 
   _Priority_Node_set_priority( &api->Sporadic.Low_priority, core_low_prio );
   api->Sporadic.sched_ss_repl_period =
diff --git a/cpukit/posix/src/pthreadgetattrnp.c b/cpukit/posix/src/pthreadgetattrnp.c
index 9df5bad..6690bda 100644
--- a/cpukit/posix/src/pthreadgetattrnp.c
+++ b/cpukit/posix/src/pthreadgetattrnp.c
@@ -60,10 +60,10 @@ int pthread_getattr_np(
   attr->stackaddr = the_thread->Start.Initial_stack.area;
   attr->stacksize = the_thread->Start.Initial_stack.size;
 
-  if ( api->created_with_explicit_scheduler ) {
-    attr->inheritsched = PTHREAD_EXPLICIT_SCHED;
-  } else {
+  if ( the_thread->was_created_with_inherited_scheduler ) {
     attr->inheritsched = PTHREAD_INHERIT_SCHED;
+  } else {
+    attr->inheritsched = PTHREAD_EXPLICIT_SCHED;
   }
 
   scheduler = _Thread_Scheduler_get_home( the_thread );
diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
index 488e961..7e0e272 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -773,6 +773,12 @@ struct _Thread_Control {
   /** This field is true if the thread uses the floating point unit. */
   bool                                  is_fp;
 
+  /**
+   * @brief True, if the thread was created with an inherited scheduler
+   * (PTHREAD_INHERIT_SCHED), and false otherwise.
+   */
+  bool was_created_with_inherited_scheduler;
+
   /** This field is the length of the time quantum that this thread is
    *  allowed to consume.  The algorithm used to manage limits on CPU usage
    *  is specified by budget_algorithm.
diff --git a/testsuites/psxtests/psxclassic01/init.c b/testsuites/psxtests/psxclassic01/init.c
index 2a38bf1..4711732 100644
--- a/testsuites/psxtests/psxclassic01/init.c
+++ b/testsuites/psxtests/psxclassic01/init.c
@@ -17,7 +17,7 @@
 #include "config.h"
 #endif
 
-#include "tmacros.h"
+#define _GNU_SOURCE
 
 #include <stdio.h>
 #include <rtems.h>
@@ -26,6 +26,7 @@
 #include <errno.h>
 #include <string.h>
 #include <sched.h>
+#include <tmacros.h>
 
 const char rtems_test_name[] = "PSXCLASSIC 1";
 
@@ -48,21 +49,76 @@ static rtems_task test_task(rtems_task_argument arg)
   int sc;
   struct sigaction new_action;
   sigset_t mask;
-  int policy;
+  void *addr;
+  size_t size;
+  int value;
   struct sched_param param;
+  cpu_set_t set;
+  pthread_attr_t attr;
 
   printf("test_task starting...\n");
 
-  policy = -1;
+  value = -1;
   memset( &param, -1, sizeof( param ) );
-  sc = pthread_getschedparam( pthread_self(), &policy, &param );
+  sc = pthread_getschedparam( pthread_self(), &value, &param );
   rtems_test_assert( sc == 0 );
-  rtems_test_assert( policy == SCHED_FIFO );
+  rtems_test_assert( value == SCHED_FIFO );
   rtems_test_assert(
     param.sched_priority == sched_get_priority_max( SCHED_FIFO )
   );
 
-  sc = pthread_setschedparam( pthread_self(), policy, &param );
+  sc = pthread_setschedparam( pthread_self(), value, &param );
+  rtems_test_assert( sc == 0 );
+
+  sc = pthread_getattr_np( pthread_self(), &attr );
+  rtems_test_assert( sc == 0 );
+
+  addr = NULL;
+  size = 0;
+  sc = pthread_attr_getstack( &attr, &addr, &size );
+  rtems_test_assert( sc == 0 );
+  rtems_test_assert( addr != NULL );
+  rtems_test_assert( size == RTEMS_MINIMUM_STACK_SIZE );
+
+  value = -1;
+  sc = pthread_attr_getscope( &attr, &value );
+  rtems_test_assert( sc == 0 );
+  rtems_test_assert( value == PTHREAD_SCOPE_PROCESS );
+
+  value = -1;
+  sc = pthread_attr_getinheritsched( &attr, &value );
+  rtems_test_assert( sc == 0 );
+  rtems_test_assert( value == PTHREAD_EXPLICIT_SCHED );
+
+  value = -1;
+  sc = pthread_attr_getschedpolicy( &attr, &value );
+  rtems_test_assert( sc == 0 );
+  rtems_test_assert( value == SCHED_FIFO );
+
+  memset( &param, -1, sizeof( param ) );
+  sc = pthread_attr_getschedparam( &attr, &param );
+  rtems_test_assert( sc == 0 );
+  rtems_test_assert(
+    param.sched_priority == sched_get_priority_max( SCHED_FIFO )
+  );
+
+  size = 1;
+  sc = pthread_attr_getguardsize( &attr, &size );
+  rtems_test_assert( sc == 0 );
+  rtems_test_assert( size == 0 );
+
+  value = -1;
+  sc = pthread_attr_getdetachstate( &attr, &value );
+  rtems_test_assert( sc == 0 );
+  rtems_test_assert( value == PTHREAD_CREATE_JOINABLE );
+
+  CPU_ZERO( &set );
+  sc = pthread_attr_getaffinity_np( &attr, sizeof( set ), &set );
+  rtems_test_assert( sc == 0 );
+  rtems_test_assert( CPU_ISSET( 0, &set ) );
+  rtems_test_assert( CPU_COUNT( &set ) == 1 );
+
+  sc = pthread_attr_destroy( &attr );
   rtems_test_assert( sc == 0 );
 
   sc = sigemptyset (&new_action.sa_mask);



More information about the vc mailing list