diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile index 6e0576748bf..3ea0c709d5b 100644 --- a/arch/sim/src/Makefile +++ b/arch/sim/src/Makefile @@ -89,8 +89,8 @@ ifeq ($(CONFIG_SPINLOCK),y) endif ifeq ($(CONFIG_SMP),y) - CSRCS += up_smpsignal.c up_smphook.c up_cpuidlestack.c - REQUIREDOBJS += up_smpsignal$(OBJEXT) up_smphook$(OBJEXT) + CSRCS += up_smpsignal.c up_cpuidlestack.c + REQUIREDOBJS += up_smpsignal$(OBJEXT) HOSTCFLAGS += -DCONFIG_SMP=1 -DCONFIG_SMP_NCPUS=$(CONFIG_SMP_NCPUS) HOSTSRCS += up_simsmp.c STDLIBS += -lpthread diff --git a/arch/sim/src/sim/up_idle.c b/arch/sim/src/sim/up_idle.c index 1848d454b5e..2b53cbfe7d5 100644 --- a/arch/sim/src/sim/up_idle.c +++ b/arch/sim/src/sim/up_idle.c @@ -40,15 +40,10 @@ #include -#include #include #include -#ifdef CONFIG_SMP -# include -#endif - #include "up_internal.h" /**************************************************************************** @@ -94,26 +89,6 @@ extern void up_x11update(void); void up_idle(void) { -#ifdef CONFIG_SMP - /* In the SMP configuration, only one CPU should do these operations. It - * should not matter which, however. - */ - - static volatile spinlock_t lock SP_SECTION = SP_UNLOCKED; - - /* The one that gets the lock is the one that executes the IDLE operations */ - - if (up_testset(&lock) != SP_UNLOCKED) - { - /* We didn't get it... Give other pthreads/CPUs a shot and try again - * later. - */ - - pthread_yield(); - return; - } -#endif - #ifdef CONFIG_SCHED_TICKLESS /* Driver the simulated interval timer */ @@ -192,14 +167,4 @@ void up_idle(void) } #endif #endif - -#ifdef CONFIG_SMP - /* Release the spinlock */ - - lock = SP_UNLOCKED; - - /* Give other pthreads/CPUs a shot */ - - pthread_yield(); -#endif } diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h index 2be6e0b9f47..6f90e2d8349 100644 --- a/arch/sim/src/sim/up_internal.h +++ b/arch/sim/src/sim/up_internal.h @@ -245,14 +245,7 @@ void sim_cpu0_start(void); /* up_smpsignal.c ***********************************************************/ #ifdef CONFIG_SMP -void sim_cpu_pause(int cpu, FAR volatile spinlock_t *wait, - FAR volatile unsigned char *paused); -#endif - -/* up_smphook.c *************************************************************/ - -#ifdef CONFIG_SMP -void sim_smp_hook(void); +void up_cpu_started(void); #endif /* up_tickless.c ************************************************************/ diff --git a/arch/sim/src/sim/up_simsmp.c b/arch/sim/src/sim/up_simsmp.c index a314418658b..5b67954233a 100644 --- a/arch/sim/src/sim/up_simsmp.c +++ b/arch/sim/src/sim/up_simsmp.c @@ -61,10 +61,6 @@ typedef unsigned char spinlock_t; -/* Task entry point type */ - -typedef int (*main_t)(int argc, char **argv); - struct sim_cpuinfo_s { int cpu; /* CPU number */ @@ -99,9 +95,9 @@ volatile spinlock_t g_cpu_paused[CONFIG_SMP_NCPUS]; * NuttX domain function prototypes ****************************************************************************/ -void nx_start(void) __attribute__ ((noreturn)); -void up_cpu_paused(int cpu); -void sim_smp_hook(void); +void nx_start(void); +void up_cpu_started(void); +int up_cpu_paused(int cpu); /**************************************************************************** * Private Functions @@ -156,14 +152,20 @@ static void *sim_idle_trampoline(void *arg) pthread_mutex_unlock(&cpuinfo->mutex); - /* Give control to the IDLE task via the nasty little sim_smp_hook(). - * sim_smp_hook() is logically a part of this function but needs to be + /* up_cpu_started() is logically a part of this function but needs to be * inserted in the path because in needs to access NuttX domain definitions. */ - sim_smp_hook(); + up_cpu_started(); - /* The IDLE task will not return. This is just to keep the compiler happy */ + /* The idle Loop */ + + for (; ; ) + { + /* Give other pthreads/CPUs a shot */ + + pthread_yield(); + } return NULL; } diff --git a/arch/sim/src/sim/up_smphook.c b/arch/sim/src/sim/up_smphook.c deleted file mode 100644 index e94625c6444..00000000000 --- a/arch/sim/src/sim/up_smphook.c +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** - * arch/sim/src/sim/up_simhook.c - * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include - -#include "sched/sched.h" - -#ifdef CONFIG_SMP - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: sim_smp_hook - * - * Description: - * This is a mindless little hook between sim_idle_trampoline() and the - * real IDLE task logic. This is only needed because we need to access - * elements of the TCB in the simulation domain but sim_idle_trampoline() - * lies in the host domain. - * - * Input Parameters: - * None - * - * Returned Value: - * None (should not return) - * - ****************************************************************************/ - -void sim_smp_hook(void) -{ - struct tcb_s *tcb = this_task(); - DEBUGASSERT(tcb != NULL && tcb->start != NULL); - - /* Transfer control to the "real" thread start-up routine */ - - tcb->start(); - - /* That function should not return. */ - - DEBUGPANIC(); -} - -#endif /* CONFIG_SMP */ diff --git a/arch/sim/src/sim/up_smpsignal.c b/arch/sim/src/sim/up_smpsignal.c index da1d8bbd3da..126269c4c4b 100644 --- a/arch/sim/src/sim/up_smpsignal.c +++ b/arch/sim/src/sim/up_smpsignal.c @@ -40,6 +40,7 @@ #include #include +#include #include #include "sched/sched.h" @@ -158,4 +159,23 @@ int up_cpu_paused(int cpu) return OK; } +/**************************************************************************** + * Name: up_cpu_started + * + * Description: + * Notify the current cpu start sucessfully. + * + ****************************************************************************/ + +void up_cpu_started(void) +{ +#ifdef CONFIG_SCHED_INSTRUMENTATION + FAR struct tcb_s *tcb = this_task(); + + /* Announce that the IDLE task has started */ + + sched_note_start(tcb); +#endif +} + #endif /* CONFIG_SMP */