diff --git a/source/tools/monitor/sched/nosched/bpf/nosched.bpf.c b/source/tools/monitor/sched/nosched/bpf/nosched.bpf.c index 9cba4a19e12bd80cd9e814b6441e73a7c39c2666..38769d316b357ca7729c30bd0bac7d4a34326c3b 100644 --- a/source/tools/monitor/sched/nosched/bpf/nosched.bpf.c +++ b/source/tools/monitor/sched/nosched/bpf/nosched.bpf.c @@ -91,15 +91,13 @@ int BPF_KPROBE(account_process_tick, struct task_struct *p, int user_tick) struct latinfo lati, *latp; struct args args, *argsp; - __builtin_memset(&args_key, 0, sizeof(int)); argsp = bpf_map_lookup_elem(&args_map, &args_key); if (!argsp) return 0; if(!test_tsk_need_resched(p, _(argsp->flag))) - //||system_state == SYSTEM_BOOTING) - return 0; + return 0; now = bpf_ktime_get_ns(); @@ -128,6 +126,8 @@ int BPF_KPROBE(account_process_tick, struct task_struct *p, int user_tick) bpf_get_current_comm(&ext_val.comm, sizeof(ext_val.comm)); ext_val.pid = bpf_get_current_pid_tgid(); ext_val.nosched_ticks = latp->ticks_without_resched; + ext_val.cpu = cpuid; + ext_val.stamp = latp->last_seen_need_resched_ns; bpf_map_update_elem(&stackmap_ext, &ext_key, &ext_val, BPF_ANY); bpf_printk("%s :lat is %ld us, %d ticks\n", ext_val.comm, resched_latency/1000, latp->ticks_without_resched); diff --git a/source/tools/monitor/sched/nosched/nosched.c b/source/tools/monitor/sched/nosched/nosched.c index 6573ac8feef4393ae1e0683798ab45891666f0a2..423660c9c5a49ef69fe4cce21532adc0c926281d 100644 --- a/source/tools/monitor/sched/nosched/nosched.c +++ b/source/tools/monitor/sched/nosched/nosched.c @@ -7,14 +7,15 @@ #include #include #include +#include #include #include #include #include #include /* bpf_obj_pin */ #include -#include "nosched.comm.h" #include "bpf/nosched.skel.h" +#include "nosched.comm.h" #define MAX_SYMS 300000 static struct ksym syms[MAX_SYMS]; @@ -139,18 +140,36 @@ static void print_stack(int fd, struct ext_key *key) } } +#define SEC_TO_NS (1000*1000*1000) +static void stamp_to_date(__u64 stamp, char dt[], int len) +{ + time_t t, diff, last; + struct tm *tm; + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + time(&t); + diff = ts.tv_sec*SEC_TO_NS + ts.tv_nsec - stamp; + diff = diff/SEC_TO_NS; + + last = t - diff; + tm = localtime(&last); + strftime(dt, len, "%F_%H:%M:%S", tm); +} + static void print_stacks(int fd, int ext_fd) { + char dt[64] = {0}; struct ext_key ext_key = {}, next_key; struct ext_val value; - printf("***********************************\n"); + fprintf(stdout, "%-21s %-6s %-16s %-8s %-10s\n", "TIME", "CPU", "COMM", "TID", "LAT(us)"); while (bpf_map_get_next_key(ext_fd, &ext_key, &next_key) == 0) { bpf_map_lookup_elem(ext_fd, &next_key, &value); - printf("%s<%d> [%lld.%lld]: lat=%lldus, lat_tick=%d\n", - value.comm, value.pid, next_key.stamp/(1000000000), - next_key.stamp%(1000000000), value.lat_us, - value.nosched_ticks); + memset(dt, 0, sizeof(dt)); + stamp_to_date(value.stamp, dt, sizeof(dt)); + fprintf(stdout, "%-21s %-6d %-16s %-8d %-10llu\n", + dt, value.cpu, value.comm, value.pid, value.lat_us); print_stack(fd, &next_key); printf("----------------------\n"); bpf_map_delete_elem(ext_fd, &next_key); diff --git a/source/tools/monitor/sched/nosched/nosched.comm.h b/source/tools/monitor/sched/nosched/nosched.comm.h index d6c4acdadf04c44af5025ac11e948cdb7d701f8c..77d26388c3004787d3a1411ee6386338c1260b4e 100644 --- a/source/tools/monitor/sched/nosched/nosched.comm.h +++ b/source/tools/monitor/sched/nosched/nosched.comm.h @@ -34,9 +34,9 @@ struct ext_key { }; struct ext_val { - int pid; + int pid, cpu; int nosched_ticks; - __u64 lat_us; + __u64 lat_us, stamp; char comm[TASK_COMM_LEN]; };