From: Oleg Nesterov <oleg@redhat.com>
To: Nicholas Mc Guire <der.herr@hofr.at>
Cc: Peter Zijlstra <peterz@infradead.org>,
Nicholas Mc Guire <hofrat@osadl.org>,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] locking: type cleanup when accessing fast_read_ctr
Date: Sun, 24 May 2015 20:18:31 +0200 [thread overview]
Message-ID: <20150524181830.GA16847@redhat.com> (raw)
In-Reply-To: <20150523092336.GA1930@opentech.at>
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.
next prev parent reply other threads:[~2015-05-24 18:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-18 17:48 Nicholas Mc Guire
2015-05-19 11:11 ` Peter Zijlstra
2015-05-19 11:25 ` Nicholas Mc Guire
2015-05-20 17:44 ` Oleg Nesterov
2015-05-23 6:46 ` Nicholas Mc Guire
2015-05-23 9:23 ` Nicholas Mc Guire
2015-05-24 18:18 ` Oleg Nesterov [this message]
2015-05-25 5:46 ` Nicholas Mc Guire
2015-05-20 17:42 ` Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150524181830.GA16847@redhat.com \
--to=oleg@redhat.com \
--cc=der.herr@hofr.at \
--cc=hofrat@osadl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome