From 5b84cf71594a4c108f3c832bf51a8a8939ac4571 Mon Sep 17 00:00:00 2001 From: Frank Du Date: Tue, 16 Jan 2024 16:00:36 +0800 Subject: [PATCH 1/3] sch: add pid display Signed-off-by: Frank Du --- lib/src/mt_main.h | 1 + lib/src/mt_sch.c | 26 +++++++++++++++++--------- tools/ebpf/.gitignore | 4 ++++ 3 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 tools/ebpf/.gitignore diff --git a/lib/src/mt_main.h b/lib/src/mt_main.h index df97b8b80..492e2affe 100644 --- a/lib/src/mt_main.h +++ b/lib/src/mt_main.h @@ -477,6 +477,7 @@ struct mtl_sch_impl { unsigned int lcore; bool run_in_thread; /* Run the tasklet inside one thread instead of a pinned lcore. */ pthread_t tid; /* thread id for run_in_thread */ + pid_t pid; int data_quota_mbs_total; /* total data quota(mb/s) for current sch */ int data_quota_mbs_limit; /* limit data quota(mb/s) for current sch */ diff --git a/lib/src/mt_sch.c b/lib/src/mt_sch.c index 29df13b20..127b6e211 100644 --- a/lib/src/mt_sch.c +++ b/lib/src/mt_sch.c @@ -99,8 +99,7 @@ static int sch_tasklet_sleep(struct mtl_main_impl* impl, struct mtl_sch_impl* sc return 0; } -static int sch_tasklet_func(void* args) { - struct mtl_sch_impl* sch = args; +static int sch_tasklet_func(struct mtl_sch_impl* sch) { struct mtl_main_impl* impl = sch->parent; int idx = sch->idx; int num_tasklet, i; @@ -112,12 +111,11 @@ static int sch_tasklet_func(void* args) { uint64_t loop_cnt = 0; num_tasklet = sch->max_tasklet_idx; - info("%s(%d), start with %d tasklets\n", __func__, idx, num_tasklet); + info("%s(%d), start with %d tasklets, pid %d\n", __func__, idx, num_tasklet, sch->pid); char thread_name[32]; snprintf(thread_name, sizeof(thread_name), "mtl_sch_%d", idx); - - mtl_thread_setname(pthread_self(), thread_name); + mtl_thread_setname(sch->tid, thread_name); for (i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i]; @@ -177,8 +175,18 @@ static int sch_tasklet_func(void* args) { return 0; } +static int sch_tasklet_lcore(void* arg) { + struct mtl_sch_impl* sch = arg; + sch->tid = pthread_self(); + sch->pid = gettid(); + sch_tasklet_func(sch); + return 0; +} + static void* sch_tasklet_thread(void* arg) { - sch_tasklet_func(arg); + struct mtl_sch_impl* sch = arg; + sch->pid = gettid(); + sch_tasklet_func(sch); return NULL; } @@ -207,7 +215,7 @@ static int sch_start(struct mtl_sch_impl* sch) { sch_unlock(sch); return ret; } - ret = rte_eal_remote_launch(sch_tasklet_func, sch, sch->lcore); + ret = rte_eal_remote_launch(sch_tasklet_lcore, sch, sch->lcore); } else { ret = pthread_create(&sch->tid, NULL, sch_tasklet_thread, sch); } @@ -377,8 +385,8 @@ static int sch_stat(void* priv) { if (!mt_sch_is_active(sch)) return 0; - notice("SCH(%d:%s): tasklets %d, lcore %u, avg loop %" PRIu64 " ns\n", idx, sch->name, - num_tasklet, sch->lcore, mt_sch_avg_ns_loop(sch)); + notice("SCH(%d:%s): tasklets %d, lcore %u(pid: %d), avg loop %" PRIu64 " ns\n", idx, + sch->name, num_tasklet, sch->lcore, sch->pid, mt_sch_avg_ns_loop(sch)); if (mt_user_tasklet_time_measure(sch->parent)) { for (int i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i]; diff --git a/tools/ebpf/.gitignore b/tools/ebpf/.gitignore new file mode 100644 index 000000000..3e7279210 --- /dev/null +++ b/tools/ebpf/.gitignore @@ -0,0 +1,4 @@ +# generated file +et +fentry.skel.h +vmlinux.h \ No newline at end of file From 9a963df3da81268bb86c5ac2779c887092e7b639 Mon Sep 17 00:00:00 2001 From: Frank Du Date: Wed, 17 Jan 2024 08:49:33 +0800 Subject: [PATCH 2/3] fix build Signed-off-by: Frank Du --- lib/src/mt_main.h | 2 +- lib/src/mt_sch.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/src/mt_main.h b/lib/src/mt_main.h index 492e2affe..b14a028f2 100644 --- a/lib/src/mt_main.h +++ b/lib/src/mt_main.h @@ -477,7 +477,7 @@ struct mtl_sch_impl { unsigned int lcore; bool run_in_thread; /* Run the tasklet inside one thread instead of a pinned lcore. */ pthread_t tid; /* thread id for run_in_thread */ - pid_t pid; + pid_t t_pid; /* gettid */ int data_quota_mbs_total; /* total data quota(mb/s) for current sch */ int data_quota_mbs_limit; /* limit data quota(mb/s) for current sch */ diff --git a/lib/src/mt_sch.c b/lib/src/mt_sch.c index 127b6e211..d443fd120 100644 --- a/lib/src/mt_sch.c +++ b/lib/src/mt_sch.c @@ -111,7 +111,8 @@ static int sch_tasklet_func(struct mtl_sch_impl* sch) { uint64_t loop_cnt = 0; num_tasklet = sch->max_tasklet_idx; - info("%s(%d), start with %d tasklets, pid %d\n", __func__, idx, num_tasklet, sch->pid); + info("%s(%d), start with %d tasklets, t_pid %d\n", __func__, idx, num_tasklet, + (int)sch->t_pid); char thread_name[32]; snprintf(thread_name, sizeof(thread_name), "mtl_sch_%d", idx); @@ -178,14 +179,18 @@ static int sch_tasklet_func(struct mtl_sch_impl* sch) { static int sch_tasklet_lcore(void* arg) { struct mtl_sch_impl* sch = arg; sch->tid = pthread_self(); - sch->pid = gettid(); +#ifndef WINDOWSENV + sch->t_pid = gettid(); +#endif sch_tasklet_func(sch); return 0; } static void* sch_tasklet_thread(void* arg) { struct mtl_sch_impl* sch = arg; - sch->pid = gettid(); +#ifndef WINDOWSENV + sch->t_pid = gettid(); +#endif sch_tasklet_func(sch); return NULL; } @@ -385,8 +390,8 @@ static int sch_stat(void* priv) { if (!mt_sch_is_active(sch)) return 0; - notice("SCH(%d:%s): tasklets %d, lcore %u(pid: %d), avg loop %" PRIu64 " ns\n", idx, - sch->name, num_tasklet, sch->lcore, sch->pid, mt_sch_avg_ns_loop(sch)); + notice("SCH(%d:%s): tasklets %d, lcore %u(t_pid: %d), avg loop %" PRIu64 " ns\n", idx, + sch->name, num_tasklet, sch->lcore, (int)sch->t_pid, mt_sch_avg_ns_loop(sch)); if (mt_user_tasklet_time_measure(sch->parent)) { for (int i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i]; From e5664a6094931a57e0a461a357a2bbf68896b190 Mon Sep 17 00:00:00 2001 From: Frank Du Date: Wed, 17 Jan 2024 09:02:23 +0800 Subject: [PATCH 3/3] fix Signed-off-by: Frank Du --- format-coding.sh | 3 ++- lib/src/mt_main.h | 2 +- lib/src/mt_sch.c | 12 ++++-------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/format-coding.sh b/format-coding.sh index f4c923255..2825150df 100755 --- a/format-coding.sh +++ b/format-coding.sh @@ -9,7 +9,8 @@ set -e echo "clang-format check" -find . -path ./build -prune -o -regex '.*\.\(cpp\|hpp\|cc\|c\|h\)' ! -name 'pymtl_wrap.c' -exec clang-format --verbose -i {} + +find . -path ./build -prune -o -regex '.*\.\(cpp\|hpp\|cc\|c\|h\)' ! -name 'pymtl_wrap.c' \ + ! -name 'vmlinux.h' -exec clang-format --verbose -i {} + black python/ isort python/ diff --git a/lib/src/mt_main.h b/lib/src/mt_main.h index b14a028f2..c16428885 100644 --- a/lib/src/mt_main.h +++ b/lib/src/mt_main.h @@ -477,7 +477,7 @@ struct mtl_sch_impl { unsigned int lcore; bool run_in_thread; /* Run the tasklet inside one thread instead of a pinned lcore. */ pthread_t tid; /* thread id for run_in_thread */ - pid_t t_pid; /* gettid */ + int t_pid; /* gettid */ int data_quota_mbs_total; /* total data quota(mb/s) for current sch */ int data_quota_mbs_limit; /* limit data quota(mb/s) for current sch */ diff --git a/lib/src/mt_sch.c b/lib/src/mt_sch.c index d443fd120..4a61fd7a4 100644 --- a/lib/src/mt_sch.c +++ b/lib/src/mt_sch.c @@ -112,7 +112,7 @@ static int sch_tasklet_func(struct mtl_sch_impl* sch) { num_tasklet = sch->max_tasklet_idx; info("%s(%d), start with %d tasklets, t_pid %d\n", __func__, idx, num_tasklet, - (int)sch->t_pid); + sch->t_pid); char thread_name[32]; snprintf(thread_name, sizeof(thread_name), "mtl_sch_%d", idx); @@ -179,18 +179,14 @@ static int sch_tasklet_func(struct mtl_sch_impl* sch) { static int sch_tasklet_lcore(void* arg) { struct mtl_sch_impl* sch = arg; sch->tid = pthread_self(); -#ifndef WINDOWSENV - sch->t_pid = gettid(); -#endif + sch->t_pid = rte_sys_gettid(); sch_tasklet_func(sch); return 0; } static void* sch_tasklet_thread(void* arg) { struct mtl_sch_impl* sch = arg; -#ifndef WINDOWSENV - sch->t_pid = gettid(); -#endif + sch->t_pid = rte_sys_gettid(); sch_tasklet_func(sch); return NULL; } @@ -391,7 +387,7 @@ static int sch_stat(void* priv) { if (!mt_sch_is_active(sch)) return 0; notice("SCH(%d:%s): tasklets %d, lcore %u(t_pid: %d), avg loop %" PRIu64 " ns\n", idx, - sch->name, num_tasklet, sch->lcore, (int)sch->t_pid, mt_sch_avg_ns_loop(sch)); + sch->name, num_tasklet, sch->lcore, sch->t_pid, mt_sch_avg_ns_loop(sch)); if (mt_user_tasklet_time_measure(sch->parent)) { for (int i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i];