SCE增加CPU绑核,install时部署table_info.conf
This commit is contained in:
@@ -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++)
|
||||
|
||||
@@ -53,7 +53,9 @@ struct sce_ctx *sce_ctx_create(const char *profile)
|
||||
|
||||
MESA_load_profile_int_def(profile, "system", "firewall_sids", (int *)&(ctx->firewall_sids), 1001);
|
||||
MESA_load_profile_int_def(profile, "system", "nr_worker_threads", (int *)&(ctx->nr_worker_threads), 8);
|
||||
ctx->nr_worker_threads = MIN(ctx->nr_worker_threads, (int)(sizeof(ctx->work_threads) / sizeof(ctx->work_threads[0])));
|
||||
MESA_load_profile_int_def(profile, "system", "enable_cpu_affinity", (int *)&ctx->enable_cpu_affinity, 0);
|
||||
MESA_load_profile_uint_range(profile, "system", "cpu_affinity_mask", MAX_THREAD_NUM, (unsigned int *)ctx->cpu_affinity_mask);
|
||||
ctx->nr_worker_threads = MIN(ctx->nr_worker_threads, MAX_THREAD_NUM);
|
||||
|
||||
ctx->io = packet_io_create(profile, ctx->nr_worker_threads);
|
||||
if (ctx->io == NULL)
|
||||
|
||||
Reference in New Issue
Block a user