17 #ifndef _RTEMS_PERCPU_H 18 #define _RTEMS_PERCPU_H 20 #include <rtems/score/cpu.h> 23 #include <rtems/asm.h> 36 #if defined( RTEMS_SMP ) 43 #if defined( RTEMS_PROFILING ) 44 #define PER_CPU_CONTROL_SIZE_LOG2 8 46 #define PER_CPU_CONTROL_SIZE_LOG2 7 49 #define PER_CPU_CONTROL_SIZE ( 1 << PER_CPU_CONTROL_SIZE_LOG2 ) 71 #if defined( RTEMS_SMP ) 115 PER_CPU_STATE_INITIAL,
131 PER_CPU_STATE_READY_TO_START_MULTITASKING,
141 PER_CPU_STATE_REQUEST_START_MULTITASKING,
151 PER_CPU_STATE_SHUTDOWN
160 #if defined( RTEMS_PROFILING ) 166 CPU_Counter_ticks thread_dispatch_disabled_instant;
172 CPU_Counter_ticks max_thread_dispatch_disabled_time;
181 CPU_Counter_ticks max_interrupt_time;
187 CPU_Counter_ticks max_interrupt_delay;
195 uint64_t thread_dispatch_disabled_count;
206 uint64_t total_thread_dispatch_disabled_time;
214 uint64_t interrupt_count;
224 uint64_t total_interrupt_time;
234 #if CPU_PER_CPU_CONTROL_SIZE > 0 241 #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE) || \ 242 (CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE) 313 #if defined( RTEMS_SMP ) 322 SMP_ticket_lock_Control Lock;
324 #if defined( RTEMS_PROFILING ) 328 SMP_lock_Stats Lock_stats;
333 SMP_lock_Stats_context Lock_stats_context;
340 SMP_lock_Context Giant_lock_context;
374 #if defined( RTEMS_SMP ) 377 char unused_space_for_cache_line_alignment
383 } Per_CPU_Control_envelope;
393 #if defined( RTEMS_SMP ) 394 #define _Per_CPU_Acquire( cpu ) \ 395 _SMP_ticket_lock_Acquire( \ 397 &( cpu )->Lock_stats, \ 398 &( cpu )->Lock_stats_context \ 401 #define _Per_CPU_Acquire( cpu ) \ 407 #if defined( RTEMS_SMP ) 408 #define _Per_CPU_Release( cpu ) \ 409 _SMP_ticket_lock_Release( \ 411 &( cpu )->Lock_stats_context \ 414 #define _Per_CPU_Release( cpu ) \ 420 #if defined( RTEMS_SMP ) 421 #define _Per_CPU_ISR_disable_and_acquire( cpu, isr_cookie ) \ 423 _ISR_Disable_without_giant( isr_cookie ); \ 424 _Per_CPU_Acquire( cpu ); \ 427 #define _Per_CPU_ISR_disable_and_acquire( cpu, isr_cookie ) \ 429 _ISR_Disable( isr_cookie ); \ 434 #if defined( RTEMS_SMP ) 435 #define _Per_CPU_Release_and_ISR_enable( cpu, isr_cookie ) \ 437 _Per_CPU_Release( cpu ); \ 438 _ISR_Enable_without_giant( isr_cookie ); \ 441 #define _Per_CPU_Release_and_ISR_enable( cpu, isr_cookie ) \ 444 _ISR_Enable( isr_cookie ); \ 448 #if defined( RTEMS_SMP ) 449 #define _Per_CPU_Acquire_all( isr_cookie ) \ 451 uint32_t ncpus = _SMP_Get_processor_count(); \ 453 _ISR_Disable( isr_cookie ); \ 454 for ( cpu = 0 ; cpu < ncpus ; ++cpu ) { \ 455 _Per_CPU_Acquire( _Per_CPU_Get_by_index( cpu ) ); \ 459 #define _Per_CPU_Acquire_all( isr_cookie ) \ 460 _ISR_Disable( isr_cookie ) 463 #if defined( RTEMS_SMP ) 464 #define _Per_CPU_Release_all( isr_cookie ) \ 466 uint32_t ncpus = _SMP_Get_processor_count(); \ 468 for ( cpu = 0 ; cpu < ncpus ; ++cpu ) { \ 469 _Per_CPU_Release( _Per_CPU_Get_by_index( cpu ) ); \ 471 _ISR_Enable( isr_cookie ); \ 474 #define _Per_CPU_Release_all( isr_cookie ) \ 475 _ISR_Enable( isr_cookie ) 485 #if defined( _CPU_Get_current_per_CPU_control ) 486 #define _Per_CPU_Get_snapshot() _CPU_Get_current_per_CPU_control() 488 #define _Per_CPU_Get_snapshot() \ 489 ( &_Per_CPU_Information[ _SMP_Get_current_processor() ].per_cpu ) 492 #if defined( RTEMS_SMP ) 504 #define _Per_CPU_Get() _Per_CPU_Get_snapshot() 509 return &_Per_CPU_Information[ index ].per_cpu;
512 static inline uint32_t _Per_CPU_Get_index(
const Per_CPU_Control *cpu )
514 const Per_CPU_Control_envelope *per_cpu_envelope =
515 (
const Per_CPU_Control_envelope * ) cpu;
517 return ( uint32_t ) ( per_cpu_envelope - &_Per_CPU_Information[ 0 ] );
520 static inline bool _Per_CPU_Is_processor_started(
524 #if defined( RTEMS_SMP ) 533 #if defined( RTEMS_SMP ) 535 static inline void _Per_CPU_Send_interrupt(
const Per_CPU_Control *cpu )
537 _CPU_SMP_Send_interrupt( _Per_CPU_Get_index( cpu ) );
545 void _Per_CPU_Initialize(
void);
547 void _Per_CPU_State_change(
549 Per_CPU_State new_state
577 bool _Per_CPU_State_wait_for_non_initial_state(
579 uint32_t timeout_in_ns
588 #define _Thread_Dispatch_disable_level \ 589 _Per_CPU_Get()->thread_dispatch_disable_level 590 #define _Thread_Heir \ 592 #define _Thread_Executing \ 593 _Per_CPU_Get()->executing 594 #define _ISR_Nest_level \ 595 _Per_CPU_Get()->isr_nest_level 596 #define _CPU_Interrupt_stack_low \ 597 _Per_CPU_Get()->interrupt_stack_low 598 #define _CPU_Interrupt_stack_high \ 599 _Per_CPU_Get()->interrupt_stack_high 600 #define _Thread_Dispatch_necessary \ 601 _Per_CPU_Get()->dispatch_necessary 602 #define _Thread_Time_of_last_context_switch \ 603 _Per_CPU_Get()->time_of_last_context_switch 618 #if defined( RTEMS_SMP ) 621 _ISR_Disable_without_giant( level );
624 executing = _Thread_Executing;
626 #if defined( RTEMS_SMP ) 627 _ISR_Enable_without_giant( level );
637 #if defined( ASM ) || defined( _RTEMS_PERCPU_DEFINE_OFFSETS ) 639 #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE) || \ 640 (CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE) 645 #define PER_CPU_INTERRUPT_STACK_LOW \ 646 CPU_PER_CPU_CONTROL_SIZE 647 #define PER_CPU_INTERRUPT_STACK_HIGH \ 648 PER_CPU_INTERRUPT_STACK_LOW + CPU_SIZEOF_POINTER 649 #define PER_CPU_END_STACK \ 650 PER_CPU_INTERRUPT_STACK_HIGH + CPU_SIZEOF_POINTER 652 #define INTERRUPT_STACK_LOW \ 653 (SYM(_Per_CPU_Information) + PER_CPU_INTERRUPT_STACK_LOW) 654 #define INTERRUPT_STACK_HIGH \ 655 (SYM(_Per_CPU_Information) + PER_CPU_INTERRUPT_STACK_HIGH) 657 #define PER_CPU_END_STACK \ 658 CPU_PER_CPU_CONTROL_SIZE 664 #define PER_CPU_ISR_NEST_LEVEL \ 666 #define PER_CPU_THREAD_DISPATCH_DISABLE_LEVEL \ 667 PER_CPU_ISR_NEST_LEVEL + 4 668 #define PER_CPU_OFFSET_EXECUTING \ 669 PER_CPU_THREAD_DISPATCH_DISABLE_LEVEL + 4 670 #define PER_CPU_OFFSET_HEIR \ 671 PER_CPU_OFFSET_EXECUTING + CPU_SIZEOF_POINTER 672 #define PER_CPU_DISPATCH_NEEDED \ 673 PER_CPU_OFFSET_HEIR + CPU_SIZEOF_POINTER 675 #define THREAD_DISPATCH_DISABLE_LEVEL \ 676 (SYM(_Per_CPU_Information) + PER_CPU_THREAD_DISPATCH_DISABLE_LEVEL) 677 #define ISR_NEST_LEVEL \ 678 (SYM(_Per_CPU_Information) + PER_CPU_ISR_NEST_LEVEL) 679 #define DISPATCH_NEEDED \ 680 (SYM(_Per_CPU_Information) + PER_CPU_DISPATCH_NEEDED) Per-CPU statistics.
Definition: percpu.h:159
void * interrupt_stack_high
This contains a pointer to the interrupt stack pointer for this CPU.
Definition: percpu.h:253
Definition: media-server.c:33
Scheduler context.
Definition: scheduler.h:180
struct Thread_Control * heir
This is the heir thread for this processor.
Definition: percpu.h:292
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
Helpers for Manipulating Timestamps.
SuperCore SMP Support API.
#define _ISR_Get_level()
Return current interrupt level.
Definition: isrlevel.h:120
Per_CPU_Control_envelope _Per_CPU_Information [] CPU_STRUCTURE_ALIGNMENT
Set of Per CPU Core Information.
Definition: cpu.h:797
The CPU specific per-CPU control.
Definition: cpu.h:367
uint32_t ISR_Level
The following type defines the control block used to manage the interrupt level portion of the status...
Definition: isrlevel.h:42
This structure defines the Thread Control Block (TCB).
Definition: thread.h:671
Per CPU Core Structure.
Definition: percpu.h:233
uint32_t isr_nest_level
This contains the current interrupt nesting level on this CPU.
Definition: percpu.h:260
void * interrupt_stack_low
This contains a pointer to the lower range of the interrupt stack for this CPU.
Definition: percpu.h:247
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:83
volatile bool dispatch_necessary
This is set to true when this processor needs to run the dispatcher.
Definition: percpu.h:308
struct bintime Timestamp_Control
Define the Timestamp control type.
Definition: timestamp.h:55
struct Per_CPU_Control Per_CPU_Control
Per CPU Core Structure.
struct Thread_Control * executing
This is the thread executing on this processor.
Definition: percpu.h:278
volatile uint32_t thread_dispatch_disable_level
The thread dispatch critical section nesting counter which is used to prevent context switches at ino...
Definition: percpu.h:266
Timestamp_Control time_of_last_context_switch
This is the time of the last context switch on this CPU.
Definition: percpu.h:311
RTEMS_INLINE_ROUTINE struct Thread_Control * _Thread_Get_executing(void)
Returns the thread control block of the executing thread.
Definition: percpu.h:614