From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755239AbcFQIYG (ORCPT ); Fri, 17 Jun 2016 04:24:06 -0400 Received: from merlin.infradead.org ([205.233.59.134]:40110 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752337AbcFQIYB (ORCPT ); Fri, 17 Jun 2016 04:24:01 -0400 Date: Fri, 17 Jun 2016 10:23:37 +0200 From: Peter Zijlstra To: Andrey Ryabinin Cc: Yuyang Du , Chris Wilson , Linus Torvalds , Mike Galbraith , Thomas Gleixner , bsegall@google.com, morten.rasmussen@arm.com, pjt@google.com, steve.muckle@linaro.org, linux-kernel@vger.kernel.org, kernel@kyup.com Subject: Re: Divide-by-zero in post_init_entity_util_avg Message-ID: <20160617082337.GM30154@twins.programming.kicks-ass.net> References: <20160609090142.GS32344@nuc-i3427.alporthouse.com> <20160609013324.GH8105@intel.com> <20160609130750.GQ30909@twins.programming.kicks-ass.net> <20160616085040.GF30927@twins.programming.kicks-ass.net> <20160616122504.GG30927@twins.programming.kicks-ass.net> <5763B1D8.1010707@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5763B1D8.1010707@virtuozzo.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 17, 2016 at 11:16:24AM +0300, Andrey Ryabinin wrote: > > I suppose instead we'd want something like: > > > > tmp = READ_ONCE(*ptr); > > if (tmp > val) > > tmp -= val; > > else > > tmp = 0; > > WRITE_ONCE(*ptr, tmp); > > > > In order to generate: > > > > xchg %rax,0xa0(%r13) > > mov 0x78(%r13),%rcx > > sub %rax,%rcx > > cmovae %r15,%rcx > > mov %rcx,0x78(%r13) > > > > however, GCC isn't smart enough and generates: > > > > xchg %rax,0x98(%r13) > > mov 0x70(%r13),%rsi > > mov %rsi,%rcx > > sub %rax,%rcx > > cmp %rsi,%rax > > cmovae %r15,%rcx > > mov %rcx,0x70(%r13) > > > > Doing a CMP with the _same_ values it does the SUB with, resulting in > > exactly the same CC values. > > > > FYI - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3507 (Reported: 2001-07-01) > I found this one when I was googling yesterday: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30315 But yes, it seems this is a 'known' issue.