Skip to content

hrtimer/tick: Optimizations, cleanups and solutions for various issues

Thomas Gleixner alsa-devel linux-pm lkml netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest38 of 39 patches 22 repliesIn review

38 of 39 patches are in this archive. The cover letter announces 39.

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/39hrtimer: Update active_bases before calling hrtimer_force_reprogram()kernel/time/hrtimer.c+3 -20 replies
2/39hrtimer: Get rid of the resolution field in hrtimer_clock_baseinclude/linux/hrtimer.h kernel/time/hrtimer.c kernel/time/timer_list.c+17 -233 replies
3/39net: sched: Use hrtimer_resolution instead of hrtimer_get_res()net/sched/sch_api.c+1 -41 reply
4/39sound: Use hrtimer_resolution instead of hrtimer_get_res()sound/core/hrtimer.c sound/drivers/pcsp/pcsp.c+7 -172 replies
5/39hrtimer: Get rid of hrtimer_get_res()include/linux/hrtimer.h kernel/time/alarmtimer.c kernel/time/hrtimer.c +1 more+15 -250 replies
6/39hrtimer: Make the statistics fields smallerinclude/linux/hrtimer.h kernel/time/hrtimer.c kernel/time/timer_list.c+7 -70 replies
7/39hrtimer: Get rid of softirq timeinclude/linux/hrtimer.h kernel/time/hrtimer.c kernel/time/timekeeping.c +1 more+64 -1430 replies
8/39hrtimer: Make offset update smarterinclude/linux/hrtimer.h include/linux/timekeeper_internal.h kernel/time/hrtimer.c +2 more+26 -131 reply
9/39hrtimer: Use a bits for various boolean indicatorsinclude/linux/hrtimer.h kernel/time/hrtimer.c+19 -110 replies
10/39hrtimer: Use cpu_base->active_base for hotpath iteratorskernel/time/hrtimer.c+8 -93 replies
11/39hrtimer: Cache line align the hrtimer cpu baseinclude/linux/hrtimer.h+1 -10 replies
12/39hrtimer: Align the hrtimer clock bases as wellinclude/linux/hrtimer.h+9 -10 replies
13/39timerqueue: Let timerqueue_add/del return informationinclude/linux/timerqueue.h lib/timerqueue.c+11 -70 replies
14/39hrtimer: Make use of timerqueue_add/del return valueskernel/time/hrtimer.c+2 -40 replies
15/39hrtimer: Keep pointer to first timer and simplify __remove_hrtimer()include/linux/hrtimer.h kernel/time/hrtimer.c+34 -180 replies
16/39hrtimer: Get rid of hrtimer softirqinclude/linux/hrtimer.h include/linux/interrupt.h include/trace/events/irq.h +3 more+44 -1260 replies
17/39tick: sched: Remove hrtimer_active() checkskernel/time/tick-sched.c+4 -151 reply
18/39tick: sched: Force tick interrupt and get rid of softirq magickernel/time/tick-sched.c+29 -545 replies
19/39tick: sched: Restructure codekernel/time/tick-sched.c+82 -910 replies
20/39tick: nohz: Rework next timer evaluationinclude/linux/hrtimer.h include/linux/rcupdate.h include/linux/rcutree.h +8 more+107 -1262 replies
21/39x86: perf: Use hrtimer_start()arch/x86/kernel/cpu/perf_event_intel_rapl.c+2 -30 replies
22/39x86: perf: uncore: Use hrtimer_start()arch/x86/kernel/cpu/perf_event_intel_uncore.c+2 -30 replies
23/39perf: core: Use hrtimer_start()kernel/events/core.c+3 -60 replies
24/39sched: core: Use hrtimer_start[_expires]()kernel/sched/core.c kernel/sched/fair.c+9 -210 replies
25/39sched: deadline: Use hrtimer_start()kernel/sched/deadline.c+2 -100 replies
26/39hrtimer: Get rid of __hrtimer_start_range_ns()include/linux/hrtimer.h kernel/time/hrtimer.c+15 -270 replies
27/39hrtimer: Make hrtimer_start() a inline wrapperinclude/linux/hrtimer.h kernel/time/hrtimer.c+17 -210 replies
28/39hrtimer: Remove bogus hrtimer_active() checkkernel/time/hrtimer.c+0 -40 replies
29/39hrtimer: Rmove bogus hrtimer_active() checkkernel/futex.c+1 -40 replies
30/39rtmutex: Remove bogus hrtimer_active() checkkernel/locking/rtmutex.c+1 -40 replies
31/39net: core: pktgen: Remove bogus hrtimer_active() checknet/core/pktgen.c+0 -21 reply
32/39alarmtimer: Get rid of unused return valueinclude/linux/alarmtimer.h kernel/time/alarmtimer.c+6 -90 replies
34/39tick: broadcast-hrtimer: Remove overly clever return value abusekernel/time/tick-broadcast-hrtimer.c+5 -31 reply
35/39hrtimer: Remove hrtimer_start() return valueinclude/linux/hrtimer.h include/linux/interrupt.h kernel/time/hrtimer.c+19 -320 replies
36/39hrtimer: Avoid locking in hrtimer_cancel() if timer not activekernel/time/hrtimer.c+9 -00 replies
37/39staging: ozwpan: Remove hrtimer_active() checkdrivers/staging/ozwpan/ozpd.c+3 -50 replies
38/39timer: Remove pointless return value of do_usleep_range()kernel/time/timer.c+2 -20 replies
39/39timer: Put usleep_range into the __sched sectionkernel/time/timer.c+1 -10 replies

Reviews trailers per patch

