Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1607903 > unrolled thread
| Started by | Luiz Capitulino <lcapitulino@redhat.com> |
|---|---|
| First post | 2017-03-23 22:00 +0100 |
| Last post | 2017-03-30 03:50 +0200 |
| Articles | 14 on this page of 54 — 6 participants |
Back to article view | Back to linux.kernel
[BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-03-23 22:00 +0100
Re: [BUG nohz]: wrong user and system time accounting Rik van Riel <riel@redhat.com> - 2017-03-24 02:00 +0100
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-03-24 02:10 +0100
Re: [BUG nohz]: wrong user and system time accounting Rik van Riel <riel@redhat.com> - 2017-03-24 02:10 +0100
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-03-24 02:50 +0100
Re: [BUG nohz]: wrong user and system time accounting lkml@pengaru.com - 2017-03-27 07:40 +0200
Re: [BUG nohz]: wrong user and system time accounting Wanpeng Li <kernellwp@gmail.com> - 2017-03-24 03:00 +0100
Re: [BUG nohz]: wrong user and system time accounting Wanpeng Li <kernellwp@gmail.com> - 2017-03-27 04:00 +0200
Re: [BUG nohz]: wrong user and system time accounting Rik van Riel <riel@redhat.com> - 2017-03-27 19:40 +0200
Re: [BUG nohz]: wrong user and system time accounting Wanpeng Li <kernellwp@gmail.com> - 2017-03-28 09:30 +0200
Re: [BUG nohz]: wrong user and system time accounting Rik van Riel <riel@redhat.com> - 2017-03-28 23:10 +0200
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-03-28 23:30 +0200
Re: [BUG nohz]: wrong user and system time accounting Wanpeng Li <kernellwp@gmail.com> - 2017-03-29 12:00 +0200
Re: [BUG nohz]: wrong user and system time accounting Frederic Weisbecker <fweisbec@gmail.com> - 2017-03-29 15:00 +0200
Re: [BUG nohz]: wrong user and system time accounting Rik van Riel <riel@redhat.com> - 2017-03-28 23:30 +0200
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-03-28 23:40 +0200
Re: [BUG nohz]: wrong user and system time accounting Rik van Riel <riel@redhat.com> - 2017-03-29 22:20 +0200
Re: [BUG nohz]: wrong user and system time accounting Frederic Weisbecker <fweisbec@gmail.com> - 2017-03-30 01:00 +0200
Re: [BUG nohz]: wrong user and system time accounting Rik van Riel <riel@redhat.com> - 2017-03-30 15:00 +0200
Re: [BUG nohz]: wrong user and system time accounting Wanpeng Li <kernellwp@gmail.com> - 2017-03-30 04:00 +0200
Re: [BUG nohz]: wrong user and system time accounting Frederic Weisbecker <fweisbec@gmail.com> - 2017-03-30 14:50 +0200
Re: [BUG nohz]: wrong user and system time accounting Mike Galbraith <efault@gmx.de> - 2017-03-30 15:20 +0200
Re: [BUG nohz]: wrong user and system time accounting Mike Galbraith <efault@gmx.de> - 2017-03-30 06:30 +0200
Re: [BUG nohz]: wrong user and system time accounting Wanpeng Li <kernellwp@gmail.com> - 2017-03-30 08:50 +0200
Re: [BUG nohz]: wrong user and system time accounting Wanpeng Li <kernellwp@gmail.com> - 2017-03-30 14:00 +0200
Re: [BUG nohz]: wrong user and system time accounting Mike Galbraith <efault@gmx.de> - 2017-03-30 14:40 +0200
Re: [BUG nohz]: wrong user and system time accounting Frederic Weisbecker <fweisbec@gmail.com> - 2017-03-30 15:40 +0200
Re: [BUG nohz]: wrong user and system time accounting Wanpeng Li <kernellwp@gmail.com> - 2017-03-30 16:10 +0200
Re: [BUG nohz]: wrong user and system time accounting Frederic Weisbecker <fweisbec@gmail.com> - 2017-03-30 16:30 +0200
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-03-30 23:30 +0200
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-03-31 22:10 +0200
Re: [BUG nohz]: wrong user and system time accounting Frederic Weisbecker <fweisbec@gmail.com> - 2017-04-01 01:30 +0200
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-04-01 05:20 +0200
Re: [BUG nohz]: wrong user and system time accounting Frederic Weisbecker <fweisbec@gmail.com> - 2017-04-03 17:30 +0200
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-04-03 21:10 +0200
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-04-04 20:10 +0200
Re: [BUG nohz]: wrong user and system time accounting Rik van Riel <riel@redhat.com> - 2017-04-05 16:30 +0200
Re: [BUG nohz]: wrong user and system time accounting Frederic Weisbecker <fweisbec@gmail.com> - 2017-03-30 15:00 +0200
Re: [BUG nohz]: wrong user and system time accounting Rik van Riel <riel@redhat.com> - 2017-03-30 15:10 +0200
Re: [BUG nohz]: wrong user and system time accounting Mike Galbraith <efault@gmx.de> - 2017-03-30 15:40 +0200
Re: [BUG nohz]: wrong user and system time accounting Frederic Weisbecker <fweisbec@gmail.com> - 2017-04-03 16:50 +0200
Re: [BUG nohz]: wrong user and system time accounting Mike Galbraith <efault@gmx.de> - 2017-04-04 09:40 +0200
Re: [BUG nohz]: wrong user and system time accounting Frederic Weisbecker <fweisbec@gmail.com> - 2017-03-30 15:50 +0200
Re: [BUG nohz]: wrong user and system time accounting Wanpeng Li <kernellwp@gmail.com> - 2017-03-30 00:50 +0200
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-03-30 04:20 +0200
Re: [BUG nohz]: wrong user and system time accounting Wanpeng Li <kernellwp@gmail.com> - 2017-03-30 14:30 +0200
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-03-27 20:50 +0200
Re: [BUG nohz]: wrong user and system time accounting Wanpeng Li <kernellwp@gmail.com> - 2017-03-28 07:40 +0200
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-03-28 16:00 +0200
Re: [BUG nohz]: wrong user and system time accounting Frederic Weisbecker <fweisbec@gmail.com> - 2017-03-29 15:10 +0200
Re: [BUG nohz]: wrong user and system time accounting Rik van Riel <riel@redhat.com> - 2017-03-29 15:20 +0200
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-03-29 15:30 +0200
Re: [BUG nohz]: wrong user and system time accounting Frederic Weisbecker <fweisbec@gmail.com> - 2017-03-29 23:20 +0200
Re: [BUG nohz]: wrong user and system time accounting Luiz Capitulino <lcapitulino@redhat.com> - 2017-03-30 03:50 +0200
Page 3 of 3 — ← Prev page 1 2 [3]
| From | Frederic Weisbecker <fweisbec@gmail.com> |
|---|---|
| Date | 2017-04-03 16:50 +0200 |
| Message-ID | <tsbsS-89y-21@gated-at.bofh.it> |
| In reply to | #1613068 |
On Thu, Mar 30, 2017 at 03:35:22PM +0200, Mike Galbraith wrote: > On Thu, 2017-03-30 at 09:02 -0400, Rik van Riel wrote: > > On Thu, 2017-03-30 at 14:51 +0200, Frederic Weisbecker wrote: > > > > Also, why does it raise power consumption issues? > > > > On a system without either nohz_full or nohz idle > > mode, skewed ticks result in CPU cores waking up > > at different times, and keeping an idle system > > consuming power for more time than it would if all > > the ticks happened simultaneously. > > And if your server farm is mostly idle, that power savings may delay > your bankruptcy proceedings by a whole microsecond ;-) > > Or more seriously, what skew does do on boxen of size X today is > something for perf to say. At the time, removal was very bad for my 8 > socket box, and allegedly caused huge SGI beasts in horrific pain. I see. Nohz_full is already bad for powersavings anyway. CPU 0 always ticks :-)
[toc] | [prev] | [next] | [standalone]
| From | Mike Galbraith <efault@gmx.de> |
|---|---|
| Date | 2017-04-04 09:40 +0200 |
| Message-ID | <tsrei-1N1-9@gated-at.bofh.it> |
| In reply to | #1615274 |
On Mon, 2017-04-03 at 16:40 +0200, Frederic Weisbecker wrote: > On Thu, Mar 30, 2017 at 03:35:22PM +0200, Mike Galbraith wrote: > Nohz_full is already bad for powersavings anyway. CPU 0 always ticks :-) OTOH, if a nohz_full set is doing what it was born to do, CPU0 tick spikes won't be noticeable on your (pegged/glowing) watt meter :)
[toc] | [prev] | [next] | [standalone]
| From | Frederic Weisbecker <fweisbec@gmail.com> |
|---|---|
| Date | 2017-03-30 15:50 +0200 |
| Message-ID | <tqICB-74s-5@gated-at.bofh.it> |
| In reply to | #1613045 |
On Thu, Mar 30, 2017 at 09:02:31AM -0400, Rik van Riel wrote: > On Thu, 2017-03-30 at 14:51 +0200, Frederic Weisbecker wrote: > > On Thu, Mar 30, 2017 at 06:27:31AM +0200, Mike Galbraith wrote: > > > On Wed, 2017-03-29 at 16:08 -0400, Rik van Riel wrote: > > > > > > > A random offset, or better yet a somewhat randomized > > > > tick length to make sure that simultaneous ticks are > > > > fairly rare and the vtime sampling does not end up > > > > "in phase" with the jiffies incrementing, could make > > > > the accounting work right again. > > > > > > That improves jitter, especially on big boxen. I have an 8 socket > > > box > > > that thinks it's an extra large PC, there, collision avoidance > > > matters > > > hugely. I couldn't reproduce bean counting woes, no idea if > > > collision > > > avoidance will help that. > > > > Out of curiosity, where is the main contention between ticks? I > > indeed > > know some locks that can be taken on special cases, such as posix cpu > > timers. > > > > Also, why does it raise power consumption issues? > > On a system without either nohz_full or nohz idle > mode, skewed ticks result in CPU cores waking up > at different times, and keeping an idle system > consuming power for more time than it would if all > the ticks happened simultaneously. Ah fair point! > > This is not a factor at all on systems that switch > off the tick while idle, since the CPU will be busy > anyway while the tick is enabled. I see. Thanks!
[toc] | [prev] | [next] | [standalone]
| From | Wanpeng Li <kernellwp@gmail.com> |
|---|---|
| Date | 2017-03-30 00:50 +0200 |
| Message-ID | <tquzD-5dc-5@gated-at.bofh.it> |
| In reply to | #1610014 |
2017-03-30 6:17 GMT+08:00 Frederic Weisbecker <fweisbec@gmail.com>: > On Wed, Mar 29, 2017 at 01:16:56PM -0400, Luiz Capitulino wrote: >> On Tue, 28 Mar 2017 13:24:06 -0400 >> Luiz Capitulino <lcapitulino@redhat.com> wrote: >> >> > 1. In my tracing I'm seeing that sometimes (always?) the >> > time interval between two timer interrupts is less than 1ms >> >> I think that's the root cause. >> >> I'm getting traces like this: >> >> hog-11980 [015] 341.494491: function: enter_from_user_mode <-- apic_timer_interrupt >> <idle>-0 [000] 341.494492: function: smp_apic_timer_interrupt <-- apic_timer_interrupt >> hog-11980 [015] 341.494492: function: __context_tracking_exit <-- enter_from_user_mode >> <idle>-0 [000] 341.494492: function: irq_enter <-- smp_apic_timer_interrupt >> hog-11980 [015] 341.494492: bprint: vtime_delta: diff=0 (now=4295008339 vtime_snap=4295008339) >> hog-11980 [015] 341.494492: function: smp_apic_timer_interrupt <-- apic_timer_interrupt >> hog-11980 [015] 341.494492: function: irq_enter <-- smp_apic_timer_interrupt >> hog-11980 [015] 341.494493: function: tick_sched_timer <-- __hrtimer_run_queues >> <idle>-0 [000] 341.494493: function: tick_sched_timer <-- __hrtimer_run_queues >> <idle>-0 [000] 341.494493: function: tick_do_update_jiffies64.part.14 <-- tick_sched_do_timer >> <idle>-0 [000] 341.494494: function: do_timer <-- tick_do_update_jiffies64.part.14 >> hog-11980 [015] 341.494494: function: irq_exit <-- smp_apic_timer_interrupt >> <idle>-0 [000] 341.494494: bprint: do_timer: updated jiffies_64=4295008340 ticks=1 >> hog-11980 [015] 341.494494: function: __context_tracking_enter <-- prepare_exit_to_usermode >> hog-11980 [015] 341.494494: function: vtime_user_enter <-- __context_tracking_enter >> hog-11980 [015] 341.494495: bprint: vtime_delta: diff=1000000 (now=4295008340 vtime_snap=4295008339) >> hog-11980 [015] 341.494495: function: __vtime_account_system <-- vtime_user_enter >> hog-11980 [015] 341.494495: bprint: get_vtime_delta: vtime_snap=4295008339 now=4295008340 >> hog-11980 [015] 341.494495: function: account_system_time <-- __vtime_account_system >> hog-11980 [015] 341.494495: bprint: account_system_time: cputime=995488 >> <idle>-0 [000] 341.494497: function: irq_exit <-- smp_apic_timer_interrupt >> >> In this trace, we see the following: >> >> 1. On CPU15, we transition from user-space to kernel-space because >> of a timer interrupt (it's the tick) >> >> 2. vtimer_delta() returns 0, because jiffies didn't change since the >> last accounting >> >> 3. While CPU15 is executing in kernel-space, jiffies is updated >> by CPU0 >> >> 4. When going back to user-space, vtime_delta() returns non-zero >> and the whole time is accounted for system time (observe how >> the cputime parameter in account_system_time() is less than 1ms) > > Aah, so the issue can indeed happen if all CPUs fire their ticks at the same time: > > > CPU 0 CPU 1 > ----- ----- > exit_user() // no cputime update > tick X update_jiffies > enter_user() // cputime update > > > exit_user() //no cputime update > tick X+1 update_jiffies > enter_user() // cputime update > >> >> That's why my patch from yesterday fixed the issue, it increased the >> tick period to more than 1ms. So vtime_delta() always evaluate to true >> when transitioning from user-space to kernel-space (because we spend >> more than 1ms in user-space between ticks). The patch below achieves >> the same result by adding 10us to the tick period. >> >> diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c >> index 7fe53be..00e46df 100644 >> --- a/kernel/time/tick-sched.c >> +++ b/kernel/time/tick-sched.c >> @@ -1165,7 +1165,7 @@ static enum hrtimer_restart tick_sched_timer(struct hrtimer *timer) >> if (unlikely(ts->tick_stopped)) >> return HRTIMER_NORESTART; >> >> - hrtimer_forward(timer, now, tick_period); >> + hrtimer_forward(timer, now, tick_period + 10000); > > I'm surprised it works though. If the 10us shift was only applied to CPU 0 and not the > others then yes, but if it is applied to all CPUs, the ticks stay synchronized and the > problem should stay... > > Ah wait! It can work because the nohz_full CPUs have their ticks sometimes scheduled > by tick_nohz_stop_sched_tick() or tick_nohz_restart_sched_tick() which don't have the > 10us shift. So a drift happens everytime the nohz_full CPUs have their tick stopped. > >> Now, why is the tick ticking at less than 1ms? I think it's the time >> difference between "now" (that we pass to hrtimer_forward()) and the >> time the timer hardware is actually programmed. That should account >> for a few microseconds. > > Right, that's my feeling. And if it is the case, then it shouldn't matter. > > So! Now we need to find a proper fix :o) > > Hmm, how bad would it be to revert to sched_clock() instead of jiffies in vtime_delta()? > We could use nanosecond granularity to check deltas but only perform an actual cputime update > when that delta >= TICK_NSEC. That should keep the load ok. Yeah, I mentioned something similar before. https://lkml.org/lkml/2017/3/26/138 However, Rik's commit optimized syscalls by not utilize sched_clock(), so if we should distinguish between syscalls/exceptions and irqs? Regards, Wanpeng Li
[toc] | [prev] | [next] | [standalone]
| From | Luiz Capitulino <lcapitulino@redhat.com> |
|---|---|
| Date | 2017-03-30 04:20 +0200 |
| Message-ID | <tqxQR-7M1-1@gated-at.bofh.it> |
| In reply to | #1612427 |
On Thu, 30 Mar 2017 06:46:30 +0800
Wanpeng Li <kernellwp@gmail.com> wrote:
> > So! Now we need to find a proper fix :o)
> >
> > Hmm, how bad would it be to revert to sched_clock() instead of jiffies in vtime_delta()?
> > We could use nanosecond granularity to check deltas but only perform an actual cputime update
> > when that delta >= TICK_NSEC. That should keep the load ok.
>
> Yeah, I mentioned something similar before.
> https://lkml.org/lkml/2017/3/26/138 However, Rik's commit optimized
> syscalls by not utilize sched_clock(), so if we should distinguish
> between syscalls/exceptions and irqs?
Why not use ktime_get()?
Here's the solution I was thinking about, it's mostly untested. I'm
rate limiting below TICK_NSEC because I want to avoid syncing with
the tick.
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index f3778e2b..a8b1e85 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -676,18 +676,20 @@ void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st)
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
static u64 vtime_delta(struct task_struct *tsk)
{
- unsigned long now = READ_ONCE(jiffies);
+ return ktime_sub(ktime_get(), tsk->vtime_snap);
+}
- if (time_before(now, (unsigned long)tsk->vtime_snap))
- return 0;
+/* A little bit less than the tick period */
+#define VTIME_RATE_LIMIT (TICK_NSEC - 200000)
- return jiffies_to_nsecs(now - tsk->vtime_snap);
+static bool vtime_should_account(struct task_struct *tsk)
+{
+ return vtime_delta(tsk) > VTIME_RATE_LIMIT;
}
static u64 get_vtime_delta(struct task_struct *tsk)
{
- unsigned long now = READ_ONCE(jiffies);
- u64 delta, other;
+ u64 delta, other, now = ktime_get();
/*
* Unlike tick based timing, vtime based timing never has lost
@@ -696,7 +698,7 @@ static u64 get_vtime_delta(struct task_struct *tsk)
* elapsed time. Limit account_other_time to prevent rounding
* errors from causing elapsed vtime to go negative.
*/
- delta = jiffies_to_nsecs(now - tsk->vtime_snap);
+ delta = ktime_sub(now, tsk->vtime_snap);
other = account_other_time(delta);
WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE);
tsk->vtime_snap = now;
@@ -711,7 +713,7 @@ static void __vtime_account_system(struct task_struct *tsk)
void vtime_account_system(struct task_struct *tsk)
{
- if (!vtime_delta(tsk))
+ if (!vtime_should_account(tsk))
return;
write_seqcount_begin(&tsk->vtime_seqcount);
@@ -723,7 +725,7 @@ void vtime_account_user(struct task_struct *tsk)
{
write_seqcount_begin(&tsk->vtime_seqcount);
tsk->vtime_snap_whence = VTIME_SYS;
- if (vtime_delta(tsk))
+ if (vtime_should_account(tsk))
account_user_time(tsk, get_vtime_delta(tsk));
write_seqcount_end(&tsk->vtime_seqcount);
}
@@ -731,7 +733,7 @@ void vtime_account_user(struct task_struct *tsk)
void vtime_user_enter(struct task_struct *tsk)
{
write_seqcount_begin(&tsk->vtime_seqcount);
- if (vtime_delta(tsk))
+ if (vtime_should_account(tsk))
__vtime_account_system(tsk);
tsk->vtime_snap_whence = VTIME_USER;
write_seqcount_end(&tsk->vtime_seqcount);
@@ -747,7 +749,7 @@ void vtime_guest_enter(struct task_struct *tsk)
* that can thus safely catch up with a tickless delta.
*/
write_seqcount_begin(&tsk->vtime_seqcount);
- if (vtime_delta(tsk))
+ if (vtime_should_account(tsk))
__vtime_account_system(tsk);
current->flags |= PF_VCPU;
write_seqcount_end(&tsk->vtime_seqcount);
@@ -776,7 +778,7 @@ void arch_vtime_task_switch(struct task_struct *prev)
write_seqcount_begin(¤t->vtime_seqcount);
current->vtime_snap_whence = VTIME_SYS;
- current->vtime_snap = jiffies;
+ current->vtime_snap = ktime_get();
write_seqcount_end(¤t->vtime_seqcount);
}
[toc] | [prev] | [next] | [standalone]
| From | Wanpeng Li <kernellwp@gmail.com> |
|---|---|
| Date | 2017-03-30 14:30 +0200 |
| Message-ID | <tqHnb-6iA-7@gated-at.bofh.it> |
| In reply to | #1612498 |
2017-03-30 10:14 GMT+08:00 Luiz Capitulino <lcapitulino@redhat.com>:
> On Thu, 30 Mar 2017 06:46:30 +0800
> Wanpeng Li <kernellwp@gmail.com> wrote:
>
>> > So! Now we need to find a proper fix :o)
>> >
>> > Hmm, how bad would it be to revert to sched_clock() instead of jiffies in vtime_delta()?
>> > We could use nanosecond granularity to check deltas but only perform an actual cputime update
>> > when that delta >= TICK_NSEC. That should keep the load ok.
>>
>> Yeah, I mentioned something similar before.
>> https://lkml.org/lkml/2017/3/26/138 However, Rik's commit optimized
>> syscalls by not utilize sched_clock(), so if we should distinguish
>> between syscalls/exceptions and irqs?
>
> Why not use ktime_get()?
I believe ktime_get() is more heavy than local_clock() when sched
clock is stable. So we can cooperate to improve
https://lkml.org/lkml/2017/3/30/456.
Regards,
Wanpeng Li
>
> Here's the solution I was thinking about, it's mostly untested. I'm
> rate limiting below TICK_NSEC because I want to avoid syncing with
> the tick.
>
> diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
> index f3778e2b..a8b1e85 100644
> --- a/kernel/sched/cputime.c
> +++ b/kernel/sched/cputime.c
> @@ -676,18 +676,20 @@ void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st)
> #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
> static u64 vtime_delta(struct task_struct *tsk)
> {
> - unsigned long now = READ_ONCE(jiffies);
> + return ktime_sub(ktime_get(), tsk->vtime_snap);
> +}
>
> - if (time_before(now, (unsigned long)tsk->vtime_snap))
> - return 0;
> +/* A little bit less than the tick period */
> +#define VTIME_RATE_LIMIT (TICK_NSEC - 200000)
>
> - return jiffies_to_nsecs(now - tsk->vtime_snap);
> +static bool vtime_should_account(struct task_struct *tsk)
> +{
> + return vtime_delta(tsk) > VTIME_RATE_LIMIT;
> }
>
> static u64 get_vtime_delta(struct task_struct *tsk)
> {
> - unsigned long now = READ_ONCE(jiffies);
> - u64 delta, other;
> + u64 delta, other, now = ktime_get();
>
> /*
> * Unlike tick based timing, vtime based timing never has lost
> @@ -696,7 +698,7 @@ static u64 get_vtime_delta(struct task_struct *tsk)
> * elapsed time. Limit account_other_time to prevent rounding
> * errors from causing elapsed vtime to go negative.
> */
> - delta = jiffies_to_nsecs(now - tsk->vtime_snap);
> + delta = ktime_sub(now, tsk->vtime_snap);
> other = account_other_time(delta);
> WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE);
> tsk->vtime_snap = now;
> @@ -711,7 +713,7 @@ static void __vtime_account_system(struct task_struct *tsk)
>
> void vtime_account_system(struct task_struct *tsk)
> {
> - if (!vtime_delta(tsk))
> + if (!vtime_should_account(tsk))
> return;
>
> write_seqcount_begin(&tsk->vtime_seqcount);
> @@ -723,7 +725,7 @@ void vtime_account_user(struct task_struct *tsk)
> {
> write_seqcount_begin(&tsk->vtime_seqcount);
> tsk->vtime_snap_whence = VTIME_SYS;
> - if (vtime_delta(tsk))
> + if (vtime_should_account(tsk))
> account_user_time(tsk, get_vtime_delta(tsk));
> write_seqcount_end(&tsk->vtime_seqcount);
> }
> @@ -731,7 +733,7 @@ void vtime_account_user(struct task_struct *tsk)
> void vtime_user_enter(struct task_struct *tsk)
> {
> write_seqcount_begin(&tsk->vtime_seqcount);
> - if (vtime_delta(tsk))
> + if (vtime_should_account(tsk))
> __vtime_account_system(tsk);
> tsk->vtime_snap_whence = VTIME_USER;
> write_seqcount_end(&tsk->vtime_seqcount);
> @@ -747,7 +749,7 @@ void vtime_guest_enter(struct task_struct *tsk)
> * that can thus safely catch up with a tickless delta.
> */
> write_seqcount_begin(&tsk->vtime_seqcount);
> - if (vtime_delta(tsk))
> + if (vtime_should_account(tsk))
> __vtime_account_system(tsk);
> current->flags |= PF_VCPU;
> write_seqcount_end(&tsk->vtime_seqcount);
> @@ -776,7 +778,7 @@ void arch_vtime_task_switch(struct task_struct *prev)
>
> write_seqcount_begin(¤t->vtime_seqcount);
> current->vtime_snap_whence = VTIME_SYS;
> - current->vtime_snap = jiffies;
> + current->vtime_snap = ktime_get();
> write_seqcount_end(¤t->vtime_seqcount);
> }
>
[toc] | [prev] | [next] | [standalone]
| From | Luiz Capitulino <lcapitulino@redhat.com> |
|---|---|
| Date | 2017-03-27 20:50 +0200 |
| Message-ID | <tpHSi-42B-11@gated-at.bofh.it> |
| In reply to | #1609427 |
On Mon, 27 Mar 2017 09:56:47 +0800
Wanpeng Li <kernellwp@gmail.com> wrote:
> Actually after I bisect, the first bad commit is ff9a9b4c4334 ("sched,
> time: Switch VIRT_CPU_ACCOUNTING_GEN to jiffy granularity"). The bug
> can be reproduced readily if CONFIG_CONTEXT_TRACKING_FORCE is true,
> then just stress all the online cpus or just one cpu and leave others
> idle(so it stresses the global timekeeping one), top show 100%
> sys-time. And another way to reproduce it is by nohz_full, and gives
> the stress to the house keeping cpu, the top show 100% sys-time of the
> house keeping cpu, and also the other cpus who have at least two tasks
> running on and in full_nohz mode.
We're not short on reproducers, I have a new one too:
http://people.redhat.com/~lcapitul/real-time/acct-bug.c
This is a single threaded task that reproduces the issue. If you
run it as instructed, you'll get:
- nohz_full CPU: 95% system time 5% idle time
- non-nohz_full CPU: 95% user time 5% idle time (expected behavior)
This reproduces the issue, but not for the reasons I expected. I was
trying to mimic what I was seeing on my trace when tracing the two
task problem. Which is: a task stays 995us in user-space and then
enters the kernel. Time won't be accounted for user-space because
we're not 1 jiffies yet, but if the task stays in the kernel for more
than 5us, then time will be accounted for system time when going
back to user-space.
However, what really seems to be happening is: acct-bug is causing
the tick to be re-activated (why? it shouldn't) and that causes the
issue to appear. This is consistent with my other observations: I
can only reproduce the issue if the nohz_full CPU re-activates the tick.
> Let's consider the cpu which has responsibility for the global
> timekeeping, as the tracing posted above, the vtime_account_user() is
> called before tick_sched_timer() which will update jiffies,
But the vtime_account_user() call and the jiffies update happen
on different CPUs, no? So the ordering shouldn't matter.
> so jiffies
> is stale in vtime_account_user() and the run time in userspace is
> skipped, the vtime_user_enter() is called after jiffies update, so
> both the time in userspace and in kernel are accumulated to sys time.
>
> If the housekeeping cpu is idle when CONFIG_NO_HZ_FULL, everything is
> fine. However, if you give stress to the housekeeping cpu, top will
> show 100% sys-time of both the housekeeping cpu and the other cpus who
> have at least two tasks running on and in full_nohz mode.
The housekeeping CPUs are idle with my reproducers.
> I think it
> is because the stress delays the timer interrupt handling in some
> degree, then the jiffies is not updated timely before other cpus
> access it in vtime_account_user().
>
> I think we can keep syscalls/exceptions context tracking still in
> jiffies based sampling and utilize local_clock() in vtime_delta()
> again for irqs which avoids jiffies stale influence. I can make a
> patch if the idea is acceptable or there is any better proposal. :)
>
> Regards,
> Wanpeng Li
>
[toc] | [prev] | [next] | [standalone]
| From | Wanpeng Li <kernellwp@gmail.com> |
|---|---|
| Date | 2017-03-28 07:40 +0200 |
| Message-ID | <tpS1j-2ZP-1@gated-at.bofh.it> |
| In reply to | #1610072 |
2017-03-28 2:38 GMT+08:00 Luiz Capitulino <lcapitulino@redhat.com>:
> On Mon, 27 Mar 2017 09:56:47 +0800
> Wanpeng Li <kernellwp@gmail.com> wrote:
>
>> Actually after I bisect, the first bad commit is ff9a9b4c4334 ("sched,
>> time: Switch VIRT_CPU_ACCOUNTING_GEN to jiffy granularity"). The bug
>> can be reproduced readily if CONFIG_CONTEXT_TRACKING_FORCE is true,
>> then just stress all the online cpus or just one cpu and leave others
>> idle(so it stresses the global timekeeping one), top show 100%
>> sys-time. And another way to reproduce it is by nohz_full, and gives
>> the stress to the house keeping cpu, the top show 100% sys-time of the
>> house keeping cpu, and also the other cpus who have at least two tasks
>> running on and in full_nohz mode.
>
> We're not short on reproducers, I have a new one too:
>
> http://people.redhat.com/~lcapitul/real-time/acct-bug.c
>
> This is a single threaded task that reproduces the issue. If you
> run it as instructed, you'll get:
>
> - nohz_full CPU: 95% system time 5% idle time
> - non-nohz_full CPU: 95% user time 5% idle time (expected behavior)
>
> This reproduces the issue, but not for the reasons I expected. I was
> trying to mimic what I was seeing on my trace when tracing the two
> task problem. Which is: a task stays 995us in user-space and then
> enters the kernel. Time won't be accounted for user-space because
> we're not 1 jiffies yet, but if the task stays in the kernel for more
> than 5us, then time will be accounted for system time when going
> back to user-space.
>
> However, what really seems to be happening is: acct-bug is causing
> the tick to be re-activated (why? it shouldn't) and that causes the
> issue to appear. This is consistent with my other observations: I
> can only reproduce the issue if the nohz_full CPU re-activates the tick.
I see there are other kthreads like migration, kworker,
torture_shuffle etc on the isolated CPU.
Regards,
Wanpeng Li
>
>> Let's consider the cpu which has responsibility for the global
>> timekeeping, as the tracing posted above, the vtime_account_user() is
>> called before tick_sched_timer() which will update jiffies,
>
> But the vtime_account_user() call and the jiffies update happen
> on different CPUs, no? So the ordering shouldn't matter.
>
>> so jiffies
>> is stale in vtime_account_user() and the run time in userspace is
>> skipped, the vtime_user_enter() is called after jiffies update, so
>> both the time in userspace and in kernel are accumulated to sys time.
>>
>> If the housekeeping cpu is idle when CONFIG_NO_HZ_FULL, everything is
>> fine. However, if you give stress to the housekeeping cpu, top will
>> show 100% sys-time of both the housekeeping cpu and the other cpus who
>> have at least two tasks running on and in full_nohz mode.
>
> The housekeeping CPUs are idle with my reproducers.
>
>> I think it
>> is because the stress delays the timer interrupt handling in some
>> degree, then the jiffies is not updated timely before other cpus
>> access it in vtime_account_user().
>>
>> I think we can keep syscalls/exceptions context tracking still in
>> jiffies based sampling and utilize local_clock() in vtime_delta()
>> again for irqs which avoids jiffies stale influence. I can make a
>> patch if the idea is acceptable or there is any better proposal. :)
>>
>> Regards,
>> Wanpeng Li
>>
>
[toc] | [prev] | [next] | [standalone]
| From | Luiz Capitulino <lcapitulino@redhat.com> |
|---|---|
| Date | 2017-03-28 16:00 +0200 |
| Message-ID | <tpZPd-8sh-39@gated-at.bofh.it> |
| In reply to | #1610308 |
On Tue, 28 Mar 2017 13:28:13 +0800
Wanpeng Li <kernellwp@gmail.com> wrote:
> 2017-03-28 2:38 GMT+08:00 Luiz Capitulino <lcapitulino@redhat.com>:
> > On Mon, 27 Mar 2017 09:56:47 +0800
> > Wanpeng Li <kernellwp@gmail.com> wrote:
> >
> >> Actually after I bisect, the first bad commit is ff9a9b4c4334 ("sched,
> >> time: Switch VIRT_CPU_ACCOUNTING_GEN to jiffy granularity"). The bug
> >> can be reproduced readily if CONFIG_CONTEXT_TRACKING_FORCE is true,
> >> then just stress all the online cpus or just one cpu and leave others
> >> idle(so it stresses the global timekeeping one), top show 100%
> >> sys-time. And another way to reproduce it is by nohz_full, and gives
> >> the stress to the house keeping cpu, the top show 100% sys-time of the
> >> house keeping cpu, and also the other cpus who have at least two tasks
> >> running on and in full_nohz mode.
> >
> > We're not short on reproducers, I have a new one too:
> >
> > http://people.redhat.com/~lcapitul/real-time/acct-bug.c
> >
> > This is a single threaded task that reproduces the issue. If you
> > run it as instructed, you'll get:
> >
> > - nohz_full CPU: 95% system time 5% idle time
> > - non-nohz_full CPU: 95% user time 5% idle time (expected behavior)
> >
> > This reproduces the issue, but not for the reasons I expected. I was
> > trying to mimic what I was seeing on my trace when tracing the two
> > task problem. Which is: a task stays 995us in user-space and then
> > enters the kernel. Time won't be accounted for user-space because
> > we're not 1 jiffies yet, but if the task stays in the kernel for more
> > than 5us, then time will be accounted for system time when going
> > back to user-space.
> >
> > However, what really seems to be happening is: acct-bug is causing
> > the tick to be re-activated (why? it shouldn't) and that causes the
> > issue to appear. This is consistent with my other observations: I
> > can only reproduce the issue if the nohz_full CPU re-activates the tick.
>
> I see there are other kthreads like migration, kworker,
> torture_shuffle etc on the isolated CPU.
Except for torture_shuffle (which is new to me, and I guess could
be disabled in .config) the other threads should not be runnable
for most of the time.
>
> Regards,
> Wanpeng Li
>
> >
> >> Let's consider the cpu which has responsibility for the global
> >> timekeeping, as the tracing posted above, the vtime_account_user() is
> >> called before tick_sched_timer() which will update jiffies,
> >
> > But the vtime_account_user() call and the jiffies update happen
> > on different CPUs, no? So the ordering shouldn't matter.
> >
> >> so jiffies
> >> is stale in vtime_account_user() and the run time in userspace is
> >> skipped, the vtime_user_enter() is called after jiffies update, so
> >> both the time in userspace and in kernel are accumulated to sys time.
> >>
> >> If the housekeeping cpu is idle when CONFIG_NO_HZ_FULL, everything is
> >> fine. However, if you give stress to the housekeeping cpu, top will
> >> show 100% sys-time of both the housekeeping cpu and the other cpus who
> >> have at least two tasks running on and in full_nohz mode.
> >
> > The housekeeping CPUs are idle with my reproducers.
> >
> >> I think it
> >> is because the stress delays the timer interrupt handling in some
> >> degree, then the jiffies is not updated timely before other cpus
> >> access it in vtime_account_user().
> >>
> >> I think we can keep syscalls/exceptions context tracking still in
> >> jiffies based sampling and utilize local_clock() in vtime_delta()
> >> again for irqs which avoids jiffies stale influence. I can make a
> >> patch if the idea is acceptable or there is any better proposal. :)
> >>
> >> Regards,
> >> Wanpeng Li
> >>
> >
>
[toc] | [prev] | [next] | [standalone]
| From | Frederic Weisbecker <fweisbec@gmail.com> |
|---|---|
| Date | 2017-03-29 15:10 +0200 |
| Message-ID | <tqlwl-7hB-9@gated-at.bofh.it> |
| In reply to | #1607903 |
On Thu, Mar 23, 2017 at 04:55:12PM -0400, Luiz Capitulino wrote:
>
> When there are two or more tasks executing in user-space and
> taking 100% of a nohz_full CPU, top reports 70% system time
> and 30% user time utilization. Sometimes I'm even able to get
> 100% system time and 0% user time.
>
> This was reproduced with latest Linus tree (093b995), but I
> don't believe it's a regression (at least not a recent one)
> as I can reproduce it with older kernels. Also, I have
> CONFIG_IRQ_TIME_ACCOUNTING=y and haven't tried to reproduce
> without it yet.
>
> Below you'll find the steps to reproduce and some initial
> analysis.
>
> Steps to reproduce
> ------------------
>
> 1. Set up a CPU for nohz_full with isolcpus= nohz_full=
>
> 2. Pin two tasks that hog the CPU 100% of the time to that CPU
I failed to reproduce with your config. I'm still getting 99% userspace
cputime. So I'm wondering if the hogging style plays a role.
I run pure user loops:
int main(int argc, char **argv)
{
for (;;);
return 0
}
Does your user program perform syscalls or IOs of some sort?
[toc] | [prev] | [next] | [standalone]
| From | Rik van Riel <riel@redhat.com> |
|---|---|
| Date | 2017-03-29 15:20 +0200 |
| Message-ID | <tqlG1-7mo-11@gated-at.bofh.it> |
| In reply to | #1611919 |
On Wed, 2017-03-29 at 15:04 +0200, Frederic Weisbecker wrote:
> On Thu, Mar 23, 2017 at 04:55:12PM -0400, Luiz Capitulino wrote:
> >
> > When there are two or more tasks executing in user-space and
> > taking 100% of a nohz_full CPU, top reports 70% system time
> > and 30% user time utilization. Sometimes I'm even able to get
> > 100% system time and 0% user time.
> >
> > This was reproduced with latest Linus tree (093b995), but I
> > don't believe it's a regression (at least not a recent one)
> > as I can reproduce it with older kernels. Also, I have
> > CONFIG_IRQ_TIME_ACCOUNTING=y and haven't tried to reproduce
> > without it yet.
> >
> > Below you'll find the steps to reproduce and some initial
> > analysis.
> >
> > Steps to reproduce
> > ------------------
> >
> > 1. Set up a CPU for nohz_full with isolcpus= nohz_full=
> >
> > 2. Pin two tasks that hog the CPU 100% of the time to that CPU
>
> I failed to reproduce with your config. I'm still getting 99%
> userspace
> cputime. So I'm wondering if the hogging style plays a role.
>
> I run pure user loops:
>
> int main(int argc, char **argv)
> {
> for (;;);
> return 0
> }
>
> Does your user program perform syscalls or IOs of some sort?
Luiz's program makes a syscall every millisecond,
if started with the arguments he gave as his
reproducer.
[toc] | [prev] | [next] | [standalone]
| From | Luiz Capitulino <lcapitulino@redhat.com> |
|---|---|
| Date | 2017-03-29 15:30 +0200 |
| Message-ID | <tqlPI-7sg-7@gated-at.bofh.it> |
| In reply to | #1611922 |
[Multipart message — attachments visible in raw view] — view raw
On Wed, 29 Mar 2017 09:14:32 -0400
Rik van Riel <riel@redhat.com> wrote:
> > I failed to reproduce with your config. I'm still getting 99%
> > userspace
> > cputime. So I'm wondering if the hogging style plays a role.
> >
> > I run pure user loops:
> >
> > int main(int argc, char **argv)
> > {
> > for (;;);
> > return 0
> > }
> >
> > Does your user program perform syscalls or IOs of some sort?
>
> Luiz's program makes a syscall every millisecond,
> if started with the arguments he gave as his
> reproducer.
There are various reproducers actually. I started off with the simple
loop above, then wrote the attach program and then wrote the one
you're mentioning:
http://people.redhat.com/~lcapitul/real-time/acct-bug.c
All of them reproduce the issue 100% of the time for me.
[toc] | [prev] | [next] | [standalone]
| From | Frederic Weisbecker <fweisbec@gmail.com> |
|---|---|
| Date | 2017-03-29 23:20 +0200 |
| Message-ID | <tqtaz-4hp-47@gated-at.bofh.it> |
| In reply to | #1611931 |
On Wed, Mar 29, 2017 at 09:23:57AM -0400, Luiz Capitulino wrote:
>
> There are various reproducers actually. I started off with the simple
> loop above, then wrote the attach program and then wrote the one
> you're mentioning:
>
> http://people.redhat.com/~lcapitul/real-time/acct-bug.c
>
> All of them reproduce the issue 100% of the time for me.
> #define _GNU_SOURCE
> #include <stdio.h>
> #include <unistd.h>
> #include <stdlib.h>
> #include <sched.h>
> #include <sys/types.h>
>
> static int move_to_cpu(int cpu)
> {
> cpu_set_t set;
>
> CPU_ZERO(&set);
> CPU_SET(cpu, &set);
> return sched_setaffinity(0, sizeof(set), &set);
> }
>
> static void loop(void)
> {
> for (;;) ;
> }
>
> static int fork_hog(int cpu)
> {
> int pid;
>
> pid = (int) fork();
> if (pid == 0) {
> move_to_cpu(cpu);
> loop();
> exit(0);
> }
>
> return pid;
> }
>
> int main(int argc, char *argv[])
> {
> int i, pid, cpu, nr_procs;
>
> if (argc != 3) {
> printf("usage: hog < nr-procs > < CPU >\n");
> exit(1);
> }
>
> cpu = atoi(argv[2]);
> nr_procs = atoi(argv[1]);
>
> for (i = 0; i < nr_procs; i++) {
> pid = fork_hog(cpu);
> fprintf(stderr, "created hog%d pid=%d\n", i, pid);
> }
>
> fprintf(stderr, "pausing...\n");
> pause();
>
> return 0;
> }
I just tried both of these and none seem to show incorrect cputime :-/
I'm wondering if that bug depends on some hardware.
[toc] | [prev] | [next] | [standalone]
| From | Luiz Capitulino <lcapitulino@redhat.com> |
|---|---|
| Date | 2017-03-30 03:50 +0200 |
| Message-ID | <tqxnP-7bX-3@gated-at.bofh.it> |
| In reply to | #1612367 |
On Wed, 29 Mar 2017 23:12:00 +0200
Frederic Weisbecker <fweisbec@gmail.com> wrote:
> On Wed, Mar 29, 2017 at 09:23:57AM -0400, Luiz Capitulino wrote:
> >
> > There are various reproducers actually. I started off with the simple
> > loop above, then wrote the attach program and then wrote the one
> > you're mentioning:
> >
> > http://people.redhat.com/~lcapitul/real-time/acct-bug.c
> >
> > All of them reproduce the issue 100% of the time for me.
>
> > #define _GNU_SOURCE
> > #include <stdio.h>
> > #include <unistd.h>
> > #include <stdlib.h>
> > #include <sched.h>
> > #include <sys/types.h>
> >
> > static int move_to_cpu(int cpu)
> > {
> > cpu_set_t set;
> >
> > CPU_ZERO(&set);
> > CPU_SET(cpu, &set);
> > return sched_setaffinity(0, sizeof(set), &set);
> > }
> >
> > static void loop(void)
> > {
> > for (;;) ;
> > }
> >
> > static int fork_hog(int cpu)
> > {
> > int pid;
> >
> > pid = (int) fork();
> > if (pid == 0) {
> > move_to_cpu(cpu);
> > loop();
> > exit(0);
> > }
> >
> > return pid;
> > }
> >
> > int main(int argc, char *argv[])
> > {
> > int i, pid, cpu, nr_procs;
> >
> > if (argc != 3) {
> > printf("usage: hog < nr-procs > < CPU >\n");
> > exit(1);
> > }
> >
> > cpu = atoi(argv[2]);
> > nr_procs = atoi(argv[1]);
> >
> > for (i = 0; i < nr_procs; i++) {
> > pid = fork_hog(cpu);
> > fprintf(stderr, "created hog%d pid=%d\n", i, pid);
> > }
> >
> > fprintf(stderr, "pausing...\n");
> > pause();
> >
> > return 0;
> > }
>
> I just tried both of these and none seem to show incorrect cputime :-/
> I'm wondering if that bug depends on some hardware.
Are you running on x86? My CPU is:
Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
I wonder if this issue depends on the timer used by the hrtimer
subsystem.
[toc] | [prev] | [standalone]
Page 3 of 3 — ← Prev page 1 2 [3]
Back to top | Article view | linux.kernel
csiph-web