summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorJennifer Averett <jennifer.averett@oarcorp.com>2014-02-06 12:42:24 -0600
committerJennifer Averett <jennifer.averett@oarcorp.com>2014-03-07 09:07:59 -0600
commit9db8705cc8ad2863dc0173b846783487742b313e (patch)
tree8e3c8ee82053cc68097e359a3087e418c13e9d69 /cpukit
parentspcpuset01: Add check for sys/cpuset.h. (diff)
downloadrtems-9db8705cc8ad2863dc0173b846783487742b313e.tar.bz2
score: Add cpuset support to Score.
This new Score Handler provides a structure to manage a cpu_set_t plus helper routines to validate the contents against the current system configuration.
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/score/Makefile.am4
-rw-r--r--cpukit/score/include/rtems/score/cpuset.h64
-rw-r--r--cpukit/score/include/rtems/score/cpusetimpl.h83
-rw-r--r--cpukit/score/include/rtems/score/thread.h18
-rw-r--r--cpukit/score/preinstall.am8
-rw-r--r--cpukit/score/src/cpuset.c94
-rw-r--r--cpukit/score/src/cpusetprintsupport.c84
-rw-r--r--cpukit/score/src/threadinitialize.c7
8 files changed, 361 insertions, 1 deletions
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 6663d5c905..0dc21b202b 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -29,6 +29,8 @@ include_rtems_score_HEADERS += include/rtems/score/coremutex.h
include_rtems_score_HEADERS += include/rtems/score/coremuteximpl.h
include_rtems_score_HEADERS += include/rtems/score/coresem.h
include_rtems_score_HEADERS += include/rtems/score/coresemimpl.h
+include_rtems_score_HEADERS += include/rtems/score/cpuset.h
+include_rtems_score_HEADERS += include/rtems/score/cpusetimpl.h
include_rtems_score_HEADERS += include/rtems/score/heap.h
include_rtems_score_HEADERS += include/rtems/score/heapimpl.h
include_rtems_score_HEADERS += include/rtems/score/protectedheap.h
@@ -124,6 +126,8 @@ libscore_a_SOURCES += src/schedulerprioritysmp.c
libscore_a_SOURCES += src/schedulersimplesmp.c
libscore_a_SOURCES += src/schedulersmpstartidle.c
libscore_a_SOURCES += src/smp.c
+libscore_a_SOURCES += src/cpuset.c
+libscore_a_SOURCES += src/cpusetprintsupport.c
endif
## CORE_APIMUTEX_C_FILES
diff --git a/cpukit/score/include/rtems/score/cpuset.h b/cpukit/score/include/rtems/score/cpuset.h
new file mode 100644
index 0000000000..0359862a2b
--- /dev/null
+++ b/cpukit/score/include/rtems/score/cpuset.h
@@ -0,0 +1,64 @@
+/**
+ * @file rtems/score/cpuset.h
+ *
+ * @brief Information About the CPU Set
+ *
+ * This include file contains all information about the thread
+ * CPU Set.
+ */
+
+/*
+ * COPYRIGHT (c) 2014.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * 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.
+ */
+
+#ifndef _RTEMS_SCORE_CPUSET_H
+#define _RTEMS_SCORE_CPUSET_H
+
+#include <rtems/score/basedefs.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __RTEMS_HAVE_SYS_CPUSET_H__
+
+/**
+ * @defgroup ScoreCpuset
+ *
+ * @ingroup Score
+ *
+ * This handler encapsulates functionality which is used in the management
+ * of thread's CPU set.
+ */
+/**@{*/
+
+/**
+ * The following defines the control block used to manage the cpuset.
+ * The names do not include affinity in the front in case the set is
+ * ever used for something other than affinity. The usage in thread
+ * uses the attribute affinity such that accesses will read
+ * thread->affinity.set.
+ */
+typedef struct {
+ /** This is the size of the set */
+ size_t setsize;
+ /** This is the preallocated space to store the set */
+ cpu_set_t preallocated;
+ /** This is a pointer to the set in use */
+ cpu_set_t *set;
+} CPU_set_Control;
+
+#endif
+
+/**@}*/
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/cpusetimpl.h b/cpukit/score/include/rtems/score/cpusetimpl.h
new file mode 100644
index 0000000000..a611354550
--- /dev/null
+++ b/cpukit/score/include/rtems/score/cpusetimpl.h
@@ -0,0 +1,83 @@
+/**
+ * @file rtems/score/cpusetimpl.h
+ *
+ * @brief Implementation Prototypes for CPU Set
+ *
+ * This file contains the implementation prototypes for
+ * CPU set methods.
+ */
+
+/*
+ * COPYRIGHT (c) 2014.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * 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.
+ */
+
+#ifndef _RTEMS_SCORE_CPUSETIMPL_H
+#define _RTEMS_SCORE_CPUSETIMPL_H
+
+#include <rtems/score/cpuset.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __RTEMS_HAVE_SYS_CPUSET_H__
+
+/**
+ * _CPU_set_Is_valid
+ *
+ * This routine validates a cpuset size corresponds to
+ * the system correct size, that at least one
+ * valid cpu is set and that no invalid cpus are set.
+ */
+int _CPU_set_Is_valid( const cpu_set_t *cpuset, size_t setsize );
+
+/**
+ * _CPU_set_Show
+ *
+ * This routine will print the value of the given cpuset.
+ */
+void _CPU_set_Show( const char *description, const cpu_set_t *cpuset);
+
+/**
+ * _CPU_set_Show_default
+ *
+ * This routine will print the value of the default cpuset.
+ */
+void _CPU_set_Show_default( const char *description );
+
+/**
+ * _CPU_set_Default
+ *
+ * This routine returns the default cpuset for
+ * this system.
+ */
+const CPU_set_Control *_CPU_set_Default(void);
+
+#endif
+
+/**
+ * _CPU_set_Handler_initialization
+ *
+ * This routine validates a cpuset sets at least one
+ * valid cpu and that it does not set any invalid
+ * cpus.
+ */
+
+#if __RTEMS_HAVE_SYS_CPUSET_H__ && defined( RTEMS_SMP )
+void _CPU_set_Handler_initialization(void);
+#else
+#define _CPU_set_Handler_initialization() do { } while ( 0 )
+#endif
+
+/**@}*/
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
index bf500fe6f5..74852385b5 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -31,6 +31,13 @@
#include <rtems/score/threadq.h>
#include <rtems/score/watchdog.h>
+#ifdef RTEMS_SMP
+#if __RTEMS_HAVE_SYS_CPUSET_H__
+#include <sys/cpuset.h>
+#include <rtems/score/cpuset.h>
+#endif
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -406,7 +413,18 @@ struct Thread_Control_struct {
* happen in the meantime.
*/
bool is_executing;
+
+#if __RTEMS_HAVE_SYS_CPUSET_H__
+ /**
+ * @brief This field controls affinity attributes for this thread.
+ *
+ * Affinity attributes indicate which cpus the thread can run on
+ * in an SMP system.
+ */
+ CPU_set_Control affinity;
+#endif
#endif
+
#if __RTEMS_ADA__
/** This field is the GNAT self context pointer. */
void *rtems_ada_self;
diff --git a/cpukit/score/preinstall.am b/cpukit/score/preinstall.am
index 4d36ebe513..051582ccc2 100644
--- a/cpukit/score/preinstall.am
+++ b/cpukit/score/preinstall.am
@@ -99,6 +99,14 @@ $(PROJECT_INCLUDE)/rtems/score/coresemimpl.h: include/rtems/score/coresemimpl.h
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coresemimpl.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coresemimpl.h
+$(PROJECT_INCLUDE)/rtems/score/cpuset.h: include/rtems/score/cpuset.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpuset.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpuset.h
+
+$(PROJECT_INCLUDE)/rtems/score/cpusetimpl.h: include/rtems/score/cpusetimpl.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpusetimpl.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpusetimpl.h
+
$(PROJECT_INCLUDE)/rtems/score/heap.h: include/rtems/score/heap.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/heap.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/heap.h
diff --git a/cpukit/score/src/cpuset.c b/cpukit/score/src/cpuset.c
new file mode 100644
index 0000000000..4cf24288b1
--- /dev/null
+++ b/cpukit/score/src/cpuset.c
@@ -0,0 +1,94 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreCpuset
+ *
+ * @brief Routines to Control a CPU Set.
+ */
+
+/*
+ * COPYRIGHT (c) 2014.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * 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
+
+#ifdef __RTEMS_HAVE_SYS_CPUSET_H__
+#include <sys/cpuset.h>
+#include <rtems/score/cpusetimpl.h>
+#include <rtems/score/assert.h>
+#include <rtems/score/percpu.h>
+
+static CPU_set_Control cpuset_default;
+
+/*
+ * _CPU_set_Handler_initialization
+ */
+void _CPU_set_Handler_initialization()
+{
+ int i;
+ int max_cpus;
+
+ /* We do not support a cpu count over CPU_SETSIZE */
+ max_cpus = _SMP_Get_processor_count();
+
+ /* This should never happen */
+ _Assert( max_cpus <= CPU_SETSIZE );
+
+ /* Initialize the affinity to be the set of all available CPU's */
+ cpuset_default.set = &cpuset_default.preallocated;
+ cpuset_default.setsize = sizeof( *cpuset_default.set );
+ CPU_ZERO_S( cpuset_default.setsize, &cpuset_default.preallocated );
+
+ for (i=0; i<max_cpus; i++)
+ CPU_SET_S(i, cpuset_default.setsize, cpuset_default.set );
+}
+
+/**
+ * _CPU_set_Is_valid
+ *
+ * This routine validates a cpuset size corresponds to
+ * the system correct size, that at least one
+ * valid cpu is set and that no invalid cpus are set.
+ */
+int _CPU_set_Is_valid( const cpu_set_t *cpuset, size_t setsize )
+{
+ cpu_set_t temp;
+
+ if ( !cpuset )
+ return -1;
+
+ if (setsize != cpuset_default.setsize )
+ return -1;
+
+ /* Validate at least 1 valid cpu is set in cpuset */
+ CPU_AND_S( cpuset_default.setsize, &temp, cpuset, cpuset_default.set );
+
+ if ( CPU_COUNT_S( setsize, &temp ) == 0 )
+ return -1;
+
+ /* Validate that no invalid cpu's are set in cpuset */
+ if ( !CPU_EQUAL_S( setsize, &temp, cpuset ) )
+ return -1;
+
+ return 0;
+}
+
+/**
+ * _CPU_set_Default
+ *
+ * This routine returns the default cpuset.
+ */
+const CPU_set_Control *_CPU_set_Default()
+{
+ return &cpuset_default;
+}
+#endif
+
+
diff --git a/cpukit/score/src/cpusetprintsupport.c b/cpukit/score/src/cpusetprintsupport.c
new file mode 100644
index 0000000000..a56305e443
--- /dev/null
+++ b/cpukit/score/src/cpusetprintsupport.c
@@ -0,0 +1,84 @@
+/**
+ * @file
+ *
+ * @brief CPU Set Print Support Routines
+ * @ingroup ScoreCpuset
+ */
+
+/*
+ * COPYRIGHT (c) 2014.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <inttypes.h>
+#include <rtems/bspIo.h>
+#include <rtems/score/cpusetimpl.h>
+
+#ifdef __RTEMS_HAVE_SYS_CPUSET_H__
+
+ void _CPU_set_Show_with_plugin(
+ void *context,
+ rtems_printk_plugin_t print,
+ const char *description,
+ const cpu_set_t *cpuset
+ );
+
+ /*
+ * _CPU_set_Show_with_plugin
+ *
+ * This routine shows cpuset cpuset using a
+ * print plugin .
+ */
+ void _CPU_set_Show_with_plugin(
+ void *context,
+ rtems_printk_plugin_t print,
+ const char *description,
+ const cpu_set_t *cpuset
+ )
+ {
+ int i;
+
+ if ( !print )
+ return;
+
+ (*print)(context ,"%s: ", description);
+ for(i=0; i<_NCPUWORDS; i++)
+ (*print)(context ,"%x", cpuset->__bits[i]);
+ (*print)(context ,"\n");
+ }
+
+ /*
+ * _CPU_set_Show
+ *
+ * This routine shows a cpuset using the
+ * printk plugin.
+ */
+ void _CPU_set_Show( const char *description, const cpu_set_t *cpuset)
+ {
+ _CPU_set_Show_with_plugin( NULL, printk_plugin, description, cpuset );
+ }
+
+ /*
+ * _CPU_set_Show_default
+ *
+ * This routine shows the default cpuset.
+ */
+ void _CPU_set_Show_default( const char *description )
+ {
+ const CPU_set_Control *ctl;
+ ctl = _CPU_set_Default();
+ _CPU_set_Show( description, ctl->set );
+ }
+#endif
diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
index 94ff8650c2..acd6636ac8 100644
--- a/cpukit/score/src/threadinitialize.c
+++ b/cpukit/score/src/threadinitialize.c
@@ -5,7 +5,7 @@
* @ingroup ScoreThread
*/
/*
- * COPYRIGHT (c) 1989-2011.
+ * COPYRIGHT (c) 1989-2014.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -24,6 +24,7 @@
#include <rtems/score/userextimpl.h>
#include <rtems/score/watchdogimpl.h>
#include <rtems/score/wkspace.h>
+#include <rtems/score/cpusetimpl.h>
#include <rtems/config.h>
bool _Thread_Initialize(
@@ -206,6 +207,10 @@ bool _Thread_Initialize(
/* Initialize the cpu field for the non-SMP schedulers */
the_thread->cpu = _Per_CPU_Get_by_index( 0 );
+#if __RTEMS_HAVE_SYS_CPUSET_H__
+ the_thread->affinity = *(_CPU_set_Default());
+ the_thread->affinity.set = &the_thread->affinity.preallocated;
+#endif
#endif
the_thread->current_state = STATES_DORMANT;