Skip to content

Commit 8ce405f

Browse files
zhuzhuzhusRbb666
authored andcommitted
smp
1 parent d468b93 commit 8ce405f

File tree

5 files changed

+61
-61
lines changed

5 files changed

+61
-61
lines changed

components/smp/SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ src = []
55
if GetDepend("RT_USING_SMP"):
66
src += Glob('*.c')
77
CPPPATH = [cwd]
8-
group = DefineGroup('mprotect', src, depend = [''], CPPPATH = CPPPATH)
8+
group = DefineGroup('smp', src, depend = [''], CPPPATH = CPPPATH)
99

1010
Return('group')

components/smp/smp.c

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
#define DBG_LVL DBG_INFO
1515
#include <rtdbg.h>
1616

17-
struct smp_call global_work[RT_CPUS_NR];
18-
rt_atomic_t wait;
19-
rt_err_t smp_call_handler(struct smp_event *event)
17+
struct rt_smp_call rt_smp_work[RT_CPUS_NR];
18+
rt_atomic_t rt_smp_wait;
19+
rt_err_t smp_call_handler(struct rt_smp_event *event)
2020
{
21-
switch(event->event_id)
21+
switch (event->event_id)
2222
{
2323
case SMP_CALL_EVENT_FUNC:
2424
event->func(event->data);
25-
rt_atomic_add(&wait,1);
25+
rt_atomic_add(&rt_smp_wait, 1);
2626
break;
2727
default:
2828
LOG_E("error event id\n");
@@ -34,20 +34,20 @@ void rt_smp_call_ipi_handler(int vector, void *param)
3434
{
3535
int err;
3636
int cur_cpu = rt_hw_cpu_id();
37-
rt_spin_lock(&global_work[cur_cpu].lock);
38-
if(global_work[cur_cpu].event.event_id)
37+
rt_spin_lock(&rt_smp_work[cur_cpu].lock);
38+
39+
if (rt_smp_work[cur_cpu].event.event_id)
3940
{
40-
err = smp_call_handler(&global_work[cur_cpu].event);
41-
if(err)
41+
err = smp_call_handler(&rt_smp_work[cur_cpu].event);
42+
if (err)
4243
{
4344
LOG_E("Have no event\n");
44-
rt_memset(&global_work[cur_cpu].event,0,sizeof(struct smp_event));
45-
rt_spin_unlock(&global_work[cur_cpu].lock);
45+
rt_memset(&rt_smp_work[cur_cpu].event, 0, sizeof(struct rt_smp_event));
46+
rt_spin_unlock(&rt_smp_work[cur_cpu].lock);
4647
}
47-
rt_memset(&global_work[cur_cpu].event,0,sizeof(struct smp_event));
48+
rt_memset(&rt_smp_work[cur_cpu].event, 0, sizeof(struct rt_smp_event));
4849
}
49-
rt_spin_unlock(&global_work[cur_cpu].lock);
50-
50+
rt_spin_unlock(&rt_smp_work[cur_cpu].lock);
5151
}
5252

5353
/**
@@ -61,85 +61,85 @@ void rt_smp_call_ipi_handler(int vector, void *param)
6161
* else it will call function on specified CPU and return immediately
6262
* @param cond the condition function pointer,if you set it then it will call function only when cond return true
6363
*/
64-
void rt_smp_call_func_cond(int cpu_mask, smp_call_func_back func, void *data,rt_uint8_t flag,smp_cond cond)
64+
void rt_smp_call_func_cond(int cpu_mask, smp_call_func_back func, void *data, rt_uint8_t flag, smp_cond cond)
6565
{
6666
RT_DEBUG_NOT_IN_INTERRUPT;
67-
struct smp_event event;
68-
rt_bool_t need_call = RT_TRUE,need_wait = RT_FALSE;
69-
int cur_cpu = rt_hw_cpu_id();
70-
int cpuid = 1 << cur_cpu;
71-
int tmp_id = 0,cpu_nr = 0;
72-
int tmp_mask;
67+
struct rt_smp_event event;
68+
rt_bool_t need_call = RT_TRUE, need_wait = RT_FALSE;
69+
int cur_cpu = rt_hw_cpu_id();
70+
int cpuid = 1 << cur_cpu;
71+
int tmp_id = 0, cpu_nr = 0;
72+
int tmp_mask;
7373

74-
if(flag == SMP_CALL_WAIT_ALL)
74+
if (flag == SMP_CALL_WAIT_ALL)
7575
{
7676
need_wait = RT_TRUE;
77-
rt_atomic_store(&wait,0);
77+
rt_atomic_store(&rt_smp_wait, 0);
7878
}
7979

80-
if(cpuid & cpu_mask)
80+
if (cpuid & cpu_mask)
8181
{
8282
func(data);
8383
cpu_mask = cpu_mask & (~cpuid);
8484
}
8585

86-
if(!cpu_mask)
86+
if (!cpu_mask)
8787
need_call = RT_FALSE;
8888

8989
tmp_mask = cpu_mask;
90-
if(need_call)
90+
if (need_call)
9191
{
92-
while(tmp_mask)
92+
while (tmp_mask)
9393
{
94-
if((tmp_mask & 1) && (tmp_id < RT_CPUS_NR))
94+
if ((tmp_mask & 1) && (tmp_id < RT_CPUS_NR))
9595
{
96-
if(cond && !cond(tmp_id,data))
96+
if (cond && !cond(tmp_id, data))
9797
continue;
9898
cpu_nr++;
9999
event.event_id = SMP_CALL_EVENT_FUNC;
100-
event.func = func;
101-
event.data = data;
100+
event.func = func;
101+
event.data = data;
102102
event.cpu_mask = cpu_mask;
103-
rt_spin_lock(&global_work[tmp_id].lock);
104-
global_work[tmp_id].event = event;
105-
rt_spin_unlock(&global_work[tmp_id].lock);
103+
rt_spin_lock(&rt_smp_work[tmp_id].lock);
104+
rt_smp_work[tmp_id].event = event;
105+
rt_spin_unlock(&rt_smp_work[tmp_id].lock);
106106
}
107107
tmp_id++;
108108
tmp_mask = tmp_mask >> 1;
109109
}
110110
rt_hw_ipi_send(RT_FUNC_IPI, cpu_mask);
111111
}
112112

113-
if(need_wait)
113+
if (need_wait)
114114
{
115-
while(rt_atomic_load(&wait) != cpu_nr);
115+
while (rt_atomic_load(&rt_smp_wait) != cpu_nr);
116116
}
117117
}
118118

119-
void rt_call_each_cpu(smp_call_func_back func, void *data,rt_uint8_t flag)
119+
void rt_smp_call_each_cpu(smp_call_func_back func, void *data, rt_uint8_t flag)
120120
{
121-
rt_smp_call_func_cond(RT_ALL_CPU,func,data,flag,RT_NULL);
121+
rt_smp_call_func_cond(RT_ALL_CPU, func, data, flag, RT_NULL);
122122
}
123123

124-
void rt_call_each_cpu_cond(smp_call_func_back func, void *data,rt_uint8_t flag,smp_cond cond_func)
124+
void rt_smp_call_each_cpu_cond(smp_call_func_back func, void *data, rt_uint8_t flag, smp_cond cond_func)
125125
{
126-
rt_smp_call_func_cond(RT_ALL_CPU,func,data,flag,cond_func);
126+
rt_smp_call_func_cond(RT_ALL_CPU, func, data, flag, cond_func);
127127
}
128-
void rt_call_any_cpu(int cpu_mask,smp_call_func_back func, void *data,rt_uint8_t flag)
128+
void rt_smp_call_any_cpu(int cpu_mask, smp_call_func_back func, void *data, rt_uint8_t flag)
129129
{
130-
rt_smp_call_func_cond(cpu_mask,func,data,flag,RT_NULL);
130+
rt_smp_call_func_cond(cpu_mask, func, data, flag, RT_NULL);
131131
}
132132

133-
void rt_call_any_cpu_cond(int cpu_mask,smp_call_func_back func, void *data,rt_uint8_t flag,smp_cond cond_func)
133+
void rt_smp_call_any_cpu_cond(int cpu_mask, smp_call_func_back func, void *data, rt_uint8_t flag, smp_cond cond_func)
134134
{
135-
rt_smp_call_func_cond(cpu_mask,func,data,flag,cond_func);
135+
rt_smp_call_func_cond(cpu_mask, func, data, flag, cond_func);
136136
}
137137

138-
void smp_init(void)
138+
void rt_smp_init(void)
139139
{
140-
for(int i = 0; i < RT_CPUS_NR; i++)
140+
for (int i = 0; i < RT_CPUS_NR; i++)
141141
{
142-
rt_memset(&global_work[i],0,sizeof(struct smp_call));
143-
rt_spin_lock_init(&global_work[i].lock);
142+
rt_memset(&rt_smp_work[i], 0, sizeof(struct rt_smp_call));
143+
rt_spin_lock_init(&rt_smp_work[i].lock);
144144
}
145145
}

components/smp/smp.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ typedef rt_bool_t (*smp_cond)(int cpu, void *info);
1010
#define SMP_CALL_NO_WAIT (1 << 1)
1111

1212
#define RT_ALL_CPU ((1 << RT_CPUS_NR) - 1)
13-
struct smp_event
13+
struct rt_smp_event
1414
{
1515
int cpu_mask;
1616
int event_id;
1717
void *data;
1818
smp_call_func_back func;
1919
};
20-
struct smp_call
20+
struct rt_smp_call
2121
{
2222
struct rt_spinlock lock;
23-
struct smp_event event;
23+
struct rt_smp_event event;
2424
};
2525

2626

2727
void rt_smp_call_ipi_handler(int vector, void *param);
28-
void rt_call_each_cpu(smp_call_func_back func, void *data,rt_uint8_t flag);
29-
void rt_call_each_cpu_cond(smp_call_func_back func, void *data,rt_uint8_t flag,smp_cond cond_func);
30-
void rt_call_any_cpu(int cpu_mask,smp_call_func_back func, void *data,rt_uint8_t flag);
31-
void rt_call_any_cpu_cond(int cpu_mask,smp_call_func_back func, void *data,rt_uint8_t flag,smp_cond cond_func);
32-
void smp_init(void);
28+
void rt_smp_call_each_cpu(smp_call_func_back func, void *data,rt_uint8_t flag);
29+
void rt_smp_call_each_cpu_cond(smp_call_func_back func, void *data,rt_uint8_t flag,smp_cond cond_func);
30+
void rt_smp_call_any_cpu(int cpu_mask,smp_call_func_back func, void *data,rt_uint8_t flag);
31+
void rt_smp_call_any_cpu_cond(int cpu_mask,smp_call_func_back func, void *data,rt_uint8_t flag,smp_cond cond_func);
32+
void rt_smp_init(void);
3333

3434
#endif

examples/utest/testcases/smp/smp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void test1()
2626
cpu_mask = rand() % 0xf;
2727
if (cpu_mask == 0)
2828
pass--;
29-
rt_call_any_cpu(cpu_mask,test_call, &cpu_mask, SMP_CALL_WAIT_ALL);
29+
rt_smp_call_any_cpu(cpu_mask,test_call, &cpu_mask, SMP_CALL_WAIT_ALL);
3030
if (i % 20 == 0)
3131
rt_kprintf("#");
3232
}
@@ -46,11 +46,11 @@ void test_call2(void *data)
4646
void test2(void)
4747
{
4848
int data = 0;
49-
rt_call_each_cpu(test_call2, &data, SMP_CALL_WAIT_ALL);
49+
rt_smp_call_each_cpu(test_call2, &data, SMP_CALL_WAIT_ALL);
5050
uassert_true(data == RT_CPUS_NR);
5151
rt_thread_mdelay(10);
5252
data = 0;
53-
rt_call_each_cpu(test_call2, &data, SMP_CALL_NO_WAIT);
53+
rt_smp_call_each_cpu(test_call2, &data, SMP_CALL_NO_WAIT);
5454
uassert_true(data != RT_CPUS_NR);
5555
}
5656

libcpu/aarch64/common/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void rt_hw_common_setup(void)
302302
rt_thread_idle_sethook(rt_hw_idle_wfi);
303303

304304
#ifdef RT_USING_SMP
305-
smp_init();
305+
rt_smp_init();
306306
/* Install the IPI handle */
307307
rt_hw_ipi_handler_install(RT_SCHEDULE_IPI, rt_scheduler_ipi_handler);
308308
rt_hw_ipi_handler_install(RT_STOP_IPI, rt_scheduler_ipi_handler);

0 commit comments

Comments
 (0)