Skip to content

Commit da7bd0a

Browse files
anna-marialxKAGA-KOKO
authored andcommitted
timers: Move *sleep*() and timeout functions into a separate file
All schedule_timeout() and *sleep*() related functions are interfaces on top of timer list timers and hrtimers to add a sleep to the code. As they are built on top of the timer list timers and hrtimers, the [hr]timer interfaces are already used except when queuing the timer in schedule_timeout(). But there exists the appropriate interface add_timer() which does the same job with an extra check for an already pending timer. Split all those functions as they are into a separate file and use add_timer() instead of __mod_timer() in schedule_timeout(). While at it fix minor formatting issues and a multi line printk function call in schedule_timeout(). Signed-off-by: Anna-Maria Behnsen <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Frederic Weisbecker <[email protected]> Link: https://lore.kernel.org/all/20241014-devel-anna-maria-b4-timers-flseep-v3-2-dc8b907cb62f@linutronix.de
1 parent 3a2e83d commit da7bd0a

File tree

5 files changed

+319
-313
lines changed

5 files changed

+319
-313
lines changed

MAINTAINERS

+1
Original file line numberDiff line numberDiff line change
@@ -10167,6 +10167,7 @@ F: include/linux/hrtimer.h
1016710167
F: include/linux/timer.h
1016810168
F: kernel/time/clockevents.c
1016910169
F: kernel/time/hrtimer.c
10170+
F: kernel/time/sleep_timeout.c
1017010171
F: kernel/time/timer.c
1017110172
F: kernel/time/timer_list.c
1017210173
F: kernel/time/timer_migration.*

kernel/time/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
obj-y += time.o timer.o hrtimer.o
2+
obj-y += time.o timer.o hrtimer.o sleep_timeout.o
33
obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o
44
obj-y += timeconv.o timecounter.o alarmtimer.o
55

kernel/time/hrtimer.c

-120
Original file line numberDiff line numberDiff line change
@@ -2242,123 +2242,3 @@ void __init hrtimers_init(void)
22422242
hrtimers_prepare_cpu(smp_processor_id());
22432243
open_softirq(HRTIMER_SOFTIRQ, hrtimer_run_softirq);
22442244
}
2245-
2246-
/**
2247-
* schedule_hrtimeout_range_clock - sleep until timeout
2248-
* @expires: timeout value (ktime_t)
2249-
* @delta: slack in expires timeout (ktime_t)
2250-
* @mode: timer mode
2251-
* @clock_id: timer clock to be used
2252-
*/
2253-
int __sched
2254-
schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta,
2255-
const enum hrtimer_mode mode, clockid_t clock_id)
2256-
{
2257-
struct hrtimer_sleeper t;
2258-
2259-
/*
2260-
* Optimize when a zero timeout value is given. It does not
2261-
* matter whether this is an absolute or a relative time.
2262-
*/
2263-
if (expires && *expires == 0) {
2264-
__set_current_state(TASK_RUNNING);
2265-
return 0;
2266-
}
2267-
2268-
/*
2269-
* A NULL parameter means "infinite"
2270-
*/
2271-
if (!expires) {
2272-
schedule();
2273-
return -EINTR;
2274-
}
2275-
2276-
hrtimer_init_sleeper_on_stack(&t, clock_id, mode);
2277-
hrtimer_set_expires_range_ns(&t.timer, *expires, delta);
2278-
hrtimer_sleeper_start_expires(&t, mode);
2279-
2280-
if (likely(t.task))
2281-
schedule();
2282-
2283-
hrtimer_cancel(&t.timer);
2284-
destroy_hrtimer_on_stack(&t.timer);
2285-
2286-
__set_current_state(TASK_RUNNING);
2287-
2288-
return !t.task ? 0 : -EINTR;
2289-
}
2290-
EXPORT_SYMBOL_GPL(schedule_hrtimeout_range_clock);
2291-
2292-
/**
2293-
* schedule_hrtimeout_range - sleep until timeout
2294-
* @expires: timeout value (ktime_t)
2295-
* @delta: slack in expires timeout (ktime_t)
2296-
* @mode: timer mode
2297-
*
2298-
* Make the current task sleep until the given expiry time has
2299-
* elapsed. The routine will return immediately unless
2300-
* the current task state has been set (see set_current_state()).
2301-
*
2302-
* The @delta argument gives the kernel the freedom to schedule the
2303-
* actual wakeup to a time that is both power and performance friendly
2304-
* for regular (non RT/DL) tasks.
2305-
* The kernel give the normal best effort behavior for "@expires+@delta",
2306-
* but may decide to fire the timer earlier, but no earlier than @expires.
2307-
*
2308-
* You can set the task state as follows -
2309-
*
2310-
* %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
2311-
* pass before the routine returns unless the current task is explicitly
2312-
* woken up, (e.g. by wake_up_process()).
2313-
*
2314-
* %TASK_INTERRUPTIBLE - the routine may return early if a signal is
2315-
* delivered to the current task or the current task is explicitly woken
2316-
* up.
2317-
*
2318-
* The current task state is guaranteed to be TASK_RUNNING when this
2319-
* routine returns.
2320-
*
2321-
* Returns 0 when the timer has expired. If the task was woken before the
2322-
* timer expired by a signal (only possible in state TASK_INTERRUPTIBLE) or
2323-
* by an explicit wakeup, it returns -EINTR.
2324-
*/
2325-
int __sched schedule_hrtimeout_range(ktime_t *expires, u64 delta,
2326-
const enum hrtimer_mode mode)
2327-
{
2328-
return schedule_hrtimeout_range_clock(expires, delta, mode,
2329-
CLOCK_MONOTONIC);
2330-
}
2331-
EXPORT_SYMBOL_GPL(schedule_hrtimeout_range);
2332-
2333-
/**
2334-
* schedule_hrtimeout - sleep until timeout
2335-
* @expires: timeout value (ktime_t)
2336-
* @mode: timer mode
2337-
*
2338-
* Make the current task sleep until the given expiry time has
2339-
* elapsed. The routine will return immediately unless
2340-
* the current task state has been set (see set_current_state()).
2341-
*
2342-
* You can set the task state as follows -
2343-
*
2344-
* %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
2345-
* pass before the routine returns unless the current task is explicitly
2346-
* woken up, (e.g. by wake_up_process()).
2347-
*
2348-
* %TASK_INTERRUPTIBLE - the routine may return early if a signal is
2349-
* delivered to the current task or the current task is explicitly woken
2350-
* up.
2351-
*
2352-
* The current task state is guaranteed to be TASK_RUNNING when this
2353-
* routine returns.
2354-
*
2355-
* Returns 0 when the timer has expired. If the task was woken before the
2356-
* timer expired by a signal (only possible in state TASK_INTERRUPTIBLE) or
2357-
* by an explicit wakeup, it returns -EINTR.
2358-
*/
2359-
int __sched schedule_hrtimeout(ktime_t *expires,
2360-
const enum hrtimer_mode mode)
2361-
{
2362-
return schedule_hrtimeout_range(expires, 0, mode);
2363-
}
2364-
EXPORT_SYMBOL_GPL(schedule_hrtimeout);

0 commit comments

Comments
 (0)