diff options
author | xingfeng2510 <xingfeng25100@163.com> | 2022-03-07 17:35:49 +0800 |
---|---|---|
committer | yonghong-song <ys114321@gmail.com> | 2022-03-07 09:36:23 -0800 |
commit | c5baa7be7d80e22312de5b05d02cdb457369f1c9 (patch) | |
tree | fd53e0e2a0c34368eb6c37cf6a3226778a294391 | |
parent | 109453eb6140fcf2488216a3849216ed72b0f49c (diff) | |
download | bcc-c5baa7be7d80e22312de5b05d02cdb457369f1c9.tar.gz |
bcc/tools: Add cpu filter (-c CPU) for softirqs & hardirqs
-rw-r--r-- | man/man8/hardirqs.8 | 9 | ||||
-rw-r--r-- | man/man8/softirqs.8 | 9 | ||||
-rwxr-xr-x | tools/hardirqs.py | 29 | ||||
-rwxr-xr-x | tools/softirqs.py | 21 |
4 files changed, 58 insertions, 10 deletions
diff --git a/man/man8/hardirqs.8 b/man/man8/hardirqs.8 index 12ae6be5..aa9afb84 100644 --- a/man/man8/hardirqs.8 +++ b/man/man8/hardirqs.8 @@ -33,6 +33,9 @@ Count events only. .TP \-d Show IRQ time distribution as histograms. +.TP +\-c CPU +Trace on this CPU only. .SH EXAMPLES .TP Sum hard IRQ event time until Ctrl-C: @@ -50,6 +53,10 @@ Print 1 second summaries, 10 times: 1 second summaries, printed in nanoseconds, with timestamps: # .B hardirqs \-NT 1 +.TP +Sum hard IRQ event time on CPU 1 until Ctrl-C: +# +.B hardirqs \-c 1 .SH FIELDS .TP HARDIRQ @@ -91,6 +98,6 @@ Linux .SH STABILITY Unstable - in development. .SH AUTHOR -Brendan Gregg, Hengqi Chen +Brendan Gregg, Hengqi Chen, Rocky Xing .SH SEE ALSO softirqs(8) diff --git a/man/man8/softirqs.8 b/man/man8/softirqs.8 index a9a14414..408c5a02 100644 --- a/man/man8/softirqs.8 +++ b/man/man8/softirqs.8 @@ -30,6 +30,9 @@ Output in nanoseconds .TP \-d Show IRQ time distribution as histograms +.TP +\-c CPU +Trace on this CPU only. .SH EXAMPLES .TP Sum soft IRQ event time until Ctrl-C: @@ -47,6 +50,10 @@ Print 1 second summaries, 10 times: 1 second summaries, printed in nanoseconds, with timestamps: # .B softirqs \-NT 1 +.TP +Sum soft IRQ event time on CPU 1 until Ctrl-C: +# +.B softirqs \-c 1 .SH FIELDS .TP SOFTIRQ @@ -88,6 +95,6 @@ Linux .SH STABILITY Unstable - in development. .SH AUTHORS -Brendan Gregg, Sasha Goldshtein +Brendan Gregg, Sasha Goldshtein, Rocky Xing .SH SEE ALSO hardirqs(8) diff --git a/tools/hardirqs.py b/tools/hardirqs.py index 0eeddddc..4e373d9c 100755 --- a/tools/hardirqs.py +++ b/tools/hardirqs.py @@ -4,7 +4,7 @@ # hardirqs Summarize hard IRQ (interrupt) event time. # For Linux, uses BCC, eBPF. # -# USAGE: hardirqs [-h] [-T] [-N] [-C] [-d] [interval] [outputs] +# USAGE: hardirqs [-h] [-T] [-N] [-C] [-d] [-c CPU] [interval] [outputs] # # Thanks Amer Ather for help understanding irq behavior. # @@ -13,6 +13,7 @@ # # 19-Oct-2015 Brendan Gregg Created this. # 22-May-2021 Hengqi Chen Migrated to kernel tracepoints. +# 07-Mar-2022 Rocky Xing Added CPU filter support. from __future__ import print_function from bcc import BPF @@ -25,6 +26,7 @@ examples = """examples: ./hardirqs -d # show hard irq event time as histograms ./hardirqs 1 10 # print 1 second summaries, 10 times ./hardirqs -NT 1 # 1s summaries, nanoseconds, and timestamps + ./hardirqs -c 1 # sum hard irq event time on CPU 1 only """ parser = argparse.ArgumentParser( description="Summarize hard irq event time as histograms", @@ -38,6 +40,8 @@ parser.add_argument("-C", "--count", action="store_true", help="show event counts instead of timing") parser.add_argument("-d", "--dist", action="store_true", help="show distributions as histograms") +parser.add_argument("-c", "--cpu", type=int, + help="trace this CPU only") parser.add_argument("interval", nargs="?", default=99999999, help="output interval, in seconds") parser.add_argument("outputs", nargs="?", default=99999999, @@ -94,9 +98,12 @@ TRACEPOINT_PROBE(irq, irq_handler_entry) { struct entry_key key = {}; irq_name_t name = {}; + u32 cpu = bpf_get_smp_processor_id(); + + FILTER_CPU key.tid = bpf_get_current_pid_tgid(); - key.cpu_id = bpf_get_smp_processor_id(); + key.cpu_id = cpu; TP_DATA_LOC_READ_STR(&name.name, name, sizeof(name)); irqnames.update(&key, &name); @@ -106,9 +113,12 @@ TRACEPOINT_PROBE(irq, irq_handler_entry) TRACEPOINT_PROBE(irq, irq_handler_exit) { struct entry_key key = {}; + u32 cpu = bpf_get_smp_processor_id(); + + FILTER_CPU key.tid = bpf_get_current_pid_tgid(); - key.cpu_id = bpf_get_smp_processor_id(); + key.cpu_id = cpu; // check ret value of irq handler is not IRQ_NONE to make sure // the current event belong to this irq handler @@ -137,9 +147,12 @@ TRACEPOINT_PROBE(irq, irq_handler_entry) u64 ts = bpf_ktime_get_ns(); irq_name_t name = {}; struct entry_key key = {}; + u32 cpu = bpf_get_smp_processor_id(); + + FILTER_CPU key.tid = bpf_get_current_pid_tgid(); - key.cpu_id = bpf_get_smp_processor_id(); + key.cpu_id = cpu; TP_DATA_LOC_READ_STR(&name.name, name, sizeof(name)); irqnames.update(&key, &name); @@ -152,9 +165,10 @@ TRACEPOINT_PROBE(irq, irq_handler_exit) u64 *tsp, delta; irq_name_t *namep; struct entry_key key = {}; + u32 cpu = bpf_get_smp_processor_id(); key.tid = bpf_get_current_pid_tgid(); - key.cpu_id = bpf_get_smp_processor_id(); + key.cpu_id = cpu; // check ret value of irq handler is not IRQ_NONE to make sure // the current event belong to this irq handler @@ -195,6 +209,11 @@ else: 'irq_key_t key = {.slot = 0 /* ignore */};' + 'bpf_probe_read_kernel(&key.name, sizeof(key.name), name);' + 'dist.atomic_increment(key, delta);') +if args.cpu is not None: + bpf_text = bpf_text.replace('FILTER_CPU', + 'if (cpu != %d) { return 0; }' % int(args.cpu)) +else: + bpf_text = bpf_text.replace('FILTER_CPU', '') if debug or args.ebpf: print(bpf_text) if args.ebpf: diff --git a/tools/softirqs.py b/tools/softirqs.py index ba0dac36..3d4f8d27 100755 --- a/tools/softirqs.py +++ b/tools/softirqs.py @@ -4,13 +4,14 @@ # softirqs Summarize soft IRQ (interrupt) event time. # For Linux, uses BCC, eBPF. # -# USAGE: softirqs [-h] [-T] [-N] [-d] [interval] [count] +# USAGE: softirqs [-h] [-T] [-N] [-d] [-c CPU] [interval] [count] # # Copyright (c) 2015 Brendan Gregg. # Licensed under the Apache License, Version 2.0 (the "License") # # 20-Oct-2015 Brendan Gregg Created this. # 03-Apr-2017 Sasha Goldshtein Migrated to kernel tracepoints. +# 07-Mar-2022 Rocky Xing Added CPU filter support. from __future__ import print_function from bcc import BPF @@ -23,6 +24,7 @@ examples = """examples: ./softirqs -d # show soft irq event time as histograms ./softirqs 1 10 # print 1 second summaries, 10 times ./softirqs -NT 1 # 1s summaries, nanoseconds, and timestamps + ./softirqs -c 1 # sum soft irq event time on CPU 1 only """ parser = argparse.ArgumentParser( description="Summarize soft irq event time as histograms.", @@ -34,6 +36,8 @@ parser.add_argument("-N", "--nanoseconds", action="store_true", help="output in nanoseconds") parser.add_argument("-d", "--dist", action="store_true", help="show distributions as histograms") +parser.add_argument("-c", "--cpu", type=int, + help="trace this CPU only") parser.add_argument("interval", nargs="?", default=99999999, help="output interval, in seconds") parser.add_argument("count", nargs="?", default=99999999, @@ -77,9 +81,12 @@ TRACEPOINT_PROBE(irq, softirq_entry) { account_val_t val = {}; entry_key_t key = {}; + u32 cpu = bpf_get_smp_processor_id(); + + FILTER_CPU key.pid = bpf_get_current_pid_tgid(); - key.cpu = bpf_get_smp_processor_id(); + key.cpu = cpu; val.ts = bpf_ktime_get_ns(); val.vec = args->vec; @@ -95,9 +102,12 @@ TRACEPOINT_PROBE(irq, softirq_exit) account_val_t *valp; irq_key_t key = {0}; entry_key_t entry_key = {}; + u32 cpu = bpf_get_smp_processor_id(); + + FILTER_CPU entry_key.pid = bpf_get_current_pid_tgid(); - entry_key.cpu = bpf_get_smp_processor_id(); + entry_key.cpu = cpu; // fetch timestamp and calculate delta valp = start.lookup(&entry_key); @@ -124,6 +134,11 @@ else: bpf_text = bpf_text.replace('STORE', 'key.vec = valp->vec; ' + 'dist.atomic_increment(key, delta);') +if args.cpu is not None: + bpf_text = bpf_text.replace('FILTER_CPU', + 'if (cpu != %d) { return 0; }' % int(args.cpu)) +else: + bpf_text = bpf_text.replace('FILTER_CPU', '') if debug or args.ebpf: print(bpf_text) if args.ebpf: |