This invention discloses a hardware topology detection method for kernel
instrumentation, comprising: obtaining and extracting key structure definitions from the current
Linux kernel through the BTF infrastructure, and
copying the structure definitions into the kernel module
source code; reading the kernel symbol table, selecting the instrumented function from it, and filling the kernel module
source code; obtaining the kernel header file of the target
machine, compiling and loading the kernel module in conjunction with the modified kernel module
source code, and specifying the storage path of the output file; obtaining the number of on-
chip systems in the current
system according to the sysfs interface, performing a counting operation on the
performance monitoring units on each on-
chip system, triggering the instrumented function, and obtaining the pointer to the key structure of the kernel driver; using the pointer to the key structure of the kernel driver to calculate the coordinates of the XP node and its
connected device type information, obtaining the data through MMI / O access and outputting it in a structured format. This invention also discloses a detection
system for implementing the above detection method, which has a wide range of application scenarios.