V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
dingzs3
V2EX  ›  程序员

一个 DPDK 的 ring 疑问

  •  
  •   dingzs3 · 2018-09-27 10:17:07 +08:00 · 1895 次点击
    这是一个创建于 2031 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 吗,更进一步减少伪共享?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5053 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 09:35 · PVG 17:35 · LAX 02:35 · JFK 05:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.