Various fixes for the stable RT series - part I
Subsystems (5)
cover Various fixes for the stable RT series - part I
The following patch series is a collection of bug fixes, which should go into the 3.x based stable RT trees.
I have them locally applied to my 3.5 devel queue, but I'm still distracted by other events (leap seconds and the like) to get a 3.5 devel queue released.
Steven, please pick up the lot.
I have a part II series pending which is addressing the widely observed CPU hotplug issue. I'm going to send that out soon, despite the fact that I fundamentaly hate it. Though the hotplug rework which I have in the queue has turned out to be more work than expected and there is no real way to backport all of the necessary changes into any of the existing 3.x based RT trees. So I bite the bullet and go with the workarounds to get rid of the last obstacles in the 3.x based RT series.
Thanks,
tglx
PATCH 1/7 Latency histogramms: Cope with backwards running local trace clock
Thanks to the wonders of modern technology, the local trace clock can now run backwards. Since this never happened before, the time difference between now and somewhat earlier was expected to never become negative and, thus, stored in an unsigned integer variable. Nowadays, we need a signed integer to ensure that the value is stored as underflow in the related histogram. (In cases where this is not a misfunction, bipolar histograms can be used.)
This patch takes care that all latency variables are represented as signed integers and negative numbers are considered as histogram underflows.
In one of the misbehaving processors switching to global clock solved the problem:
echo global >/sys/kernel/debug/tracing/trace_clock
--- include/linux/sched.h | 2 +- kernel/trace/latency_hist.c | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-)
include/linux/sched.h +1 -1
@@ -1629,7 +1629,7 @@ struct task_struct {#ifdef CONFIG_WAKEUP_LATENCY_HIST u64 preempt_timestamp_hist;#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST -unsigned long timer_offset; +long timer_offset;#endif #endif #endif /* CONFIG_TRACING */
kernel/trace/latency_hist.c +37 -34
198 lines not on this page · raw message
PATCH 2/7 Latency histograms: Adjust timer, if already elapsed when programmed
In reply to Thomas GleixnerNothing prevents a programmer from calling clock_nanosleep() with an already elapsed wakeup time in absolute time mode or with a too small delay in relative time mode. Such timers cannot wake up in time and, thus, should be corrected when entered into the missed timers latency histogram (CONFIG_MISSED_TIMERS_HIST).
This patch marks such timers and uses a corrected expiration time.
--- include/linux/hrtimer.h | 3 +++ kernel/hrtimer.c | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-)
include/linux/hrtimer.h +3 -0
@@ -113,6 +113,9 @@ struct hrtimer {unsigned long state;struct list_head cb_entry;int irqsafe; +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST +ktime_t praecox; +#endif #ifdef CONFIG_TIMER_STATS int start_pid;void *start_site;
kernel/hrtimer.c +14 -2
@@ -1021,6 +1021,17 @@ int __hrtimer_start_range_ns(struct hrti#endif } +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST + { +ktime_t now = new_base->get_time (); + +if (ktime_to_ns (tim) <ktime_to_ns (now)) + timer->praecox = now; +else + timer->praecox =ktime_set (0 ,0 ); + } +#endif +hrtimer_set_expires_range_ns (timer, tim, delta_ns);timer_stats_hrtimer_set_start_info (timer);
@@ -1458,8 +1469,9 @@ retry: timer = container_of(node, struct hrtimer, node); trace_hrtimer_interrupt(raw_smp_processor_id(), - ktime_to_ns(ktime_sub( - hrtimer_get_expires(timer), basenow)), + ktime_to_ns(ktime_sub(ktime_to_ns(timer->praecox) ? + timer->praecox : hrtimer_get_expires(timer), + basenow)), current, timer->function == hrtimer_wakeup ? container_of(timer, struct hrtimer_sleeper,
PATCH 3/7 Disable RT_GROUP_SCHED in PREEMPT_RT_FULL
In reply to Thomas GleixnerStrange CPU stalls have been observed in RT when RT_GROUP_SCHED was configured.
Disable it for now.
--- init/Kconfig | 1 + 1 file changed, 1 insertion(+)
init/Kconfig +1 -0
@@ -746,6 +746,7 @@ config RT_GROUP_SCHED bool "Group scheduling for SCHED_RR/FIFO" depends on EXPERIMENTAL depends on CGROUP_SCHED + depends on !PREEMPT_RT_FULL default n help This feature lets you explicitly allocate real CPU bandwidth
PATCH 4/7 Latency histograms: Detect another yet overlooked sharedprio condition
In reply to Thomas GleixnerWhile waiting for an RT process to be woken up, the previous process may go to wait and switch to another one with the same priority which then becomes current. This condition was not correctly recognized and led to erroneously high latency recordings during periods of low CPU load.
This patch correctly marks such latencies as sharedprio and prevents them from being recorded as actual system latency.
--- kernel/trace/latency_hist.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/latency_hist.c +3 -0
@@ -935,6 +935,9 @@ static notrace void probe_wakeup_latency goto out; } +if (current->prio == cpu_wakeup_task->prio) +per_cpu (wakeup_sharedprio, cpu) =1 ; +/* * The task we are waiting for is about to be switched to. * Calculate latency and store it in histogram.
PATCH 5/7 slab: Prevent local lock deadlock
In reply to Thomas GleixnerOn RT we avoid the cross cpu function calls and take the per cpu local locks instead. Now the code missed that taking the local lock on the cpu which runs the code must use the proper local lock functions and not a simple spin_lock(). Otherwise it deadlocks later when trying to acquire the local lock with the proper function.
--- mm/slab.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
mm/slab.c +22 -4
@@ -743,8 +743,26 @@ slab_on_each_cpu(void (*func)(void *arg, {unsigned int i; +get_cpu_light ();for_each_online_cpu (i)func (arg, i); +put_cpu_light (); +} + +static void lock_slab_on (unsigned int cpu) +{ +if (cpu ==smp_processor_id ()) +local_lock_irq (slab_lock); +else +local_spin_lock_irq (slab_lock, &per_cpu (slab_lock, cpu).lock); +} + +static void unlock_slab_on (unsigned int cpu) +{ +if (cpu ==smp_processor_id ()) +local_unlock_irq (slab_lock); +else +local_spin_unlock_irq (slab_lock, &per_cpu (slab_lock, cpu).lock); }#endif
@@ -2692,10 +2710,10 @@ static void do_drain(void *arg, int cpu) {LIST_HEAD (tmp); -spin_lock_irq (&per_cpu (slab_lock, cpu).lock); +lock_slab_on (cpu);__do_drain (arg, cpu);list_splice_init (&per_cpu (slab_free_list, cpu), &tmp); -spin_unlock_irq (&per_cpu (slab_lock, cpu).lock); +unlock_slab_on (cpu);free_delayed (&tmp); }#endif
@@ -4163,9 +4181,9 @@ static void do_ccupdate_local(void *info#else static void do_ccupdate_local (void *info,int cpu) { -spin_lock_irq (&per_cpu (slab_lock, cpu).lock); +lock_slab_on (cpu);__do_ccupdate_local (info, cpu); -spin_unlock_irq (&per_cpu (slab_lock, cpu).lock); +unlock_slab_on (cpu); }#endif
PATCH 6/7 fs, jbd: pull your plug when waiting for space
In reply to Thomas GleixnerWith an -rt kernel, and a heavy sync IO load, tasks can jam up on journal locks without unplugging, which can lead to terminal IO starvation. Unplug and schedule when waiting for space.
--- fs/jbd/checkpoint.c | 2 ++ 1 file changed, 2 insertions(+)
fs/jbd/checkpoint.c +2 -0
@@ -129,6 +129,8 @@ void __log_wait_for_space(journal_t *jouif (journal->j_flags &JFS_ABORT )return ;spin_unlock (&journal->j_state_lock); +if (current->plug) +io_schedule ();mutex_lock (&journal->j_checkpoint_mutex);/*
PATCH 7/7 perf: Make swevent hrtimer run in irq instead of softirq
In reply to Thomas GleixnerFrom: Yong Zhang <[email protected]>
Otherwise we get a deadlock like below:
[ 1044.042749] BUG: scheduling while atomic: ksoftirqd/21/141/0x00010003 [ 1044.042752] INFO: lockdep is turned off. [ 1044.042754] Modules linked in: [ 1044.042757] Pid: 141, comm: ksoftirqd/21 Tainted: G W 3.4.0-rc2-rt3-23676-ga723175-dirty #29 [ 1044.042759] Call Trace: [ 1044.042761] <IRQ> [<ffffffff8107d8e5>] __schedule_bug+0x65/0x80 [ 1044.042770] [<ffffffff8168978c>] __schedule+0x83c/0xa70 [ 1044.042775] [<ffffffff8106bdd2>] ? prepare_to_wait+0x32/0xb0 [ 1044.042779] [<ffffffff81689a5e>] schedule+0x2e/0xa0 [ 1044.042782] [<ffffffff81071ebd>] hrtimer_wait_for_timer+0x6d/0xb0 [ 1044.042786] [<ffffffff8106bb30>] ? wake_up_bit+0x40/0x40 [ 1044.042790] [<ffffffff81071f20>] hrtimer_cancel+0x20/0x40 [ 1044.042794] [<ffffffff8111da0c>] perf_swevent_cancel_hrtimer+0x3c/0x50 [ 1044.042798] [<ffffffff8111da31>] task_clock_event_stop+0x11/0x40 [ 1044.042802] [<ffffffff8111da6e>] task_clock_event_del+0xe/0x10 [ 1044.042805] [<ffffffff8111c568>] event_sched_out+0x118/0x1d0 [ 1044.042809] [<ffffffff8111c649>] group_sched_out+0x29/0x90 [ 1044.042813] [<ffffffff8111ed7e>] __perf_event_disable+0x18e/0x200 [ 1044.042817] [<ffffffff8111c343>] remote_function+0x63/0x70 [ 1044.042821] [<ffffffff810b0aae>] generic_smp_call_function_single_interrupt+0xce/0x120 [ 1044.042826] [<ffffffff81022bc7>] smp_call_function_single_interrupt+0x27/0x40 [ 1044.042831] [<ffffffff8168d50c>] call_function_single_interrupt+0x6c/0x80 [ 1044.042833] <EOI> [<ffffffff811275b0>] ? perf_event_overflow+0x20/0x20 [ 1044.042840] [<ffffffff8168b970>] ? _raw_spin_unlock_irq+0x30/0x70 [ 1044.042844] [<ffffffff8168b976>] ? _raw_spin_unlock_irq+0x36/0x70 [ 1044.042848] [<ffffffff810702e2>] run_hrtimer_softirq+0xc2/0x200 [ 1044.042853] [<ffffffff811275b0>] ? perf_event_overflow+0x20/0x20 [ 1044.042857] [<ffffffff81045265>] __do_softirq_common+0xf5/0x3a0 [ 1044.042862] [<ffffffff81045c3d>] __thread_do_softirq+0x15d/0x200 [ 1044.042865] [<ffffffff81045dda>] run_ksoftirqd+0xfa/0x210 [ 1044.042869] [<ffffffff81045ce0>] ? __thread_do_softirq+0x200/0x200 [ 1044.042873] [<ffffffff81045ce0>] ? __thread_do_softirq+0x200/0x200 [ 1044.042877] [<ffffffff8106b596>] kthread+0xb6/0xc0 [ 1044.042881] [<ffffffff8168b97b>] ? _raw_spin_unlock_irq+0x3b/0x70 [ 1044.042886] [<ffffffff8168d994>] kernel_thread_helper+0x4/0x10 [ 1044.042889] [<ffffffff8107d98c>] ? finish_task_switch+0x8c/0x110 [ 1044.042894] [<ffffffff8168b97b>] ? _raw_spin_unlock_irq+0x3b/0x70 [ 1044.042897] [<ffffffff8168bd5d>] ? retint_restore_args+0xe/0xe [ 1044.042900] [<ffffffff8106b4e0>] ? kthreadd+0x1e0/0x1e0 [ 1044.042902] [<ffffffff8168d990>] ? gs_change+0xb/0xb
--- kernel/events/core.c | 1 + 1 file changed, 1 insertion(+)
kernel/events/core.c +1 -0
@@ -5403,6 +5403,7 @@ static void perf_swevent_init_hrtimer(sthrtimer_init (&hwc->hrtimer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); hwc->hrtimer.function = perf_swevent_hrtimer; + hwc->hrtimer.irqsafe =1 ;/* * Since hrtimers have a fixed rate, we can do a static freq->period
Steven Rostedt
maintainerQuoted 9 lines · Thomas Gleixner
The following patch series is a collection of bug fixes, which should go into the 3.x based stable RT trees.
I have them locally applied to my 3.5 devel queue, but I'm still distracted by other events (leap seconds and the like) to get a 3.5 devel queue released.
Steven, please pick up the lot.
Quoted 8 lines
I have a part II series pending which is addressing the widely observed CPU hotplug issue. I'm going to send that out soon, despite the fact that I fundamentaly hate it. Though the hotplug rework which I have in the queue has turned out to be more work than expected and there is no real way to backport all of the necessary changes into any of the existing 3.x based RT trees. So I bite the bullet and go with the workarounds to get rid of the last obstacles in the 3.x based RT series.
I'll pull these in and start running my tests. I noticed that some of them are Signed-off-by Carsten first. Did he author them? If so, I'll make it so his name gets the git author.
Same for Mike Galbraith on patch 6. Only patch 7 has a 'From:' tag.
-- Steve
Re: [patch RT 3/7] Disable RT_GROUP_SCHED in PREEMPT_RT_FULL
In reply to Thomas GleixnerQuoted 24 lines · Thomas Gleixner
plain text document attachment (disable-rt_group_sched-in-preempt_rt_full.patch) Strange CPU stalls have been observed in RT when
RT_GROUP_SCHEDwas configured.Disable it for now.
Signed-off-by Carsten Emde <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>--- init/Kconfig | 1 + 1 file changed, 1 insertion(+)Index: linux-3.4.4-rt13-64+/init/Kconfig
===================================================================
init/Kconfig config RT_GROUP_SCHED · line 752
Quoted 7 lines
init/Kconfig +1
-0@@ -746,6 +746,7 @@ config RT_GROUP_SCHED bool "Group scheduling for SCHED_RR/FIFO" depends on EXPERIMENTAL depends on CGROUP_SCHED + depends on !PREEMPT_RT_FULL default n help This feature lets you explicitly allocate real CPU bandwidth
I turn the thing off because it doesn't make any sense to me for -rt, and because it's busted. The below works around isolation bustage I encountered. Peter didn't like it (what's to like?) but it saves the day, so shall live on in non-rt kernels until I hopefully someday see RT_GROUP_SCHED being fed into a Bitwolf-9000 ;-)
sched,rt: fix isolated CPUs leaving root_task_group indefinitely throttled
Root task group bandwidth replentishment must service all CPUs regardless of where it was last started.
--- kernel/sched/rt.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
kernel/sched/rt.c +13 -0
@@ -782,6 +782,19 @@ static int do_sched_rt_period_timer(struconst struct cpumask *span; span =sched_rt_period_mask (); +#ifdef CONFIG_RT_GROUP_SCHED +/* +* FIXME: isolated CPUs should really leave the root task group, +* whether they are isolcpus or were isolated via cpusets, lest +* the timer run on a CPU which does not service all runqueues, +* potentially leaving other CPUs indefinitely throttled. If +* isolation is really required, the user will turn the throttle +* off to kill the perturbations it causes anyway. Meanwhile, +* this maintains functionallity for boot and/or troubleshooting. +*/ +if (rt_b == &root_task_group.rt_bandwidth) + span = cpu_online_mask; +#endif for_each_cpu (i, span) {int enqueue =0 ;struct rt_rq *rt_rq =sched_rt_period_rt_rq (rt_b, i);
Quoted 19 lines · Steven Rostedt
Quoted 9 lines · Thomas Gleixner
The following patch series is a collection of bug fixes, which should go into the 3.x based stable RT trees.
I have them locally applied to my 3.5 devel queue, but I'm still distracted by other events (leap seconds and the like) to get a 3.5 devel queue released.
Steven, please pick up the lot.
Quoted 8 lines
I have a part II series pending which is addressing the widely observed CPU hotplug issue. I'm going to send that out soon, despite the fact that I fundamentaly hate it. Though the hotplug rework which I have in the queue has turned out to be more work than expected and there is no real way to backport all of the necessary changes into any of the existing 3.x based RT trees. So I bite the bullet and go with the workarounds to get rid of the last obstacles in the 3.x based RT series.
Quoted 5 lines
I'll pull these in and start running my tests. I noticed that some of them are Signed-off-by Carsten first. Did he author them? If so, I'll make it so his name gets the git author.
Same for Mike Galbraith on patch 6. Only patch 7 has a 'From:' tag.
Gah. Forgot to add the From lines. 1-4 are from Carsten, 5 is mine, 6 is Mike and 7 is Yong.
Thanks,
tglx