Changeset 2d51251 in rtems-schedsim


Ignore:
Timestamp:
May 9, 2014, 1:35:58 PM (5 years ago)
Author:
Jennifer Averett <jennifer.averett@…>
Branches:
master
Children:
b1b31c0
Parents:
0745eed
git-author:
Jennifer Averett <jennifer.averett@…> (05/09/14 13:35:58)
git-committer:
Jennifer Averett <jennifer.averett@…> (05/09/14 13:37:18)
Message:

schedsim: Add smp support.

Location:
schedsim
Files:
9 added
13 edited

Legend:

Unmodified
Added
Removed
  • schedsim/configure.ac

    r0745eed r2d51251  
    7777  [1],
    7878  [if SMP is enabled])
     79
     80RTEMS_CPUOPT([__RTEMS_HAVE_SYS_CPUSET_H__],
     81  [true],
     82  [1],
     83  [<sys/cpuset.h> is provided])
    7984
    8085RTEMS_CPUOPT([RTEMS_NETWORKING],
  • schedsim/rtems/Makefile.am

    r0745eed r2d51251  
    44
    55cpukitdir=@rtems_srcdir@/cpukit
     6rtemscdir=@rtems_srcdir@/c
    67librtems_a_CPPFLAGS  = -D__RTEMS_VIOLATE_KERNEL_VISIBILITY__
     8librtems_a_CPPFLAGS += -D_GNU_SOURCE
    79librtems_a_CPPFLAGS += -I$(top_builddir)/score/include
    810librtems_a_CPPFLAGS += -I$(srcdir)/sched_cpu
     
    246248librtems_a_SOURCES += $(cpukitdir)/score/src/schedulerprioritysmp.c
    247249librtems_a_SOURCES += $(cpukitdir)/score/src/schedulersimplesmp.c
    248 librtems_a_SOURCES += $(cpukitdir)/score/src/schedulersmpstartidle.c
     250librtems_a_SOURCES += $(cpukitdir)/score/src/debugisthreaddispatchingallowed.c
     251librtems_a_SOURCES += $(cpukitdir)/score/src/schedulerdefaultgetaffinity.c
     252librtems_a_SOURCES += $(cpukitdir)/score/src/schedulerdefaultsetaffinity.c
     253librtems_a_SOURCES += $(cpukitdir)/score/src/cpuset.c
    249254endif
    250255
     
    255260
    256261schedsim_include_HEADERS  = \
    257  ${cpukitdir}/rtems/include/rtems.h
     262  ${cpukitdir}/rtems/include/rtems.h \
     263  sched_cpu/stdatomic.h \
     264  sched_cpu/sys/_types.h \
     265  sched_cpu/machine/_types.h \
     266  sched_cpu/machine/_default_types.h \
     267  sched_cpu/sys/features.h \
     268  sched_cpu/sys/lock.h \
     269  sched_cpu/sys/cpuset.h
    258270
    259271schedsim_rtems_include_HEADERS  = \
     
    282294  $(cpukitdir)/libcsupport/include/rtems/malloc.h \
    283295  sched_cpu/rtems/stringto.h \
    284   sched_cpu/rtems/asm.h 
     296  sched_cpu/rtems/asm.h
    285297
    286298if HAS_PTHREADS
     
    293305  ${cpukitdir}/score/include/rtems/score/coremutex.h \
    294306  ${cpukitdir}/score/include/rtems/score/corerwlock.h \
     307  ${cpukitdir}/score/include/rtems/score/cpuset.h \
     308  ${cpukitdir}/score/include/rtems/score/cpusetimpl.h \
     309  ${cpukitdir}/score/include/rtems/score/cpustdatomic.h \
    295310  ${cpukitdir}/score/include/rtems/score/threadsync.h \
    296311  ${cpukitdir}/score/include/rtems/score/priority.h \
     
    335350  $(top_builddir)/score/include/rtems/score/cpuopts.h \
    336351  sched_cpu/rtems/score/cpu.h \
     352  sched_cpu/rtems/score/cpuatomic.h \
    337353  sched_cpu/rtems/score/types.h \
    338354  sched_cpu/rtems/score/no_cpu.h
  • schedsim/rtems/rtems_init.c

    r0745eed r2d51251  
    4646
    4747#include <rtems/posix/keyimpl.h>
     48
     49void Init__wrap__Thread_Dispatch();
    4850
    4951/*
     
    136138  _System_state_Set( SYSTEM_STATE_UP );
    137139
    138  _SMP_Request_start_multitasking();
     140  _SMP_Request_start_multitasking();
    139141
    140142  _Thread_Start_multitasking();
     143
     144  /* Add Initialization of the Thread_Dispatch wrapper */
     145  Init__wrap__Thread_Dispatch();
    141146
    142147  /*
     
    144149   */
    145150  #if defined(RTEMS_SMP)
    146     #error "NOT IMPLEMENTED"
     151   {
     152      ISR_Level  level;
     153
     154      /*
     155       * On SMP we enter _Thread_Handler() with interrupts disabled and
     156       * _Thread_Dispatch() obtained the per-CPU lock for us.  We have to
     157       * release it here and set the desired interrupt level of the thread.
     158       */
     159      Per_CPU_Control *cpu_self = _Per_CPU_Get();
     160
     161      _Assert( cpu_self->thread_dispatch_disable_level == 1 );
     162      _Assert( _ISR_Get_level() != 0 );
     163
     164      cpu_self->thread_dispatch_disable_level = 0;
     165      _Profiling_Thread_dispatch_enable( cpu_self, 0 );
     166
     167      _Per_CPU_Release( cpu_self );
     168
     169      level =  _Thread_Executing->Start.isr_level;
     170      _ISR_Set_level( level);
     171
     172      /*
     173       * The thread dispatch level changed from one to zero.  Make sure we lose
     174       * no thread dispatch necessary update.
     175       */
     176      _Thread_Dispatch();
     177    }
    147178  #else
    148179    _Thread_Enable_dispatch();
  • schedsim/rtems/sched_cpu/cpu.c

    r0745eed r2d51251  
    2020#include <rtems/score/wkspace.h>
    2121
     22int _CPU_ISR_level_on_sched_cpu;
     23
    2224/*  _CPU_Initialize
    2325 *
     
    3335void _CPU_Initialize(void)
    3436{
    35   /*
    36    *  If there is not an easy way to initialize the FP context
    37    *  during Context_Initialize, then it is usually easier to
    38    *  save an "uninitialized" FP context here and copy it to
    39    *  the task's during Context_Initialize.
    40    */
    41 
    42   /* FP context initialization support goes here */
     37  _CPU_ISR_level_on_sched_cpu = 1;
    4338}
    4439
    45 /*PAGE
    46  *
    47  *  _CPU_ISR_Get_level
    48  *
    49  *  NO_CPU Specific Information:
    50  *
    51  *  XXX document implementation including references if appropriate
    52  */
    53 
    54 uint32_t   _CPU_ISR_Get_level( void )
    55 {
    56   /*
    57    *  This routine returns the current interrupt level.
    58    */
    59 
    60   return 0;
    61 }
    62 
    63 /*PAGE
    64  *
     40/*
    6541 *  _CPU_ISR_install_raw_handler
    6642 *
     
    8258}
    8359
    84 /*PAGE
    85  *
     60/*
    8661 *  _CPU_ISR_install_vector
    8762 *
     
    126101}
    127102
    128 /*PAGE
    129  *
     103/*
    130104 *  _CPU_Install_interrupt_stack
    131105 *
     
    139113}
    140114
    141 /*PAGE
    142  *
     115/*
    143116 *  _CPU_Thread_Idle_body
    144117 *
  • schedsim/rtems/sched_cpu/rtems/score/cpu.h

    r0745eed r2d51251  
    721721
    722722/**
     723 *  XXX fake cpu isr level variable
     724 */
     725extern int _CPU_ISR_level_on_sched_cpu;
     726
     727/**
    723728 *  @ingroup CPUInterrupt
    724729 *  Disable all interrupts for an RTEMS critical section.  The previous
     
    733738#define _CPU_ISR_Disable( _isr_cookie ) \
    734739  { \
    735     (_isr_cookie) = 0;   /* do something to prevent warnings */ \
     740    (_isr_cookie) = _CPU_ISR_level_on_sched_cpu; \
     741    _CPU_ISR_level_on_sched_cpu = 1; \
    736742  }
    737743
     
    750756#define _CPU_ISR_Enable( _isr_cookie )  \
    751757  { \
     758    _CPU_ISR_level_on_sched_cpu = (_isr_cookie); \
    752759  }
    753760
     
    788795#define _CPU_ISR_Set_level( new_level ) \
    789796  { \
     797    _CPU_ISR_level_on_sched_cpu = (new_level); \
    790798  }
    791799
     
    801809 *  XXX document implementation including references if appropriate
    802810 */
    803 uint32_t   _CPU_ISR_Get_level( void );
     811#define _CPU_ISR_Get_level() (uint32_t) _CPU_ISR_level_on_sched_cpu
    804812
    805813/* end of ISR handler macros */
     
    12211229  #define _CPU_Context_switch_to_first_task_smp(_context )
    12221230
    1223   RTEMS_COMPILER_PURE_ATTRIBUTE static inline uint32_t
    1224     _CPU_SMP_Get_current_processor( void )
    1225   {
    1226     return 0;
    1227   }
    1228 
    1229   #define _CPU_SMP_Send_interrupt( dest);
    1230 
    1231   static inline void _CPU_SMP_Processor_event_broadcast( void )
    1232   {
    1233   }
    1234 
    1235   static inline void _CPU_SMP_Processor_event_receive( void )
    1236   {
    1237   }
     1231  uint32_t _CPU_SMP_Get_current_processor( void );
     1232  uint32_t _CPU_SMP_Initialize( void );
     1233  bool _CPU_SMP_Start_processor( uint32_t cpu_index );
     1234  void _CPU_SMP_Finalize_initialization( uint32_t cpu_count );
     1235  void _CPU_SMP_Send_interrupt( uint32_t target_processor_index );
     1236  void _CPU_SMP_Processor_event_broadcast( void );
     1237  void _CPU_SMP_Processor_event_receive( void );
    12381238#endif
    12391239typedef struct {
  • schedsim/shell/schedsim_priority/smp_stub.c

    r0745eed r2d51251  
    1212#include <rtems.h>
    1313#include <rtems/bspIo.h>
    14 #include <rtems/bspsmp.h>
    1514#include <stdlib.h>
    1615
     16uint32_t _CPU_SMP_Initialize( void )
     17{
     18  /* return the number of CPUs */
     19  return 1; /* XXX */
     20}
    1721
    18 void bsp_smp_secondary_cpu_initialize(int cpu)
     22bool _CPU_SMP_Start_processor( uint32_t cpu_index )
     23{
     24  return true;
     25}
     26
     27void _CPU_SMP_Finalize_initialization( uint32_t cpu_count )
    1928{
    2029}
    2130
    22 int bsp_smp_processor_id(void)
     31void _CPU_SMP_Send_interrupt( uint32_t target_processor_index )
     32{
     33}
     34
     35void _CPU_SMP_Processor_event_broadcast( void )
     36{
     37}
     38
     39void _CPU_SMP_Processor_event_receive( void )
     40{
     41}
     42
     43uint32_t _CPU_SMP_Get_current_processor( void )
    2344{
    2445  return 0;
    2546}
    26 
    27 uint32_t bsp_smp_initialize(
    28   uint32_t configured_cpu_count
    29 )
    30 {
    31   /* return the number of CPUs */
    32   return configured_cpu_count;
    33 }
    34 
    35 void bsp_smp_broadcast_interrupt(void)
    36 {
    37 }
    38 
    39 void bsp_smp_broadcast_message(
    40   uint32_t  message
    41 )
    42 {
    43 }
    44 
    45 void bsp_smp_interrupt_cpu(
    46   int cpu
    47 )
    48 {
    49 }
    50 
    51 void bsp_smp_delay( int max )
    52 {
    53 }
    54 
    55 void bsp_smp_wait_for(
    56   volatile unsigned int *address,
    57   unsigned int           desired,
    58   int                    maximum_usecs
    59 )
    60 {
    61   int iterations;
    62   volatile int i;
    63   volatile unsigned int *p = address;
    64 
    65   for (iterations=0 ;  iterations < maximum_usecs ; iterations++ ) {
    66     *p = desired;
    67     /* XXX hack to make simulator happy */
    68   }
    69 }
    70 
  • schedsim/shell/schedsim_priority/wrap_thread_dispatch.c

    r0745eed r2d51251  
    2525extern void __real__Thread_Dispatch(void);
    2626
     27void Init__wrap__Thread_Dispatch()
     28{
     29}
     30
    2731void check_heir_and_executing(void)
    2832{
  • schedsim/shell/schedsim_smpsimple/Makefile.am

    r0745eed r2d51251  
    2525schedsim_smpsimple_CPPFLAGS += -I$(cpukitdir)/posix/inline
    2626endif
     27## Ensure all linker provided symbols are available
     28schedsim_smpsimple_LDFLAGS =
     29schedsim_smpsimple_LDFLAGS += -Wl,--defsym=_TLS_Data_begin=0
     30schedsim_smpsimple_LDFLAGS += -Wl,--defsym=_TLS_BSS_end=0
     31schedsim_smpsimple_LDFLAGS += -Wl,--defsym=_TLS_Alignment=4
    2732
    28 schedsim_smpsimple_LDFLAGS =-Wl,--wrap=_Thread_Dispatch
     33## Wrap _Thread_Dispatch so we can see context switches
     34schedsim_smpsimple_LDFLAGS +=-Wl,--wrap=_Thread_Dispatch
     35
    2936## schedsim_smpsimple_LDADD +=-Wl,--start-group
    3037schedsim_smpsimple_LDADD = ../shared/libschedsim.a
  • schedsim/shell/schedsim_smpsimple/main_current_cpu.c

    r0745eed r2d51251  
    1818
    1919#include <rtems.h>
    20 #include <rtems/bspsmp.h>
    2120#include <rtems/score/percpu.h>
    2221#include <rtems/score/schedulerpriority.h>
  • schedsim/shell/schedsim_smpsimple/main_dispatch.c

    r0745eed r2d51251  
    1818
    1919#include <rtems.h>
    20 #include <rtems/bspsmp.h>
    2120#include <rtems/score/percpu.h>
    2221#include <rtems/score/smp.h>
  • schedsim/shell/schedsim_smpsimple/main_dump_ready_tasks.c

    r0745eed r2d51251  
    1818#include <rtems/score/chainimpl.h>
    1919#include <rtems/score/thread.h>
     20#include <rtems/score/assert.h>
    2021
    21 #include <rtems/score/schedulerpriority.h>
     22/*
     23 * Note: This source depends upon the scheduler being
     24 *       tested.
     25 */
     26#include <rtems/score/schedulersimplesmp.h>
    2227
    2328int main_dump_ready_tasks(int argc, char **argv)
     
    2732  Thread_Control *t;
    2833
     34  Scheduler_simple_SMP_Context * self =
     35    (Scheduler_simple_SMP_Context *) _Scheduler_Table[0].context;
     36
     37  /* We don't support this yet */
     38  _Assert( _Scheduler_Count != 1 );
     39
    2940  printf( "=== Ready Set of Threads\n" );
    30   chain = (Chain_Control *)_Scheduler.information;
     41  chain = &self->Ready;
    3142  for (n = _Chain_First( chain ); !_Chain_Is_tail(chain, n); n = n->next) {
    3243    t = (Thread_Control *)n;
  • schedsim/shell/schedsim_smpsimple/smp_stub.c

    r0745eed r2d51251  
    1212#include <rtems.h>
    1313#include <rtems/bspIo.h>
    14 #include <rtems/bspsmp.h>
    1514#include <stdlib.h>
    1615
     
    1817extern uint32_t Schedsim_Maximum_CPUs_From_Command_Line;
    1918
    20 void bsp_smp_secondary_cpu_initialize(int cpu)
    21 {
    22   Schedsim_Current_cpu = 0;
    23 }
    24 
    25 int bsp_smp_processor_id(void)
    26 {
    27   return Schedsim_Current_cpu;
    28 }
    29 
    30 uint32_t bsp_smp_initialize(
    31   uint32_t configured_cpu_count
    32 )
     19uint32_t _CPU_SMP_Initialize( void )
    3320{
    3421  if ( configured_cpu_count < Schedsim_Maximum_CPUs_From_Command_Line ) {
     
    4431}
    4532
    46 void bsp_smp_broadcast_interrupt(void)
     33bool _CPU_SMP_Start_processor( uint32_t cpu_index )
     34{
     35  return true;
     36}
     37
     38void _CPU_SMP_Finalize_initialization( uint32_t cpu_count )
    4739{
    4840}
    4941
    50 void bsp_smp_broadcast_message(
    51   uint32_t  message
    52 )
     42void _CPU_SMP_Send_interrupt( uint32_t target_processor_index )
     43{
     44}
     45
     46void _CPU_SMP_Processor_event_broadcast( void )
     47{
     48  Per_CPU_Control  *cpu = _Per_CPU_Get();
     49  uint32_t         cpu_count = _SMP_Get_processor_count();
     50  uint32_t         cpu_index;
     51  Per_CPU_State    state = cpu->state;
     52
     53  if (state == PER_CPU_STATE_REQUEST_START_MULTITASKING) {
     54    for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) {
     55      cpu = _Per_CPU_Get_by_index( cpu_index );
     56      state = cpu->state;
     57      if (state == PER_CPU_STATE_INITIAL )
     58         cpu->state = PER_CPU_STATE_READY_TO_START_MULTITASKING;
     59    }
     60  }
     61}
     62
     63
     64void _CPU_SMP_Processor_event_receive( void )
    5365{
    5466}
    5567
    56 void bsp_smp_interrupt_cpu(
    57   int cpu
    58 )
     68uint32_t _CPU_SMP_Get_current_processor( void )
    5969{
     70  return Schedsim_Current_cpu;
    6071}
    61 
    62 void bsp_smp_delay( int max )
    63 {
    64 }
    65 
    66 void bsp_smp_wait_for(
    67   volatile unsigned int *address,
    68   unsigned int           desired,
    69   int                    maximum_usecs
    70 )
    71 {
    72   int iterations;
    73   volatile int i;
    74   volatile unsigned int *p = address;
    75 
    76   for (iterations=0 ;  iterations < maximum_usecs ; iterations++ ) {
    77     *p = desired;
    78     /* XXX hack to make simulator happy */
    79   }
    80 }
    81 
  • schedsim/shell/schedsim_smpsimple/wrap_thread_dispatch.c

    r0745eed r2d51251  
    1313#include <schedsim_shell.h>
    1414
     15#include <stdlib.h>
    1516#include <stdio.h>
    1617#include <rtems.h>
    1718
    18 Thread_Control *last_heir = NULL;
    19 Thread_Control *last_executing = NULL;
     19typedef Thread_Control * Thread_Control_ptr;
     20extern uint32_t Schedsim_Current_cpu;
     21
     22Thread_Control_ptr *last_heir = NULL;
     23Thread_Control_ptr *last_executing = NULL;
    2024
    2125extern void __real__Thread_Dispatch(void);
    2226
     27void Init__wrap__Thread_Dispatch()
     28{
     29  last_heir = (Thread_Control_ptr *) calloc( sizeof( Thread_Control_ptr ), _SMP_Processor_count );
     30  last_executing =  (Thread_Control_ptr *) calloc( sizeof( Thread_Control_ptr ), _SMP_Processor_count );
     31}
     32
    2333void check_heir_and_executing(void)
    2434{
    25   if ( last_heir != _Thread_Heir )
     35  if ( last_heir[Schedsim_Current_cpu] != _Thread_Heir )
    2636    PRINT_HEIR();
    2737
    28   if ( last_executing != _Thread_Executing )
     38  if ( last_executing[Schedsim_Current_cpu] != _Thread_Executing )
    2939    PRINT_EXECUTING();
    3040
    31   last_heir = _Thread_Heir;
    32   last_executing = _Thread_Executing;
     41  last_heir[Schedsim_Current_cpu] = _Thread_Heir;
     42  last_executing[Schedsim_Current_cpu] = _Thread_Executing;
    3343}
    3444
    3545void __wrap__Thread_Dispatch(void)
    3646{
    37   check_heir_and_executing();
     47  uint32_t   cpu;
     48  uint32_t   current_cpu;
     49
     50  current_cpu = Schedsim_Current_cpu;
     51  for ( cpu=0 ; cpu < _SMP_Processor_count ; cpu++ ) {
     52    Schedsim_Current_cpu = cpu;
     53    check_heir_and_executing();
    3854    __real__Thread_Dispatch();
    39   check_heir_and_executing();
     55    check_heir_and_executing();
     56  }
     57 
     58  Schedsim_Current_cpu = current_cpu;
    4059}
     60
Note: See TracChangeset for help on using the changeset viewer.