一个 DPDK 的 ring 疑问

2018-09-27 10:17:07 +08:00
 dingzs3

DPDK 版本: dpdk-stable-17.11.3

查看定义 rte_ring 结构: struct rte_ring {

char name[RTE_MEMZONE_NAMESIZE] __rte_cache_aligned; /**< Name of the ring. */

int flags;               /**< Flags supplied at creation. */

const struct rte_memzone *memzone;

uint32_t size;           /**< Size of ring. */

uint32_t mask;           /**< Mask (size-1) of ring. */

uint32_t capacity;       /**< Usable size of ring */

struct rte_ring_headtail prod __rte_aligned(PROD_ALIGN);

struct rte_ring_headtail cons __rte_aligned(CONS_ALIGN);

}

其中 rte_ring_headtail 以及对齐的定义: #if RTE_CACHE_LINE_SIZE < 128

#define PROD_ALIGN (RTE_CACHE_LINE_SIZE * 2)

#define CONS_ALIGN (RTE_CACHE_LINE_SIZE * 2)

#else

#define PROD_ALIGN RTE_CACHE_LINE_SIZE

#define CONS_ALIGN RTE_CACHE_LINE_SIZE

#endif

/* structure to hold a pair of head/tail values and other metadata */

struct rte_ring_headtail {

volatile uint32_t head;  /**< Prod/consumer head. */
volatile uint32_t tail;  /**< Prod/consumer tail. */
uint32_t single;         /**< True if single prod/cons */

};

这个生产者和消费者的结构体定义成 2 个 cacheline ( 64byte )的大小(我的是 intel 的 64 位环境) 是为了减少 cacheline 伪共享吗?为啥是 2 个,1 个不行吗?

2 个 cacheline 大小和硬件基于局部性原理会预取 2 个 cacheline 吗,更进一步减少伪共享?

1908 次点击
所在节点    程序员
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/493036

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX