Skip to content

Commit

Permalink
runtime: fix per cpu map low performance (#255)
Browse files Browse the repository at this point in the history
* add static to ensure

* fix
  • Loading branch information
yunwei37 authored Mar 23, 2024
1 parent 9b0cc4e commit 3a831ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion runtime/src/bpf_map/map_common_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ using bytes_vec = boost::interprocess::vector<uint8_t, bytes_vec_allocator>;
template <class T>
static inline T ensure_on_current_cpu(std::function<T(int cpu)> func)
{
static thread_local int currcpu = -1;
if (currcpu == sched_getcpu()) {
return func(currcpu);
}
cpu_set_t orig, set;
CPU_ZERO(&orig);
CPU_ZERO(&set);
sched_getaffinity(0, sizeof(orig), &orig);
int currcpu = sched_getcpu();
currcpu = sched_getcpu();
CPU_SET(currcpu, &set);
sched_setaffinity(0, sizeof(set), &set);
T ret = func(currcpu);
Expand All @@ -38,6 +42,10 @@ static inline T ensure_on_current_cpu(std::function<T(int cpu)> func)
template <class T>
static inline T ensure_on_certain_cpu(int cpu, std::function<T()> func)
{
static thread_local int currcpu = -1;
if (currcpu == sched_getcpu()) {
return func(currcpu);
}
cpu_set_t orig, set;
CPU_ZERO(&orig);
CPU_ZERO(&set);
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bpf_map/userspace/prog_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class prog_array_map_impl {
i32_vec data;

public:
const static bool should_lock = true;
const static bool should_lock = false;
prog_array_map_impl(boost::interprocess::managed_shared_memory &memory,
uint32_t key_size, uint32_t value_size,
uint32_t max_entries);
Expand Down

0 comments on commit 3a831ac

Please sign in to comment.