Skip to content

Commit 592a438

Browse files
KAGA-KOKOingomolnar
authored andcommitted
clockevents: Provide explicit broadcast control functions
clockevents_notify() is a leftover from the early design of the clockevents facility. It's really not a notification mechanism, it's a multiplex call. We are way better off to have explicit calls instead of this monstrosity. Split out the broadcast control into a separate function and provide inline helpers. Switch clockevents_notify() over. This will go away once all callers are converted. This also gets rid of the nested locking of clockevents_lock and broadcast_lock. The broadcast control functions do not require clockevents_lock. Only the managing functions (setup/shutdown/suspend/resume of the broadcast device require clockevents_lock. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Cc: Daniel Lezcano <daniel.lezcano@linaro.org> Cc: Len Brown <lenb@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Tony Lindgren <tony@atomide.com> Link: http://lkml.kernel.org/r/8086559.ttsuS0n1Xr@vostro.rjw.lan Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 3ff7055 commit 592a438

4 files changed

Lines changed: 57 additions & 38 deletions

File tree

‎include/linux/tick.h‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,31 @@ extern void hotplug_cpu__broadcast_tick_pull(int dead_cpu);
4242
static inline void hotplug_cpu__broadcast_tick_pull(int dead_cpu) { }
4343
#endif
4444

45+
enum tick_broadcast_mode {
46+
TICK_BROADCAST_OFF,
47+
TICK_BROADCAST_ON,
48+
TICK_BROADCAST_FORCE,
49+
};
50+
51+
#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
52+
extern void tick_broadcast_control(enum tick_broadcast_mode mode);
53+
#else
54+
static inline void tick_broadcast_control(enum tick_broadcast_mode mode) { }
55+
#endif /* BROADCAST */
56+
57+
static inline void tick_broadcast_enable(void)
58+
{
59+
tick_broadcast_control(TICK_BROADCAST_ON);
60+
}
61+
static inline void tick_broadcast_disable(void)
62+
{
63+
tick_broadcast_control(TICK_BROADCAST_OFF);
64+
}
65+
static inline void tick_broadcast_force(void)
66+
{
67+
tick_broadcast_control(TICK_BROADCAST_FORCE);
68+
}
69+
4570
#ifdef CONFIG_NO_HZ_COMMON
4671
extern int tick_nohz_tick_stopped(void);
4772
extern void tick_nohz_idle_enter(void);

‎kernel/time/clockevents.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,13 @@ int clockevents_notify(unsigned long reason, void *arg)
656656

657657
switch (reason) {
658658
case CLOCK_EVT_NOTIFY_BROADCAST_ON:
659+
tick_broadcast_enable();
660+
break;
659661
case CLOCK_EVT_NOTIFY_BROADCAST_OFF:
662+
tick_broadcast_disable();
663+
break;
660664
case CLOCK_EVT_NOTIFY_BROADCAST_FORCE:
661-
tick_broadcast_on_off(reason, arg);
665+
tick_broadcast_force();
662666
break;
663667

664668
case CLOCK_EVT_NOTIFY_BROADCAST_ENTER:

‎kernel/time/tick-broadcast.c‎

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static cpumask_var_t tick_broadcast_mask;
3333
static cpumask_var_t tick_broadcast_on;
3434
static cpumask_var_t tmpmask;
3535
static DEFINE_RAW_SPINLOCK(tick_broadcast_lock);
36-
static int tick_broadcast_force;
36+
static int tick_broadcast_forced;
3737

3838
#ifdef CONFIG_TICK_ONESHOT
3939
static void tick_broadcast_clear_oneshot(int cpu);
@@ -326,49 +326,54 @@ static void tick_handle_periodic_broadcast(struct clock_event_device *dev)
326326
raw_spin_unlock(&tick_broadcast_lock);
327327
}
328328

329-
/*
330-
* Powerstate information: The system enters/leaves a state, where
331-
* affected devices might stop
329+
/**
330+
* tick_broadcast_control - Enable/disable or force broadcast mode
331+
* @mode: The selected broadcast mode
332+
*
333+
* Called when the system enters a state where affected tick devices
334+
* might stop. Note: TICK_BROADCAST_FORCE cannot be undone.
335+
*
336+
* Called with interrupts disabled, so clockevents_lock is not
337+
* required here because the local clock event device cannot go away
338+
* under us.
332339
*/
333-
static void tick_do_broadcast_on_off(unsigned long *reason)
340+
void tick_broadcast_control(enum tick_broadcast_mode mode)
334341
{
335342
struct clock_event_device *bc, *dev;
336343
struct tick_device *td;
337-
unsigned long flags;
338344
int cpu, bc_stopped;
339345

340-
raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
341-
342-
cpu = smp_processor_id();
343-
td = &per_cpu(tick_cpu_device, cpu);
346+
td = this_cpu_ptr(&tick_cpu_device);
344347
dev = td->evtdev;
345-
bc = tick_broadcast_device.evtdev;
346348

347349
/*
348350
* Is the device not affected by the powerstate ?
349351
*/
350352
if (!dev || !(dev->features & CLOCK_EVT_FEAT_C3STOP))
351-
goto out;
353+
return;
352354

353355
if (!tick_device_is_functional(dev))
354-
goto out;
356+
return;
355357

358+
raw_spin_lock(&tick_broadcast_lock);
359+
cpu = smp_processor_id();
360+
bc = tick_broadcast_device.evtdev;
356361
bc_stopped = cpumask_empty(tick_broadcast_mask);
357362

358-
switch (*reason) {
359-
case CLOCK_EVT_NOTIFY_BROADCAST_ON:
360-
case CLOCK_EVT_NOTIFY_BROADCAST_FORCE:
363+
switch (mode) {
364+
case TICK_BROADCAST_FORCE:
365+
tick_broadcast_forced = 1;
366+
case TICK_BROADCAST_ON:
361367
cpumask_set_cpu(cpu, tick_broadcast_on);
362368
if (!cpumask_test_and_set_cpu(cpu, tick_broadcast_mask)) {
363369
if (tick_broadcast_device.mode ==
364370
TICKDEV_MODE_PERIODIC)
365371
clockevents_shutdown(dev);
366372
}
367-
if (*reason == CLOCK_EVT_NOTIFY_BROADCAST_FORCE)
368-
tick_broadcast_force = 1;
369373
break;
370-
case CLOCK_EVT_NOTIFY_BROADCAST_OFF:
371-
if (tick_broadcast_force)
374+
375+
case TICK_BROADCAST_OFF:
376+
if (tick_broadcast_forced)
372377
break;
373378
cpumask_clear_cpu(cpu, tick_broadcast_on);
374379
if (!tick_device_is_functional(dev))
@@ -390,22 +395,9 @@ static void tick_do_broadcast_on_off(unsigned long *reason)
390395
else
391396
tick_broadcast_setup_oneshot(bc);
392397
}
393-
out:
394-
raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
395-
}
396-
397-
/*
398-
* Powerstate information: The system enters/leaves a state, where
399-
* affected devices might stop.
400-
*/
401-
void tick_broadcast_on_off(unsigned long reason, int *oncpu)
402-
{
403-
if (!cpumask_test_cpu(*oncpu, cpu_online_mask))
404-
printk(KERN_ERR "tick-broadcast: ignoring broadcast for "
405-
"offline CPU #%d\n", *oncpu);
406-
else
407-
tick_do_broadcast_on_off(&reason);
398+
raw_spin_unlock(&tick_broadcast_lock);
408399
}
400+
EXPORT_SYMBOL_GPL(tick_broadcast_control);
409401

410402
/*
411403
* Set the periodic handler depending on broadcast on/off

‎kernel/time/tick-internal.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
5353
extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
5454
extern void tick_install_broadcast_device(struct clock_event_device *dev);
5555
extern int tick_is_broadcast_device(struct clock_event_device *dev);
56-
extern void tick_broadcast_on_off(unsigned long reason, int *oncpu);
5756
extern void tick_shutdown_broadcast(unsigned int *cpup);
5857
extern void tick_suspend_broadcast(void);
5958
extern void tick_resume_broadcast(void);
@@ -68,7 +67,6 @@ static inline void tick_install_broadcast_device(struct clock_event_device *dev)
6867
static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
6968
static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
7069
static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
71-
static inline void tick_broadcast_on_off(unsigned long reason, int *oncpu) { }
7270
static inline void tick_shutdown_broadcast(unsigned int *cpup) { }
7371
static inline void tick_suspend_broadcast(void) { }
7472
static inline void tick_resume_broadcast(void) { }

0 commit comments

Comments
 (0)