Skip to content

Commit bf9aa14

Browse files
committed
Merge tag 'timers-core-2024-11-18' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer updates from Thomas Gleixner: "A rather large update for timekeeping and timers: - The final step to get rid of auto-rearming posix-timers posix-timers are currently auto-rearmed by the kernel when the signal of the timer is ignored so that the timer signal can be delivered once the corresponding signal is unignored. This requires to throttle the timer to prevent a DoS by small intervals and keeps the system pointlessly out of low power states for no value. This is a long standing non-trivial problem due to the lock order of posix-timer lock and the sighand lock along with life time issues as the timer and the sigqueue have different life time rules. Cure this by: - Embedding the sigqueue into the timer struct to have the same life time rules. Aside of that this also avoids the lookup of the timer in the signal delivery and rearm path as it's just a always valid container_of() now. - Queuing ignored timer signals onto a seperate ignored list. - Moving queued timer signals onto the ignored list when the signal is switched to SIG_IGN before it could be delivered. - Walking the ignored list when SIG_IGN is lifted and requeue the signals to the actual signal lists. This allows the signal delivery code to rearm the timer. This also required to consolidate the signal delivery rules so they are consistent across all situations. With that all self test scenarios finally succeed. - Core infrastructure for VFS multigrain timestamping This is required to allow the kernel to use coarse grained time stamps by default and switch to fine grained time stamps when inode attributes are actively observed via getattr(). These changes have been provided to the VFS tree as well, so that the VFS specific infrastructure could be built on top. - Cleanup and consolidation of the sleep() infrastructure - Move all sleep and timeout functions into one file - Rework udelay() and ndelay() into proper documented inline functions and replace the hardcoded magic numbers by proper defines. - Rework the fsleep() implementation to take the reality of the timer wheel granularity on different HZ values into account. Right now the boundaries are hard coded time ranges which fail to provide the requested accuracy on different HZ settings. - Update documentation for all sleep/timeout related functions and fix up stale documentation links all over the place - Fixup a few usage sites - Rework of timekeeping and adjtimex(2) to prepare for multiple PTP clocks A system can have multiple PTP clocks which are participating in seperate and independent PTP clock domains. So far the kernel only considers the PTP clock which is based on CLOCK TAI relevant as that's the clock which drives the timekeeping adjustments via the various user space daemons through adjtimex(2). The non TAI based clock domains are accessible via the file descriptor based posix clocks, but their usability is very limited. They can't be accessed fast as they always go all the way out to the hardware and they cannot be utilized in the kernel itself. As Time Sensitive Networking (TSN) gains traction it is required to provide fast user and kernel space access to these clocks. The approach taken is to utilize the timekeeping and adjtimex(2) infrastructure to provide this access in a similar way how the kernel provides access to clock MONOTONIC, REALTIME etc. Instead of creating a duplicated infrastructure this rework converts timekeeping and adjtimex(2) into generic functionality which operates on pointers to data structures instead of using static variables. This allows to provide time accessors and adjtimex(2) functionality for the independent PTP clocks in a subsequent step. - Consolidate hrtimer initialization hrtimers are set up by initializing the data structure and then seperately setting the callback function for historical reasons. That's an extra unnecessary step and makes Rust support less straight forward than it should be. Provide a new set of hrtimer_setup*() functions and convert the core code and a few usage sites of the less frequently used interfaces over. The bulk of the htimer_init() to hrtimer_setup() conversion is already prepared and scheduled for the next merge window. - Drivers: - Ensure that the global timekeeping clocksource is utilizing the cluster 0 timer on MIPS multi-cluster systems. Otherwise CPUs on different clusters use their cluster specific clocksource which is not guaranteed to be synchronized with other clusters. - Mostly boring cleanups, fixes, improvements and code movement" * tag 'timers-core-2024-11-18' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (140 commits) posix-timers: Fix spurious warning on double enqueue versus do_exit() clocksource/drivers/arm_arch_timer: Use of_property_present() for non-boolean properties clocksource/drivers/gpx: Remove redundant casts clocksource/drivers/timer-ti-dm: Fix child node refcount handling dt-bindings: timer: actions,owl-timer: convert to YAML clocksource/drivers/ralink: Add Ralink System Tick Counter driver clocksource/drivers/mips-gic-timer: Always use cluster 0 counter as clocksource clocksource/drivers/timer-ti-dm: Don't fail probe if int not found clocksource/drivers:sp804: Make user selectable clocksource/drivers/dw_apb: Remove unused dw_apb_clockevent functions hrtimers: Delete hrtimer_init_on_stack() alarmtimer: Switch to use hrtimer_setup() and hrtimer_setup_on_stack() io_uring: Switch to use hrtimer_setup_on_stack() sched/idle: Switch to use hrtimer_setup_on_stack() hrtimers: Delete hrtimer_init_sleeper_on_stack() wait: Switch to use hrtimer_setup_sleeper_on_stack() timers: Switch to use hrtimer_setup_sleeper_on_stack() net: pktgen: Switch to use hrtimer_setup_sleeper_on_stack() futex: Switch to use hrtimer_setup_sleeper_on_stack() fs/aio: Switch to use hrtimer_setup_sleeper_on_stack() ...
2 parents 0352387 + cdc905d commit bf9aa14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2357
-2159
lines changed

