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.
This commit is contained in:
Jennifer Averett
2014-03-07 09:07:59 -06:00
parent 13ab94be6c
commit 9db8705cc8
8 changed files with 361 additions and 1 deletions
+4
View File
@@ -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
+64
View File
@@ -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 */
@@ -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 */
+18
View File
@@ -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;
+8
View File
@@ -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
+94
View File
@@ -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
+84
View File
@@ -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
+6 -1
View File
@@ -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;