In GCC10.2 suffix '.isra.0' was appended to 'finish_task_switch'
authorGuodong Xu <guodong.xu@linaro.org>
Sat, 13 Mar 2021 02:23:47 +0000 (02:23 +0000)
committeryonghong-song <ys114321@gmail.com>
Sun, 14 Mar 2021 16:57:51 +0000 (09:57 -0700)
When buildiing kernel with GCC10 [2] in Debian on an Arm64 machine, it was
found the new "inter-procedural optimization improvements" [1] makes symbol
name 'finish_task_switch' changed to 'finish_task_switch.isra.0'.

Details:
The results, when built with gcc 9.3:
nm ../linux.buildout/kernel/sched/core.o | grep finish_task_switch
0000000000001288 t finish_task_switch

However, when built with gcc 10.2:
nm ../linux.buildout/kernel/sched/core.o | grep finish_task_switch
00000000000012d0 t finish_task_switch.isra.0

The same symbols (with xxx.isra.0 or without, respectively of course) also
appear in final file 'System.map' and in '/proc/kallsyms' when booting. This
negatively impact the tracing tools commonly used in kernel debugging, such
as bcc tools offcputime and runqlat. They hardcode 'finish_task_switch'
(without the .isra.0 suffix) into their scripts.

This patch fix the issue by changing the hardcoded 'finish_task_switch' string
to a python regular expression pattern who can match both the traditional form
'finish_task_switch' and the new gcc10 form 'finish_task_switch.isra.0'
(with single digit at the end). attach_kprobe()'s input parameter 'event_re'
is used for this type of pattern matching.

[1] https://gcc.gnu.org/gcc-10/changes.html
[2] ARCH=arm64 make Image

Signed-off-by: Guodong Xu <guodong.xu@linaro.org>
examples/tracing/task_switch.py
tests/python/test_trace2.py
tools/cpudist.py
tools/offcputime.py
tools/offwaketime.py
tools/runqlat.py
tools/runqslower.py

index 43a4f3f8d0b253b418a65f8da1631aaa0cf57a0d..90c374cd5623d27a474c97e26c7a5a145e02fcb9 100755 (executable)
@@ -6,7 +6,8 @@ from bcc import BPF
 from time import sleep
 
 b = BPF(src_file="task_switch.c")
-b.attach_kprobe(event="finish_task_switch", fn_name="count_sched")
+b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
+                fn_name="count_sched")
 
 # generate many schedule events
 for i in range(0, 100): sleep(0.01)
index 4900c5f75819675d3e2698dde9bf02953fde54a8..8614bca79ccc35c899b835143b783304f3e7dbc1 100755 (executable)
@@ -31,7 +31,8 @@ class TestTracingEvent(TestCase):
     def setUp(self):
         b = BPF(text=text, debug=0)
         self.stats = b.get_table("stats")
-        b.attach_kprobe(event="finish_task_switch", fn_name="count_sched")
+        b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
+                        fn_name="count_sched")
 
     def test_sched1(self):
         for i in range(0, 100):
index 4e549ac482090efcb0bf9e1e804e6603439d4b87..eb04f590ddecbadb54f3274a87dbe67545f6cf8a 100755 (executable)
@@ -159,7 +159,8 @@ if debug or args.ebpf:
 max_pid = int(open("/proc/sys/kernel/pid_max").read())
 
 b = BPF(text=bpf_text, cflags=["-DMAX_PID=%d" % max_pid])
-b.attach_kprobe(event="finish_task_switch", fn_name="sched_switch")
+b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
+                fn_name="sched_switch")
 
 print("Tracing %s-CPU time... Hit Ctrl-C to end." %
       ("off" if args.offcpu else "on"))
index 7ba5dc51bcb5b3394cef5a1413a9fda176603aef..128c6496d3d6ea09cfe70fe993480ba895e279bf 100755 (executable)
@@ -251,7 +251,8 @@ if debug or args.ebpf:
 
 # initialize BPF
 b = BPF(text=bpf_text)
-b.attach_kprobe(event="finish_task_switch", fn_name="oncpu")
+b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
+                fn_name="oncpu")
 matched = b.num_open_kprobes()
 if matched == 0:
     print("error: 0 functions traced. Exiting.", file=stderr)
index 117c6e794cb07b0e2c75dc6ad11c4b11793e973c..753eee97fb490bf2b5f4c6de1b2ff43bb8d75ae7 100755 (executable)
@@ -288,7 +288,8 @@ if args.ebpf:
 
 # initialize BPF
 b = BPF(text=bpf_text)
-b.attach_kprobe(event="finish_task_switch", fn_name="oncpu")
+b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
+                fn_name="oncpu")
 b.attach_kprobe(event="try_to_wake_up", fn_name="waker")
 matched = b.num_open_kprobes()
 if matched == 0:
index 9fd40642beb913089086126b3523f2c1d19a1c66..b13ff2d1935e794c8b9915e96931fdf1542ea428 100755 (executable)
@@ -252,7 +252,8 @@ b = BPF(text=bpf_text)
 if not is_support_raw_tp:
     b.attach_kprobe(event="ttwu_do_wakeup", fn_name="trace_ttwu_do_wakeup")
     b.attach_kprobe(event="wake_up_new_task", fn_name="trace_wake_up_new_task")
-    b.attach_kprobe(event="finish_task_switch", fn_name="trace_run")
+    b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
+                    fn_name="trace_run")
 
 print("Tracing run queue latency... Hit Ctrl-C to end.")
 
index e1583e54bdce49b76a3a4c43419b6499e209e0ba..6df98d9f1175dd6b00910754c178141c585d1141 100755 (executable)
@@ -255,7 +255,8 @@ b = BPF(text=bpf_text)
 if not is_support_raw_tp:
     b.attach_kprobe(event="ttwu_do_wakeup", fn_name="trace_ttwu_do_wakeup")
     b.attach_kprobe(event="wake_up_new_task", fn_name="trace_wake_up_new_task")
-    b.attach_kprobe(event="finish_task_switch", fn_name="trace_run")
+    b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
+                    fn_name="trace_run")
 
 print("Tracing run queue latency higher than %d us" % min_us)
 print("%-8s %-16s %-6s %14s" % ("TIME", "COMM", "TID", "LAT(us)"))