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}
0 commit comments