Skip to content

Commit a0e928e

Browse files
committed
Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer updates from Ingo Molnar: "This cycle had the following changes: - Timer tracing improvements (Anna-Maria Gleixner) - Continued tasklet reduction work: remove the hrtimer_tasklet (Thomas Gleixner) - Fix CPU hotplug remove race in the tick-broadcast mask handling code (Thomas Gleixner) - Force upper bound for setting CLOCK_REALTIME, to fix ABI inconsistencies with handling values that are close to the maximum supported and the vagueness of when uptime related wraparound might occur. Make the consistent maximum the year 2232 across all relevant ABIs and APIs. (Thomas Gleixner) - various cleanups and smaller fixes" * 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: tick: Fix typos in comments tick/broadcast: Fix warning about undefined tick_broadcast_oneshot_offline() timekeeping: Force upper bound for setting CLOCK_REALTIME timer/trace: Improve timer tracing timer/trace: Replace deprecated vsprintf pointer extension %pf by %ps timer: Move trace point to get proper index tick/sched: Update tick_sched struct documentation tick: Remove outgoing CPU from broadcast masks timekeeping: Consistently use unsigned int for seqcount snapshot softirq: Remove tasklet_hrtimer xfrm: Replace hrtimer tasklet with softirq hrtimer mac80211_hwsim: Replace hrtimer tasklet with softirq hrtimer
2 parents 5a2bf1a + 13e792a commit a0e928e

20 files changed

Lines changed: 173 additions & 183 deletions

File tree

