Skip to content

Commit

Permalink
Add MPOL_* to numa.hh and clflush to pememops_clwb
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashmahar committed Jun 3, 2024
1 parent 97ceb27 commit 2268074
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
14 changes: 13 additions & 1 deletion include/nvsl/numa.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include "numa.h"
#include <unistd.h>

#ifndef MPOL_MF_MOVE_ALL
#define MPOL_MF_MOVE_ALL (1<<2)
#endif

static inline int numa_node_of_page(void *page) {
int result;
const auto _ =
Expand All @@ -20,8 +24,10 @@ static inline int numa_node_of_page(void *page) {
return result;
}

static inline void move_region_to_node(int node, void *start, size_t size,
static inline bool move_region_to_node(int node, void *start, size_t size,
size_t page_size = 4096) {
bool result = true;

const auto page_cnt = size / page_size;
int *nodes = new int[page_cnt];
int *status = new int[page_cnt];
Expand All @@ -39,6 +45,8 @@ static inline void move_region_to_node(int node, void *start, size_t size,
std::cerr << "perror: " << strerror(errno) << std::endl;
std::cerr << "Warning: first page might not be on the target node. ";
std::cerr << "Expected: " << node << ", got: " << status[0] << std::endl;

result = false;
}

for (auto i = 0UL; i < page_cnt; i++) {
Expand All @@ -47,11 +55,15 @@ static inline void move_region_to_node(int node, void *start, size_t size,
std::cerr << "Expected: " << node << ", got: " << status[i] << std::endl;
std::cerr << "Not checking further pages." << std::endl;

result = false;

break;
}
}

delete[] nodes;
delete[] status;
delete[] pages;

return result;
}
4 changes: 4 additions & 0 deletions include/nvsl/pmemops/declarations.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ namespace nvsl {
/** @brief Clwb on a single addr, to flush a range use flush() */
void clwb(void *addr) const;

/** @brief Clflush on single addr, to evict a range, use evict() */
void clflush(void *addr) const;

public:
void flush(void *base, size_t size) const;
void persist(void *base, size_t size) const;
Expand All @@ -64,6 +67,7 @@ namespace nvsl {
void memmove(void *dest, void *src, size_t size) const;
void memset(void *base, char c, size_t size) const;
void streaming_wr(void *dest, const void *src, size_t bytes) const;
void evict(void *base, size_t size) const;
};

class PMemOpsMsync : public PMemOps {
Expand Down
18 changes: 18 additions & 0 deletions include/nvsl/pmemops/pmemops_clwb.hh
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ inline void nvsl::PMemOpsClwb::clwb(void *addr) const {
_mm_clwb(addr);
}

inline void nvsl::PMemOpsClwb::clflush(void *addr) const {
_mm_clflush(addr);
}

inline void nvsl::PMemOpsClwb::flush(void *base, size_t size) const {
uintptr_t uptr;

Expand All @@ -170,6 +174,20 @@ inline void nvsl::PMemOpsClwb::flush(void *base, size_t size) const {
}
}

/** @brief Evict the given range from the cache */
inline void nvsl::PMemOpsClwb::evict(void *base, size_t size) const {
uintptr_t uptr;

/*
* Loop through cache-line-size (typically 64B) aligned chunks
* covering the given range.
*/
for (uptr = (uintptr_t)base & ~(CL_SIZE - 1); uptr < (uintptr_t)base + size;
uptr += CL_SIZE) {
this->clflush((void *)uptr);
}
}

inline void nvsl::PMemOpsClwb::drain() const {
#ifdef SFENCE_AVAIL
_mm_sfence();
Expand Down

0 comments on commit 2268074

Please # to comment.