Diff for: Documentation/dev-tools/checkpatch.rst

-2
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,6 @@ API usage
470470
usleep_range() should be preferred over udelay(). The proper way of
471471
using usleep_range() is mentioned in the kernel docs.
472472

473-
See: https://www.kernel.org/doc/html/latest/timers/timers-howto.html#delays-information-on-the-various-kernel-delay-sleep-mechanisms
474-
475473

476474
Comments
477475
--------

Diff for: Documentation/devicetree/bindings/timer/actions,owl-timer.txt

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/timer/actions,owl-timer.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Actions Semi Owl timer
8+
9+
maintainers:
10+
- Andreas Färber <[email protected]>
11+
12+
description:
13+
Actions Semi Owl SoCs provide 32bit and 2Hz timers.
14+
The 32bit timers support dynamic irq, as well as one-shot mode.
15+
16+
properties:
17+
compatible:
18+
enum:
19+
- actions,s500-timer
20+
- actions,s700-timer
21+
- actions,s900-timer
22+
23+
clocks:
24+
maxItems: 1
25+
26+
interrupts:
27+
minItems: 1
28+
maxItems: 6
29+
30+
interrupt-names:
31+
minItems: 1
32+
maxItems: 6
33+
items:
34+
enum:
35+
- 2hz0
36+
- 2hz1
37+
- timer0
38+
- timer1
39+
- timer2
40+
- timer3
41+
42+
reg:
43+
maxItems: 1
44+
45+
required:
46+
- compatible
47+
- clocks
48+
- interrupts
49+
- interrupt-names
50+
- reg
51+
52+
allOf:
53+
- if:
54+
properties:
55+
compatible:
56+
contains:
57+
enum:
58+
- actions,s500-timer
59+
then:
60+
properties:
61+
interrupts:
62+
minItems: 4
63+
maxItems: 4
64+
interrupt-names:
65+
items:
66+
- const: 2hz0
67+
- const: 2hz1
68+
- const: timer0
69+
- const: timer1
70+
71+
- if:
72+
properties:
73+
compatible:
74+
contains:
75+
enum:
76+
- actions,s700-timer
77+
- actions,s900-timer
78+
then:
79+
properties:
80+
interrupts:
81+
minItems: 1
82+
maxItems: 1
83+
interrupt-names:
84+
items:
85+
- const: timer1
86+
87+
additionalProperties: false
88+
89+
examples:
90+
- |
91+
#include <dt-bindings/interrupt-controller/arm-gic.h>
92+
#include <dt-bindings/interrupt-controller/irq.h>
93+
soc {
94+
#address-cells = <1>;
95+
#size-cells = <1>;
96+
timer@b0168000 {
97+
compatible = "actions,s500-timer";
98+
reg = <0xb0168000 0x100>;
99+
clocks = <&hosc>;
100+
interrupts = <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>,
101+
<GIC_SPI 9 IRQ_TYPE_LEVEL_HIGH>,
102+
<GIC_SPI 10 IRQ_TYPE_LEVEL_HIGH>,
103+
<GIC_SPI 11 IRQ_TYPE_LEVEL_HIGH>;
104+
interrupt-names = "2hz0", "2hz1", "timer0", "timer1";
105+
};
106+
};
107+
...

