IO-Uring Archive on lore.kernel.org
 help / color / Atom feed
* are volatile and memory barriers necessary for single threaded code?
@ 2020-05-04 16:54 Lorenzo Gabriele
  2020-05-06 13:44 ` Pavel Begunkov
  0 siblings, 1 reply; 3+ messages in thread
From: Lorenzo Gabriele @ 2020-05-04 16:54 UTC (permalink / raw)
  To: io-uring

Hi everyone,
I'm a complete noob so sorry if I'm saying something stupid.
I want to have a liburing-like library for the Scala Native language.
I can't easily use liburing itself because of some limitations of the
language.. So I was rewriting the C code in liburing in Scala Native.
The language is single threaded and, sadly, doesn't support atomic,
nor volatile. I was thinking what are the implications of completely
removing the memory barriers.
Are they needed for something related with multithreading or they are
needed regardless to utilize io_uring?
Thank you very much.
Lorenzo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: are volatile and memory barriers necessary for single threaded code?
  2020-05-04 16:54 are volatile and memory barriers necessary for single threaded code? Lorenzo Gabriele
@ 2020-05-06 13:44 ` Pavel Begunkov
  2020-05-18 11:31   ` Lorenzo Gabriele
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Begunkov @ 2020-05-06 13:44 UTC (permalink / raw)
  To: Lorenzo Gabriele, io-uring

On 04/05/2020 19:54, Lorenzo Gabriele wrote:
> Hi everyone,
> I'm a complete noob so sorry if I'm saying something stupid.
> I want to have a liburing-like library for the Scala Native language.
> I can't easily use liburing itself because of some limitations of the
> language.. So I was rewriting the C code in liburing in Scala Native.
> The language is single threaded and, sadly, doesn't support atomic,
> nor volatile. I was thinking what are the implications of completely
> removing the memory barriers.
> Are they needed for something related with multithreading or they are
> needed regardless to utilize io_uring?

Long story short, even if your app is single-threaded, io_uring is _not_.
I wouldn't recommend removing it. See the comment below picked from io_uring.h

/*
 * After the application reads the CQ ring tail, it must use an
 * appropriate smp_rmb() to pair with the smp_wmb() the kernel uses
 * before writing the tail (using smp_load_acquire to read the tail will
 * do). It also needs a smp_mb() before updating CQ head (ordering the
 * entry load(s) with the head store), pairing with an implicit barrier
 * through a control-dependency in io_get_cqring (smp_store_release to
 * store head will do). Failure to do so could lead to reading invalid
 * CQ entries.
 */


More difficult to say, what will actually happen. E.g. if you don't use polling
io_uring modes, and if you don't do speculative CQ reaping, there is a pairing
smp_rmb() just before returning from a wait. But, again, the io_uring ABI
doesn't guarantee correctness without them.

-- 
Pavel Begunkov

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: are volatile and memory barriers necessary for single threaded code?
  2020-05-06 13:44 ` Pavel Begunkov
@ 2020-05-18 11:31   ` Lorenzo Gabriele
  0 siblings, 0 replies; 3+ messages in thread
From: Lorenzo Gabriele @ 2020-05-18 11:31 UTC (permalink / raw)
  To: Pavel Begunkov; +Cc: io-uring

Thank you very much for the detailed answer!
So I think I will more safely build on top of liburing!

Lorenzo

Il giorno mer 6 mag 2020 alle ore 15:45 Pavel Begunkov
<asml.silence@gmail.com> ha scritto:
>
> On 04/05/2020 19:54, Lorenzo Gabriele wrote:
> > Hi everyone,
> > I'm a complete noob so sorry if I'm saying something stupid.
> > I want to have a liburing-like library for the Scala Native language.
> > I can't easily use liburing itself because of some limitations of the
> > language.. So I was rewriting the C code in liburing in Scala Native.
> > The language is single threaded and, sadly, doesn't support atomic,
> > nor volatile. I was thinking what are the implications of completely
> > removing the memory barriers.
> > Are they needed for something related with multithreading or they are
> > needed regardless to utilize io_uring?
>
> Long story short, even if your app is single-threaded, io_uring is _not_.
> I wouldn't recommend removing it. See the comment below picked from io_uring.h
>
> /*
>  * After the application reads the CQ ring tail, it must use an
>  * appropriate smp_rmb() to pair with the smp_wmb() the kernel uses
>  * before writing the tail (using smp_load_acquire to read the tail will
>  * do). It also needs a smp_mb() before updating CQ head (ordering the
>  * entry load(s) with the head store), pairing with an implicit barrier
>  * through a control-dependency in io_get_cqring (smp_store_release to
>  * store head will do). Failure to do so could lead to reading invalid
>  * CQ entries.
>  */
>
>
> More difficult to say, what will actually happen. E.g. if you don't use polling
> io_uring modes, and if you don't do speculative CQ reaping, there is a pairing
> smp_rmb() just before returning from a wait. But, again, the io_uring ABI
> doesn't guarantee correctness without them.
>
> --
> Pavel Begunkov

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-04 16:54 are volatile and memory barriers necessary for single threaded code? Lorenzo Gabriele
2020-05-06 13:44 ` Pavel Begunkov
2020-05-18 11:31   ` Lorenzo Gabriele

IO-Uring Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/io-uring/0 io-uring/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 io-uring io-uring/ https://lore.kernel.org/io-uring \
		io-uring@vger.kernel.org
	public-inbox-index io-uring

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.io-uring


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git