Skip to content

Commit 043cf46

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: "The main changes in the timer code in this cycle were: - Clockevent updates: - timer-of framework cleanups. (Geert Uytterhoeven) - Use timer-of for the renesas-ostm and the device name to prevent name collision in case of multiple timers. (Geert Uytterhoeven) - Check if there is an error after calling of_clk_get in asm9260 (Chuhong Yuan) - ABI fix: Zero out high order bits of nanoseconds on compat syscalls. This got broken a year ago, with apparently no side effects so far. Since the kernel would use random data otherwise I don't think we'd have other options but to fix the bug, even if there was a side effect to applications (Dmitry Safonov) - Optimize ns_to_timespec64() on 32-bit systems: move away from div_s64_rem() which can be slow, to div_u64_rem() which is faster (Arnd Bergmann) - Annotate KCSAN-reported false positive data races in hrtimer_is_queued() users by moving timer->state handling over to the READ_ONCE()/WRITE_ONCE() APIs. This documents these accesses (Eric Dumazet) - Misc cleanups and small fixes" [ I undid the "ABI fix" and updated the comments instead. The reason there were apparently no side effects is that the fix was a no-op. The updated comment is to say _why_ it was a no-op. - Linus ] * 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: time: Zero the upper 32-bits in __kernel_timespec on 32-bit time: Rename tsk->real_start_time to ->start_boottime hrtimer: Remove the comment about not used HRTIMER_SOFTIRQ time: Fix spelling mistake in comment time: Optimize ns_to_timespec64() hrtimer: Annotate lockless access to timer->state clocksource/drivers/asm9260: Add a check for of_clk_get clocksource/drivers/renesas-ostm: Use unique device name instead of ostm clocksource/drivers/renesas-ostm: Convert to timer_of clocksource/drivers/timer-of: Use unique device name instead of timer clocksource/drivers/timer-of: Convert last full_name to %pOF
2 parents b22bfea + 83bae01 commit 043cf46

File tree

12 files changed

+117
-145
lines changed

12 files changed

+117
-145
lines changed

drivers/clocksource/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ config SH_TIMER_MTU2
528528
config RENESAS_OSTM
529529
bool "Renesas OSTM timer driver" if COMPILE_TEST
530530
select CLKSRC_MMIO
531+
select TIMER_OF
531532
help
532533
Enables the support for the Renesas OSTM.
533534

drivers/clocksource/asm9260_timer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ static int __init asm9260_timer_init(struct device_node *np)
194194
}
195195

196196
clk = of_clk_get(np, 0);
197+
if (IS_ERR(clk)) {
198+
pr_err("Failed to get clk!\n");
199+
return PTR_ERR(clk);
200+
}
197201

