Skip to content

Commit a320e6d

Browse files
hujun260xiaoxiang781216
authored andcommitted
smpcall: add nxsched_smp_call_async and nxsched_smp_call_single_async
reason: The old implementation of the SMP call, even when using the "no wait" parameter, could still result in waiting, if invoking it within a critical section may lead to deadlocks. Therefore, in order to implement a truly asynchronous SMP call strategy, we have added nxsched_smp_call_async. Signed-off-by: hujun5 <[email protected]>
1 parent 5048d6b commit a320e6d

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

testing/ostest/smp_call.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929

3030
#include <nuttx/sched.h>
3131

32+
/****************************************************************************
33+
* Private Data
34+
****************************************************************************/
35+
36+
static struct smp_call_data_s g_call_data;
37+
3238
#if defined(CONFIG_SMP) && defined(CONFIG_BUILD_FLAT)
3339
/****************************************************************************
3440
* Private Functions
@@ -37,14 +43,17 @@
3743
static int smp_call_func(void *arg)
3844
{
3945
FAR sem_t *psem = arg;
46+
4047
sem_post(psem);
4148
return OK;
4249
}
4350

4451
static void wdg_wdentry(wdparm_t arg)
4552
{
46-
nxsched_smp_call((1 << CONFIG_SMP_NCPUS) - 1, smp_call_func,
47-
(FAR void *)arg, false);
53+
cpu_set_t cpus = (1 << CONFIG_SMP_NCPUS) - 1;
54+
55+
nxsched_smp_call_init(&g_call_data, smp_call_func, (FAR void *)arg);
56+
nxsched_smp_call_async(cpus, &g_call_data);
4857
}
4958

5059
/****************************************************************************
@@ -54,6 +63,7 @@ static void wdg_wdentry(wdparm_t arg)
5463
void smp_call_test(void)
5564
{
5665
cpu_set_t cpuset;
66+
struct smp_call_data_s call_data;
5767
sem_t sem;
5868
int cpucnt;
5969
int cpu;
@@ -67,12 +77,13 @@ void smp_call_test(void)
6777
printf("smp_call_test: Test start\n");
6878

6979
sem_init(&sem, 0, 0);
80+
nxsched_smp_call_init(&call_data, smp_call_func, &sem);
7081

7182
for (cpu = 0; cpu < CONFIG_SMP_NCPUS; cpu++)
7283
{
7384
printf("smp_call_test: Call cpu %d, nowait\n", cpu);
7485

75-
nxsched_smp_call_single(cpu, smp_call_func, &sem, false);
86+
nxsched_smp_call_single_async(cpu, &call_data);
7687

7788
status = sem_wait(&sem);
7889
if (status != 0)
@@ -83,7 +94,7 @@ void smp_call_test(void)
8394

8495
printf("smp_call_test: Call cpu %d, wait\n", cpu);
8596

86-
nxsched_smp_call_single(cpu, smp_call_func, &sem, true);
97+
nxsched_smp_call_single(cpu, smp_call_func, &sem);
8798

8899
sem_getvalue(&sem, &value);
89100
if (value != 1)
@@ -100,7 +111,7 @@ void smp_call_test(void)
100111
sched_getaffinity(0, sizeof(cpu_set_t), &cpuset);
101112
cpucnt = CPU_COUNT(&cpuset);
102113

103-
nxsched_smp_call(cpuset, smp_call_func, &sem, false);
114+
nxsched_smp_call_async(cpuset, &call_data);
104115

105116
for (cpu = 0; cpu < cpucnt; cpu++)
106117
{
@@ -128,7 +139,7 @@ void smp_call_test(void)
128139

129140
printf("smp_call_test: Call multi cpu, wait\n");
130141

131-
nxsched_smp_call(cpuset, smp_call_func, &sem, true);
142+
nxsched_smp_call(cpuset, smp_call_func, &sem);
132143

133144
sem_getvalue(&sem, &value);
134145
if (value != cpucnt)

0 commit comments

Comments
 (0)