Skip to contentSkip to conversation

Timer core updates for 4.16

GIT PULL Thomas Gleixner 3 participants 6 messages Jan 29, 2018 – Jan 31, 2018

Subsystems (12)
lore
Share & tools
lore
#0 lore raw

Linus,

please pull the latest timers-core-for-linus git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers-core-for-linus

The timer departement presents:

- A rather large rework of the hrtimer infrastructure which introduces softirq based hrtimers to replace the spread of hrtimer/tasklet combos which force the actual callback execution into softirq context. The approach is completely different from the initial implementation which you cursed at 10 years ago rightfully. The softirq based timers have their own queues and there is no nasty indirection and list reshuffling in the hard interrupt anymore. This comes with conversion of some of the hrtimer/tasklet users, the rest and the final removal of that horrible interface will come towards the end of the merge window or go through the relevant maintainer trees.

Note: The top commit merged the last minute bugfix for the 10 years old CPU hotplug bug as I wanted to make sure that I fatfinger the merge conflict resolution myself.

- The overhaul of the STM32 clocksource/clockevents driver

- A new driver for the Spreadtrum SC9860 timer

- A new driver dor the Actions Semi S700 timer

- The usual set of fixes and updates all over the place

Thanks,

tglx

------------------>
Andreas Färber (3):
dt-bindings/clocksource: Add Actions Semi S700 timer clocksource/drivers/owl: Adopt TIMER_OF_DECLARE() clocksource/drivers/owl: Add the S700 timer

Anna-Maria Gleixner (27):
hrtimer: Fix kerneldoc syntax for 'struct hrtimer_cpu_base'
hrtimer: Clean up the 'int clock' parameter of schedule_hrtimeout_range_clock()
hrtimer: Fix hrtimer_start[_range_ns]() function descriptions
hrtimer: Ensure POSIX compliance (relative CLOCK_REALTIME hrtimers)
hrtimer: Clean up 'enum hrtimer_mode'
tracing/hrtimer: Fix tracing bugs by taking all clock bases and modes into account tracing/hrtimer: Print the hrtimer mode in the 'hrtimer_start' tracepoint
hrtimer: Switch 'for' loop to _ffs() evaluation
hrtimer: Store running timer in hrtimer_clock_base
hrtimer: Make room in 'struct hrtimer_cpu_base'
hrtimer: Make the hrtimer_cpu_base::hres_active field unconditional, to simplify the code
hrtimer: Use accesor functions instead of direct access
hrtimer: Make the remote enqueue check unconditional
hrtimer: Make hrtimer_cpu_base.next_timer handling unconditional
hrtimer: Make hrtimer_reprogramm() unconditional
hrtimer: Make hrtimer_force_reprogramm() unconditionally available
hrtimer: Unify hrtimer removal handling
hrtimer: Unify remote enqueue handling
hrtimer: Make remote enqueue decision less restrictive
hrtimer: Remove the 'base' parameter from hrtimer_reprogram()
hrtimer: Factor out __hrtimer_start_range_ns()
hrtimer: Factor out __hrtimer_next_event_base()
hrtimer: Use irqsave/irqrestore around __run_hrtimer()
hrtimer: Add clock bases and hrtimer mode for softirq context
hrtimer: Prepare handling of hard and softirq based hrtimers
hrtimer: Implement support for softirq based hrtimers
hrtimer: Implement SOFT/HARD clock base selection

Baolin Wang (2):
dt-bindings/clocksource: Add Spreadtrum SC9860 timer documentation clocksource/drivers/spreadtrum: Add timer driver for the Spreadtrum SC9860 platform

Benjamin Gaignard (4):
clocksource/drivers/stm32: Convert the driver to timer_of primitives clocksource/drivers/stm32: Compute a prescaler value with a targeted rate clocksource/drivers/stm32: Add oneshot mode clocksource/drivers/stm32: Add clocksource functionality

Daniel Lezcano (10):
clocksource/drivers/timer-of: Fix function names clocksource/drivers/timer-of: Add kernel documentation clocksource/drivers/timer-of: Store the device node pointer in 'struct timer_of' clocksource/drivers/timer-of: Don't request the resource by name clocksource/drivers/stm32: Fix kernel panic with multiple timers clocksource/drivers/stm32: Use the node name as timer name clocksource/drivers/stm32: Factor out the timer width sorting code clocksource/drivers/stm32: Factor out more of the clockevent code clocksource/drivers/stm32: Add the timer delay callback clocksource/drivers/stm32: Start the timer's counter sooner