198202
ret = clk_prepare_enable(clk);
199203
if (ret) {

drivers/clocksource/renesas-ostm.c

Lines changed: 72 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
* Copyright (C) 2017 Chris Brandt
77
*/
88

9-
#include <linux/of_address.h>
10-
#include <linux/of_irq.h>
119
#include <linux/clk.h>
1210
#include <linux/clockchips.h>
1311
#include <linux/interrupt.h>
1412
#include <linux/sched_clock.h>
1513
#include <linux/slab.h>
1614

15+
#include "timer-of.h"
16+
1717
/*
1818
* The OSTM contains independent channels.
1919
* The first OSTM channel probed will be set up as a free running
@@ -24,12 +24,6 @@
2424
* driven clock event.
2525
*/
2626

27-
struct ostm_device {
28-
void __iomem *base;
29-
unsigned long ticks_per_jiffy;
30-
struct clock_event_device ced;
31-
};
32-
3327
static void __iomem *system_clock; /* For sched_clock() */
3428

3529
/* OSTM REGISTERS */
@@ -47,129 +41,108 @@ static void __iomem *system_clock; /* For sched_clock() */
4741
#define CTL_ONESHOT 0x02
4842
#define CTL_FREERUN 0x02
4943

50-
static struct ostm_device *ced_to_ostm(struct clock_event_device *ced)
51-
{
52-
return container_of(ced, struct ostm_device, ced);
53-
}
54-
55-
static void ostm_timer_stop(struct ostm_device *ostm)
44+
static void ostm_timer_stop(struct timer_of *to)
5645
{
57-
if (readb(ostm->base + OSTM_TE) & TE) {
58-
writeb(TT, ostm->base + OSTM_TT);
46+
if (readb(timer_of_base(to) + OSTM_TE) & TE) {
47+
writeb(TT, timer_of_base(to) + OSTM_TT);
5948

6049
/*
6150
* Read back the register simply to confirm the write operation
6251
* has completed since I/O writes can sometimes get queued by
6352
* the bus architecture.
6453
*/
65-
while (readb(ostm->base + OSTM_TE) & TE)
54+
while (readb(timer_of_base(to) + OSTM_TE) & TE)
6655
;
6756
}
6857
}
6958

70-
static int __init ostm_init_clksrc(struct ostm_device *ostm, unsigned long rate)
59+
static int __init ostm_init_clksrc(struct timer_of *to)
7160
{
72-
/*
73-
* irq not used (clock sources don't use interrupts)
74-
*/
75-
76-
ostm_timer_stop(ostm);
61+
ostm_timer_stop(to);
7762

78-
writel(0, ostm->base + OSTM_CMP);
79-
writeb(CTL_FREERUN, ostm->base + OSTM_CTL);
80-
writeb(TS, ostm->base + OSTM_TS);
63+
writel(0, timer_of_base(to) + OSTM_CMP);
64+
writeb(CTL_FREERUN, timer_of_base(to) + OSTM_CTL);
65+
writeb(TS, timer_of_base(to) + OSTM_TS);
8166

82-
return clocksource_mmio_init(ostm->base + OSTM_CNT,
83-
"ostm", rate,
84-
300, 32, clocksource_mmio_readl_up);
67+
return clocksource_mmio_init(timer_of_base(to) + OSTM_CNT,
68+
to->np->full_name, timer_of_rate(to), 300,
69+
32, clocksource_mmio_readl_up);
8570
}
8671

8772
static u64 notrace ostm_read_sched_clock(void)
8873
{
8974
return readl(system_clock);
9075
}
9176

92-
static void __init ostm_init_sched_clock(struct ostm_device *ostm,
93-
unsigned long rate)
77+
static void __init ostm_init_sched_clock(struct timer_of *to)
9478
{
95-
system_clock = ostm->base + OSTM_CNT;
96-
sched_clock_register(ostm_read_sched_clock, 32, rate);
79+
system_clock = timer_of_base(to) + OSTM_CNT;
80+
sched_clock_register(ostm_read_sched_clock, 32, timer_of_rate(to));
9781
}
9882

9983
static int ostm_clock_event_next(unsigned long delta,
100-
struct clock_event_device *ced)
84+
struct clock_event_device *ced)
10185
{
102-
struct ostm_device *ostm = ced_to_ostm(ced);
86+
struct timer_of *to = to_timer_of(ced);
10387

104-
ostm_timer_stop(ostm);
88+
ostm_timer_stop(to);
10589

106-
writel(delta, ostm->base + OSTM_CMP);
107-
writeb(CTL_ONESHOT, ostm->base + OSTM_CTL);
108-
writeb(TS, ostm->base + OSTM_TS);
90+
writel(delta, timer_of_base(to) + OSTM_CMP);
91+
writeb(CTL_ONESHOT, timer_of_base(to) + OSTM_CTL);
92+
writeb(TS, timer_of_base(to) + OSTM_TS);
10993

11094
return 0;
11195
}
11296

11397
static int ostm_shutdown(struct clock_event_device *ced)
11498
{
115-
struct ostm_device *ostm = ced_to_ostm(ced);
99+
struct timer_of *to = to_timer_of(ced);
116100

117-
ostm_timer_stop(ostm);
101+
ostm_timer_stop(to);
118102

119103
return 0;
120104
}
121105
static int ostm_set_periodic(struct clock_event_device *ced)
122106
{
123-
struct ostm_device *ostm = ced_to_ostm(ced);
107+
struct timer_of *to = to_timer_of(ced);
124108

125109
if (clockevent_state_oneshot(ced) || clockevent_state_periodic(ced))
126-
ostm_timer_stop(ostm);
110+
ostm_timer_stop(to);
127111

128-
writel(ostm->ticks_per_jiffy - 1, ostm->base + OSTM_CMP);
129-
writeb(CTL_PERIODIC, ostm->base + OSTM_CTL);
130-
writeb(TS, ostm->base + OSTM_TS);
112+
writel(timer_of_period(to) - 1, timer_of_base(to) + OSTM_CMP);
113+
writeb(CTL_PERIODIC, timer_of_base(to) + OSTM_CTL);
114+
writeb(TS, timer_of_base(to) + OSTM_TS);
131115

132116
return 0;
133117
}
134118

135119
static int ostm_set_oneshot(struct clock_event_device *ced)
136120
{
137-
struct ostm_device *ostm = ced_to_ostm(ced);
121+
struct timer_of *to = to_timer_of(ced);
138122

139-
ostm_timer_stop(ostm);
123+
ostm_timer_stop(to);
140124

141125
return 0;
142126
}
143127

144128
static irqreturn_t ostm_timer_interrupt(int irq, void *dev_id)
145129
{
146-
struct ostm_device *ostm = dev_id;
130+
struct clock_event_device *ced = dev_id;
147131

148-
if (clockevent_state_oneshot(&ostm->ced))
149-
ostm_timer_stop(ostm);
132+
if (clockevent_state_oneshot(ced))
133+
ostm_timer_stop(to_timer_of(ced));
150134

151135
/* notify clockevent layer */
152-
if (ostm->ced.event_handler)
153-
ostm->ced.event_handler(&ostm->ced);
136+
if (ced->event_handler)
137+
ced->event_handler(ced);
154138

155139
return IRQ_HANDLED;
156140
}
157141

158-
static int __init ostm_init_clkevt(struct ostm_device *ostm, int irq,
159-
unsigned long rate)
142+
static int __init ostm_init_clkevt(struct timer_of *to)
160143
{
161-
struct clock_event_device *ced = &ostm->ced;
162-
int ret = -ENXIO;
163-
164-
ret = request_irq(irq, ostm_timer_interrupt,
165-
IRQF_TIMER | IRQF_IRQPOLL,
166-
"ostm", ostm);
167-
if (ret) {
168-
pr_err("ostm: failed to request irq\n");
169-
return ret;
170-
}
144+
struct clock_event_device *ced = &to->clkevt;
171145

172-
ced->name = "ostm";
173146
ced->features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_PERIODIC;
174147
ced->set_state_shutdown = ostm_shutdown;
175148
ced->set_state_periodic = ostm_set_periodic;
@@ -178,79 +151,61 @@ static int __init ostm_init_clkevt(struct ostm_device *ostm, int irq,
178151
ced->shift = 32;
179152
ced->rating = 300;
180153
ced->cpumask = cpumask_of(0);
181-
clockevents_config_and_register(ced, rate, 0xf, 0xffffffff);
154+
clockevents_config_and_register(ced, timer_of_rate(to), 0xf,
155+
0xffffffff);
182156

183157
return 0;
184158
}
185159

186160
static int __init ostm_init(struct device_node *np)
187161
{
188-
struct ostm_device *ostm;
189-
int ret = -EFAULT;
190-
struct clk *ostm_clk = NULL;
191-
int irq;
192-
unsigned long rate;
193-
194-
ostm = kzalloc(sizeof(*ostm), GFP_KERNEL);
195-
if (!ostm)
196-
return -ENOMEM;
197-
198-
ostm->base = of_iomap(np, 0);
199-
if (!ostm->base) {
200-
pr_err("ostm: failed to remap I/O memory\n");
201-
goto err;
202-
}
203-
204-
irq = irq_of_parse_and_map(np, 0);
205-
if (irq < 0) {
206-
pr_err("ostm: Failed to get irq\n");
207-
goto err;
208-
}
162+
struct timer_of *to;
163+
int ret;
209164

210-
ostm_clk = of_clk_get(np, 0);
211-
if (IS_ERR(ostm_clk)) {
212-
pr_err("ostm: Failed to get clock\n");
213-
ostm_clk = NULL;
214-
goto err;
215-
}
165+
to = kzalloc(sizeof(*to), GFP_KERNEL);
166+
if (!to)
167+
return -ENOMEM;
216168

217-
ret = clk_prepare_enable(ostm_clk);
218-
if (ret) {
219-
pr_err("ostm: Failed to enable clock\n");
220-
goto err;
169+
to->flags = TIMER_OF_BASE | TIMER_OF_CLOCK;
170+
if (system_clock) {
171+
/*
172+
* clock sources don't use interrupts, clock events do
173+
*/
174+
to->flags |= TIMER_OF_IRQ;
175+
to->of_irq.flags = IRQF_TIMER | IRQF_IRQPOLL;
176+
to->of_irq.handler = ostm_timer_interrupt;
221177
}
222178

223-
rate = clk_get_rate(ostm_clk);
224-
ostm->ticks_per_jiffy = DIV_ROUND_CLOSEST(rate, HZ);
179+
ret = timer_of_init(np, to);
180+
if (ret)
181+
goto err_free;
225182

226183
/*
227184
* First probed device will be used as system clocksource. Any
228185
* additional devices will be used as clock events.
229186
*/
230187
if (!system_clock) {
231-
ret = ostm_init_clksrc(ostm, rate);
232-
233-
if (!ret) {
234-
ostm_init_sched_clock(ostm, rate);
235-
pr_info("ostm: used for clocksource\n");
236-
}
188+
ret = ostm_init_clksrc(to);
189+
if (ret)
190+
goto err_cleanup;
237191

192+
ostm_init_sched_clock(to);
193+
pr_info("%pOF: used for clocksource\n", np);
238194
} else {
239-
ret = ostm_init_clkevt(ostm, irq, rate);
195+
ret = ostm_init_clkevt(to);
196+
if (ret)
197+
goto err_cleanup;
240198

241-
if (!ret)
242-
pr_info("ostm: used for clock events\n");
243-
}
244-
245-
err:
246-
if (ret) {
247-
clk_disable_unprepare(ostm_clk);
248-
iounmap(ostm->base);
249-
kfree(ostm);
250-
return ret;
199+
pr_info("%pOF: used for clock events\n", np);
251200
}
252201

253202
return 0;
203+
204+
err_cleanup:
205+
timer_of_cleanup(to);
206+
err_free:
207+
kfree(to);
208+
return ret;
254209
}
255210

256211
TIMER_OF_DECLARE(ostm, "renesas,ostm", ostm_init);

drivers/clocksource/timer-of.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ static __init int timer_of_irq_init(struct device_node *np,
5757
if (of_irq->name) {
5858
of_irq->irq = ret = of_irq_get_byname(np, of_irq->name);
5959
if (ret < 0) {
60-
pr_err("Failed to get interrupt %s for %s\n",
61-
of_irq->name, np->full_name);
60+
pr_err("Failed to get interrupt %s for %pOF\n",
61+
of_irq->name, np);
6262
return ret;
6363
}
6464
} else {
@@ -192,7 +192,7 @@ int __init timer_of_init(struct device_node *np, struct timer_of *to)
192192
}
193193

194194
if (!to->clkevt.name)
195-
to->clkevt.name = np->name;
195+
to->clkevt.name = np->full_name;
196196

197197
to->np = np;
198198

fs/exec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ static int de_thread(struct task_struct *tsk)
11311131
* also take its birthdate (always earlier than our own).
11321132
*/
11331133
tsk->start_time = leader->start_time;
1134-
tsk->real_start_time = leader->real_start_time;
1134+
tsk->start_boottime = leader->start_boottime;
11351135

11361136
BUG_ON(!same_thread_group(leader, tsk));
11371137
BUG_ON(has_group_leader_pid(tsk));

fs/proc/array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
533533
nice = task_nice(task);
534534

535535
/* convert nsec -> ticks */
536-
start_time = nsec_to_clock_t(task->real_start_time);
536+
start_time = nsec_to_clock_t(task->start_boottime);
537537

538538
seq_put_decimal_ull(m, "", pid_nr_ns(pid, ns));
539539
seq_puts(m, " (");

include/linux/hrtimer.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,18 @@ extern u64 hrtimer_next_event_without(const struct hrtimer *exclude);
456456

457457
extern bool hrtimer_active(const struct hrtimer *timer);
458458

459-
/*
460-
* Helper function to check, whether the timer is on one of the queues
459+
/**
460+
* hrtimer_is_queued = check, whether the timer is on one of the queues
461+
* @timer: Timer to check
462+
*
463+
* Returns: True if the timer is queued, false otherwise
464+
*
465+
* The function can be used lockless, but it gives only a current snapshot.
461466
*/
462-
static inline int hrtimer_is_queued(struct hrtimer *timer)
467+
static inline bool hrtimer_is_queued(struct hrtimer *timer)
463468
{
464-
return timer->state & HRTIMER_STATE_ENQUEUED;
469+
/* The READ_ONCE pairs with the update functions of timer->state */
470+
return !!(READ_ONCE(timer->state) & HRTIMER_STATE_ENQUEUED);
465471
}
466472

467473
/*

include/linux/interrupt.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,7 @@ enum
533533
IRQ_POLL_SOFTIRQ,
534534
TASKLET_SOFTIRQ,
535535
SCHED_SOFTIRQ,
536-
HRTIMER_SOFTIRQ, /* Unused, but kept as tools rely on the
537-
numbering. Sigh! */
536+
HRTIMER_SOFTIRQ,
538537
RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */
539538

540539
NR_SOFTIRQS

0 commit comments

Comments
 (0)