From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753119AbdF2R6r (ORCPT ); Thu, 29 Jun 2017 13:58:47 -0400 Received: from gateway22.websitewelcome.com ([192.185.46.142]:32189 "EHLO gateway22.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752689AbdF2R6h (ORCPT ); Thu, 29 Jun 2017 13:58:37 -0400 Date: Thu, 29 Jun 2017 12:58:04 -0500 Message-ID: <20170629125804.Horde.gm62Mi9SrTXYOk8B_t9Srrr@gator4166.hostgator.com> From: "Gustavo A. R. Silva" To: Frans Klaver Cc: Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org Subject: Re: [kernel-sched-cputime] question about probable bug in cputime_adjust() References: <20170627180353.Horde.IIRh_TLNBuucfm8xZhbOEix@gator4166.hostgator.com> <20170628185719.Horde.2-GXEXxQwqkKUOuLD4nHa0d@gator4166.hostgator.com> <6F120D18-437E-45C5-9235-F51F0E7ADC6F@gmail.com> In-Reply-To: <6F120D18-437E-45C5-9235-F51F0E7ADC6F@gmail.com> User-Agent: Horde Application Framework 5 Content-Type: text/plain; charset=utf-8; format=flowed; DelSp=Yes MIME-Version: 1.0 Content-Disposition: inline X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 108.167.133.22 X-Exim-ID: 1dQdhd-001rJ4-1s X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: gator4166.hostgator.com [108.167.133.22]:13614 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 8 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Frans Klaver : > 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. Oh yeah! something like: if (stime != 0) { if (stime != 0 && utime == 0) stime = rtime; else stime = scale_stime(stime, rtime, stime + utime); } I'll be right back with the final patch. Thanks for your time, Frans. Much appreciated :) -- Gustavo A. R. Silva