[ovs-dev,2/7] cmap: Use PADDED_MEMBERS_CACHELINE_MARKER in cmap_impl.

Message ID 1506844660-4902-2-git-send-email-bhanuprakash.bodireddy@intel.com
State New
Headers show
Series
  • [ovs-dev,1/7] ccmap: Use PADDED_MEMBERS macro in ccmap_impl structure.
Related show

Commit Message

Bodireddy, Bhanuprakash Oct. 1, 2017, 7:57 a.m.
Instead of explicitly adding the pad bytes to force the structure an
exact multiple of cacheline size, let the macro do the job. This way
the pad bytes will be auto adjusted when the new members get introduced
in to the structure.

Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
---
 lib/cmap.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

Patch

diff --git a/lib/cmap.c b/lib/cmap.c
index 8c7312d..35decea 100644
--- a/lib/cmap.c
+++ b/lib/cmap.c
@@ -165,13 +165,18 @@  BUILD_ASSERT_DECL(sizeof(struct cmap_bucket) == CACHE_LINE_SIZE);
 
 /* The implementation of a concurrent hash map. */
 struct cmap_impl {
-    unsigned int n;             /* Number of in-use elements. */
-    unsigned int max_n;         /* Max elements before enlarging. */
-    unsigned int min_n;         /* Min elements before shrinking. */
-    uint32_t mask;              /* Number of 'buckets', minus one. */
-    uint32_t basis;             /* Basis for rehashing client's hash values. */
-    uint8_t pad[CACHE_LINE_SIZE - 4 * 5]; /* Pad to end of cache line. */
-    struct cmap_bucket buckets[1];
+    PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline0,
+        unsigned int n;             /* Number of in-use elements. */
+        unsigned int max_n;         /* Max elements before enlarging. */
+        unsigned int min_n;         /* Min elements before shrinking. */
+        uint32_t mask;              /* Number of 'buckets', minus one. */
+        uint32_t basis;             /* Basis for rehashing client's
+                                       hash values. */
+    );
+
+    PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline1,
+        struct cmap_bucket buckets[1];
+    );
 };
 BUILD_ASSERT_DECL(sizeof(struct cmap_impl) == CACHE_LINE_SIZE * 2);