Max R. P. Grossmann (1):
posix-cpu-timers: Make set_process_cpu_timer() more robust

Nick Desaulniers (1):
posix-timers: Prevent UB from shifting negative signed value

Romain Izard (1):
clocksource/drivers/tcb_clksrc: Fix clock speed message

Thomas Gleixner (4):
hrtimer: Optimize the hrtimer code by using static keys for migration_enable/nohz_active
hrtimer: Correct blatantly incorrect comment
ALSA/dummy: Replace tasklet with softirq hrtimer
usb/gadget/NCM: Replace tasklet with softirq hrtimer

 .../bindings/timer/actions,owl-timer.txt           |   1 +
 .../bindings/timer/spreadtrum,sprd-timer.txt       |  20 +
 drivers/clocksource/Kconfig                        |   8 +
 drivers/clocksource/Makefile                       |   1 +
 drivers/clocksource/owl-timer.c                    |   5 +-
 drivers/clocksource/tcb_clksrc.c                   |   2 +-
 drivers/clocksource/timer-of.c                     |  84 ++-
 drivers/clocksource/timer-of.h                     |   1 +
 drivers/clocksource/timer-sprd.c                   | 159 +++++
 drivers/clocksource/timer-stm32.c                  | 358 +++++++----
 drivers/usb/gadget/function/f_ncm.c                |  30 +-
 include/linux/hrtimer.h                            | 113 ++--
 include/linux/posix-timers.h                       |  25 +-
 include/trace/events/timer.h                       |  37 +-
 kernel/time/hrtimer.c                              | 657 +++++++++++++--------
 kernel/time/posix-clock.c                          |   2 +-
 kernel/time/posix-cpu-timers.c                     |   7 +-
 kernel/time/tick-internal.h                        |  13 +-
 kernel/time/tick-sched.c                           |   2 +-
 kernel/time/timer.c                                |  90 +--
 sound/drivers/dummy.c                              |  27 +-
 tools/testing/selftests/ptp/testptp.c              |   4 +-
 22 files changed, 1123 insertions(+), 523 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/timer/spreadtrum,sprd-timer.txt
 create mode 100644 drivers/clocksource/timer-sprd.c
Documentation/devicetree/bindings/timer/actions,owl-timer.txt +1 -0
index e3c28da80cb2..977054f87563 100644
@@ -2,6 +2,7 @@ Actions Semi Owl Timer
 
 Required properties:
 - compatible      :  "actions,s500-timer" for S500
+                     "actions,s700-timer" for S700
                      "actions,s900-timer" for S900
 - reg             :  Offset and length of the register set for the device.
 - interrupts      :  Should contain the interrupts.
Documentation/devicetree/bindings/timer/spreadtrum,sprd-timer.txt new file +20 -0
new file mode 100644
index 000000000000..6d97e7d0f6e8
@@ -0,0 +1,20 @@
+Spreadtrum timers
+
+The Spreadtrum SC9860 platform provides 3 general-purpose timers.
+These timers can support 32bit or 64bit counter, as well as supporting
+period mode or one-shot mode, and they are can be wakeup source
+during deep sleep.
+
+Required properties:
+- compatible: should be "sprd,sc9860-timer" for SC9860 platform.
+- reg: The register address of the timer device.
+- interrupts: Should contain the interrupt for the timer device.
+- clocks: The phandle to the source clock (usually a 32.768 KHz fixed clock).
+
+Example:
+	timer@40050000 {
+		compatible = "sprd,sc9860-timer";
+		reg = <0 0x40050000 0 0x20>;
+		interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&ext_32k>;
+	};
drivers/clocksource/Kconfig +8 -0
index c729a88007d0..b3b4ed9b6874 100644
@@ -269,6 +269,7 @@ config CLKSRC_STM32
 	bool "Clocksource for STM32 SoCs" if !ARCH_STM32
 	depends on OF && ARM && (ARCH_STM32 || COMPILE_TEST)
 	select CLKSRC_MMIO
