From: Honnappa Nagarahalli <honnappa.nagaraha...@arm.com>

Add pad to pool_cache_t so that it always ends at cache line boundary.
Since an array of pool_cache_t is used in pool_t, this change
will ensure that cache lines are not shared between cores.

Signed-off-by: Honnappa Nagarahalli <honnappa.nagaraha...@arm.com>
Reviewed-by: Ola Liljedahl <ola.liljed...@arm.com>
Reviewed-by: Kevin Wang <kevin.w...@arm.com>
---
/** Email created from pull request 346 (nagarahalli:cp-pad-pool-cache)
 ** https://github.com/Linaro/odp/pull/346
 ** Patch: https://github.com/Linaro/odp/pull/346.patch
 ** Base sha: bbbe6c0ef65c16f6d7d327712f177fbf6740e96f
 ** Merge commit sha: c453edadb1e6f0cfbe31e17432d4f046d0511a05
 **/
 platform/linux-generic/buffer/generic.c            | 18 +++++++++---------
 platform/linux-generic/include/odp_pool_internal.h |  7 ++++++-
 platform/linux-generic/pool/generic.c              |  8 ++++----
 3 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/platform/linux-generic/buffer/generic.c 
b/platform/linux-generic/buffer/generic.c
index cf99407cc..9631078a4 100644
--- a/platform/linux-generic/buffer/generic.c
+++ b/platform/linux-generic/buffer/generic.c
@@ -117,7 +117,7 @@ int buffer_alloc_multi(pool_t *pool, odp_buffer_hdr_t 
*buf_hdr[], int max_num)
 
        cache = local.cache[pool->pool_idx];
 
-       cache_num = cache->num;
+       cache_num = cache->s.num;
        num_ch    = max_num;
        num_deq   = 0;
        burst     = CACHE_BURST;
@@ -135,7 +135,7 @@ int buffer_alloc_multi(pool_t *pool, odp_buffer_hdr_t 
*buf_hdr[], int max_num)
        for (i = 0; i < num_ch; i++) {
                uint32_t j = cache_num - num_ch + i;
 
-               buf_hdr[i] = buf_hdr_from_index(pool, cache->buf_index[j]);
+               buf_hdr[i] = buf_hdr_from_index(pool, cache->s.buf_index[j]);
        }
 
        /* If needed, get more from the global pool */
@@ -164,11 +164,11 @@ int buffer_alloc_multi(pool_t *pool, odp_buffer_hdr_t 
*buf_hdr[], int max_num)
 
                /* Cache extra buffers. Cache is currently empty. */
                for (i = 0; i < cache_num; i++)
-                       cache->buf_index[i] = data[num_deq + i];
+                       cache->s.buf_index[i] = data[num_deq + i];
 
-               cache->num = cache_num;
+               cache->s.num = cache_num;
        } else {
-               cache->num = cache_num - num_ch;
+               cache->s.num = cache_num - num_ch;
        }
 
        return num_ch + num_deq;
@@ -202,7 +202,7 @@ static inline void buffer_free_to_pool(pool_t *pool,
 
        /* Make room into local cache if needed. Do at least burst size
         * transfer. */
-       cache_num = cache->num;
+       cache_num = cache->s.num;
 
        if (odp_unlikely((int)(CONFIG_POOL_CACHE_SIZE - cache_num) < num)) {
                uint32_t index;
@@ -224,7 +224,7 @@ static inline void buffer_free_to_pool(pool_t *pool,
                        index = cache_num - burst;
 
                        for (i = 0; i < burst; i++)
-                               data[i] = cache->buf_index[index + i];
+                               data[i] = cache->s.buf_index[index + i];
 
                        ring_enq_multi(ring, mask, data, burst);
                }
@@ -233,9 +233,9 @@ static inline void buffer_free_to_pool(pool_t *pool,
        }
 
        for (i = 0; i < num; i++)
-               cache->buf_index[cache_num + i] = buf_hdr[i]->index;
+               cache->s.buf_index[cache_num + i] = buf_hdr[i]->index;
 
-       cache->num = cache_num + num;
+       cache->s.num = cache_num + num;
 }
 
 void buffer_free_multi(odp_buffer_hdr_t *buf_hdr[], int num_total)
diff --git a/platform/linux-generic/include/odp_pool_internal.h 
b/platform/linux-generic/include/odp_pool_internal.h
index a124697e9..3a2fe25fc 100644
--- a/platform/linux-generic/include/odp_pool_internal.h
+++ b/platform/linux-generic/include/odp_pool_internal.h
@@ -29,10 +29,15 @@ extern "C" {
 
 #define CACHE_BURST    32
 
-typedef struct pool_cache_t {
+struct pool_cache_s {
        uint32_t num;
        uint32_t buf_index[CONFIG_POOL_CACHE_SIZE];
 
+};
+
+typedef union pool_cache_u {
+       struct pool_cache_s s;
+       uint8_t pad[ROUNDUP_CACHE_LINE(sizeof(struct pool_cache_s))];
 } pool_cache_t ODP_ALIGNED_CACHE;
 
 /* Buffer header ring */
diff --git a/platform/linux-generic/pool/generic.c 
b/platform/linux-generic/pool/generic.c
index 7a068472c..802c5a0bb 100644
--- a/platform/linux-generic/pool/generic.c
+++ b/platform/linux-generic/pool/generic.c
@@ -120,7 +120,7 @@ static int generic_pool_init_local(void)
        for (i = 0; i < ODP_CONFIG_POOLS; i++) {
                pool           = pool_entry(i);
                local.cache[i] = &pool->local_cache[thr_id];
-               local.cache[i]->num = 0;
+               local.cache[i]->s.num = 0;
        }
 
        local.thr_id = thr_id;
@@ -135,12 +135,12 @@ static void flush_cache(pool_cache_t *cache, pool_t *pool)
 
        ring = &pool->ring->hdr;
        mask = pool->ring_mask;
-       cache_num = cache->num;
+       cache_num = cache->s.num;
 
        for (i = 0; i < cache_num; i++)
-               ring_enq(ring, mask, cache->buf_index[i]);
+               ring_enq(ring, mask, cache->s.buf_index[i]);
 
-       cache->num = 0;
+       cache->s.num = 0;
 }
 
 static int generic_pool_term_local(void)

Reply via email to