From cc00d2b2b09cd695a4efa6ee5cf5aa8fbdaac112 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Wed, 22 Jul 2020 03:00:08 +0800 Subject: [PATCH] arch/sim: Call sched_note_cpu_* when SCHED_INSTRUMENTATION equal true Signed-off-by: Xiang Xiao --- arch/sim/src/Makefile | 3 +++ arch/sim/src/sim/up_simsmp.c | 27 ++++++++++++++++++++++++++- arch/sim/src/sim/up_smpsignal.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile index 8dfe1063b1..ed9e2ce893 100644 --- a/arch/sim/src/Makefile +++ b/arch/sim/src/Makefile @@ -102,6 +102,9 @@ ifeq ($(CONFIG_SMP),y) HOSTCFLAGS += -DCONFIG_USEC_PER_TICK=$(CONFIG_USEC_PER_TICK) ifeq ($(CONFIG_SIM_WALLTIME),y) HOSTCFLAGS += -DCONFIG_SIM_WALLTIME=1 +endif +ifeq ($(CONFIG_SCHED_INSTRUMENTATION),y) + HOSTCFLAGS += -DCONFIG_SCHED_INSTRUMENTATION=1 endif HOSTSRCS += up_simsmp.c STDLIBS += -lpthread diff --git a/arch/sim/src/sim/up_simsmp.c b/arch/sim/src/sim/up_simsmp.c index 187c55707a..669562dc9f 100644 --- a/arch/sim/src/sim/up_simsmp.c +++ b/arch/sim/src/sim/up_simsmp.c @@ -99,9 +99,16 @@ volatile spinlock_t g_cpu_paused[CONFIG_SMP_NCPUS]; void nx_start(void); void up_cpu_started(void); -int up_cpu_paused(int cpu); +int up_cpu_paused(int cpu); void host_sleepuntil(uint64_t nsec); +#ifdef CONFIG_SCHED_INSTRUMENTATION +struct tcb_s *up_this_task(void); +void sched_note_cpu_start(struct tcb_s *tcb, int cpu); +void sched_note_cpu_pause(struct tcb_s *tcb, int cpu); +void sched_note_cpu_resume(struct tcb_s *tcb, int cpu); +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -330,6 +337,12 @@ int up_cpu_start(int cpu) struct sim_cpuinfo_s cpuinfo; int ret; +#ifdef CONFIG_SCHED_INSTRUMENTATION + /* Notify of the start event */ + + sched_note_cpu_start(up_this_task(), cpu); +#endif + /* Initialize the CPU info */ cpuinfo.cpu = cpu; @@ -400,6 +413,12 @@ errout_with_mutex: int up_cpu_pause(int cpu) { +#ifdef CONFIG_SCHED_INSTRUMENTATION + /* Notify of the pause event */ + + sched_note_cpu_pause(up_this_task(), cpu); +#endif + /* Take the spinlock that will prevent the CPU thread from running */ g_cpu_wait[cpu] = SP_LOCKED; @@ -440,6 +459,12 @@ int up_cpu_pause(int cpu) int up_cpu_resume(int cpu) { +#ifdef CONFIG_SCHED_INSTRUMENTATION + /* Notify of the resume event */ + + sched_note_cpu_resume(up_this_task(), cpu); +#endif + /* Release the spinlock that will alloc the CPU thread to continue */ g_cpu_wait[cpu] = SP_UNLOCKED; diff --git a/arch/sim/src/sim/up_smpsignal.c b/arch/sim/src/sim/up_smpsignal.c index eabeb1aaed..0179bbc00e 100644 --- a/arch/sim/src/sim/up_smpsignal.c +++ b/arch/sim/src/sim/up_smpsignal.c @@ -105,6 +105,12 @@ int up_cpu_paused(int cpu) nxsched_suspend_scheduler(rtcb); +#ifdef CONFIG_SCHED_INSTRUMENTATION + /* Notify that we are paused */ + + sched_note_cpu_paused(rtcb); +#endif + /* Copy the exception context into the TCB at the (old) head of the * CPUs assigned task list. if up_setjmp returns a non-zero value, then * this is really the previously running task restarting! @@ -145,6 +151,12 @@ int up_cpu_paused(int cpu) rtcb->xcp.sigdeliver = NULL; } +#ifdef CONFIG_SCHED_INSTRUMENTATION + /* Notify that we have resumed */ + + sched_note_cpu_resumed(rtcb); +#endif + /* Reset scheduler parameters */ nxsched_resume_scheduler(rtcb); @@ -170,8 +182,25 @@ void up_cpu_started(void) #ifdef CONFIG_SCHED_INSTRUMENTATION FAR struct tcb_s *tcb = this_task(); + /* Notify that this CPU has started */ + + sched_note_cpu_started(tcb); + /* Announce that the IDLE task has started */ sched_note_start(tcb); #endif } + +/**************************************************************************** + * Name: up_this_task + * + * Description: + * Return the currrent task tcb. + * + ****************************************************************************/ + +struct tcb_s *up_this_task(void) +{ + return this_task(); +}