Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752184AbdGDJRr (ORCPT ); Tue, 4 Jul 2017 05:17:47 -0400 Received: from merlin.infradead.org ([205.233.59.134]:49230 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750830AbdGDJRp (ORCPT ); Tue, 4 Jul 2017 05:17:45 -0400 Date: Tue, 4 Jul 2017 11:17:31 +0200 From: Peter Zijlstra To: mingo@kernel.org, fransklaver@gmail.com, hpa@zytor.com, fweisbec@gmail.com, torvalds@linux-foundation.org, riel@redhat.com, tglx@linutronix.de, wanpeng.li@hotmail.com, linux-kernel@vger.kernel.org, garsilva@embeddedor.com, sgruszka@redhat.com Cc: linux-tip-commits@vger.kernel.org Subject: Re: [tip:sched/core] sched/cputime: Refactor the cputime_adjust() code Message-ID: <20170704091731.oux3ejxhgspgrlqb@hirez.programming.kicks-ass.net> References: <20170629184128.GA5271@embeddedgus> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2757 Lines: 94 On Fri, Jun 30, 2017 at 06:10:35AM -0700, tip-bot for Gustavo A. R. Silva wrote: > Commit-ID: 72298e5c92c50edd8cb7cfda4519483ce65fa166 > Gitweb: http://git.kernel.org/tip/72298e5c92c50edd8cb7cfda4519483ce65fa166 > Author: Gustavo A. R. Silva > AuthorDate: Thu, 29 Jun 2017 13:41:28 -0500 > Committer: Ingo Molnar > CommitDate: Fri, 30 Jun 2017 09:37:59 +0200 > > sched/cputime: Refactor the cputime_adjust() code > > Address a Coverity false positive, which is caused by overly > convoluted code: > > Value assigned to variable 'utime' at line 619:utime = rtime; > is overwritten at line 642:utime = rtime - stime; before it > can be used. This makes such variable assignment useless. > > Remove this variable assignment and refactor the code related. > > Addresses-Coverity-ID: 1371643 > Signed-off-by: Gustavo A. R. Silva > Cc: Frans Klaver > Cc: Frederic Weisbecker > Cc: Linus Torvalds > Cc: Peter Zijlstra > Cc: Rik van Riel > Cc: Stanislaw Gruszka > Cc: Thomas Gleixner > Cc: Wanpeng Li > Link: http://lkml.kernel.org/r/20170629184128.GA5271@embeddedgus > Signed-off-by: Ingo Molnar > --- > kernel/sched/cputime.c | 16 +++++----------- > 1 file changed, 5 insertions(+), 11 deletions(-) > > diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c > index aea3135..67c70e2 100644 > --- a/kernel/sched/cputime.c > +++ b/kernel/sched/cputime.c > @@ -615,19 +615,13 @@ 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 (stime != 0) { > + if (utime == 0) > + stime = rtime; > + else > + stime = scale_stime(stime, rtime, stime + utime); > } > > - if (utime == 0) { > - stime = rtime; > - goto update; > - } > - > - stime = scale_stime(stime, rtime, stime + utime); > - > -update: > /* > * Make sure stime doesn't go backwards; this preserves monotonicity > * for utime because rtime is monotonic. Argh, no... That code was perfectly fine. The new code otoh is convoluted crap. It had the form: if (exception1) deal with exception1 if (execption2) deal with exception2 do normal stuff Which is as simple and straight forward as it gets. The new code otoh reads like: if (!exception1) { if (exception2) deal with exception 2 else do normal stuff } which is absolute shit. So NAK on this.