ck_bag: Disable pointer packing by default.

ck_pring
Samy Al Bahra 13 years ago
parent 8bed9627a6
commit 4fcb6a5e5f

@ -29,10 +29,11 @@
#define _CK_BAG_H #define _CK_BAG_H
#include <ck_cc.h> #include <ck_cc.h>
#include <ck_pr.h>
#include <ck_malloc.h> #include <ck_malloc.h>
#include <ck_stdint.h> #include <ck_md.h>
#include <ck_pr.h>
#include <ck_queue.h> #include <ck_queue.h>
#include <ck_stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
@ -72,10 +73,17 @@ struct ck_bag_block_info {
size_t bytes; size_t bytes;
}; };
/*
* Determine whether pointer packing should be enabled.
*/
#if defined(CK_BAG_PP) && defined(CK_MD_POINTER_PACK_ENABLE)
#define CK_BAG_PP
#endif
#define CK_BAG_DEFAULT 0 #define CK_BAG_DEFAULT 0
struct ck_bag_block_md { struct ck_bag_block_md {
#ifdef __x86_64__ #ifdef CK_BAG_PP
struct ck_bag_block *ptr; struct ck_bag_block *ptr;
#else #else
struct ck_bag_block *ptr; struct ck_bag_block *ptr;
@ -106,7 +114,7 @@ struct ck_bag_iterator {
}; };
typedef struct ck_bag_iterator ck_bag_iterator_t; typedef struct ck_bag_iterator ck_bag_iterator_t;
#ifdef __x86_64__ #ifdef CK_BAG_PP
#define CK_BAG_BLOCK_ENTRIES_MASK ((uintptr_t)0xFFFF << 48) #define CK_BAG_BLOCK_ENTRIES_MASK ((uintptr_t)0xFFFF << 48)
#endif #endif
@ -114,7 +122,7 @@ CK_CC_INLINE static struct ck_bag_block *
ck_bag_block_next(struct ck_bag_block *block) ck_bag_block_next(struct ck_bag_block *block)
{ {
#ifdef __x86_64__ #ifdef CK_BAG_PP
return (struct ck_bag_block *)((uintptr_t)block & ~CK_BAG_BLOCK_ENTRIES_MASK); return (struct ck_bag_block *)((uintptr_t)block & ~CK_BAG_BLOCK_ENTRIES_MASK);
#else #else
return block; return block;
@ -132,7 +140,7 @@ CK_CC_INLINE static uint16_t
ck_bag_block_count(struct ck_bag_block *block) ck_bag_block_count(struct ck_bag_block *block)
{ {
#ifdef __x86_64__ #ifdef CK_BAG_PP
return (uintptr_t)ck_pr_load_ptr(&block->next.ptr) >> 48; return (uintptr_t)ck_pr_load_ptr(&block->next.ptr) >> 48;
#else #else
return (uintptr_t)ck_pr_load_ptr(&block->next.n_entries); return (uintptr_t)ck_pr_load_ptr(&block->next.n_entries);

@ -36,7 +36,7 @@
#define CK_BAG_PAGESIZE CK_MD_PAGESIZE #define CK_BAG_PAGESIZE CK_MD_PAGESIZE
#ifdef __x86_64__ #ifdef CK_BAG_PP
#define CK_BAG_MAX_N_ENTRIES (1 << 12) #define CK_BAG_MAX_N_ENTRIES (1 << 12)
#endif #endif
@ -66,7 +66,7 @@ ck_bag_init(struct ck_bag *bag,
bag->info.max = (block_size / sizeof(void *)); bag->info.max = (block_size / sizeof(void *));
#ifdef __x86_64__ #ifdef CK_BAG_PP
if (bag->info.max > CK_BAG_MAX_N_ENTRIES) if (bag->info.max > CK_BAG_MAX_N_ENTRIES)
return false; return false;
#endif #endif
@ -140,7 +140,7 @@ ck_bag_put_spmc(struct ck_bag *bag, void *entry)
if (new_block == NULL) if (new_block == NULL)
return false; return false;
#ifdef __x86_64__ #ifdef CK_BAG_PP
new_block->next.ptr = NULL; new_block->next.ptr = NULL;
#else #else
new_block->next.n_entries = 0; new_block->next.n_entries = 0;
@ -163,7 +163,7 @@ ck_bag_put_spmc(struct ck_bag *bag, void *entry)
cursor->array[n_entries_block++] = entry; cursor->array[n_entries_block++] = entry;
ck_pr_fence_store(); ck_pr_fence_store();
#ifdef __x86_64__ #ifdef CK_BAG_PP
next = ((uintptr_t)n_entries_block << 48); next = ((uintptr_t)n_entries_block << 48);
#endif #endif
@ -171,14 +171,14 @@ ck_bag_put_spmc(struct ck_bag *bag, void *entry)
if (n_entries_block == 1) { if (n_entries_block == 1) {
/* Place newly filled block at the head of bag list */ /* Place newly filled block at the head of bag list */
if (bag->head != NULL) { if (bag->head != NULL) {
#ifdef __x86_64__ #ifdef CK_BAG_PP
next += ((uintptr_t)(void *)ck_bag_block_next(bag->head)); next += ((uintptr_t)(void *)ck_bag_block_next(bag->head));
#else #else
next = (uintptr_t)(void *)ck_bag_block_next(bag->head); next = (uintptr_t)(void *)ck_bag_block_next(bag->head);
#endif #endif
} }
#ifndef __x86_64__ #ifndef CK_BAG_PP
ck_pr_store_ptr(&cursor->next.n_entries, (void *)(uintptr_t)n_entries_block); ck_pr_store_ptr(&cursor->next.n_entries, (void *)(uintptr_t)n_entries_block);
#endif #endif
@ -186,7 +186,7 @@ ck_bag_put_spmc(struct ck_bag *bag, void *entry)
ck_pr_store_ptr(&bag->head, cursor); ck_pr_store_ptr(&bag->head, cursor);
} else { } else {
/* Block is already on bag list, update n_entries */ /* Block is already on bag list, update n_entries */
#ifdef __x86_64__ #ifdef CK_BAG_PP
next += ((uintptr_t)(void *)ck_bag_block_next(cursor->next.ptr)); next += ((uintptr_t)(void *)ck_bag_block_next(cursor->next.ptr));
ck_pr_store_ptr(&cursor->next, (void *)next); ck_pr_store_ptr(&cursor->next, (void *)next);
#else #else
@ -261,7 +261,7 @@ found:
ck_pr_store_ptr(&bag->head, new_head); ck_pr_store_ptr(&bag->head, new_head);
} else { } else {
uintptr_t next; uintptr_t next;
#ifdef __x86_64__ #ifdef CK_BAG_PP
next = ((uintptr_t)prev->next.ptr & (CK_BAG_BLOCK_ENTRIES_MASK)) | next = ((uintptr_t)prev->next.ptr & (CK_BAG_BLOCK_ENTRIES_MASK)) |
(uintptr_t)(void *)ck_bag_block_next(cursor->next.ptr); (uintptr_t)(void *)ck_bag_block_next(cursor->next.ptr);
#else #else
@ -283,7 +283,7 @@ found:
copy->array[block_index] = copy->array[--n_entries]; copy->array[block_index] = copy->array[--n_entries];
next_ptr = (uintptr_t)(void *)ck_bag_block_next(copy->next.ptr); next_ptr = (uintptr_t)(void *)ck_bag_block_next(copy->next.ptr);
#ifdef __x86_64__ #ifdef CK_BAG_PP
copy->next.ptr = (void *)(((uintptr_t)n_entries << 48) | next_ptr); copy->next.ptr = (void *)(((uintptr_t)n_entries << 48) | next_ptr);
#else #else
copy->next.n_entries = n_entries; copy->next.n_entries = n_entries;
@ -295,7 +295,7 @@ found:
if (prev == NULL) { if (prev == NULL) {
ck_pr_store_ptr(&bag->head, copy); ck_pr_store_ptr(&bag->head, copy);
} else { } else {
#ifdef __x86_64__ #ifdef CK_BAG_PP
uintptr_t next = ((uintptr_t)prev->next.ptr & (CK_BAG_BLOCK_ENTRIES_MASK)) | uintptr_t next = ((uintptr_t)prev->next.ptr & (CK_BAG_BLOCK_ENTRIES_MASK)) |
(uintptr_t)(void *)ck_bag_block_next(copy); (uintptr_t)(void *)ck_bag_block_next(copy);
ck_pr_store_ptr(&prev->next.ptr, (struct ck_bag_block *)next); ck_pr_store_ptr(&prev->next.ptr, (struct ck_bag_block *)next);

Loading…
Cancel
Save