All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Metcalf <cmetcalf@ezchip.com>
To: Frederic Weisbecker <fweisbec@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Luiz Capitulino <lcapitulino@redhat.com>,
	Christoph Lameter <cl@linux.com>, Ingo Molnar <mingo@kernel.org>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Rik van Riel <riel@redhat.com>
Subject: Re: [PATCH 1/7] atomic: Export fetch_or()
Date: Tue, 24 Nov 2015 16:48:35 -0500	[thread overview]
Message-ID: <5654DB33.1080706@ezchip.com> (raw)
In-Reply-To: <20151124211951.GA16609@lerouge>

On 11/24/2015 04:19 PM, Frederic Weisbecker wrote:
>> Also, I wonder about the nomenclature here: other than cmpxchg
>> >and xchg, all the atomic ops are named "atomic_xxx".  For something
>> >that returns the old value, I'd expect it to be atomic_or_return()
>> >and be otherwise like the existing atomic_or() routine, and thus you'd
>> >specify "atomic_t tick_dependency".
> I think Peterz needs it to be type-generic, like cmpxchg, such that he can
> use it on tsk->thread_info->flags which type can vary. But if we happen to
> need an atomic_t version, we can also provide an atomic_fetch_or() version.

Yes, I think my point is that Peter Z's version is what is needed for
the scheduler, but it may not be the thing we want to start providing
to the entire kernel without thinking a little harder about the semantics,
the namespace issues, and whether there is or should be room for
some appropriate family of similar calls.  Just tossing in fetch_or()
because it's easy doesn't necessarily seem like what we should be doing.

> Also note that or_return() means that you first do OR and then return the new value.

Yeah, actually fair point.  I keep forgetting Linux does this "backwards".

I still think we should use an atomic_xxx() name here rather than just
adding things into the namespace willy-nilly.

It's tempting to use atomic_fetch_or() but that actually conflicts with the
C11 names, and remarkably, we haven't done that yet in the kernel,
so we may want to avoid doing so for now.  I can imagine in the not
too distant future we detect C11 compilers and allow using <stdatomic.h>
if possible.  (Obviously some platforms require kernel support or
other tricky things for stdatomic.h, so we couldn't use it everywhere.)

We could use something like gcc's old __sync_fetch_and_XXX vs
__sync_XXX_and_fetch nomenclature and call it atomic_return_or()
to contrast with atomic_or_return().  That avoids clashing with C11
for now and is obviously distinct from atomic_or_return().  I suppose
something like atomic_fetch_and_or() isn't terrible either.

There is boilerplate for building generic atomic functions already in
include/asm-generic/atomic.h and that could be extended.
Unfortunately the atomic64 generic code isn't similarly constructed,
so you can't just provide a default atomic64_return_or() based on that
stuff, or at least, you only can on platforms that use an array of locks
to implement 64-bit atomics.  Ugh.

If we did this and then wanted Peter Z's code to take advantage of it,
in principle we could just have some macrology which would compare
the sizeof(thread_info.flags) to sizeof(int) and sizeof(long) to see which
one to use and then cast to the appropriate atomic_t or atomic64_t.
That's a little painful but not terrible.

Boy, the whole situation is pretty tangled up, though.

Unless you want to take a big diversion into atomics, I'd be tempted
to leave Peter's macro alone and just write it off as necessary evil
to handle the fact that thread_info.flags is all kinds of different sizes
and types on different platforms, and definitely never an atomic_t.
Instead just create an inline function atomic_return_or(), or
whatever name you prefer, that operates on an atomic_t, and use
the atomic_t type for your structure field.  It's clearly a win to mark
the data types as being atomic to the extent we can do so, I think.

-- 
Chris Metcalf, EZChip Semiconductor
http://www.ezchip.com


  reply	other threads:[~2015-11-24 21:48 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-13 14:22 [PATCH 0/7] nohz: Tick dependency mask v3 Frederic Weisbecker
2015-11-13 14:22 ` [PATCH 1/7] atomic: Export fetch_or() Frederic Weisbecker
2015-11-24 15:58   ` Chris Metcalf
2015-11-24 21:19     ` Frederic Weisbecker
2015-11-24 21:48       ` Chris Metcalf [this message]
2015-11-30 17:36         ` Frederic Weisbecker
2015-11-30 18:17           ` Chris Metcalf
2015-11-25  9:13       ` Peter Zijlstra
2015-11-13 14:22 ` [PATCH 2/7] nohz: New tick dependency mask Frederic Weisbecker
2015-11-24 16:19   ` Chris Metcalf
2015-11-25 11:32     ` Frederic Weisbecker
2015-12-01 20:41   ` Peter Zijlstra
2015-12-01 22:20     ` Frederic Weisbecker
2015-12-02 10:56       ` Peter Zijlstra
2015-12-02 14:08         ` Frederic Weisbecker
2015-12-02 15:09           ` Peter Zijlstra
2015-12-08 15:57             ` Frederic Weisbecker
2015-12-02 12:45       ` Peter Zijlstra
2015-12-02 14:10         ` Frederic Weisbecker
2015-12-02 12:48       ` Peter Zijlstra
2015-12-02 14:11         ` Frederic Weisbecker
2015-11-13 14:22 ` [PATCH 3/7] perf: Migrate perf to use new tick dependency mask model Frederic Weisbecker
2015-11-24 16:19   ` Chris Metcalf
2015-11-25 12:34     ` Frederic Weisbecker
2015-12-02 16:17       ` Peter Zijlstra
2015-12-02 17:03         ` Frederic Weisbecker
2015-12-02 17:15           ` Peter Zijlstra
2015-11-13 14:22 ` [PATCH 4/7] sched: Account rr and fifo tasks separately Frederic Weisbecker
2015-12-02 12:53   ` Peter Zijlstra
2015-12-02 14:16     ` Frederic Weisbecker
2015-11-13 14:22 ` [PATCH 5/7] sched: Migrate sched to use new tick dependency mask model Frederic Weisbecker
2015-11-13 14:22 ` [PATCH 6/7] posix-cpu-timers: Migrate " Frederic Weisbecker
2015-11-13 14:22 ` [PATCH 7/7] sched-clock: " Frederic Weisbecker

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=5654DB33.1080706@ezchip.com \
    --to=cmetcalf@ezchip.com \
    --cc=cl@linux.com \
    --cc=fweisbec@gmail.com \
    --cc=lcapitulino@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=viresh.kumar@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.