arch/sim: Reuse the main thread as the simulated CPU0
This commit is contained in:
parent
a87271617a
commit
e06a4226ed
@ -81,13 +81,7 @@ int main(int argc, char **argv, char **envp)
|
||||
syslog_rpmsg_init_early("server", g_logbuffer, sizeof(g_logbuffer));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
/* In the SMP case, configure the main thread as CPU 0 */
|
||||
|
||||
sim_cpu0_initialize();
|
||||
#endif
|
||||
|
||||
/* Then start NuttX */
|
||||
/* Start NuttX */
|
||||
|
||||
if (setjmp(g_simabort) == 0)
|
||||
{
|
||||
|
@ -239,7 +239,6 @@ int up_hostusleep(unsigned int usec);
|
||||
/* up_simsmp.c **************************************************************/
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
int sim_cpu0_initialize(void);
|
||||
void sim_cpu0_start(void);
|
||||
#endif
|
||||
|
||||
|
@ -107,54 +107,6 @@ void sim_smp_hook(void);
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sim_cpu0_trampoline
|
||||
*
|
||||
* Description:
|
||||
* This is a pthread task entry point. This (host) pthread is used to
|
||||
* simulate a CPU0. It simply calls OS start.
|
||||
*
|
||||
* Input Parameters:
|
||||
* arg - Standard pthread argument
|
||||
*
|
||||
* Returned Value:
|
||||
* This function does not return
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void *sim_cpu0_trampoline(void *arg)
|
||||
{
|
||||
sigset_t set;
|
||||
int ret;
|
||||
|
||||
/* Set the CPU number zero for the CPU thread */
|
||||
|
||||
ret = pthread_setspecific(g_cpukey, (const void *)0);
|
||||
if (ret != 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Make sure the SIGUSR1 is not masked */
|
||||
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGUSR1);
|
||||
|
||||
ret = pthread_sigmask(SIG_UNBLOCK, &set, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Give control to nx_start() */
|
||||
|
||||
nx_start();
|
||||
|
||||
/* nx_start() should not return */
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sim_idle_trampoline
|
||||
*
|
||||
@ -243,7 +195,7 @@ static void sim_handle_signal(int signo, siginfo_t *info, void *context)
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sim_cpu0_initialize
|
||||
* Name: sim_cpu0_start
|
||||
*
|
||||
* Description:
|
||||
* Create the pthread-specific data key and set the indication of CPU0
|
||||
@ -253,83 +205,60 @@ static void sim_handle_signal(int signo, siginfo_t *info, void *context)
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
|
||||
* corresponds to the currently executing CPU.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sim_cpu0_initialize(void)
|
||||
{
|
||||
struct sigaction act;
|
||||
sigset_t set;
|
||||
int ret;
|
||||
|
||||
/* Create the pthread key */
|
||||
|
||||
ret = pthread_key_create(&g_cpukey, NULL);
|
||||
if (ret != 0)
|
||||
{
|
||||
return -ret;
|
||||
}
|
||||
|
||||
/* Register the common signal handler for all threads */
|
||||
|
||||
act.sa_sigaction = sim_handle_signal;
|
||||
act.sa_flags = SA_SIGINFO;
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
ret = sigaction(SIGUSR1, &act, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* Make sure the SIGUSR1 is not masked */
|
||||
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGUSR1);
|
||||
|
||||
ret = sigprocmask(SIG_UNBLOCK, &set, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
return -errno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sim_cpu0_start
|
||||
*
|
||||
* Description:
|
||||
* Start CPU0 and initialize the operating system.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Does not return
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void sim_cpu0_start(void)
|
||||
{
|
||||
void *value;
|
||||
struct sigaction act;
|
||||
sigset_t set;
|
||||
int ret;
|
||||
|
||||
/* Start the CPU0 emulation thread. This is analogous to power-up reset
|
||||
* of CPU0 in a multi-CPU hardware model.
|
||||
*/
|
||||
g_sim_cputhread[0] = pthread_self();
|
||||
|
||||
ret = pthread_create(&g_sim_cputhread[0], NULL, sim_cpu0_trampoline, NULL);
|
||||
if (ret == 0)
|
||||
/* Create the pthread key */
|
||||
|
||||
ret = pthread_key_create(&g_cpukey, NULL);
|
||||
if (ret != 0)
|
||||
{
|
||||
/* The CPU0 emulation thread should never return, the main thread will
|
||||
* wait just in case.
|
||||
*/
|
||||
|
||||
pthread_join(g_sim_cputhread[0], &value);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Set the CPU number zero for the CPU thread */
|
||||
|
||||
ret = pthread_setspecific(g_cpukey, (const void *)0);
|
||||
if (ret != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Register the common signal handler for all threads */
|
||||
|
||||
act.sa_sigaction = sim_handle_signal;
|
||||
act.sa_flags = SA_SIGINFO;
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
ret = sigaction(SIGUSR1, &act, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make sure the SIGUSR1 is not masked */
|
||||
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGUSR1);
|
||||
|
||||
ret = sigprocmask(SIG_UNBLOCK, &set, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Give control to nx_start() */
|
||||
|
||||
nx_start();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user