README 2.7 KB

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