1*fbc05142SNamhyung KimWhy we want a copy of kernel headers in tools? 2*fbc05142SNamhyung Kim============================================== 3*fbc05142SNamhyung Kim 4*fbc05142SNamhyung KimThere used to be no copies, with tools/ code using kernel headers 5*fbc05142SNamhyung Kimdirectly. From time to time tools/perf/ broke due to legitimate kernel 6*fbc05142SNamhyung Kimhacking. At some point Linus complained about such direct usage. Then we 7*fbc05142SNamhyung Kimadopted the current model. 8*fbc05142SNamhyung Kim 9*fbc05142SNamhyung KimThe way these headers are used in perf are not restricted to just 10*fbc05142SNamhyung Kimincluding them to compile something. 11*fbc05142SNamhyung Kim 12*fbc05142SNamhyung KimThere are sometimes used in scripts that convert defines into string 13*fbc05142SNamhyung Kimtables, etc, so some change may break one of these scripts, or new MSRs 14*fbc05142SNamhyung Kimmay use some different #define pattern, etc. 15*fbc05142SNamhyung Kim 16*fbc05142SNamhyung KimE.g.: 17*fbc05142SNamhyung Kim 18*fbc05142SNamhyung Kim $ ls -1 tools/perf/trace/beauty/*.sh | head -5 19*fbc05142SNamhyung Kim tools/perf/trace/beauty/arch_errno_names.sh 20*fbc05142SNamhyung Kim tools/perf/trace/beauty/drm_ioctl.sh 21*fbc05142SNamhyung Kim tools/perf/trace/beauty/fadvise.sh 22*fbc05142SNamhyung Kim tools/perf/trace/beauty/fsconfig.sh 23*fbc05142SNamhyung Kim tools/perf/trace/beauty/fsmount.sh 24*fbc05142SNamhyung Kim $ 25*fbc05142SNamhyung Kim $ tools/perf/trace/beauty/fadvise.sh 26*fbc05142SNamhyung Kim static const char *fadvise_advices[] = { 27*fbc05142SNamhyung Kim [0] = "NORMAL", 28*fbc05142SNamhyung Kim [1] = "RANDOM", 29*fbc05142SNamhyung Kim [2] = "SEQUENTIAL", 30*fbc05142SNamhyung Kim [3] = "WILLNEED", 31*fbc05142SNamhyung Kim [4] = "DONTNEED", 32*fbc05142SNamhyung Kim [5] = "NOREUSE", 33*fbc05142SNamhyung Kim }; 34*fbc05142SNamhyung Kim $ 35*fbc05142SNamhyung Kim 36*fbc05142SNamhyung KimThe tools/perf/check-headers.sh script, part of the tools/ build 37*fbc05142SNamhyung Kimprocess, points out changes in the original files. 38*fbc05142SNamhyung Kim 39*fbc05142SNamhyung KimSo its important not to touch the copies in tools/ when doing changes in 40*fbc05142SNamhyung Kimthe original kernel headers, that will be done later, when 41*fbc05142SNamhyung Kimcheck-headers.sh inform about the change to the perf tools hackers. 42*fbc05142SNamhyung Kim 43*fbc05142SNamhyung KimAnother explanation from Ingo Molnar: 44*fbc05142SNamhyung KimIt's better than all the alternatives we tried so far: 45*fbc05142SNamhyung Kim 46*fbc05142SNamhyung Kim - Symbolic links and direct #includes: this was the original approach but 47*fbc05142SNamhyung Kim was pushed back on from the kernel side, when tooling modified the 48*fbc05142SNamhyung Kim headers and broke them accidentally for kernel builds. 49*fbc05142SNamhyung Kim 50*fbc05142SNamhyung Kim - Duplicate self-defined ABI headers like glibc: double the maintenance 51*fbc05142SNamhyung Kim burden, double the chance for mistakes, plus there's no tech-driven 52*fbc05142SNamhyung Kim notification mechanism to look at new kernel side changes. 53*fbc05142SNamhyung Kim 54*fbc05142SNamhyung KimWhat we are doing now is a third option: 55*fbc05142SNamhyung Kim 56*fbc05142SNamhyung Kim - A software-enforced copy-on-write mechanism of kernel headers to 57*fbc05142SNamhyung Kim tooling, driven by non-fatal warnings on the tooling side build when 58*fbc05142SNamhyung Kim kernel headers get modified: 59*fbc05142SNamhyung Kim 60*fbc05142SNamhyung Kim Warning: Kernel ABI header differences: 61*fbc05142SNamhyung Kim diff -u tools/include/uapi/drm/i915_drm.h include/uapi/drm/i915_drm.h 62*fbc05142SNamhyung Kim diff -u tools/include/uapi/linux/fs.h include/uapi/linux/fs.h 63*fbc05142SNamhyung Kim diff -u tools/include/uapi/linux/kvm.h include/uapi/linux/kvm.h 64*fbc05142SNamhyung Kim ... 65*fbc05142SNamhyung Kim 66*fbc05142SNamhyung Kim The tooling policy is to always pick up the kernel side headers as-is, 67*fbc05142SNamhyung Kim and integate them into the tooling build. The warnings above serve as a 68*fbc05142SNamhyung Kim notification to tooling maintainers that there's changes on the kernel 69*fbc05142SNamhyung Kim side. 70*fbc05142SNamhyung Kim 71*fbc05142SNamhyung KimWe've been using this for many years now, and it might seem hacky, but 72*fbc05142SNamhyung Kimworks surprisingly well. 73*fbc05142SNamhyung Kim 74