Diff for: Documentation/timers/delay_sleep_functions.rst

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
Delay and sleep mechanisms
4+
==========================
5+
6+
This document seeks to answer the common question: "What is the
7+
RightWay (TM) to insert a delay?"
8+
9+
This question is most often faced by driver writers who have to
10+
deal with hardware delays and who may not be the most intimately
11+
familiar with the inner workings of the Linux Kernel.
12+
13+
The following table gives a rough overview about the existing function
14+
'families' and their limitations. This overview table does not replace the
15+
reading of the function description before usage!
16+
17+
.. list-table::
18+
:widths: 20 20 20 20 20
19+
:header-rows: 2
20+
21+
* -
22+
- `*delay()`
23+
- `usleep_range*()`
24+
- `*sleep()`
25+
- `fsleep()`
26+
* -
27+
- busy-wait loop
28+
- hrtimers based
29+
- timer list timers based
30+
- combines the others
31+
* - Usage in atomic Context
32+
- yes
33+
- no
34+
- no
35+
- no
36+
* - precise on "short intervals"
37+
- yes
38+
- yes
39+
- depends
40+
- yes
41+
* - precise on "long intervals"
42+
- Do not use!
43+
- yes
44+
- max 12.5% slack
45+
- yes
46+
* - interruptible variant
47+
- no
48+
- yes
49+
- yes
50+
- no
51+
52+
A generic advice for non atomic contexts could be:
53+
54+
#. Use `fsleep()` whenever unsure (as it combines all the advantages of the
55+
others)
56+
#. Use `*sleep()` whenever possible
57+
#. Use `usleep_range*()` whenever accuracy of `*sleep()` is not sufficient
58+
#. Use `*delay()` for very, very short delays
59+
60+
Find some more detailed information about the function 'families' in the next
61+
sections.
62+
63+
`*delay()` family of functions
64+
------------------------------
65+
66+
These functions use the jiffy estimation of clock speed and will busy wait for
67+
enough loop cycles to achieve the desired delay. udelay() is the basic
68+
implementation and ndelay() as well as mdelay() are variants.
69+
70+
These functions are mainly used to add a delay in atomic context. Please make
71+
sure to ask yourself before adding a delay in atomic context: Is this really
72+
required?
73+
74+
.. kernel-doc:: include/asm-generic/delay.h
75+
:identifiers: udelay ndelay
76+
77+
.. kernel-doc:: include/linux/delay.h
78+
:identifiers: mdelay
79+
80+
81+
`usleep_range*()` and `*sleep()` family of functions
82+
----------------------------------------------------
83+
84+
These functions use hrtimers or timer list timers to provide the requested
85+
sleeping duration. In order to decide which function is the right one to use,
86+
take some basic information into account:
87+
88+
#. hrtimers are more expensive as they are using an rb-tree (instead of hashing)
89+
#. hrtimers are more expensive when the requested sleeping duration is the first
90+
timer which means real hardware has to be programmed
91+
#. timer list timers always provide some sort of slack as they are jiffy based
92+
93+
The generic advice is repeated here:
94+
95+
#. Use `fsleep()` whenever unsure (as it combines all the advantages of the
96+
others)
97+
#. Use `*sleep()` whenever possible
98+
#. Use `usleep_range*()` whenever accuracy of `*sleep()` is not sufficient
99+
100+
First check fsleep() function description and to learn more about accuracy,
101+
please check msleep() function description.
102+
103+
104+
`usleep_range*()`
105+
~~~~~~~~~~~~~~~~~
106+
107+
.. kernel-doc:: include/linux/delay.h
108+
:identifiers: usleep_range usleep_range_idle
109+
110+
.. kernel-doc:: kernel/time/sleep_timeout.c
111+
:identifiers: usleep_range_state
112+
113+
114+
`*sleep()`
115+
~~~~~~~~~~
116+
117+
.. kernel-doc:: kernel/time/sleep_timeout.c
118+
:identifiers: msleep msleep_interruptible
119+
120+
.. kernel-doc:: include/linux/delay.h
121+
:identifiers: ssleep fsleep

Diff for: Documentation/timers/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Timers
1212
hrtimers
1313
no_hz
1414
timekeeping
15-
timers-howto
15+
delay_sleep_functions
1616

1717
.. only:: subproject and html
1818

Diff for: Documentation/timers/timers-howto.rst

-115
This file was deleted.

0 commit comments

Comments
 (0)