Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006121OCamlback end (clambda to assembly)public2013-08-06 16:202017-03-07 13:55
Reporterchambart 
Assigned Toshinwell 
PrioritynormalSeverityfeatureReproducibilityhave not tried
StatusassignedResolutionopen 
PlatformOSOS Version
Product Version 
Target VersionlaterFixed in Version 
Summary0006121: Atomic load primitives
DescriptionThe mirage project has reported that they need to be able to load and store values using %caml_bigstring_(get/set)* primitives atomically.
Since the addresses passed to thoses primitives can be non aligned, on architectures that does not support unaligned access, those primitives are implemented as byte by byte reads.

There are two possibilities:
* either add %caml_atomic_bigstring_(get/set)* primitives that can fail on non-aligned access
* change the implementation to something like

  if addr is aligned
  then read_one_word
  else fallback to byte by byte read

  the guaranty of atomicity is lifted on unaligned load since it is impossible to ensure.

The patch propose a way to implement a reasonably efficient version of that (only shown for 32 bit load). This is probably always faster than byte by byte read.
Tagspatch
Attached Filespatch file icon 0001-atomic-32-bit-load.patch [^] (3,774 bytes) 2013-08-06 16:20 [Show Content]

- Relationships
related to 0007251acknowledged Provide alignment-requiring versions of the string and bigstring data access primitives 

-  Notes
(0010127)
chambart (developer)
2013-08-06 16:21

Of course if any solution is chosen, I can propose a full patch for it.
(0010447)
avsm (developer)
2013-10-10 11:49

Our specific use-case is to satisfy existing shared memory protocols in Xen, for example vchan: https://github.com/mirage/ocaml-vchan/blob/master/lib/vchan_stubs.c [^]

These use the gcc atomic builtins: http://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Atomic-Builtins.html [^]

Since these atomicops are showing more often in lock-free data structures, it might be better for OCaml to provide explicit equivalent primops to them that libraries can use, rather than having more ambiguous modes such as the Bigarray "fallback to byte-by-byte" proposal above. For now, we're just using C bindings as shown in the link above.
(0016915)
shinwell (developer)
2016-12-08 17:11

@avsm Do you still have a need for these?
(0016940)
avsm (developer)
2016-12-09 11:25

We do indeed still use manual C bindings for this in vchan (and other shared memory protocols that require atomics)
(0017385)
xleroy (administrator)
2017-02-20 15:07

How atomic should "atomic" be? Generating word-sized loads and stores is one thing; handling multiple coherence models (in the style of C11 atomics) on all the ocamlopt-supported platforms is another.
(0017386)
xleroy (administrator)
2017-02-20 15:08

Also: how expensive is it to call into C primitives (of the "noalloc" kind) that implement those atomic memory accesses? If the cost is small wrt the total running time of the application, I'd question the need to emit inline code from ocamlopt.

- Issue History
Date Modified Username Field Change
2013-08-06 16:20 chambart New Issue
2013-08-06 16:20 chambart File Added: 0001-atomic-32-bit-load.patch
2013-08-06 16:21 chambart Note Added: 0010127
2013-08-19 17:22 doligez Status new => acknowledged
2013-08-19 17:22 doligez Target Version => 4.01.1+dev
2013-10-10 11:49 avsm Note Added: 0010447
2013-10-28 15:52 shinwell Assigned To => shinwell
2013-10-28 15:52 shinwell Status acknowledged => assigned
2014-01-17 17:44 doligez Tag Attached: patch
2014-05-25 20:20 doligez Target Version 4.01.1+dev => 4.02.0+dev
2014-07-17 11:22 shinwell Target Version 4.02.0+dev => 4.03.0+dev / +beta1
2016-04-18 16:42 doligez Target Version 4.03.0+dev / +beta1 => 4.03.1+dev
2016-12-08 17:11 shinwell Note Added: 0016915
2016-12-09 11:25 avsm Note Added: 0016940
2017-02-16 14:00 doligez Target Version 4.03.1+dev => undecided
2017-02-20 15:05 xleroy Relationship added related to 0007251
2017-02-20 15:07 xleroy Note Added: 0017385
2017-02-20 15:07 xleroy Target Version undecided => later
2017-02-20 15:08 xleroy Note Added: 0017386
2017-02-23 16:35 doligez Category OCaml backend (code generation) => Back end (clambda to assembly)
2017-02-23 16:44 doligez Category Back end (clambda to assembly) => back end (clambda to assembly)
2017-03-07 13:55 shinwell Severity minor => feature


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker