All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frans Klaver <fransklaver@gmail.com>
To: "Gustavo A. R. Silva" <garsilva@embeddedor.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [kernel-sched-cputime] question about probable bug in cputime_adjust()
Date: Thu, 29 Jun 2017 06:51:16 +0200	[thread overview]
Message-ID: <6F120D18-437E-45C5-9235-F51F0E7ADC6F@gmail.com> (raw)
In-Reply-To: <20170628185719.Horde.2-GXEXxQwqkKUOuLD4nHa0d@gator4166.hostgator.com>



On 29 June 2017 01:57:19 CEST, "Gustavo A. R. Silva" <garsilva@embeddedor.com> wrote:
>>>> --- a/kernel/sched/cputime.c
>>>> +++ b/kernel/sched/cputime.c
>>>> @@ -637,9 +637,10 @@ static void cputime_adjust(struct task_cputime
>*curr,
>>>>          *            = (rtime_i+1 - rtime_i) + utime_i
>>>>          *            >= utime_i
>>>>          */
>>>> -       if (stime < prev->stime)
>>>> +       if (stime < prev->stime) {
>>>>                 stime = prev->stime;
>>>> -       utime = rtime - stime;
>>>> +               utime = rtime - stime;
>>>> +       }
>>>>
>>>>
>>>> If you confirm this, I will send a patch in a full and proper form.
>>>>
>>>> I'd really appreciate your comments.
>>>
>>> If you do that, how would you meet the guarantee made in line 583?
>>>
>
>You are right, I see now.
>
>Then in this case the following patch would be the way to go:
>
>--- a/kernel/sched/cputime.c
>+++ b/kernel/sched/cputime.c
>@@ -615,10 +615,8 @@ static void cputime_adjust(struct task_cputime
>*curr,
>       * userspace. Once a task gets some ticks, the monotonicy code at
>          * 'update' will ensure things converge to the observed ratio.
>          */
>-       if (stime == 0) {
>-               utime = rtime;
>+       if (stime == 0)
>                 goto update;
>-       }
>
>         if (utime == 0) {
>                 stime = rtime;
>
>
>but I think this one is even better:
>
>
>--- a/kernel/sched/cputime.c
>+++ b/kernel/sched/cputime.c
>@@ -615,19 +615,11 @@ static void cputime_adjust(struct task_cputime
>*curr,
>       * userspace. Once a task gets some ticks, the monotonicy code at
>          * 'update' will ensure things converge to the observed ratio.
>          */
>-       if (stime == 0) {
>-               utime = rtime;
>-               goto update;
>-       }
>-
>-       if (utime == 0) {
>+       if (stime != 0 && utime == 0)
>                 stime = rtime;
>-               goto update;
>-       }
>-
>-       stime = scale_stime(stime, rtime, stime + utime);
>+       else
>+               stime = scale_stime(stime, rtime, stime + utime);

I don't think it is better. The stime == 0 case is gone now. So scale_time() will be called in that case. This whole if/else block should only be executed if stime != 0. 

  reply	other threads:[~2017-06-29  4:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-27 23:03 [kernel-sched-cputime] question about probable bug in cputime_adjust() Gustavo A. R. Silva
2017-06-28  5:35 ` Frans Klaver
2017-06-28  6:03   ` Frans Klaver
2017-06-28 23:57     ` Gustavo A. R. Silva
2017-06-29  4:51       ` Frans Klaver [this message]
2017-06-29 17:58         ` Gustavo A. R. Silva
2017-06-29 18:41           ` [PATCH] sched/cputime: code refactoring " Gustavo A. R. Silva
2017-06-30 13:10             ` [tip:sched/core] sched/cputime: Refactor the cputime_adjust() code tip-bot for Gustavo A. R. Silva
2017-06-30 14:00               ` Rik van Riel
2017-06-30 14:41                 ` Frans Klaver
2017-06-30 15:46                   ` Frederic Weisbecker
2017-06-30 16:17               ` Stanislaw Gruszka
2017-07-04  9:17               ` Peter Zijlstra
2017-07-04 10:01                 ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6F120D18-437E-45C5-9235-F51F0E7ADC6F@gmail.com \
    --to=fransklaver@gmail.com \
    --cc=garsilva@embeddedor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.