NDN-DPDK
High-Speed Named Data Networking Forwarder
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
alloc.h
Go to the documentation of this file.
1 #ifndef NDNDPDK_DISK_ALLOC_H
2 #define NDNDPDK_DISK_ALLOC_H
3 
6 #include "../core/common.h"
7 #include <rte_bitmap.h>
8 
14 typedef struct DiskAlloc {
15  uint64_t min;
16  uint64_t max;
17  uint64_t slab;
18  uint32_t pos;
19  struct rte_bitmap bmp[0] __rte_cache_aligned;
20 } __rte_cache_aligned DiskAlloc;
21 static_assert(offsetof(DiskAlloc, bmp[0]) % RTE_CACHE_LINE_SIZE == 0, "");
22 
27 __attribute__((nonnull)) static inline uint64_t
28 DiskAlloc_Alloc(DiskAlloc* a) {
29  if (a->slab == 0) {
30  int found = rte_bitmap_scan(a->bmp, &a->pos, &a->slab);
31  if (unlikely(found == 0)) {
32  return 0;
33  }
34  }
35 
36  uint64_t offset = rte_bsf64(a->slab);
37  a->slab &= ~((uint64_t)1 << offset);
38  uint64_t pos = a->pos + offset;
39  rte_bitmap_clear(a->bmp, pos);
40  return a->min + pos;
41 }
42 
44 __attribute__((nonnull)) static inline void
45 DiskAlloc_Free(DiskAlloc* a, uint64_t slotID) {
46  NDNDPDK_ASSERT(slotID >= a->min && slotID <= a->max);
47  uint32_t pos = slotID - a->min;
48  NDNDPDK_ASSERT(rte_bitmap_get(a->bmp, pos) == 0);
49  rte_bitmap_set(a->bmp, pos);
50 
51  // if s->slab reflects the modified bitmap slab, DiskAlloc_Alloc can't use it right away but
52  // will pick up the newly available slotID during bitmap scan
53 }
54 
61 __attribute__((returns_nonnull)) DiskAlloc*
62 DiskAlloc_New(uint64_t min, uint64_t max, int numaSocket);
63 
64 #endif // NDNDPDK_DISK_ALLOC_H
struct DiskAlloc DiskAlloc
Disk slot allocator.
DiskAlloc * DiskAlloc_New(uint64_t min, uint64_t max, int numaSocket)
Create DiskAlloc.
Definition: alloc.c:4
#define NDNDPDK_ASSERT(x)
Definition: common.h:60
Disk slot allocator.
Definition: alloc.h:14
uint64_t min
Definition: alloc.h:15
struct rte_bitmap bmp[0] __rte_cache_aligned
Definition: alloc.h:19
uint64_t max
Definition: alloc.h:16
uint64_t slab
Definition: alloc.h:17
uint32_t pos
Definition: alloc.h:18