summaryrefslogtreecommitdiff
path: root/platform/src/main.cpp
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2023-03-02 16:13:02 +0800
committerluwenpeng <[email protected]>2023-03-02 17:06:51 +0800
commit336e5a7bf384722966cb3856cbd0ea6889b87162 (patch)
tree8a0bf01df3f9b32a984290a74b8681eefac93bff /platform/src/main.cpp
parent73486ef55d8258541746edab8ebcf03b9c2eeebf (diff)
SCE增加CPU绑核,install时部署table_info.conf
Diffstat (limited to 'platform/src/main.cpp')
-rw-r--r--platform/src/main.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/platform/src/main.cpp b/platform/src/main.cpp
index 2643bb7..1516258 100644
--- a/platform/src/main.cpp
+++ b/platform/src/main.cpp
@@ -2,6 +2,7 @@
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
+#include <sys/prctl.h>
#include "sce.h"
#include "log.h"
@@ -19,13 +20,39 @@ static void sig_handler(int signo)
}
}
+static int thread_set_affinity(int core_id)
+{
+ int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
+ if (core_id < 0 || core_id >= num_cores)
+ {
+ return EINVAL;
+ }
+
+ cpu_set_t cpuset;
+ CPU_ZERO(&cpuset);
+ CPU_SET(core_id, &cpuset);
+
+ return pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
+}
+
static void *worker_thread_cycle(void *arg)
{
struct thread_ctx *thread_ctx = (struct thread_ctx *)arg;
struct packet_io *handle = thread_ctx->ref_io;
int n_packet_recv;
- LOG_INFO("%s: worker thread %d running", LOG_TAG_SCE, thread_ctx->thread_index);
+ char thread_name[16];
+ snprintf(thread_name, sizeof(thread_name), "sce:worker-%d", thread_ctx->thread_index);
+ prctl(PR_SET_NAME, (unsigned long long)thread_name, NULL, NULL, NULL);
+
+ char affinity[32] = {0};
+ if (thread_ctx->cpu_mask >= 0)
+ {
+ thread_set_affinity(thread_ctx->cpu_mask);
+ snprintf(affinity, sizeof(affinity), "affinity cpu%d", thread_ctx->cpu_mask);
+ }
+
+ LOG_INFO("%s: worker thread %d %s is running", LOG_TAG_SCE, thread_ctx->thread_index, thread_ctx->cpu_mask >= 0 ? affinity : "");
while (1)
{
@@ -96,6 +123,7 @@ int main(int argc, char **argv)
ctx->work_threads[i].ref_sce_ctx = ctx;
ctx->work_threads[i].session_table_need_reset = 0;
ctx->work_threads[i].sf_metrics_need_send = 0;
+ ctx->work_threads[i].cpu_mask = ctx->enable_cpu_affinity ? ctx->cpu_affinity_mask[i] : -1;
}
for (int i = 0; i < ctx->nr_worker_threads; i++)