19 #ifndef _RTEMS_PERCPU_H 20 #define _RTEMS_PERCPU_H 22 #include <rtems/score/cpuimpl.h> 25 #include <rtems/asm.h> 27 #include <rtems/score/assert.h> 40 #if defined(RTEMS_SMP) 41 #if defined(RTEMS_PROFILING) 42 #define PER_CPU_CONTROL_SIZE_APPROX ( 512 + CPU_INTERRUPT_FRAME_SIZE ) 43 #elif defined(RTEMS_DEBUG) || CPU_SIZEOF_POINTER > 4 44 #define PER_CPU_CONTROL_SIZE_APPROX ( 256 + CPU_INTERRUPT_FRAME_SIZE ) 46 #define PER_CPU_CONTROL_SIZE_APPROX ( 128 + CPU_INTERRUPT_FRAME_SIZE ) 55 #if PER_CPU_CONTROL_SIZE_APPROX > 1024 56 #define PER_CPU_CONTROL_SIZE_LOG2 11 57 #elif PER_CPU_CONTROL_SIZE_APPROX > 512 58 #define PER_CPU_CONTROL_SIZE_LOG2 10 59 #elif PER_CPU_CONTROL_SIZE_APPROX > 256 60 #define PER_CPU_CONTROL_SIZE_LOG2 9 61 #elif PER_CPU_CONTROL_SIZE_APPROX > 128 62 #define PER_CPU_CONTROL_SIZE_LOG2 8 64 #define PER_CPU_CONTROL_SIZE_LOG2 7 67 #define PER_CPU_CONTROL_SIZE ( 1 << PER_CPU_CONTROL_SIZE_LOG2 ) 91 #if defined( RTEMS_SMP ) 135 PER_CPU_STATE_INITIAL,
151 PER_CPU_STATE_READY_TO_START_MULTITASKING,
161 PER_CPU_STATE_REQUEST_START_MULTITASKING,
171 PER_CPU_STATE_SHUTDOWN
180 #if defined( RTEMS_PROFILING ) 186 CPU_Counter_ticks thread_dispatch_disabled_instant;
192 CPU_Counter_ticks max_thread_dispatch_disabled_time;
201 CPU_Counter_ticks max_interrupt_time;
207 CPU_Counter_ticks max_interrupt_delay;
215 uint64_t thread_dispatch_disabled_count;
226 uint64_t total_thread_dispatch_disabled_time;
234 uint64_t interrupt_count;
244 uint64_t total_interrupt_time;
291 #if CPU_PER_CPU_CONTROL_SIZE > 0 350 bool reserved_for_executing_alignment[ 3 ];
380 #if defined(RTEMS_SMP) 419 #if defined( RTEMS_SMP ) 428 SMP_ticket_lock_Control Lock;
430 #if defined( RTEMS_PROFILING ) 434 SMP_lock_Stats Lock_stats;
439 SMP_lock_Stats_context Lock_stats_context;
503 Atomic_Uintptr before_multitasking_action;
523 #if defined( RTEMS_SMP ) 526 char unused_space_for_cache_line_alignment
532 } Per_CPU_Control_envelope;
542 #if defined( RTEMS_SMP ) 543 #define _Per_CPU_Acquire( cpu ) \ 544 _SMP_ticket_lock_Acquire( \ 546 &( cpu )->Lock_stats, \ 547 &( cpu )->Lock_stats_context \ 550 #define _Per_CPU_Acquire( cpu ) \ 556 #if defined( RTEMS_SMP ) 557 #define _Per_CPU_Release( cpu ) \ 558 _SMP_ticket_lock_Release( \ 560 &( cpu )->Lock_stats_context \ 563 #define _Per_CPU_Release( cpu ) \ 569 #if defined( RTEMS_SMP ) 570 #define _Per_CPU_ISR_disable_and_acquire( cpu, isr_cookie ) \ 572 _ISR_Local_disable( isr_cookie ); \ 573 _Per_CPU_Acquire( cpu ); \ 576 #define _Per_CPU_ISR_disable_and_acquire( cpu, isr_cookie ) \ 578 _ISR_Local_disable( isr_cookie ); \ 583 #if defined( RTEMS_SMP ) 584 #define _Per_CPU_Release_and_ISR_enable( cpu, isr_cookie ) \ 586 _Per_CPU_Release( cpu ); \ 587 _ISR_Local_enable( isr_cookie ); \ 590 #define _Per_CPU_Release_and_ISR_enable( cpu, isr_cookie ) \ 593 _ISR_Local_enable( isr_cookie ); \ 597 #if defined( RTEMS_SMP ) 598 #define _Per_CPU_Acquire_all( isr_cookie ) \ 600 uint32_t ncpus = _SMP_Get_processor_count(); \ 602 _ISR_Local_disable( isr_cookie ); \ 603 for ( cpu = 0 ; cpu < ncpus ; ++cpu ) { \ 604 _Per_CPU_Acquire( _Per_CPU_Get_by_index( cpu ) ); \ 608 #define _Per_CPU_Acquire_all( isr_cookie ) \ 609 _ISR_Local_disable( isr_cookie ) 612 #if defined( RTEMS_SMP ) 613 #define _Per_CPU_Release_all( isr_cookie ) \ 615 uint32_t ncpus = _SMP_Get_processor_count(); \ 617 for ( cpu = 0 ; cpu < ncpus ; ++cpu ) { \ 618 _Per_CPU_Release( _Per_CPU_Get_by_index( cpu ) ); \ 620 _ISR_Local_enable( isr_cookie ); \ 623 #define _Per_CPU_Release_all( isr_cookie ) \ 624 _ISR_Local_enable( isr_cookie ) 634 #if defined( _CPU_Get_current_per_CPU_control ) 635 #define _Per_CPU_Get_snapshot() _CPU_Get_current_per_CPU_control() 637 #define _Per_CPU_Get_snapshot() \ 638 ( &_Per_CPU_Information[ _SMP_Get_current_processor() ].per_cpu ) 641 #if defined( RTEMS_SMP ) 653 #define _Per_CPU_Get() _Per_CPU_Get_snapshot() 658 return &_Per_CPU_Information[ index ].per_cpu;
661 static inline uint32_t _Per_CPU_Get_index(
const Per_CPU_Control *cpu )
663 const Per_CPU_Control_envelope *per_cpu_envelope =
664 (
const Per_CPU_Control_envelope * ) cpu;
666 return ( uint32_t ) ( per_cpu_envelope - &_Per_CPU_Information[ 0 ] );
676 static inline bool _Per_CPU_Is_processor_online(
680 #if defined( RTEMS_SMP ) 689 static inline bool _Per_CPU_Is_boot_processor(
693 #if defined( RTEMS_SMP ) 702 #if defined( RTEMS_SMP ) 709 void _Per_CPU_Initialize(
void);
711 void _Per_CPU_State_change(
713 Per_CPU_State new_state
741 bool _Per_CPU_State_wait_for_non_initial_state(
743 uint32_t timeout_in_ns
752 #define _Thread_Dispatch_disable_level \ 753 _Per_CPU_Get()->thread_dispatch_disable_level 754 #define _Thread_Heir \ 757 #if defined(_CPU_Get_thread_executing) 758 #define _Thread_Executing \ 759 _CPU_Get_thread_executing() 761 #define _Thread_Executing \ 762 _Per_CPU_Get_executing( _Per_CPU_Get() ) 765 #define _ISR_Nest_level \ 766 _Per_CPU_Get()->isr_nest_level 767 #define _CPU_Interrupt_stack_low \ 768 _Per_CPU_Get()->interrupt_stack_low 769 #define _CPU_Interrupt_stack_high \ 770 _Per_CPU_Get()->interrupt_stack_high 771 #define _Thread_Dispatch_necessary \ 772 _Per_CPU_Get()->dispatch_necessary 788 #if defined(RTEMS_SMP) && !defined(_CPU_Get_thread_executing) 794 executing = _Thread_Executing;
796 #if defined(RTEMS_SMP) && !defined(_CPU_Get_thread_executing) 807 #if defined( ASM ) || defined( _RTEMS_PERCPU_DEFINE_OFFSETS ) 809 #define PER_CPU_INTERRUPT_STACK_LOW \ 810 CPU_PER_CPU_CONTROL_SIZE 811 #define PER_CPU_INTERRUPT_STACK_HIGH \ 812 PER_CPU_INTERRUPT_STACK_LOW + CPU_SIZEOF_POINTER 814 #define INTERRUPT_STACK_LOW \ 815 (SYM(_Per_CPU_Information) + PER_CPU_INTERRUPT_STACK_LOW) 816 #define INTERRUPT_STACK_HIGH \ 817 (SYM(_Per_CPU_Information) + PER_CPU_INTERRUPT_STACK_HIGH) 822 #define PER_CPU_ISR_NEST_LEVEL \ 823 PER_CPU_INTERRUPT_STACK_HIGH + CPU_SIZEOF_POINTER 824 #define PER_CPU_ISR_DISPATCH_DISABLE \ 825 PER_CPU_ISR_NEST_LEVEL + 4 826 #define PER_CPU_THREAD_DISPATCH_DISABLE_LEVEL \ 827 PER_CPU_ISR_DISPATCH_DISABLE + 4 828 #define PER_CPU_DISPATCH_NEEDED \ 829 PER_CPU_THREAD_DISPATCH_DISABLE_LEVEL + 4 830 #define PER_CPU_OFFSET_EXECUTING \ 831 PER_CPU_DISPATCH_NEEDED + 4 832 #define PER_CPU_OFFSET_HEIR \ 833 PER_CPU_OFFSET_EXECUTING + CPU_SIZEOF_POINTER 834 #if defined(RTEMS_SMP) 835 #define PER_CPU_INTERRUPT_FRAME_AREA \ 836 PER_CPU_OFFSET_HEIR + CPU_SIZEOF_POINTER 839 #define THREAD_DISPATCH_DISABLE_LEVEL \ 840 (SYM(_Per_CPU_Information) + PER_CPU_THREAD_DISPATCH_DISABLE_LEVEL) 841 #define ISR_NEST_LEVEL \ 842 (SYM(_Per_CPU_Information) + PER_CPU_ISR_NEST_LEVEL) 843 #define DISPATCH_NEEDED \ 844 (SYM(_Per_CPU_Information) + PER_CPU_DISPATCH_NEEDED) Per-CPU statistics.
Definition: percpu.h:179
void * interrupt_stack_high
The interrupt stack high address for this processor.
Definition: percpu.h:306
SuperCore SMP Support API.
Index for realtime clock per-CPU watchdog header.
Definition: percpu.h:268
Definition: media-server.c:33
int64_t Timestamp_Control
Definition: timestamp.h:52
Count of per-CPU watchdog headers.
Definition: percpu.h:282
Scheduler context.
Definition: scheduler.h:249
struct _Thread_Control * executing
This is the thread executing on this processor.
Definition: percpu.h:362
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
#define ISR_LOCK_MEMBER(_designator)
Defines an ISR lock member.
Definition: isrlock.h:89
Interrupt stack frame (ISF).
Definition: cpu.h:306
Helpers for Manipulating Timestamps.
Thread_Scheduler_control Scheduler
Scheduler related control.
Definition: thread.h:767
#define _ISR_Get_level()
Return current interrupt level.
Definition: isrlevel.h:125
Per_CPU_Control_envelope _Per_CPU_Information [] CPU_STRUCTURE_ALIGNMENT
Set of Per CPU Core Information.
Timestamp_Control cpu_usage_timestamp
The CPU usage timestamp contains the time point of the last heir thread change or last CPU usage upda...
Definition: percpu.h:394
Per_CPU_Watchdog_index
Per-CPU watchdog header index.
Definition: percpu.h:251
The CPU specific per-CPU control.
Definition: cpuimpl.h:54
#define _ISR_Local_disable(_level)
Disables interrupts on this processor.
Definition: isrlevel.h:54
uint32_t ISR_Level
Definition: isrlevel.h:38
Per CPU Core Structure.
Definition: percpu.h:290
uint32_t isr_nest_level
Definition: percpu.h:312
void * interrupt_stack_low
The interrupt stack low address for this processor.
Definition: percpu.h:301
#define _ISR_Local_enable(_level)
Enables interrupts on this processor.
Definition: isrlevel.h:71
Constants and Structures Associated with Watchdog Timers.
uint32_t isr_dispatch_disable
Indicetes if an ISR thread dispatch is disabled.
Definition: percpu.h:322
Definition: intercom.c:74
volatile bool dispatch_necessary
This is set to true when this processor needs to run the thread dispatcher.
Definition: percpu.h:343
struct _Thread_Control * heir
This is the heir thread for this processor.
Definition: percpu.h:378
struct Per_CPU_Control Per_CPU_Control
Per CPU Core Structure.
unsigned context
Definition: tlb.h:108
RTEMS_INLINE_ROUTINE struct _Thread_Control * _Thread_Get_executing(void)
Returns the thread control block of the executing thread.
Definition: percpu.h:784
Scheduler control.
Definition: scheduler.h:266
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:328
Index for monotonic clock per-CPU watchdog header.
Definition: percpu.h:277
Index for tick clock per-CPU watchdog header.
Definition: percpu.h:259