diff --git a/arch b/arch index 790c6be472..bceb7b7852 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 790c6be472dd5c386723e5b54bef495300ad6d7d +Subproject commit bceb7b7852a855d0de9afc4caeee801b4349db8e diff --git a/include/sched.h b/include/sched.h index 4fe16542d6..f3b675da72 100644 --- a/include/sched.h +++ b/include/sched.h @@ -145,13 +145,27 @@ int sched_lockcount(void); void sched_note_start(FAR struct tcb_s *tcb); void sched_note_stop(FAR struct tcb_s *tcb); -void sched_note_switch(FAR struct tcb_s *pFromTcb, - FAR struct tcb_s *pToTcb); +void sched_note_switch(FAR struct tcb_s *fromtcb, + FAR struct tcb_s *totcb); + +#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION +void sched_note_premption(FAR struct tcb_s *tcb, bool locked); +#else +# define sched_note_premption(t,l) +#endif + +#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION +void sched_note_csection(FAR struct tcb_s *tcb, bool enter); +#else +# define sched_note_csection(t,e) +#endif #else -# define sched_note_start(t) -# define sched_note_stop(t) -# define sched_note_switch(t1, t2) +# define sched_note_start(t) +# define sched_note_stop(t) +# define sched_note_switch(t1, t2) +# define sched_note_premption(t,l) +# define sched_note_csection(t,e) #endif /* CONFIG_SCHED_INSTRUMENTATION */ #undef EXTERN diff --git a/libc/stdio/lib_printf.c b/libc/stdio/lib_printf.c index 7088452393..5f1096a3a2 100644 --- a/libc/stdio/lib_printf.c +++ b/libc/stdio/lib_printf.c @@ -33,10 +33,6 @@ * ****************************************************************************/ -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - /**************************************************************************** * Included Files ****************************************************************************/ @@ -46,38 +42,6 @@ #include "libc.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -108,4 +72,3 @@ int printf(FAR const IPTR char *fmt, ...) return ret; } - diff --git a/sched/Kconfig b/sched/Kconfig index c30b672b1d..574223fd67 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -601,10 +601,32 @@ config SCHED_INSTRUMENTATION If enabled, then the board-specific logic must provide the following functions (see include/sched.h): - void sched_note_start(FAR struct tcb_s *tcb); - void sched_note_stop(FAR struct tcb_s *tcb); - void sched_note_switch(FAR struct tcb_s *pFromTcb, FAR struct tcb_s *pToTcb); + void sched_note_start(FAR struct tcb_s *tcb); + void sched_note_stop(FAR struct tcb_s *tcb); + void sched_note_switch(FAR struct tcb_s *pFromTcb, FAR struct tcb_s *pToTcb); +if SCHED_INSTRUMENTATION +config SCHED_INSTRUMENTATION_PREEMPTION + bool "Preemption monitor hooks + default n + ---help--- + Enables additional hooks for changes to pre-emption state. Board- + specific logic must provide this additional logic. + + void sched_note_premption(FAR struct tcb_s *tcb, bool state); + +config SCHED_INSTRUMENTATION_CSECTION + bool "Critical section monitor hooks + default n + depends on SMP + ---help--- + Enables additional hooks for entry and exit from critical sections. + Interrupts are disabled while within a critical section. Board- + specific logic must provide this additional logic. + + void sched_note_csection(FAR struct tcb_s *tcb, bool state); + +endif # SCHED_INSTRUMENTATION endmenu # Performance Monitoring menu "Files and I/O" diff --git a/sched/irq/irq_csection.c b/sched/irq/irq_csection.c index 265236b464..34e77f3b1c 100644 --- a/sched/irq/irq_csection.c +++ b/sched/irq/irq_csection.c @@ -129,6 +129,12 @@ irqstate_t enter_critical_section(void) rtcb->irqcount = 1; g_cpu_irqset |= (1 << this_cpu()); + +#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION + /* Note that we have entered the critical section */ + + sched_note_csection(rtcb, true); +#endif } /* Then disable interrupts (they may already be disabled, be we need to @@ -170,7 +176,12 @@ void leave_critical_section(irqstate_t flags) } else { - /* NO.. Release the spinlock to allow other access. */ +#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION + /* No.. Note that we have entered the critical section */ + + sched_note_csection(rtcb, false); +#endif + /* Release the spinlock to allow other access. */ g_cpu_irqset &= ~(1 << this_cpu()); rtcb->irqcount = 0; diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index c524cdd8cc..025b0bf035 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -201,6 +201,17 @@ int sched_lock(void) */ rtcb->lockcount++; + +#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION + /* Check if we just acquired the lock */ + + if (rtcb->lockcount == 1) + { + /* Note that we have pre-emption locked */ + + sched_note_premption(rtcb, true); + } +#endif } return OK; diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 2c12f98f4d..35d9afd5fb 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -90,6 +90,13 @@ int sched_unlock(void) if (rtcb->lockcount <= 0) { +#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION + /* Note that we no longer have pre-emption */ + + sched_note_premption(rtcb, false); +#endif + /* Set the lock count to zero */ + rtcb->lockcount = 0; #ifdef CONFIG_SMP