Skip to content

Commit 627ee79

Browse files
committed
clockevents: Serialize calls to clockevents_update_freq() in the core
We can identify the broadcast device in the core and serialize all callers including interrupts on a different CPU against the update. Also, disabling interrupts is moved into the core allowing callers to leave interrutps enabled when calling clockevents_update_freq(). Signed-off-by: Soren Brinkmann <[email protected]> Cc: [email protected] Cc: Soeren Brinkmann <[email protected]> Cc: Daniel Lezcano <[email protected]> Cc: Michal Simek <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Thomas Gleixner <[email protected]>
1 parent e8b1759 commit 627ee79

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

kernel/time/clockevents.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,24 +439,39 @@ void clockevents_config_and_register(struct clock_event_device *dev,
439439
}
440440
EXPORT_SYMBOL_GPL(clockevents_config_and_register);
441441

442+
int __clockevents_update_freq(struct clock_event_device *dev, u32 freq)
443+
{
444+
clockevents_config(dev, freq);
445+
446+
if (dev->mode != CLOCK_EVT_MODE_ONESHOT)
447+
return 0;
448+
449+
return clockevents_program_event(dev, dev->next_event, false);
450+
}
451+
442452
/**
443453
* clockevents_update_freq - Update frequency and reprogram a clock event device.
444454
* @dev: device to modify
445455
* @freq: new device frequency
446456
*
447457
* Reconfigure and reprogram a clock event device in oneshot
448458
* mode. Must be called on the cpu for which the device delivers per
449-
* cpu timer events with interrupts disabled! Returns 0 on success,
450-
* -ETIME when the event is in the past.
459+
* cpu timer events. If called for the broadcast device the core takes
460+
* care of serialization.
461+
*
462+
* Returns 0 on success, -ETIME when the event is in the past.
451463
*/
452464
int clockevents_update_freq(struct clock_event_device *dev, u32 freq)
453465
{
454-
clockevents_config(dev, freq);
455-
456-
if (dev->mode != CLOCK_EVT_MODE_ONESHOT)
457-
return 0;
466+
unsigned long flags;
467+
int ret;
458468

459-
return clockevents_program_event(dev, dev->next_event, false);
469+
local_irq_save(flags);
470+
ret = tick_broadcast_update_freq(dev, freq);
471+
if (ret == -ENODEV)
472+
ret = __clockevents_update_freq(dev, freq);
473+
local_irq_restore(flags);
474+
return ret;
460475
}
461476

462477
/*

kernel/time/tick-broadcast.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ int tick_is_broadcast_device(struct clock_event_device *dev)
120120
return (dev && tick_broadcast_device.evtdev == dev);
121121
}
122122

123+
int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq)
124+
{
125+
int ret = -ENODEV;
126+
127+
if (tick_is_broadcast_device(dev)) {
128+
raw_spin_lock(&tick_broadcast_lock);
129+
ret = __clockevents_update_freq(dev, freq);
130+
raw_spin_unlock(&tick_broadcast_lock);
131+
}
132+
return ret;
133+
}
134+
135+
123136
static void err_broadcast(const struct cpumask *mask)
124137
{
125138
pr_crit_once("Failed to broadcast timer tick. Some CPUs may be unresponsive.\n");
@@ -272,12 +285,8 @@ static void tick_do_broadcast(struct cpumask *mask)
272285
*/
273286
static void tick_do_periodic_broadcast(void)
274287
{
275-
raw_spin_lock(&tick_broadcast_lock);
276-
277288
cpumask_and(tmpmask, cpu_online_mask, tick_broadcast_mask);
278289
tick_do_broadcast(tmpmask);
279-
280-
raw_spin_unlock(&tick_broadcast_lock);
281290
}
282291

283292
/*
@@ -287,13 +296,15 @@ static void tick_handle_periodic_broadcast(struct clock_event_device *dev)
287296
{
288297
ktime_t next;
289298

299+
raw_spin_lock(&tick_broadcast_lock);
300+
290301
tick_do_periodic_broadcast();
291302

292303
/*
293304
* The device is in periodic mode. No reprogramming necessary:
294305
*/
295306
if (dev->mode == CLOCK_EVT_MODE_PERIODIC)
296-
return;
307+
goto unlock;
297308

298309
/*
299310
* Setup the next period for devices, which do not have
@@ -306,9 +317,11 @@ static void tick_handle_periodic_broadcast(struct clock_event_device *dev)
306317
next = ktime_add(next, tick_period);
307318

308319
if (!clockevents_program_event(dev, next, false))
309-
return;
320+
goto unlock;
310321
tick_do_periodic_broadcast();
311322
}
323+
unlock:
324+
raw_spin_unlock(&tick_broadcast_lock);
312325
}
313326

314327
/*

kernel/time/tick-internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ extern int tick_resume_broadcast(void);
111111
extern void tick_broadcast_init(void);
112112
extern void
113113
tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
114+
int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
114115

115116
#else /* !BROADCAST */
116117

@@ -133,6 +134,8 @@ static inline void tick_shutdown_broadcast(unsigned int *cpup) { }
133134
static inline void tick_suspend_broadcast(void) { }
134135
static inline int tick_resume_broadcast(void) { return 0; }
135136
static inline void tick_broadcast_init(void) { }
137+
static inline int tick_broadcast_update_freq(struct clock_event_device *dev,
138+
u32 freq) { return -ENODEV; }
136139

137140
/*
138141
* Set the periodic handler in non broadcast mode
@@ -154,5 +157,6 @@ static inline int tick_device_is_functional(struct clock_event_device *dev)
154157

155158
#endif
156159

160+
int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
157161
extern void do_timer(unsigned long ticks);
158162
extern void update_wall_time(void);

0 commit comments

Comments
 (0)