Skip to content

Commit

Permalink
Add option to buffer.[ch] for 64-byte alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
00pauln00 committed Feb 23, 2024
1 parent 54473a4 commit c8e3777
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ buffer_set_init(struct buffer_set *bs, size_t nbufs, size_t buf_size,
CIRCLEQ_INIT(&bs->bs_free_list);
CIRCLEQ_INIT(&bs->bs_inuse_list);


if (opts & BUFSET_OPT_USER_CACHE)
{
bs->bs_allow_user_cache = 1;
Expand All @@ -491,10 +490,13 @@ buffer_set_init(struct buffer_set *bs, size_t nbufs, size_t buf_size,
bi->bi_iov.iov_len = buf_size;
bi->bi_register_idx = -1;

if (opts & BUFSET_OPT_MEMALIGN)
size_t alignment =
(opts & BUFSET_OPT_MEMALIGN_SECTOR) ? BUFFER_SECTOR_SIZE :
(opts & BUFSET_OPT_MEMALIGN_L2) ? L2_CACHELINE_SIZE_BYTES : 0;

if (alignment)
{
bi->bi_iov.iov_base =
niova_posix_memalign(buf_size, BUFFER_SECTOR_SIZE);
bi->bi_iov.iov_base = niova_posix_memalign(buf_size, alignment);

FATAL_IF(bi->bi_iov.iov_base == NULL, "niova_posix_memalign()");
}
Expand Down
10 changes: 6 additions & 4 deletions src/include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

enum buffer_set_opts
{
BUFSET_OPT_MEMALIGN = (1 << 0),
BUFSET_OPT_SERIALIZE = (1 << 1),
BUFSET_OPT_USER_CACHE = (1 << 2),
BUFSET_OPT_LREG = (1 << 3),
BUFSET_OPT_SERIALIZE = (1 << 0),
BUFSET_OPT_USER_CACHE = (1 << 1),
BUFSET_OPT_LREG = (1 << 2),
BUFSET_OPT_MEMALIGN_L2 = (1 << 3),
BUFSET_OPT_MEMALIGN_SECTOR = (1 << 4),
BUFSET_OPT_MEMALIGN = BUFSET_OPT_MEMALIGN_SECTOR,
};

struct buffer_set;
Expand Down

0 comments on commit c8e3777

Please sign in to comment.