+	select TIMER_OF
 
 config CLKSRC_MPS2
 	bool "Clocksource for MPS2 SoCs" if COMPILE_TEST
@@ -441,6 +442,13 @@ config MTK_TIMER
 	help
 	  Support for Mediatek timer driver.
 
+config SPRD_TIMER
+	bool "Spreadtrum timer driver" if COMPILE_TEST
+	depends on HAS_IOMEM
+	select TIMER_OF
+	help
+	  Enables support for the Spreadtrum timer driver.
+
 config SYS_SUPPORTS_SH_MTU2
         bool
 
drivers/clocksource/Makefile +1 -0
index 72711f1491e3..d6dec4489d66 100644
@@ -54,6 +54,7 @@ obj-$(CONFIG_CLKSRC_TI_32K)	+= timer-ti-32k.o
 obj-$(CONFIG_CLKSRC_NPS)	+= timer-nps.o
 obj-$(CONFIG_OXNAS_RPS_TIMER)	+= timer-oxnas-rps.o
 obj-$(CONFIG_OWL_TIMER)		+= owl-timer.o
+obj-$(CONFIG_SPRD_TIMER)	+= timer-sprd.o
 
 obj-$(CONFIG_ARC_TIMERS)		+= arc_timer.o
 obj-$(CONFIG_ARM_ARCH_TIMER)		+= arm_arch_timer.o
drivers/clocksource/owl-timer.c +3 -2
index c68630565079..ea00a5e8f95d 100644
@@ -168,5 +168,6 @@ static int __init owl_timer_init(struct device_node *node)
 
 	return 0;
 }
-CLOCKSOURCE_OF_DECLARE(owl_s500, "actions,s500-timer", owl_timer_init);
-CLOCKSOURCE_OF_DECLARE(owl_s900, "actions,s900-timer", owl_timer_init);
+TIMER_OF_DECLARE(owl_s500, "actions,s500-timer", owl_timer_init);
+TIMER_OF_DECLARE(owl_s700, "actions,s700-timer", owl_timer_init);
+TIMER_OF_DECLARE(owl_s900, "actions,s900-timer", owl_timer_init);
drivers/clocksource/tcb_clksrc.c +1 -1
index 9de47d4d2d9e..43f4d5c4d6fa 100644
@@ -384,7 +384,7 @@ static int __init tcb_clksrc_init(void)
 
 	printk(bootinfo, clksrc.name, CONFIG_ATMEL_TCB_CLKSRC_BLOCK,
 			divided_rate / 1000000,
-			((divided_rate + 500000) % 1000000) / 1000);
+			((divided_rate % 1000000) + 500) / 1000);
 
 	if (tc->tcb_config && tc->tcb_config->counter_width == 32) {
 		/* use apropriate function to read 32 bit counter */
drivers/clocksource/timer-of.c +62 -22

160 lines not on this page · raw message

drivers/clocksource/timer-of.h +1 -0
index 3f708f1be43d..a5478f3e8589 100644
@@ -33,6 +33,7 @@ struct of_timer_clk {
 
 struct timer_of {
 	unsigned int flags;
+	struct device_node *np;
 	struct clock_event_device clkevt;
 	struct of_timer_base of_base;
 	struct of_timer_irq  of_irq;
drivers/clocksource/timer-sprd.c new file +159 -0

159 lines not on this page · raw message

drivers/clocksource/timer-stm32.c +251 -107

432 lines not on this page · raw message

drivers/usb/gadget/function/f_ncm.c +7 -23
index c5bce8e22983..5780fba620ab 100644
@@ -73,9 +73,7 @@ struct f_ncm {
 	struct sk_buff			*skb_tx_ndp;
 	u16				ndp_dgram_count;
 	bool				timer_force_tx;
-	struct tasklet_struct		tx_tasklet;
 	struct hrtimer			task_timer;
-
 	bool				timer_stopping;
 };
 
@@ -1104,7 +1102,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 
 		/* Delay the timer. */
 		hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS,
-			      HRTIMER_MODE_REL);
+			      HRTIMER_MODE_REL_SOFT);
 
 		/* Add the datagram position entries */
 		ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len);
@@ -1148,17 +1146,15 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 }
 
 /*
- * This transmits the NTB if there are frames waiting.
+ * The transmit should only be run if no skb data has been sent
+ * for a certain duration.
  */