‎drivers/net/wireless/mac80211_hwsim.c‎

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ struct mac80211_hwsim_data {
521521
unsigned int rx_filter;
522522
bool started, idle, scanning;
523523
struct mutex mutex;
524-
struct tasklet_hrtimer beacon_timer;
524+
struct hrtimer beacon_timer;
525525
enum ps_mode {
526526
PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL
527527
} ps;
@@ -1460,7 +1460,7 @@ static void mac80211_hwsim_stop(struct ieee80211_hw *hw)
14601460
{
14611461
struct mac80211_hwsim_data *data = hw->priv;
14621462
data->started = false;
1463-
tasklet_hrtimer_cancel(&data->beacon_timer);
1463+
hrtimer_cancel(&data->beacon_timer);
14641464
wiphy_dbg(hw->wiphy, "%s\n", __func__);
14651465
}
14661466

@@ -1583,14 +1583,12 @@ static enum hrtimer_restart
15831583
mac80211_hwsim_beacon(struct hrtimer *timer)
15841584
{
15851585
struct mac80211_hwsim_data *data =
1586-
container_of(timer, struct mac80211_hwsim_data,
1587-
beacon_timer.timer);
1586+
container_of(timer, struct mac80211_hwsim_data, beacon_timer);
15881587
struct ieee80211_hw *hw = data->hw;
15891588
u64 bcn_int = data->beacon_int;
1590-
ktime_t next_bcn;
15911589

15921590
if (!data->started)
1593-
goto out;
1591+
return HRTIMER_NORESTART;
15941592

15951593
ieee80211_iterate_active_interfaces_atomic(
15961594
hw, IEEE80211_IFACE_ITER_NORMAL,
@@ -1601,12 +1599,9 @@ mac80211_hwsim_beacon(struct hrtimer *timer)
16011599
bcn_int -= data->bcn_delta;
16021600
data->bcn_delta = 0;
16031601
}
1604-
1605-
next_bcn = ktime_add(hrtimer_get_expires(timer),
1606-
ns_to_ktime(bcn_int * 1000));
1607-
tasklet_hrtimer_start(&data->beacon_timer, next_bcn, HRTIMER_MODE_ABS);
1608-
out:
1609-
return HRTIMER_NORESTART;
1602+
hrtimer_forward(&data->beacon_timer, hrtimer_get_expires(timer),
1603+
ns_to_ktime(bcn_int * NSEC_PER_USEC));
1604+
return HRTIMER_RESTART;
16101605
}
16111606

16121607
static const char * const hwsim_chanwidths[] = {
@@ -1680,15 +1675,15 @@ static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
16801675
mutex_unlock(&data->mutex);
16811676

16821677
if (!data->started || !data->beacon_int)
1683-
tasklet_hrtimer_cancel(&data->beacon_timer);
1684-
else if (!hrtimer_is_queued(&data->beacon_timer.timer)) {
1678+
hrtimer_cancel(&data->beacon_timer);
1679+
else if (!hrtimer_is_queued(&data->beacon_timer)) {
16851680
u64 tsf = mac80211_hwsim_get_tsf(hw, NULL);
16861681
u32 bcn_int = data->beacon_int;
16871682
u64 until_tbtt = bcn_int - do_div(tsf, bcn_int);
16881683

1689-
tasklet_hrtimer_start(&data->beacon_timer,
1690-
ns_to_ktime(until_tbtt * 1000),
1691-
HRTIMER_MODE_REL);
1684+
hrtimer_start(&data->beacon_timer,
1685+
ns_to_ktime(until_tbtt * NSEC_PER_USEC),
1686+
HRTIMER_MODE_REL_SOFT);
16921687
}
16931688

16941689
return 0;
@@ -1751,17 +1746,18 @@ static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw,
17511746
info->enable_beacon, info->beacon_int);
17521747
vp->bcn_en = info->enable_beacon;
17531748
if (data->started &&
1754-
!hrtimer_is_queued(&data->beacon_timer.timer) &&
1749+
!hrtimer_is_queued(&data->beacon_timer) &&
17551750
info->enable_beacon) {
17561751
u64 tsf, until_tbtt;
17571752
u32 bcn_int;
17581753
data->beacon_int = info->beacon_int * 1024;
17591754
tsf = mac80211_hwsim_get_tsf(hw, vif);
17601755
bcn_int = data->beacon_int;
17611756
until_tbtt = bcn_int - do_div(tsf, bcn_int);
1762-
tasklet_hrtimer_start(&data->beacon_timer,
1763-
ns_to_ktime(until_tbtt * 1000),
1764-
HRTIMER_MODE_REL);
1757+
1758+
hrtimer_start(&data->beacon_timer,
1759+
ns_to_ktime(until_tbtt * NSEC_PER_USEC),
1760+
HRTIMER_MODE_REL_SOFT);
17651761
} else if (!info->enable_beacon) {
17661762
unsigned int count = 0;
17671763
ieee80211_iterate_active_interfaces_atomic(
@@ -1770,7 +1766,7 @@ static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw,
17701766
wiphy_dbg(hw->wiphy, " beaconing vifs remaining: %u",
17711767
count);
17721768
if (count == 0) {
1773-
tasklet_hrtimer_cancel(&data->beacon_timer);
1769+
hrtimer_cancel(&data->beacon_timer);
17741770
data->beacon_int = 0;
17751771
}
17761772
}
@@ -2933,9 +2929,9 @@ static int mac80211_hwsim_new_radio(struct genl_info *info,
29332929

29342930
wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
29352931

2936-
tasklet_hrtimer_init(&data->beacon_timer,
2937-
mac80211_hwsim_beacon,
2938-
CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
2932+
hrtimer_init(&data->beacon_timer, CLOCK_MONOTONIC,
2933+
HRTIMER_MODE_ABS_SOFT);
2934+
data->beacon_timer.function = mac80211_hwsim_beacon;
29392935

29402936
err = ieee80211_register_hw(hw);
29412937
if (err < 0) {

‎include/linux/interrupt.h‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -668,31 +668,6 @@ extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
668668
extern void tasklet_init(struct tasklet_struct *t,
669669
void (*func)(unsigned long), unsigned long data);
670670

671-
struct tasklet_hrtimer {
672-
struct hrtimer timer;
673-
struct tasklet_struct tasklet;
674-
enum hrtimer_restart (*function)(struct hrtimer *);
675-
};
676-
677-
extern void
678-
tasklet_hrtimer_init(struct tasklet_hrtimer *ttimer,
679-
enum hrtimer_restart (*function)(struct hrtimer *),
680-
clockid_t which_clock, enum hrtimer_mode mode);
681-
682-
static inline
683-
void tasklet_hrtimer_start(struct tasklet_hrtimer *ttimer, ktime_t time,
684-
const enum hrtimer_mode mode)
685-
{
686-
hrtimer_start(&ttimer->timer, time, mode);
687-
}
688-
689-
static inline
690-
void tasklet_hrtimer_cancel(struct tasklet_hrtimer *ttimer)
691-
{
692-
hrtimer_cancel(&ttimer->timer);
693-
tasklet_kill(&ttimer->tasklet);
694-
}
695-
696671
/*
697672
* Autoprobing for irqs:
698673
*

‎include/linux/tick.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ extern void tick_broadcast_control(enum tick_broadcast_mode mode);
6868
static inline void tick_broadcast_control(enum tick_broadcast_mode mode) { }
6969
#endif /* BROADCAST */
7070

71+
#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_HOTPLUG_CPU)
72+
extern void tick_offline_cpu(unsigned int cpu);
73+
#else
74+
static inline void tick_offline_cpu(unsigned int cpu) { }
75+
#endif
76+
7177
#ifdef CONFIG_GENERIC_CLOCKEVENTS
7278
extern int tick_broadcast_oneshot_control(enum tick_broadcast_state state);
7379
#else

‎include/linux/time64.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ struct itimerspec64 {
3333
#define KTIME_MAX ((s64)~((u64)1 << 63))
3434
#define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC)
3535

36+
/*
37+
* Limits for settimeofday():
38+
*
39+
* To prevent setting the time close to the wraparound point time setting
40+
* is limited so a reasonable uptime can be accomodated. Uptime of 30 years
41+
* should be really sufficient, which means the cutoff is 2232. At that
42+
* point the cutoff is just a small part of the larger problem.
43+
*/
44+
#define TIME_UPTIME_SEC_MAX (30LL * 365 * 24 *3600)
45+
#define TIME_SETTOD_SEC_MAX (KTIME_SEC_MAX - TIME_UPTIME_SEC_MAX)
46+
3647
static inline int timespec64_equal(const struct timespec64 *a,
3748
const struct timespec64 *b)
3849
{
@@ -100,6 +111,16 @@ static inline bool timespec64_valid_strict(const struct timespec64 *ts)
100111
return true;
101112
}
102113

114+
static inline bool timespec64_valid_settod(const struct timespec64 *ts)
115+
{
116+
if (!timespec64_valid(ts))
117+
return false;
118+
/* Disallow values which cause overflow issues vs. CLOCK_REALTIME */
119+
if ((unsigned long long)ts->tv_sec >= TIME_SETTOD_SEC_MAX)
120+
return false;
121+
return true;
122+
}
123+
103124
/**
104125
* timespec64_to_ns - Convert timespec64 to nanoseconds
105126
* @ts: pointer to the timespec64 variable to be converted

‎include/net/xfrm.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ struct xfrm_state {
219219
struct xfrm_stats stats;
220220

221221
struct xfrm_lifetime_cur curlft;
222-
struct tasklet_hrtimer mtimer;
222+
struct hrtimer mtimer;
223223

224224
struct xfrm_state_offload xso;
225225

‎include/trace/events/timer.h‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ TRACE_EVENT(timer_start,
7373
__entry->flags = flags;
7474
),
7575

76-
TP_printk("timer=%p function=%pf expires=%lu [timeout=%ld] cpu=%u idx=%u flags=%s",
76+
TP_printk("timer=%p function=%ps expires=%lu [timeout=%ld] cpu=%u idx=%u flags=%s",
7777
__entry->timer, __entry->function, __entry->expires,
7878
(long)__entry->expires - __entry->now,
7979
__entry->flags & TIMER_CPUMASK,
@@ -89,23 +89,27 @@ TRACE_EVENT(timer_start,
8989
*/
9090
TRACE_EVENT(timer_expire_entry,
9191

92-
TP_PROTO(struct timer_list *timer),
92+
TP_PROTO(struct timer_list *timer, unsigned long baseclk),
9393

94-
TP_ARGS(timer),
94+
TP_ARGS(timer, baseclk),
9595

9696
TP_STRUCT__entry(
9797
__field( void *, timer )
9898
__field( unsigned long, now )
9999
__field( void *, function)
100+
__field( unsigned long, baseclk )
100101
),
101102

102103
TP_fast_assign(
103104
__entry->timer = timer;
104105
__entry->now = jiffies;
105106
__entry->function = timer->function;
107+
__entry->baseclk = baseclk;
106108
),
107109

108-
TP_printk("timer=%p function=%pf now=%lu", __entry->timer, __entry->function,__entry->now)
110+
TP_printk("timer=%p function=%ps now=%lu baseclk=%lu",
111+
__entry->timer, __entry->function, __entry->now,
112+
__entry->baseclk)
109113
);
110114

111115
/**
@@ -210,7 +214,7 @@ TRACE_EVENT(hrtimer_start,
210214
__entry->mode = mode;
211215
),
212216

213-
TP_printk("hrtimer=%p function=%pf expires=%llu softexpires=%llu "
217+
TP_printk("hrtimer=%p function=%ps expires=%llu softexpires=%llu "
214218
"mode=%s", __entry->hrtimer, __entry->function,
215219
(unsigned long long) __entry->expires,
216220
(unsigned long long) __entry->softexpires,
@@ -243,7 +247,8 @@ TRACE_EVENT(hrtimer_expire_entry,
243247
__entry->function = hrtimer->function;
244248
),
245249

246-
TP_printk("hrtimer=%p function=%pf now=%llu", __entry->hrtimer, __entry->function,
250+
TP_printk("hrtimer=%p function=%ps now=%llu",
251+
__entry->hrtimer, __entry->function,
247252
(unsigned long long) __entry->now)
248253
);
249254

‎kernel/cpu.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,8 @@ static int take_cpu_down(void *_param)
861861

862862
/* Give up timekeeping duties */
863863
tick_handover_do_timer();
864+
/* Remove CPU from timer broadcasting */
865+
tick_offline_cpu(cpu);
864866
/* Park the stopper thread */
865867
stop_machine_park(cpu);
866868
return 0;

‎kernel/softirq.c‎

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -573,57 +573,6 @@ void tasklet_kill(struct tasklet_struct *t)
573573
}
574574
EXPORT_SYMBOL(tasklet_kill);
575575

576-
/*
577-
* tasklet_hrtimer
578-
*/
579-
580-
/*
581-
* The trampoline is called when the hrtimer expires. It schedules a tasklet
582-
* to run __tasklet_hrtimer_trampoline() which in turn will call the intended
583-
* hrtimer callback, but from softirq context.
584-
*/
585-
static enum hrtimer_restart __hrtimer_tasklet_trampoline(struct hrtimer *timer)
586-
{
587-
struct tasklet_hrtimer *ttimer =
588-
container_of(timer, struct tasklet_hrtimer, timer);
589-
590-
tasklet_hi_schedule(&ttimer->tasklet);
591-
return HRTIMER_NORESTART;
592-
}
593-
594-
/*
595-
* Helper function which calls the hrtimer callback from
596-
* tasklet/softirq context
597-
*/
598-
static void __tasklet_hrtimer_trampoline(unsigned long data)
599-
{
600-
struct tasklet_hrtimer *ttimer = (void *)data;
601-
enum hrtimer_restart restart;
602-
603-
restart = ttimer->function(&ttimer->timer);
604-
if (restart != HRTIMER_NORESTART)
605-
hrtimer_restart(&ttimer->timer);
606-
}
607-
608-
/**
609-
* tasklet_hrtimer_init - Init a tasklet/hrtimer combo for softirq callbacks
610-
* @ttimer: tasklet_hrtimer which is initialized
611-
* @function: hrtimer callback function which gets called from softirq context
612-
* @which_clock: clock id (CLOCK_MONOTONIC/CLOCK_REALTIME)
613-
* @mode: hrtimer mode (HRTIMER_MODE_ABS/HRTIMER_MODE_REL)
614-
*/
615-
void tasklet_hrtimer_init(struct tasklet_hrtimer *ttimer,
616-
enum hrtimer_restart (*function)(struct hrtimer *),
617-
clockid_t which_clock, enum hrtimer_mode mode)
618-
{
619-
hrtimer_init(&ttimer->timer, which_clock, mode);
620-
ttimer->timer.function = __hrtimer_tasklet_trampoline;
621-
tasklet_init(&ttimer->tasklet, __tasklet_hrtimer_trampoline,
622-
(unsigned long)ttimer);
623-
ttimer->function = function;
624-
}
625-
EXPORT_SYMBOL_GPL(tasklet_hrtimer_init);
626-
627576
void __init softirq_init(void)
628577
{
629578
int cpu;

‎kernel/time/clockevents.c‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,22 @@ void clockevents_resume(void)
611611
}
612612

613613
#ifdef CONFIG_HOTPLUG_CPU
614+
615+
# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
616+
/**
617+
* tick_offline_cpu - Take CPU out of the broadcast mechanism
618+
* @cpu: The outgoing CPU
619+
*
620+
* Called on the outgoing CPU after it took itself offline.
621+
*/
622+
void tick_offline_cpu(unsigned int cpu)
623+
{
624+
raw_spin_lock(&clockevents_lock);
625+
tick_broadcast_offline(cpu);
626+
raw_spin_unlock(&clockevents_lock);
627+
}
628+
# endif
629+
614630
/**
615631
* tick_cleanup_dead_cpu - Cleanup the tick and clockevents of a dead cpu
616632
*/
@@ -621,8 +637,6 @@ void tick_cleanup_dead_cpu(int cpu)
621637

622638
raw_spin_lock_irqsave(&clockevents_lock, flags);
623639

624-
tick_shutdown_broadcast_oneshot(cpu);
625-
tick_shutdown_broadcast(cpu);
626640
tick_shutdown(cpu);
627641
/*
628642
* Unregister the clock event devices which were

‎kernel/time/jiffies.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ __cacheline_aligned_in_smp DEFINE_SEQLOCK(jiffies_lock);
6363
#if (BITS_PER_LONG < 64)
6464
u64 get_jiffies_64(void)
6565
{
66-
unsigned long seq;
66+
unsigned int seq;
6767
u64 ret;
6868

6969
do {

0 commit comments

Comments
 (0)