summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shaping/include/shaper.h4
-rw-r--r--shaping/src/main.cpp10
-rw-r--r--shaping/src/shaper.cpp4
-rw-r--r--shaping/src/shaper_marsio.cpp4
-rw-r--r--shaping/src/shaper_stat.cpp2
5 files changed, 16 insertions, 8 deletions
diff --git a/shaping/include/shaper.h b/shaping/include/shaper.h
index 2be4d65..7821459 100644
--- a/shaping/include/shaper.h
+++ b/shaping/include/shaper.h
@@ -1,5 +1,5 @@
#pragma once
-
+#include <sched.h>
#include <sys/queue.h>
#include <marsio.h>
#include "uthash.h"
@@ -31,7 +31,7 @@ struct shaping_system_conf {
int work_thread_num;
int cpu_affinity_enable;
int firewall_sid;
- unsigned long long cpu_affinity_mask;
+ cpu_set_t cpu_affinity_mask;
int check_rule_enable_interval_sec;
};
diff --git a/shaping/src/main.cpp b/shaping/src/main.cpp
index b526ff7..91e1202 100644
--- a/shaping/src/main.cpp
+++ b/shaping/src/main.cpp
@@ -20,7 +20,10 @@ static void *shaper_thread_loop(void *data)
{
struct shaping_thread_ctx *ctx = (struct shaping_thread_ctx *)data;
- marsio_thread_init(ctx->marsio_info->instance);
+ if (marsio_thread_init(ctx->marsio_info->instance) != 0) {
+ LOG_ERROR("%s: marsio_thread_init failed", LOG_TAG_SHAPING);
+ return NULL;
+ }
//loop to process pkts
while(!quit) {
@@ -81,7 +84,10 @@ int main(int argc, char **argv)
}
for (int i = 0; i < ctx->thread_num; i++) {
- pthread_create(&ctx->thread_ctx[i].tid, NULL, shaper_thread_loop, &ctx->thread_ctx[i]);
+ int ret = pthread_create(&ctx->thread_ctx[i].tid, NULL, shaper_thread_loop, &ctx->thread_ctx[i]);
+ if (ret < 0) {
+ LOG_ERROR("%s: create thread failed, error %d: %s", LOG_TAG_SHAPING, errno, strerror(errno));
+ }
}
while(!quit) {
diff --git a/shaping/src/shaper.cpp b/shaping/src/shaper.cpp
index 2d88b01..6a5db5e 100644
--- a/shaping/src/shaper.cpp
+++ b/shaping/src/shaper.cpp
@@ -1073,8 +1073,10 @@ int shaper_global_conf_init(struct shaping_system_conf *conf)
LOG_ERROR("%s: shaping init global conf get CPU_AFFINITY_MASK failed or incomplete config", LOG_TAG_SHAPING);
return -1;
}
+ CPU_ZERO(&conf->cpu_affinity_mask);
for (int i = 0; i < conf->work_thread_num; i++) {
- conf->cpu_affinity_mask |= 1 << cpu_mask[i];
+ int cpu_id = cpu_mask[i];
+ CPU_SET(cpu_id, &conf->cpu_affinity_mask);
}
ret = MESA_load_profile_int_def(SHAPING_GLOBAL_CONF_FILE, "SYSTEM", "firewall_sids", &conf->firewall_sid, 1001);
diff --git a/shaping/src/shaper_marsio.cpp b/shaping/src/shaper_marsio.cpp
index 605de9c..627691a 100644
--- a/shaping/src/shaper_marsio.cpp
+++ b/shaping/src/shaper_marsio.cpp
@@ -88,8 +88,8 @@ struct shaping_marsio_info* shaper_marsio_init(struct shaping_system_conf *sys_c
}
if (sys_conf->cpu_affinity_enable) {
- if (marsio_option_set(marsio_info->instance, MARSIO_OPT_THREAD_MASK, &sys_conf->cpu_affinity_mask, sizeof(sys_conf->cpu_affinity_mask)) != 0) {
- LOG_ERROR("%s: shaping marsio set MARSIO_OPT_THREAD_MASK failed", LOG_TAG_MARSIO);
+ if (marsio_option_set(marsio_info->instance, MARSIO_OPT_THREAD_MASK_IN_CPUSET, &sys_conf->cpu_affinity_mask, sizeof(cpu_set_t)) != 0) {
+ LOG_ERROR("%s: shaping marsio set MARSIO_OPT_THREAD_MASK_IN_CPUSET failed", LOG_TAG_MARSIO);
goto ERROR;
}
}
diff --git a/shaping/src/shaper_stat.cpp b/shaping/src/shaper_stat.cpp
index e7d03a1..004e69e 100644
--- a/shaping/src/shaper_stat.cpp
+++ b/shaping/src/shaper_stat.cpp
@@ -64,7 +64,7 @@ struct shaping_stat* shaper_stat_init(int thread_num)
struct shaper_stat_conf conf;
const char *column_name[] = {"in_max_latency_us", "in_queue_len", "out_max_latency_us", "out_queue_len", //first line is gauge, second line is counter
"in_pkts", "in_bytes", "in_drop_pkts", "out_pkts", "out_bytes", "out_drop_pkts"};
- enum field_type column_type[] = {FIELD_TYPE_GAUGE, FIELD_TYPE_GAUGE, FIELD_TYPE_GAUGE, FIELD_TYPE_GAUGE,
+ enum field_type column_type[] = {FIELD_TYPE_COUNTER, FIELD_TYPE_GAUGE, FIELD_TYPE_COUNTER, FIELD_TYPE_GAUGE,
FIELD_TYPE_COUNTER, FIELD_TYPE_COUNTER, FIELD_TYPE_COUNTER, FIELD_TYPE_COUNTER, FIELD_TYPE_COUNTER, FIELD_TYPE_COUNTER};
column_num = sizeof(column_name)/sizeof(column_name[0]);