From b68fc9eb1d48ad0927873ad037d89efb9cea89ef Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 22 Jul 2021 15:24:52 +0900 Subject: [PATCH] arch: sim: Workaround to make the IPI work on macOS Summary: - I noticed that sim:smp does not work correctly on macOS due to the recent changes - Actually, it can not receive the IPI host signal, so if a new task is scheduled on CPU1/2/3, it hangs. - Finally, I found the issue depends on pthread stack settings and perhaps it might affect the host signal handling. - This commit fixes this issue by just reverting the pthread stack setting only for macOS. Impact: - sim:smp on macOS - Stack usage for CPU1/2/3 IDLE will be incorrect Testing: - Tested with ostest on macOS 11.4 (x86_64) Signed-off-by: Masayuki Ishikawa --- arch/sim/src/sim/up_simsmp.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/sim/src/sim/up_simsmp.c b/arch/sim/src/sim/up_simsmp.c index c802675efbd..47337d84317 100644 --- a/arch/sim/src/sim/up_simsmp.c +++ b/arch/sim/src/sim/up_simsmp.c @@ -212,7 +212,6 @@ int up_cpu_index(void) int sim_cpu_start(int cpu, void *stack, size_t size) { struct sim_cpuinfo_s cpuinfo; - pthread_attr_t attr; int ret; /* Initialize the CPU info */ @@ -227,11 +226,19 @@ int sim_cpu_start(int cpu, void *stack, size_t size) * in a multi-CPU hardware model. */ +#ifdef __APPLE__ + /* NOTE: workaround to make IPI work on macOS */ + + ret = pthread_create(&g_cpu_thread[cpu], + NULL, sim_idle_trampoline, &cpuinfo); +#else + pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstack(&attr, stack, size); ret = pthread_create(&g_cpu_thread[cpu], &attr, sim_idle_trampoline, &cpuinfo); pthread_attr_destroy(&attr); +#endif if (ret != 0) { goto errout_with_cond;