arch/sim: fix up_idle call the wrong pthread_yield version

The logic want the host version but link to NuttX version
This commit is contained in:
Xiang Xiao 2020-02-09 14:36:02 +08:00 committed by Gregory Nutt
parent e06a4226ed
commit 406a9adfdd
6 changed files with 36 additions and 141 deletions

View File

@ -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

View File

@ -40,15 +40,10 @@
#include <nuttx/config.h>
#include <pthread.h>
#include <time.h>
#include <nuttx/arch.h>
#ifdef CONFIG_SMP
# include <nuttx/spinlock.h>
#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
}

View File

@ -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 ************************************************************/

View File

@ -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;
}

View File

@ -1,85 +0,0 @@
/****************************************************************************
* arch/sim/src/sim/up_simhook.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <nuttx/config.h>
#include <assert.h>
#include <nuttx/sched.h>
#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 */

View File

@ -40,6 +40,7 @@
#include <nuttx/config.h>
#include <nuttx/sched.h>
#include <nuttx/sched_note.h>
#include <nuttx/spinlock.h>
#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 */