Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

hrtimers: Introduce hrtimer_setup() to replace hrtimer_init()

To initialize hrtimer, hrtimer_init() needs to be called and also
hrtimer::function must be set. This is error-prone and awkward to use.

Introduce hrtimer_setup() which does both of these things, so that users of
hrtimer can be simplified.

The new setup function also has a sanity check for the provided function
pointer. If NULL, a warning is emitted and a dummy callback installed.

hrtimer_init() will be removed as soon as all of its users have been
converted to the new function.

Signed-off-by: Nam Cao <namcao@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/5057c1ddbfd4b92033cd93d37fe38e6b069d5ba6.1730386209.git.namcao@linutronix.de

authored by

Nam Cao and committed by
Thomas Gleixner
908a1d77 c95d3658

+40
+2
include/linux/hrtimer.h
··· 228 228 /* Initialize timers: */ 229 229 extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, 230 230 enum hrtimer_mode mode); 231 + extern void hrtimer_setup(struct hrtimer *timer, enum hrtimer_restart (*function)(struct hrtimer *), 232 + clockid_t clock_id, enum hrtimer_mode mode); 231 233 extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock, 232 234 enum hrtimer_mode mode); 233 235 extern void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl,
+38
kernel/time/hrtimer.c
··· 1535 1535 return HRTIMER_BASE_MONOTONIC; 1536 1536 } 1537 1537 1538 + static enum hrtimer_restart hrtimer_dummy_timeout(struct hrtimer *unused) 1539 + { 1540 + return HRTIMER_NORESTART; 1541 + } 1542 + 1538 1543 static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id, 1539 1544 enum hrtimer_mode mode) 1540 1545 { ··· 1576 1571 timerqueue_init(&timer->node); 1577 1572 } 1578 1573 1574 + static void __hrtimer_setup(struct hrtimer *timer, 1575 + enum hrtimer_restart (*function)(struct hrtimer *), 1576 + clockid_t clock_id, enum hrtimer_mode mode) 1577 + { 1578 + __hrtimer_init(timer, clock_id, mode); 1579 + 1580 + if (WARN_ON_ONCE(!function)) 1581 + timer->function = hrtimer_dummy_timeout; 1582 + else 1583 + timer->function = function; 1584 + } 1585 + 1579 1586 /** 1580 1587 * hrtimer_init - initialize a timer to the given clock 1581 1588 * @timer: the timer to be initialized ··· 1607 1590 __hrtimer_init(timer, clock_id, mode); 1608 1591 } 1609 1592 EXPORT_SYMBOL_GPL(hrtimer_init); 1593 + 1594 + /** 1595 + * hrtimer_setup - initialize a timer to the given clock 1596 + * @timer: the timer to be initialized 1597 + * @function: the callback function 1598 + * @clock_id: the clock to be used 1599 + * @mode: The modes which are relevant for initialization: 1600 + * HRTIMER_MODE_ABS, HRTIMER_MODE_REL, HRTIMER_MODE_ABS_SOFT, 1601 + * HRTIMER_MODE_REL_SOFT 1602 + * 1603 + * The PINNED variants of the above can be handed in, 1604 + * but the PINNED bit is ignored as pinning happens 1605 + * when the hrtimer is started 1606 + */ 1607 + void hrtimer_setup(struct hrtimer *timer, enum hrtimer_restart (*function)(struct hrtimer *), 1608 + clockid_t clock_id, enum hrtimer_mode mode) 1609 + { 1610 + debug_init(timer, clock_id, mode); 1611 + __hrtimer_setup(timer, function, clock_id, mode); 1612 + } 1613 + EXPORT_SYMBOL_GPL(hrtimer_setup); 1610 1614 1611 1615 /** 1612 1616 * hrtimer_init_on_stack - initialize a timer in stack memory