9 of 38 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchPreeti U MurthyFrans KlaverTakashi IwaiFrederic WeisbeckerDavid S. Miller
SeriesA-b
1/39R-b
2/39R-b
3/39A-b
4/39A-b
5/39
6/39
7/39
8/39R-b
9/39
10/39R-b
11/39
12/39
13/39
14/39
15/39
16/39
17/39R-b
18/39
19/39
20/39
21/39
22/39
23/39
24/39
25/39
26/39
27/39
28/39
29/39
30/39
31/39A-b
32/39
34/39R-b
35/39
36/39
37/39
38/39
39/39

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v1 thread

Cover letter [patch 00/39] hrtimer/tick: Optimizations, cleanups and solutions for various issues

When I returned from my break I got offended by a pile of patches which kill the patient with the cure.

The issues at hand:

- NOHZ: Get rid of the softirq invocation

- hrtimer: Use the active_bases field in order to avoid evaluating inactive bases

- hrtimer: Cache footprint issues

Aside of that Peter and I were discussing for a long time to get rid of the hrtimer softirq.

After staring at all of it for quite some time it occured to me that all issues are related in one way or the other. So I sat down and reworked the code in various ways:

- Reduce the data size, so the hrtimer clock bases can be made cache line aligned.

- Consolidate everything on the high resolution timer implementation and get rid of dubious optimizations for the non highres case which bloat code and data.

- Implement the active_bases mechanism proper and avoid touching inactive hrtimer clock bases. This includes a conditional update mechanism for the hrtimer clock offsets to update them only when they changed, which they do seldom enough instead of polluting 4 cache lines in every tick/hrtimer interrupt.

- Get rid of the softirq deferment and simply enforce a hrtimer interrupt when the timer was already expired. This allows to remove the ugly __hrtimer_start_range_ns() interface and to cleanup the usage sites (sched/perf). As a consequence this also gets rid of the forward loops in the tick nohz code.

- Analogous to the hrtimer enforcement, force a tick interrupt for NOHZ non highres systems when the forwarding code tries to fire an expired tick. This allows to get rid of the softirq invocation in the NOHZ code.

- A cleanup of the code which evaluates the next timer event: Use nsec based calculations instead of the jiffy magic. That makes it actually readable by some definition of readable.

- While doing the above I had to audit quite some usage sites of various hrtimer interfaces, which revealed some entertaining bugs. The fixes have been posted in a seperate series already. Some other bogosities have been removed as part of this series.

The total change size of this overhaul is:

   37 files changed, 515 insertions(+), 794 deletions(-)

The resulting text size of hrtimers.o shrinks in the range of 8-10% depending on the architecture.

The cache foot print of the hrtimer per cpu data shrinks as well.

    	  x8684	     i386   ARM	    ARM64   power64
Before:	  328	     248    280	    328	    328		Bytes
	    6	       4      5	      6	      6		cache lines (64byte)

After: 320 192 192 320 320 Bytes

	    5	       3      3	      5	      5		cache lines (64byte)

Note, that the new code avoids to touch the inactive clock bases which are now cache line aligned and therefor reduces the cache foot print in normal usage scenarios significantly.

I did some perf measurements on an isolated core running

- hrtimer centric workloads
- idle scenarios with periodic wakeups of various length

The patches reduce the number of instructions executed during the test runs between 2.5 and 6% depending on the scenario and the cache misses between 3 and 8%.

For your convenience this series is also available at:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/wip

Note: The branch is temporary and not meant to base other work on it.

Thanks,

tglx

---
 arch/x86/kernel/cpu/perf_event_intel_rapl.c   |    5 
 arch/x86/kernel/cpu/perf_event_intel_uncore.c |    5 
 drivers/power/reset/ltc2952-poweroff.c        |   18 
 drivers/staging/ozwpan/ozpd.c                 |    8 
 include/linux/alarmtimer.h                    |    4 
 include/linux/hrtimer.h                       |  101 ++---
 include/linux/interrupt.h                     |    7 
 include/linux/rcupdate.h                      |    6 
 include/linux/rcutree.h                       |    2 
 include/linux/timekeeper_internal.h           |    2 
 include/linux/timer.h                         |    7 
 include/linux/timerqueue.h                    |    8 
 include/trace/events/irq.h                    |    1 
 kernel/events/core.c                          |    9 
 kernel/futex.c                                |    5 
 kernel/locking/rtmutex.c                      |    5 
 kernel/rcu/tree_plugin.h                      |   14 
 kernel/sched/core.c                           |   28 -
 kernel/sched/deadline.c                       |   12 
 kernel/sched/fair.c                           |    2 
 kernel/softirq.c                              |    2 
 kernel/time/alarmtimer.c                      |   17 
 kernel/time/hrtimer.c                         |  525 +++++++++-----------------
 kernel/time/posix-timers.c                    |   17 
 kernel/time/tick-broadcast-hrtimer.c          |    8 
 kernel/time/tick-internal.h                   |    2 
 kernel/time/tick-sched.c                      |  288 +++++---------
 kernel/time/tick-sched.h                      |    2 
 kernel/time/timekeeping.c                     |   55 --
 kernel/time/timekeeping.h                     |   10 
 kernel/time/timer.c                           |   79 +--
 kernel/time/timer_list.c                      |   14 
 lib/timerqueue.c                              |   10 
 net/core/pktgen.c                             |    2 
 net/sched/sch_api.c                           |    5 
 sound/core/hrtimer.c                          |    9 
 sound/drivers/pcsp/pcsp.c                     |   15 
 37 files changed, 515 insertions(+), 794 deletions(-)