Syllo / nvtop

GPU & Accelerator process monitoring for AMD, Apple, Huawei, Intel, NVIDIA and Qualcomm
Other
7.79k stars 287 forks source link

how to solve for this 'extract_processinfo_fdinfo.c linux/kcmp.h: No such file or directory’ #195

Closed gukejun1 closed 1 year ago

gukejun1 commented 1 year ago

@Syllo

[root@p4gpu-129 build]# make 
[  5%] Building C object src/CMakeFiles/nvtop.dir/nvtop.c.o
[ 11%] Building C object src/CMakeFiles/nvtop.dir/interface.c.o
[ 17%] Building C object src/CMakeFiles/nvtop.dir/interface_layout_selection.c.o
[ 23%] Building C object src/CMakeFiles/nvtop.dir/interface_options.c.o
[ 29%] Building C object src/CMakeFiles/nvtop.dir/interface_setup_win.c.o
[ 35%] Building C object src/CMakeFiles/nvtop.dir/interface_ring_buffer.c.o
[ 41%] Building C object src/CMakeFiles/nvtop.dir/get_process_info_linux.c.o
[ 47%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo.c.o
[ 52%] Building C object src/CMakeFiles/nvtop.dir/extract_processinfo_fdinfo.c.o
/home/nvtop/src/extract_processinfo_fdinfo.c:28:10: fatal error: linux/kcmp.h: No such file or directory
   28 | #include <linux/kcmp.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [src/CMakeFiles/nvtop.dir/extract_processinfo_fdinfo.c.o] Error 1
make[1]: *** [src/CMakeFiles/nvtop.dir/all] Error 2
make: *** [all] Error 2

The same error is reported,in accordance with this practice #152 . How to solve this problem

Syllo commented 1 year ago

Depending on your distribution, you may need to install the kernel headers (e.g., linux-headers on debian/ubuntu). That's the only explanation I can come up with for the missing header really. What distribution are you using?

Lacedaemon commented 1 year ago

Installing kernel-devel on CentOS 7.9 (kernel 3.10.0-1160.90.1.el7.x86_64) didn't work, but this patch did:

diff -Naur a/src/extract_processinfo_fdinfo.c b/src/extract_processinfo_fdinfo.c
--- a/src/extract_processinfo_fdinfo.c  2022-11-06 07:33:24.000000000 -0800
+++ b/src/extract_processinfo_fdinfo.c  2023-06-13 17:38:40.550066552 -0700
@@ -25,7 +25,6 @@
 #include <ctype.h>
 #include <dirent.h>
 #include <fcntl.h>
-#include <linux/kcmp.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/syscall.h>
@@ -140,10 +139,14 @@

       fd_num = atoi(fdinfo_dent->d_name);

+      #ifndef KCMP_FILE
+      #define KCMP_FILE 0
+      #endif
+
       // check if this fd refers to the same open file as any seen ones.
       // we only care about unique opens
       for (unsigned i = 0; i < seen_fds_len; i++) {
-        if (syscall(SYS_kcmp, client_pid, client_pid, KCMP_FILE, fd_num, seen_fds[i]) <= 0)
+        if (syscall(SYS_kcmp, client_pid, client_pid, 0, fd_num, seen_fds[i]) <= 0)
           goto next_fd;
       }

Inspired by this.

Syllo commented 1 year ago

Thank you @Lacedaemon, I applied a similar patch in 9a8458b541a195a0c5cadafb66e240962c852b39