[LITMUS^RT] LITMUS^RT on v4.9: call for testing

Björn Brandenburg bbb at mpi-sws.org
Wed Mar 8 12:39:17 CET 2017


> On 8 Mar 2017, at 10:16, Andrea Bastoni <bastoni at sprg.uniroma2.it> wrote:
> So, yes, above you need a release
> semantics (but that should be coupled with an acquire one somewhere,
> perhaps where the free count is checked(?) -- why is the free_count
> incremented atomically, but not read with at least READ_ONCE? -- but
> I'm no longer familiar with the code, sorry.)

Hi Andrea,

thanks for your quick reply. The corresponding atomic access is in ft_buffer_start_write() in litmus/feather_buffer.h.

static inline int ft_buffer_start_write(struct ft_buffer* buf, void **ptr)
{

—->	int free = fetch_and_dec(&buf->free_count);

	unsigned int idx;
	if (free <= 0) {
		fetch_and_inc(&buf->free_count);
		*ptr = 0;
		fetch_and_inc(&buf->failed_writes);
		return 0;
	} else {
		idx  = fetch_and_inc((int*) &buf->write_idx) % buf->slot_count;
		buf->slots[idx] = SLOT_BUSY;
		*ptr = ((char*) buf->buffer_mem) + idx * buf->slot_size;
		return 1;
	}
}

If both instances are fully serializing (i.e., the “old” semantics of atomic_add_return()), then this should work fine, I think. 

There are also a few places where the variable is read without atomics (e.g., the single-writer case in the same file). This “relies” (i.e., it seemingly has worked to date) on the fact that word-aligned loads on x86 are actually atomic, and the fact that the variable is not used again (without a cast to atomic) in the same scope. I don’t think anyone has reasoned about portability to other platforms much to date, or taken into account what future hyper-agressive compiler optimizations might result in.

Hence my suggestion to convert everything to proper atomic_t variables… Any volunteers (not Andrea)?

> In the end, yes, there's the need of a barrier after the
> fetch_and_inc(). Probably this _untested_ patch may do the trick:
> diff --git a/include/litmus/feather_trace.h b/include/litmus/feather_trace.h
> index dbeca46..24dbc16 100644
> --- a/include/litmus/feather_trace.h
> +++ b/include/litmus/feather_trace.h
> @@ -1,7 +1,7 @@
> #ifndef _FEATHER_TRACE_H_
> #define _FEATHER_TRACE_H_
> 
> -#include <asm/atomic.h>
> +#include <linux/atomic.h>

Namhoon, can you confirm that this works?

Thanks,
Björn




More information about the litmus-dev mailing list