Commit 59edb82
bpf: Optimize recursion detection for arm64
BPF programs detect recursion by a per-cpu active flag in struct
bpf_prog. This flag is set/unset in the trampoline using atomic
operations to prevent inter-context recursion.
Some arm64 platforms have slow per-CPU atomic operations, for example,
the Neoverse V2. This commit therefore changes the recursion detection
mechanism to allow four levels of recursion (normal -> softirq -> hardirq
-> NMI). With allowing limited recursion, we can now stop using atomic
operations. This approach is similar to get_recursion_context() in perf.
Change active to a per-cpu array of four u8 values, one for each context
and use non-atomic increment/decrement on them.
This improves the performance on ARM64 (64-CPU Neoverse-N1):
+----------------+-------------------+-------------------+---------+
| Benchmark | Base run | Patched run | Δ (%) |
+----------------+-------------------+-------------------+---------+
| fentry | 3.694 ± 0.003M/s | 3.828 ± 0.007M/s | +3.63% |
| fexit | 1.389 ± 0.006M/s | 1.406 ± 0.003M/s | +1.22% |
| fmodret | 1.366 ± 0.011M/s | 1.398 ± 0.002M/s | +2.34% |
| rawtp | 3.453 ± 0.026M/s | 3.714 ± 0.003M/s | +7.56% |
| tp | 2.596 ± 0.005M/s | 2.699 ± 0.006M/s | +3.97% |
+----------------+-------------------+-------------------+---------+
Benchmarked using: tools/testing/selftests/bpf/benchs/run_bench_trigger.sh
Signed-off-by: Puranjay Mohan <[email protected]>1 parent fe98223 commit 59edb82
File tree
4 files changed
+30
-10
lines changed- include/linux
- kernel
- bpf
- trace
4 files changed
+30
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1728 | 1728 | | |
1729 | 1729 | | |
1730 | 1730 | | |
| 1731 | + | |
| 1732 | + | |
1731 | 1733 | | |
1732 | 1734 | | |
1733 | 1735 | | |
| |||
1754 | 1756 | | |
1755 | 1757 | | |
1756 | 1758 | | |
1757 | | - | |
| 1759 | + | |
1758 | 1760 | | |
1759 | 1761 | | |
1760 | 1762 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
| 116 | + | |
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
899 | 899 | | |
900 | 900 | | |
901 | 901 | | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
902 | 905 | | |
903 | 906 | | |
904 | 907 | | |
905 | 908 | | |
906 | | - | |
| 909 | + | |
| 910 | + | |
907 | 911 | | |
908 | 912 | | |
909 | 913 | | |
| |||
944 | 948 | | |
945 | 949 | | |
946 | 950 | | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
947 | 954 | | |
948 | 955 | | |
949 | 956 | | |
950 | | - | |
| 957 | + | |
951 | 958 | | |
952 | 959 | | |
953 | 960 | | |
| |||
977 | 984 | | |
978 | 985 | | |
979 | 986 | | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
980 | 990 | | |
981 | 991 | | |
982 | 992 | | |
983 | 993 | | |
984 | 994 | | |
985 | 995 | | |
986 | | - | |
| 996 | + | |
| 997 | + | |
987 | 998 | | |
988 | 999 | | |
989 | 1000 | | |
| |||
995 | 1006 | | |
996 | 1007 | | |
997 | 1008 | | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
998 | 1012 | | |
999 | 1013 | | |
1000 | 1014 | | |
1001 | | - | |
| 1015 | + | |
1002 | 1016 | | |
1003 | 1017 | | |
1004 | 1018 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2059 | 2059 | | |
2060 | 2060 | | |
2061 | 2061 | | |
| 2062 | + | |
2062 | 2063 | | |
2063 | 2064 | | |
| 2065 | + | |
2064 | 2066 | | |
2065 | 2067 | | |
2066 | | - | |
| 2068 | + | |
| 2069 | + | |
2067 | 2070 | | |
2068 | | - | |
| 2071 | + | |
2069 | 2072 | | |
| 2073 | + | |
2070 | 2074 | | |
2071 | 2075 | | |
2072 | 2076 | | |
| |||
2076 | 2080 | | |
2077 | 2081 | | |
2078 | 2082 | | |
2079 | | - | |
2080 | | - | |
| 2083 | + | |
2081 | 2084 | | |
2082 | 2085 | | |
2083 | 2086 | | |
| |||
0 commit comments