Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1403664

Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with ISO-C++11 atomics

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with ISO-C++11 atomics
Date 2016-05-19 13:40 +0200
Message-ID <rAut3-7xJ-3@gated-at.bofh.it> (permalink)
References <rAdBU-584-21@gated-at.bofh.it> <rAbqp-3On-7@gated-at.bofh.it> <rAbqq-3On-21@gated-at.bofh.it> <rAsUh-6sS-3@gated-at.bofh.it> <rAtQm-73x-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, May 19, 2016 at 12:50:00PM +0200, Peter Zijlstra wrote:
> > I suspect that might be quite a stretch.
> > 
> > I've opened:
> > 
> > 	https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71191
> > 
> > to cover this.
> 
> Thanks; until such time as this stretch has been made I don't see this
> intrinsic stuff being much use on any of the LL/SC archs.

FWIW, Will and me have been discussing a GCC/LLVM language extension
that would allow generating the insides of LL/SC loops. But neither has
had time to properly write something down yet :/


My latest thinking is something along the lines of:


static __always_inline int __load_locked(int *ptr)
{
	int val;

	__asm__ __volatile__ ("ldaxr %[val], [%[ptr]]"
				: [val] "r" (val)
				: [ptr] "m" (*ptr));

	return val;
}

static __always_inline bool __store_conditional(int *ptr, int old, int new)
{
	int ret;

	__asm__ __volatile__ ("stlxr %[ret], %[new], [%[ptr]]"
		: [ret] "r" (ret)
		: [new] "r" (new),
		  [ptr] "m" (*ptr));

	return ret != 0;
}

bool atomic_add_unless(atomic_t *v, int a, int u)
{
	int val, old;

	do __special_marker__ {
		old = val = __load_locked(&v->counter);

		if (val == u)
			goto fail;

		val += a;
	} while (__store_conditional(&v->counter, old, val));

	return true;

fail:
	return false;
}


Where the __special_marker__ marks the whole { } scope as being the
inside of LL/SC and all variables must be in registers before we start.
If the compiler is not able to guarantee this, it must generate a
compile time error etc..

The __sc takes the @old and @new arguments such that we can implement
this on CAS archs with a regular load and CAS.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics David Howells <dhowells@redhat.com> - 2016-05-18 17:20 +0200
  Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics Peter Zijlstra <peterz@infradead.org> - 2016-05-18 19:40 +0200
    Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics David Woodhouse <dwmw2@infradead.org> - 2016-05-19 09:40 +0200
      Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics Peter Zijlstra <peterz@infradead.org> - 2016-05-19 09:50 +0200
    Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with ISO-C++11 atomics David Howells <dhowells@redhat.com> - 2016-05-19 12:00 +0200
      Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics Peter Zijlstra <peterz@infradead.org> - 2016-05-19 13:00 +0200
        Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics Peter Zijlstra <peterz@infradead.org> - 2016-05-19 13:40 +0200
        Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics Peter Zijlstra <peterz@infradead.org> - 2016-05-19 13:40 +0200
        Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-05-19 16:30 +0200
          Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics Peter Zijlstra <peterz@infradead.org> - 2016-05-19 16:50 +0200
            Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-05-19 17:10 +0200
              Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics Michael Ellerman <mpe@ellerman.id.au> - 2016-05-20 11:40 +0200
                Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-05-23 20:40 +0200
  Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics Peter Zijlstra <peterz@infradead.org> - 2016-05-18 19:40 +0200
  Re: [RFC PATCH 03/15] Provide atomic_t functions implemented with  ISO-C++11 atomics Peter Zijlstra <peterz@infradead.org> - 2016-05-18 19:40 +0200

csiph-web