Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751654AbdF2Ev3 (ORCPT ); Thu, 29 Jun 2017 00:51:29 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34890 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751544AbdF2EvY (ORCPT ); Thu, 29 Jun 2017 00:51:24 -0400 Date: Thu, 29 Jun 2017 06:51:16 +0200 User-Agent: K-9 Mail for Android In-Reply-To: <20170628185719.Horde.2-GXEXxQwqkKUOuLD4nHa0d@gator4166.hostgator.com> References: <20170627180353.Horde.IIRh_TLNBuucfm8xZhbOEix@gator4166.hostgator.com> <20170628185719.Horde.2-GXEXxQwqkKUOuLD4nHa0d@gator4166.hostgator.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Subject: Re: [kernel-sched-cputime] question about probable bug in cputime_adjust() To: "Gustavo A. R. Silva" CC: Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org From: Frans Klaver Message-ID: <6F120D18-437E-45C5-9235-F51F0E7ADC6F@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id v5T4pWhq003963 Content-Length: 2261 Lines: 72 On 29 June 2017 01:57:19 CEST, "Gustavo A. R. Silva" 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.