summaryrefslogtreecommitdiff
path: root/bbq/include/bbq.h
diff options
context:
space:
mode:
authorliuyu <[email protected]>2024-07-01 23:14:39 -0400
committerliuyu <[email protected]>2024-07-01 23:14:39 -0400
commitd7b76b021a24a1090b41c5cddca10a70f731a2b4 (patch)
treeee9c9d0fe2249fe6187158c1945d7c873a1c4a9c /bbq/include/bbq.h
parent075525658564b863fe6feec425b2fe878575e3c7 (diff)
性能优化,cache line对齐dev-single
Diffstat (limited to 'bbq/include/bbq.h')
-rw-r--r--bbq/include/bbq.h30
1 files changed, 19 insertions, 11 deletions
diff --git a/bbq/include/bbq.h b/bbq/include/bbq.h
index d752130..3f0c355 100644
--- a/bbq/include/bbq.h
+++ b/bbq/include/bbq.h
@@ -1,6 +1,6 @@
/*
* @Author: [email protected]
- * @LastEditTime: 2024-07-01 09:18:56
+ * @LastEditTime: 2024-07-01 23:12:49
* @Describe: bbq(Block-based Bounded Queue)头文件
* 参考:https://www.usenix.org/system/files/atc22-wang-jiawei.pdf
*/
@@ -25,7 +25,8 @@ using aotmic_uint64 = std::atomic<uint64_t>;
#define BBQ_SOCKET_ID_ANY -1
#define BBQ_SYMBOL_MAX 64
-#define __BBQ_CACHE_ALIGNED __attribute__((__aligned__(64)))
+#define BBQ_CACHE_LINE 64
+#define __BBQ_CACHE_ALIGNED __attribute__((__aligned__(BBQ_CACHE_LINE)))
struct bbq_atomic64 {
bool single; // 如果为单生产者或单消费者,则single为true
@@ -33,22 +34,31 @@ struct bbq_atomic64 {
volatile uint64_t s; // single使用该字段
aotmic_uint64 m;
};
+};
+
+struct bbq_head {
+ struct bbq_atomic64 value; // head值
+ struct bbq_atomic64 count; // 出/入队个数统计(create时设置了统计flag才生效)
} __BBQ_CACHE_ALIGNED;
struct bbq_block {
+ // cache line 1
struct bbq_atomic64 committed; // 已提交(version|offset)
struct bbq_atomic64 allocated; // 已分配(version|offset)
struct bbq_atomic64 reserved; // 已预留(version|offset)
struct bbq_atomic64 consumed; // 已消费(version|offset)注:在drop-old模式下没用到
- char *entries; // 存储大小可变的entry,每个块分配空间:bs * entry_size
+ // cache line 2
+ char *entries; // 存储大小可变的entry,每个块分配空间:bs * entry_size
} __BBQ_CACHE_ALIGNED;
typedef void *(*bbq_malloc_f)(int32_t socket_id, size_t size);
typedef void (*bbq_free_f)(void *ptr, size_t size);
struct bbq {
+ // cache-line 1
char name[BBQ_SYMBOL_MAX] __BBQ_CACHE_ALIGNED;
+ // cache-line 2
int32_t socket_id; // 用于libnuma分配内存,socket_id小于0将使用malloc分配
uint32_t bn; // blocks的个数
uint32_t bs; // blocks.entries的个数
@@ -61,21 +71,19 @@ struct bbq {
bbq_malloc_f malloc_f; // 申请内存的函数,默认为malloc
bbq_free_f free_f; // 申请内存的函数,默认为free
- struct bbq_atomic64 phead; // 生产者头,指向块的索引,分为两部分:version|idx
- struct bbq_atomic64 chead; // 消费者头,指向块的索引,分为两部分:version|idx
+ // cache-line 3
+ struct bbq_head phead; // 生产者头,指向块的索引,分为两部分:version|idx
+ // cache-line 4
+ struct bbq_head chead; // 消费者头,指向块的索引,分为两部分:version|idx
- struct {
- struct bbq_atomic64 n_enq;
- struct bbq_atomic64 n_deq;
- } stat;
+ // cache-line 5
struct bbq_block *blocks; // bn大小的数组
-
#ifdef TEST_PERF_MEM
struct {
char *ptr; // 内存池起始地址
size_t off; // 已使用的偏移大小
size_t size; // 内存池总大小
- } memory_pool;
+ } memory_pool; // 仅在初始化和调试时会读写
#endif
} __BBQ_CACHE_ALIGNED;