-static void ncm_tx_tasklet(unsigned long data)
+static enum hrtimer_restart ncm_tx_timeout(struct hrtimer *data)
 {
-	struct f_ncm	*ncm = (void *)data;
-
-	if (ncm->timer_stopping)
-		return;
+	struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer);
 
 	/* Only send if data is available. */
-	if (ncm->skb_tx_data) {
+	if (!ncm->timer_stopping && ncm->skb_tx_data) {
 		ncm->timer_force_tx = true;
 
 		/* XXX This allowance of a NULL skb argument to ndo_start_xmit
@@ -1171,16 +1167,6 @@ static void ncm_tx_tasklet(unsigned long data)
 
 		ncm->timer_force_tx = false;
 	}
-}
-
-/*
- * The transmit should only be run if no skb data has been sent
- * for a certain duration.
- */
-static enum hrtimer_restart ncm_tx_timeout(struct hrtimer *data)
-{
-	struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer);
-	tasklet_schedule(&ncm->tx_tasklet);
 	return HRTIMER_NORESTART;
 }
 
@@ -1513,8 +1499,7 @@ static int ncm_bind(struct usb_configuration *c, struct usb_function *f)
 	ncm->port.open = ncm_open;
 	ncm->port.close = ncm_close;
 
-	tasklet_init(&ncm->tx_tasklet, ncm_tx_tasklet, (unsigned long) ncm);
-	hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+	hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
 	ncm->task_timer.function = ncm_tx_timeout;
 
 	DBG(cdev, "CDC Network: %s speed IN/%s OUT/%s NOTIFY/%s\n",
@@ -1623,7 +1608,6 @@ static void ncm_unbind(struct usb_configuration *c, struct usb_function *f)
 	DBG(c->cdev, "ncm unbind\n");
 
 	hrtimer_cancel(&ncm->task_timer);
-	tasklet_kill(&ncm->tx_tasklet);
 
 	ncm_string_defs[0].id = 0;
 	usb_free_all_descriptors(f);
include/linux/hrtimer.h +67 -46

232 lines not on this page · raw message

include/linux/posix-timers.h +19 -6
index 672c4f32311e..c85704fcdbd2 100644
@@ -42,13 +42,26 @@ struct cpu_timer_list {
 #define CLOCKFD			CPUCLOCK_MAX
 #define CLOCKFD_MASK		(CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
 
-#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
-	((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
-#define MAKE_THREAD_CPUCLOCK(tid, clock) \
-	MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
+static inline clockid_t make_process_cpuclock(const unsigned int pid,
+		const clockid_t clock)
+{
+	return ((~pid) << 3) | clock;
+}
+static inline clockid_t make_thread_cpuclock(const unsigned int tid,
+		const clockid_t clock)
+{
+	return make_process_cpuclock(tid, clock | CPUCLOCK_PERTHREAD_MASK);
+}
 
-#define FD_TO_CLOCKID(fd)	((~(clockid_t) (fd) << 3) | CLOCKFD)
-#define CLOCKID_TO_FD(clk)	((unsigned int) ~((clk) >> 3))
+static inline clockid_t fd_to_clockid(const int fd)
+{
+	return make_process_cpuclock((unsigned int) fd, CLOCKFD);
+}
+
+static inline int clockid_to_fd(const clockid_t clk)
+{
+	return ~(clk >> 3);
+}
 
 #define REQUEUE_PENDING 1
 
include/trace/events/timer.h +28 -9
index 16e305e69f34..a57e4ee989d6 100644
@@ -136,6 +136,24 @@ DEFINE_EVENT(timer_class, timer_cancel,
 	TP_ARGS(timer)
 );
 
+#define decode_clockid(type)						\
+	__print_symbolic(type,						\
+		{ CLOCK_REALTIME,	"CLOCK_REALTIME"	},	\
+		{ CLOCK_MONOTONIC,	"CLOCK_MONOTONIC"	},	\
+		{ CLOCK_BOOTTIME,	"CLOCK_BOOTTIME"	},	\
+		{ CLOCK_TAI,		"CLOCK_TAI"		})
+
+#define decode_hrtimer_mode(mode)					\
+	__print_symbolic(mode,						\
+		{ HRTIMER_MODE_ABS,		"ABS"		},	\
+		{ HRTIMER_MODE_REL,		"REL"		},	\
+		{ HRTIMER_MODE_ABS_PINNED,	"ABS|PINNED"	},	\
+		{ HRTIMER_MODE_REL_PINNED,	"REL|PINNED"	},	\
+		{ HRTIMER_MODE_ABS_SOFT,	"ABS|SOFT"	},	\
+		{ HRTIMER_MODE_REL_SOFT,	"REL|SOFT"	},	\
+		{ HRTIMER_MODE_ABS_PINNED_SOFT,	"ABS|PINNED|SOFT" },	\
+		{ HRTIMER_MODE_REL_PINNED_SOFT,	"REL|PINNED|SOFT" })
+
 /**
  * hrtimer_init - called when the hrtimer is initialized
  * @hrtimer:	pointer to struct hrtimer
@@ -162,10 +180,8 @@ TRACE_EVENT(hrtimer_init,
 	),
 
 	TP_printk("hrtimer=%p clockid=%s mode=%s", __entry->hrtimer,
-		  __entry->clockid == CLOCK_REALTIME ?
-			"CLOCK_REALTIME" : "CLOCK_MONOTONIC",
-		  __entry->mode == HRTIMER_MODE_ABS ?
-			"HRTIMER_MODE_ABS" : "HRTIMER_MODE_REL")
+		  decode_clockid(__entry->clockid),
+		  decode_hrtimer_mode(__entry->mode))
 );
 
 /**
@@ -174,15 +190,16 @@ TRACE_EVENT(hrtimer_init,
  */
 TRACE_EVENT(hrtimer_start,
 
-	TP_PROTO(struct hrtimer *hrtimer),
+	TP_PROTO(struct hrtimer *hrtimer, enum hrtimer_mode mode),
 
-	TP_ARGS(hrtimer),
+	TP_ARGS(hrtimer, mode),
 
 	TP_STRUCT__entry(
 		__field( void *,	hrtimer		)
 		__field( void *,	function	)
 		__field( s64,		expires		)
 		__field( s64,		softexpires	)
+		__field( enum hrtimer_mode,	mode	)
 	),
 
 	TP_fast_assign(
@@ -190,12 +207,14 @@ TRACE_EVENT(hrtimer_start,
 		__entry->function	= hrtimer->function;
 		__entry->expires	= hrtimer_get_expires(hrtimer);
 		__entry->softexpires	= hrtimer_get_softexpires(hrtimer);
+		__entry->mode		= mode;
 	),
 
-	TP_printk("hrtimer=%p function=%pf expires=%llu softexpires=%llu",
-		  __entry->hrtimer, __entry->function,
+	TP_printk("hrtimer=%p function=%pf expires=%llu softexpires=%llu "
+		  "mode=%s", __entry->hrtimer, __entry->function,
 		  (unsigned long long) __entry->expires,
-		  (unsigned long long) __entry->softexpires)
+		  (unsigned long long) __entry->softexpires,
+		  decode_hrtimer_mode(__entry->mode))
 );
 
 /**
kernel/time/hrtimer.c +422 -235

1,063 lines not on this page · raw message

kernel/time/posix-clock.c +1 -1
index 17cdc554c9fe..cc91d90abd84 100644
@@ -216,7 +216,7 @@ struct posix_clock_desc {
 
 static int get_clock_desc(const clockid_t id, struct posix_clock_desc *cd)
 {
-	struct file *fp = fget(CLOCKID_TO_FD(id));
+	struct file *fp = fget(clockid_to_fd(id));
 	int err = -EINVAL;
 
 	if (!fp)
kernel/time/posix-cpu-timers.c +3 -4
index 1f27887aa194..ec9f5da6f163 100644
@@ -1189,9 +1189,8 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
 	u64 now;
 
 	WARN_ON_ONCE(clock_idx == CPUCLOCK_SCHED);
-	cpu_timer_sample_group(clock_idx, tsk, &now);
 
-	if (oldval) {
+	if (oldval && cpu_timer_sample_group(clock_idx, tsk, &now) != -EINVAL) {
 		/*
 		 * We are setting itimer. The *oldval is absolute and we update
 		 * it to be relative, *newval argument is relative and we update
@@ -1363,8 +1362,8 @@ static long posix_cpu_nsleep_restart(struct restart_block *restart_block)
 	return do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t);
 }
 
-#define PROCESS_CLOCK	MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED)
-#define THREAD_CLOCK	MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED)
+#define PROCESS_CLOCK	make_process_cpuclock(0, CPUCLOCK_SCHED)
+#define THREAD_CLOCK	make_thread_cpuclock(0, CPUCLOCK_SCHED)
 
 static int process_cpu_clock_getres(const clockid_t which_clock,
 				    struct timespec64 *tp)
kernel/time/tick-internal.h +6 -7
index f8e1845aa464..e277284c2831 100644
@@ -150,16 +150,15 @@ static inline void tick_nohz_init(void) { }
 
 #ifdef CONFIG_NO_HZ_COMMON
 extern unsigned long tick_nohz_active;
-#else
+extern void timers_update_nohz(void);
+# ifdef CONFIG_SMP
+extern struct static_key_false timers_migration_enabled;
+# endif
+#else /* CONFIG_NO_HZ_COMMON */
+static inline void timers_update_nohz(void) { }
 #define tick_nohz_active (0)
 #endif
 
-#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
-extern void timers_update_migration(bool update_nohz);
-#else
-static inline void timers_update_migration(bool update_nohz) { }
-#endif
-
 DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
 
 extern u64 get_next_timer_interrupt(unsigned long basej, u64 basem);
kernel/time/tick-sched.c +1 -1
index f7cc7abfcf25..29a5733eff83 100644
@@ -1107,7 +1107,7 @@ static inline void tick_nohz_activate(struct tick_sched *ts, int mode)
 	ts->nohz_mode = mode;
 	/* One update is enough */
 	if (!test_and_set_bit(0, &tick_nohz_active))
-		timers_update_migration(true);
+		timers_update_nohz();
 }
 
 /**
kernel/time/timer.c +49 -41

146 lines not on this page · raw message

sound/drivers/dummy.c +12 -15
index 7b2b1f766b00..6ad2ff57833d 100644
@@ -375,17 +375,9 @@ struct dummy_hrtimer_pcm {
 	ktime_t period_time;
 	atomic_t running;
 	struct hrtimer timer;
-	struct tasklet_struct tasklet;
 	struct snd_pcm_substream *substream;
 };
 
-static void dummy_hrtimer_pcm_elapsed(unsigned long priv)
-{
-	struct dummy_hrtimer_pcm *dpcm = (struct dummy_hrtimer_pcm *)priv;
-	if (atomic_read(&dpcm->running))
-		snd_pcm_period_elapsed(dpcm->substream);
-}
-
 static enum hrtimer_restart dummy_hrtimer_callback(struct hrtimer *timer)
 {
 	struct dummy_hrtimer_pcm *dpcm;
@@ -393,7 +385,14 @@ static enum hrtimer_restart dummy_hrtimer_callback(struct hrtimer *timer)
 	dpcm = container_of(timer, struct dummy_hrtimer_pcm, timer);
 	if (!atomic_read(&dpcm->running))
 		return HRTIMER_NORESTART;
-	tasklet_schedule(&dpcm->tasklet);
+	/*
+	 * In cases of XRUN and draining, this calls .trigger to stop PCM
+	 * substream.
+	 */
+	snd_pcm_period_elapsed(dpcm->substream);
+	if (!atomic_read(&dpcm->running))
+		return HRTIMER_NORESTART;
+
 	hrtimer_forward_now(timer, dpcm->period_time);
 	return HRTIMER_RESTART;
 }
@@ -403,7 +402,7 @@ static int dummy_hrtimer_start(struct snd_pcm_substream *substream)
 	struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data;
 
 	dpcm->base_time = hrtimer_cb_get_time(&dpcm->timer);
-	hrtimer_start(&dpcm->timer, dpcm->period_time, HRTIMER_MODE_REL);
+	hrtimer_start(&dpcm->timer, dpcm->period_time, HRTIMER_MODE_REL_SOFT);
 	atomic_set(&dpcm->running, 1);
 	return 0;
 }
@@ -413,14 +412,14 @@ static int dummy_hrtimer_stop(struct snd_pcm_substream *substream)
 	struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data;
 
 	atomic_set(&dpcm->running, 0);
-	hrtimer_cancel(&dpcm->timer);
+	if (!hrtimer_callback_running(&dpcm->timer))
+		hrtimer_cancel(&dpcm->timer);
 	return 0;
 }
 
 static inline void dummy_hrtimer_sync(struct dummy_hrtimer_pcm *dpcm)
 {
 	hrtimer_cancel(&dpcm->timer);
-	tasklet_kill(&dpcm->tasklet);
 }
 
 static snd_pcm_uframes_t
@@ -465,12 +464,10 @@ static int dummy_hrtimer_create(struct snd_pcm_substream *substream)
 	if (!dpcm)
 		return -ENOMEM;
 	substream->runtime->private_data = dpcm;
-	hrtimer_init(&dpcm->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+	hrtimer_init(&dpcm->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
 	dpcm->timer.function = dummy_hrtimer_callback;
 	dpcm->substream = substream;
 	atomic_set(&dpcm->running, 0);
-	tasklet_init(&dpcm->tasklet, dummy_hrtimer_pcm_elapsed,
-		     (unsigned long)dpcm);
 	return 0;
 }
 
tools/testing/selftests/ptp/testptp.c +1 -3
index 5d2eae16f7ee..a5d8f0ab0da0 100644
@@ -60,9 +60,7 @@ static int clock_adjtime(clockid_t id, struct timex *tx)
 static clockid_t get_clockid(int fd)
 {
 #define CLOCKFD 3
-#define FD_TO_CLOCKID(fd)	((~(clockid_t) (fd) << 3) | CLOCKFD)
-
-	return FD_TO_CLOCKID(fd);
+	return (((unsigned int) ~fd) << 3) | CLOCKFD;
 }
 
 static void handle_alarm(int s)
#1 lore raw
Quoted 4 lines · Thomas Gleixner

- A rather large rework of the hrtimer infrastructure which introduces softirq based hrtimers to replace the spread of hrtimer/tasklet combos which force the actual callback execution into softirq context.

I really would have liked to see more of the rationale for this - now I'm left with just two example drivers, and a "you'll see the cleanups this allows in future driver pulls".

But pulled, since the code doesn't look disgusting.

Linus

maintainer
#2 lore raw
Quoted 11 lines · Linus Torvalds
Quoted 4 lines · Thomas Gleixner

- A rather large rework of the hrtimer infrastructure which introduces softirq based hrtimers to replace the spread of hrtimer/tasklet combos which force the actual callback execution into softirq context.

I really would have liked to see more of the rationale for this - now I'm left with just two example drivers, and a "you'll see the cleanups this allows in future driver pulls".

But pulled, since the code doesn't look disgusting.

Sorry, this is my fault: from Anna-Maria's original, full softirq-hrtimers series I didn't apply many of the usecases, because we didn't get any review feedback from the networking folks:

can/bcm: Replace hrtimer_tasklet with softirq based hrtimer

   net/can/bcm.c | 156 ++++++++++++++++++++--------------------------------------
   1 file changed, 52 insertions(+), 104 deletions(-)

mac80211_hwsim: Replace hrtimer tasklet with softirq hrtimer

   drivers/net/wireless/mac80211_hwsim.c | 44 ++++++++++++++++-------------------
   1 file changed, 20 insertions(+), 24 deletions(-)

xfrm: Replace hrtimer tasklet with softirq hrtimer

   include/net/xfrm.h    |  2 +-
   net/xfrm/xfrm_state.c | 30 ++++++++++++++++++------------
   2 files changed, 19 insertions(+), 13 deletions(-)

net/mvpp2: Replace tasklet with softirq hrtimer

   drivers/net/ethernet/marvell/mvpp2.c | 62 +++++++++++++++---------------------
   1 file changed, 25 insertions(+), 37 deletions(-)

And I felt uneasy about applying this in one go, so we decided to apply it in two phases.

These are in cases significant driver simplifications, but they also enable the real deal, the elimination of the hrtimer tasklet:

softirq: Remove tasklet_hrtimer

   include/linux/interrupt.h | 25 -----------------------
   kernel/softirq.c          | 51 -----------------------------------------------
   2 files changed, 76 deletions(-)

... which is a pretty nice thing in itself even without the driver simplifications!

Plus the _real_ secret motivation behind it all is the -rt kernel and CONFIG_PREEMPT_RT=y and the ability to push most of the hrtimer processing into softirq context - while it still keeps the main hrtimer machinery capable to run in hard-RT hardirq domain. Turns out it was possible to implement this duality via the softirq-hrtimers, with a good chunk of benefits to non-rt upstream as well.

Thanks,

Ingo

#3 lore raw
Quoted 10 lines · Ingo Molnar

These are in cases significant driver simplifications, but they also enable the real deal, the elimination of the hrtimer tasklet:

softirq: Remove tasklet_hrtimer

   include/linux/interrupt.h | 25 -----------------------
   kernel/softirq.c          | 51 -----------------------------------------------
   2 files changed, 76 deletions(-)
Quoted 8 lines

... which is a pretty nice thing in itself even without the driver simplifications!

Plus the _real_ secret motivation behind it all is the -rt kernel and CONFIG_PREEMPT_RT=y and the ability to push most of the hrtimer processing into softirq context - while it still keeps the main hrtimer machinery capable to run in hard-RT hardirq domain. Turns out it was possible to implement this duality via the softirq-hrtimers, with a good chunk of benefits to non-rt upstream as well.

So this is the kind of explanation that I would have liked in the "please pull" (and that would have been great in the merge message). Explaining not just the "what", but very much the "why".

Anyway, it's obviously pulled regardless, and I'm just pointing this out for "maybe next time".

Linus

#4 lore raw
Quoted 20 lines · Linus Torvalds
Quoted 10 lines · Ingo Molnar

These are in cases significant driver simplifications, but they also enable the real deal, the elimination of the hrtimer tasklet:

softirq: Remove tasklet_hrtimer

   include/linux/interrupt.h | 25 -----------------------
   kernel/softirq.c          | 51 -----------------------------------------------
   2 files changed, 76 deletions(-)
Quoted 8 lines

... which is a pretty nice thing in itself even without the driver simplifications!

Plus the _real_ secret motivation behind it all is the -rt kernel and CONFIG_PREEMPT_RT=y and the ability to push most of the hrtimer processing into softirq context - while it still keeps the main hrtimer machinery capable to run in hard-RT hardirq domain. Turns out it was possible to implement this duality via the softirq-hrtimers, with a good chunk of benefits to non-rt upstream as well.

Quoted 6 lines

So this is the kind of explanation that I would have liked in the "please pull" (and that would have been great in the merge message). Explaining not just the "what", but very much the "why".

Anyway, it's obviously pulled regardless, and I'm just pointing this out for "maybe next time".

Sorry about that. I usually try to be descriptive and will do so next time again.

Thanks,

tglx

maintainer
#5 lore raw
In reply to Linus Torvalds
Quoted 20 lines · Linus Torvalds
Quoted 10 lines · Ingo Molnar

These are in cases significant driver simplifications, but they also enable the real deal, the elimination of the hrtimer tasklet:

softirq: Remove tasklet_hrtimer

   include/linux/interrupt.h | 25 -----------------------
   kernel/softirq.c          | 51 -----------------------------------------------
   2 files changed, 76 deletions(-)
Quoted 8 lines

... which is a pretty nice thing in itself even without the driver simplifications!

Plus the _real_ secret motivation behind it all is the -rt kernel and CONFIG_PREEMPT_RT=y and the ability to push most of the hrtimer processing into softirq context - while it still keeps the main hrtimer machinery capable to run in hard-RT hardirq domain. Turns out it was possible to implement this duality via the softirq-hrtimers, with a good chunk of benefits to non-rt upstream as well.

Quoted 6 lines

So this is the kind of explanation that I would have liked in the "please pull" (and that would have been great in the merge message). Explaining not just the "what", but very much the "why".

Anyway, it's obviously pulled regardless, and I'm just pointing this out for "maybe next time".

Yeah, and there will be a next time: we'll apply those those networking code simplifications and the tasklet removal for the v4.17 merge window, and include the full description in that pull request.

That cannot retroactively make it easier for you to apply the first batch of patches, but at least we'll have the meta description in the next merge commit and it will be part of the v4.17 Git history.

Thanks,

Ingo