• W
    perf tools: Fix kernel version error in ubuntu · d18acd15
    Wang Nan 提交于
    On ubuntu the internal kernel version code is different from what can
    be retrived from uname:
    
     $ uname -r
     4.4.0-47-generic
     $ cat /lib/modules/`uname -r`/build/include/generated/uapi/linux/version.h
     #define LINUX_VERSION_CODE 263192
     #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
     $ cat /lib/modules/`uname -r`/build/include/generated/utsrelease.h
     #define UTS_RELEASE "4.4.0-47-generic"
     #define UTS_UBUNTU_RELEASE_ABI 47
     $ cat /proc/version_signature
     Ubuntu 4.4.0-47.68-generic 4.4.24
    
    The macro LINUX_VERSION_CODE is set to 4.4.24 (263192 == 0x40418), but
    `uname -r` reports 4.4.0.
    
    This mismatch causes LINUX_VERSION_CODE macro passed to BPF script become
    an incorrect value, results in magic failure in BPF loading:
    
     $ sudo ./buildperf/perf record -e ./tools/perf/tests/bpf-script-example.c ls
     event syntax error: './tools/perf/tests/bpf-script-example.c'
                          \___ Failed to load program for unknown reason
    
    According to Ubuntu document (https://wiki.ubuntu.com/Kernel/FAQ), the
    correct kernel version can be retrived through /proc/version_signature, which
    is ubuntu specific.
    
    This patch checks the existance of /proc/version_signature, and returns
    version number through parsing this file instead of uname. Version string
    is untouched (value returns from uname) because `uname -r` is required
    to be consistence with path of kbuild directory in /lib/module.
    Signed-off-by: NWang Nan <wangnan0@huawei.com>
    Cc: Alexei Starovoitov <ast@fb.com>
    Cc: He Kuang <hekuang@huawei.com>
    Cc: Zefan Li <lizefan@huawei.com>
    Cc: pi3orama@163.com
    Link: http://lkml.kernel.org/r/20161115040617.69788-2-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
    d18acd15
util.c 15.0 KB