@@ -16,8 +16,9 @@ uint32_t tsc_khz = 0U;
16
16
static void run_timer (struct timer * timer )
17
17
{
18
18
/* deadline = 0 means stop timer, we should skip */
19
- if ((timer -> func != NULL ) && timer -> fire_tsc != 0UL )
19
+ if ((timer -> func != NULL ) && timer -> fire_tsc != 0UL ) {
20
20
timer -> func (timer -> priv_data );
21
+ }
21
22
22
23
TRACE_2L (TRACE_TIMER_ACTION_PCKUP , timer -> fire_tsc , 0 );
23
24
}
@@ -54,17 +55,20 @@ static void __add_timer(struct per_cpu_timers *cpu_timer,
54
55
prev = & cpu_timer -> timer_list ;
55
56
list_for_each (pos , & cpu_timer -> timer_list ) {
56
57
tmp = list_entry (pos , struct timer , node );
57
- if (tmp -> fire_tsc < tsc )
58
+ if (tmp -> fire_tsc < tsc ) {
58
59
prev = & tmp -> node ;
59
- else
60
+ }
61
+ else {
60
62
break ;
63
+ }
61
64
}
62
65
63
66
list_add (& timer -> node , prev );
64
67
65
- if (need_update != NULL )
68
+ if (need_update != NULL ) {
66
69
/* update the physical timer if we're on the timer_list head */
67
70
* need_update = (prev == & cpu_timer -> timer_list );
71
+ }
68
72
}
69
73
70
74
int add_timer (struct timer * timer )
@@ -73,20 +77,23 @@ int add_timer(struct timer *timer)
73
77
uint16_t pcpu_id ;
74
78
bool need_update ;
75
79
76
- if (timer == NULL || timer -> func == NULL || timer -> fire_tsc == 0UL )
80
+ if (timer == NULL || timer -> func == NULL || timer -> fire_tsc == 0UL ) {
77
81
return - EINVAL ;
82
+ }
78
83
79
84
/* limit minimal periodic timer cycle period */
80
- if (timer -> mode == TICK_MODE_PERIODIC )
85
+ if (timer -> mode == TICK_MODE_PERIODIC ) {
81
86
timer -> period_in_cycle = max (timer -> period_in_cycle ,
82
87
us_to_ticks (MIN_TIMER_PERIOD_US ));
88
+ }
83
89
84
90
pcpu_id = get_cpu_id ();
85
91
cpu_timer = & per_cpu (cpu_timers , pcpu_id );
86
92
__add_timer (cpu_timer , timer , & need_update );
87
93
88
- if (need_update )
94
+ if (need_update ) {
89
95
update_physical_timer (cpu_timer );
96
+ }
90
97
91
98
TRACE_2L (TRACE_TIMER_ACTION_ADDED , timer -> fire_tsc , 0 );
92
99
return 0 ;
@@ -95,8 +102,9 @@ int add_timer(struct timer *timer)
95
102
96
103
void del_timer (struct timer * timer )
97
104
{
98
- if ((timer != NULL ) && !list_empty (& timer -> node ))
105
+ if ((timer != NULL ) && !list_empty (& timer -> node )) {
99
106
list_del_init (& timer -> node );
107
+ }
100
108
}
101
109
102
110
static int request_timer_irq (uint16_t pcpu_id ,
@@ -105,8 +113,9 @@ static int request_timer_irq(uint16_t pcpu_id,
105
113
{
106
114
struct dev_handler_node * node = NULL ;
107
115
108
- if (pcpu_id >= phys_cpu_num )
116
+ if (pcpu_id >= phys_cpu_num ) {
109
117
return - EINVAL ;
118
+ }
110
119
111
120
if (per_cpu (timer_node , pcpu_id ) != NULL ) {
112
121
pr_err ("CPU%d timer isr already added" , pcpu_id );
@@ -165,8 +174,9 @@ void timer_cleanup(void)
165
174
{
166
175
uint16_t pcpu_id = get_cpu_id ();
167
176
168
- if (per_cpu (timer_node , pcpu_id ) != NULL )
177
+ if (per_cpu (timer_node , pcpu_id ) != NULL ) {
169
178
unregister_handler_common (per_cpu (timer_node , pcpu_id ));
179
+ }
170
180
171
181
per_cpu (timer_node , pcpu_id ) = NULL ;
172
182
}
@@ -202,8 +212,9 @@ void timer_softirq(uint16_t pcpu_id)
202
212
timer -> fire_tsc += timer -> period_in_cycle ;
203
213
__add_timer (cpu_timer , timer , NULL );
204
214
}
205
- } else
215
+ } else {
206
216
break ;
217
+ }
207
218
}
208
219
209
220
/* update nearest timer */
@@ -276,9 +287,10 @@ static uint64_t native_calibrate_tsc(void)
276
287
cpuid (0x15 , & eax_denominator , & ebx_numerator ,
277
288
& ecx_hz , & reserved );
278
289
279
- if (eax_denominator != 0U && ebx_numerator != 0U )
290
+ if (eax_denominator != 0U && ebx_numerator != 0U ) {
280
291
return (uint64_t ) ecx_hz *
281
292
ebx_numerator / eax_denominator ;
293
+ }
282
294
}
283
295
284
296
return 0 ;
@@ -288,8 +300,9 @@ void calibrate_tsc(void)
288
300
{
289
301
uint64_t tsc_hz ;
290
302
tsc_hz = native_calibrate_tsc ();
291
- if (tsc_hz == 0U )
303
+ if (tsc_hz == 0U ) {
292
304
tsc_hz = pit_calibrate_tsc (CAL_MS );
305
+ }
293
306
tsc_khz = (uint32_t )(tsc_hz / 1000UL );
294
307
printf ("%s, tsc_khz=%lu\n" , __func__ , tsc_khz );
295
308
}
0 commit comments