Skip to content

Commit 6f3d893

Browse files
dinosaurereynir
andcommitted
Add a static check to see if we properly align our struct hvt_ring on 2 cache-lines
Co-authored-by: Reynir Björnsson <reynir@reynir.dk>
1 parent 02766fb commit 6f3d893

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

include/hvt_ring.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#ifndef HVT_RING_H
2828
#define HVT_RING_H
2929

30+
#include <stddef.h>
3031
#include <stdint.h>
3132

3233
#define HVT_RING_SIZE 1024
@@ -94,6 +95,16 @@ struct hvt_ring {
9495
struct hvt_ring_commit commits[HVT_RING_SIZE];
9596
};
9697

98+
/*
99+
* Verify that guest-written and host-written fields live on distinct cache
100+
* lines (64 bytes each), and that the data arrays start after exactly 2
101+
* cache lines of index/control fields.
102+
*/
103+
_Static_assert(offsetof(struct hvt_ring, ent_head) == 64,
104+
"ent_head must start at cache line 1 (offset 64)");
105+
_Static_assert(offsetof(struct hvt_ring, entries) == 128,
106+
"entries[] must start after 2 cache lines (offset 128)");
107+
97108
/*
98109
* Memory barriers.
99110
*

0 commit comments

Comments
 (0)