From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751364AbbEXSTQ (ORCPT ); Sun, 24 May 2015 14:19:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51468 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751244AbbEXSTO (ORCPT ); Sun, 24 May 2015 14:19:14 -0400 Date: Sun, 24 May 2015 20:18:31 +0200 From: Oleg Nesterov To: Nicholas Mc Guire Cc: Peter Zijlstra , Nicholas Mc Guire , Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [PATCH] locking: type cleanup when accessing fast_read_ctr Message-ID: <20150524181830.GA16847@redhat.com> References: <1431971282-21412-1-git-send-email-hofrat@osadl.org> <20150519111105.GB3644@twins.programming.kicks-ass.net> <20150519112513.GA1337@opentech.at> <20150520174431.GB6831@redhat.com> <20150523092336.GA1930@opentech.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150523092336.GA1930@opentech.at> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/23, Nicholas Mc Guire wrote: > > On Wed, 20 May 2015, Oleg Nesterov wrote: > > > On 05/19, Nicholas Mc Guire wrote: > > > > > > I assumed it would not matter but did not see a simple way of getting it > > > type clean with unsigned either mainly due to the atomic_t being int and > > > val in update_fast_ctr() being passed as -1. > > > > Perhaps clear_fast_ctr() should have a comment to explain why it returns > > "int"... even if "unsigned" should work too. > > > Might not be into c99 standard far enough but from reviewing 6.5/J.2 > I do not see this argument here. > > The "well defined modulo 2**n" behavior for unsigned int can be > found stated in a few places - but not in the c99 standard for > arithmetic overflow. > > The "well defined overflow behavior" as far as I understand c99, > *only* applies to left shift operations when overflowing - see 6.5.7 " > Bitwise shift operators" -> Semantics -> 4) - further for the counter > problem this well defined behavior is of little help as the sum would > be wrong in both cases. > > I still do not see the point in the implicit/automatic type conversion > here and why that should be an advantage - could somone point me to > the right c99 clauses ? Sorry, I don't really understand your question... Once again. Signed overflow is undefined behaviour according to C standard. That is why ->fast_read_ctr is "unsigned long", this counter can actually over/underflow if down/up happens on different CPU's. clear_fast_ctr() returns "signed int" just because this looks better to me, it can actually return the negative number. If you make it return "unsigned" you will simply shift this implicit/automatic type conversion to atomic_add() which accepts "int i". Let me also quote Linus: Now, I doubt you'll find an architecture or C compiler where this will actually ever make a difference, Yes. So this all is actually cosmetic. Oleg.