Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tools/event_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
 * Authors:
 *      Guowei Li <2401213322@stu.pku.edu.cn>
 */
#define _GNU_SOURCE
#include <errno.h>
#include <pthread.h>
#include <sched.h>
#include <stdlib.h>
#include <unistd.h>

Expand Down Expand Up @@ -81,6 +83,33 @@ int initialize_event_monitor() {
epoll_fd = epoll_create1(0);
log_debug("create epoll_fd %d", epoll_fd);
pthread_create(&emonitor_tid, NULL, epoll_loop, NULL);
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
if (sched_getaffinity(0, sizeof(cpu_set_t), &cpuset) == 0) {
int last_cpu = -1;
for (int i = CPU_SETSIZE - 1; i >= 1; i--) {
if (CPU_ISSET(i, &cpuset)) {
last_cpu = i;
break;
}
}

if (last_cpu != -1) {
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(last_cpu, &set);
if (pthread_setaffinity_np(emonitor_tid, sizeof(cpu_set_t), &set) !=
0) {
log_warn("failed to set epoll_loop thread to cpu %d", last_cpu);
} else {
log_info("epoll_loop thread set to cpu %d", last_cpu);
}
} else {
log_warn("No available CPU other than CPU0");
}
} else {
log_warn("failed to get cpu affinity: %d", errno);
}
if (epoll_fd >= 0)
return 0;
else {
Expand Down