Bug 2595 - [ANCK-4.19 ][Anolis7.9][x86/aarch64]安装clang包后perf-test测试套新增Basic-BPF-llvm-compile用例失败,没有安装clang时是skip
Summary: [ANCK-4.19 ][Anolis7.9][x86/aarch64]安装clang包后perf-test测试套新增Basic-BPF-llvm-com...
Status: NEW
Alias: None
Product: Anolis OS 7
Classification: Anolis OS
Component: Others (show other bugs) Others
Version: 7.9
Hardware: All Linux
: P3-Medium S3-normal
Target Milestone: ---
Assignee: yunqi-zwt
QA Contact: shuming
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-26 17:34 UTC by meil_wei
Modified: 2022-10-26 17:37 UTC (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description meil_wei alibaba_cloud_group 2022-10-26 17:34:28 UTC
Description of problem:
安装clang包后perf-test测试套新增Basic-BPF-llvm-compile用例失败,没有安装clang时是skip
安装clang前:
# perf test 38 -v
38: LLVM search and compile                               :
38.1: Basic BPF llvm compile                              :
--- start ---
test child forked, pid 5962
ERROR:  unable to find clang.
Hint:   Try to install latest clang/llvm to support BPF. Check your $PATH
        and 'clang-path' option in [llvm] section of ~/.perfconfig.
        LLVM 3.7 or newer is required. Which can be found from http://llvm.org
        You may want to try git trunk:
                git clone http://llvm.org/git/llvm.git
                     and
                git clone http://llvm.org/git/clang.git

        Or fetch the latest clang/llvm 3.7 from pre-built llvm packages for
        debian/ubuntu:
                http://llvm.org/apt

        If you are using old version of clang, change 'clang-bpf-cmd-template'
        option in [llvm] section of ~/.perfconfig to:

          "$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS \
             -working-directory $WORKING_DIR -c $CLANG_SOURCE \
             -emit-llvm -o - | /path/to/llc -march=bpf -filetype=obj -o -"
        (Replace /path/to/llc with path to your llc)

Failed to compile test case: 'Basic BPF llvm compile'
test child finished with -1
---- end ----
LLVM search and compile subtest 1: FAILED!
38.2: kbuild searching                                    :
--- force skipped ---
LLVM search and compile subtest 2: Skip
38.3: Compile source for BPF prologue generation          :
--- force skipped ---
LLVM search and compile subtest 3: Skip
38.4: Compile source for BPF relocation                   :
--- force skipped ---
LLVM search and compile subtest 4: Skip

安装clang后:
# perf test 38 -v
38: LLVM search and compile                               :
38.1: Basic BPF llvm compile                              :
--- start ---
test child forked, pid 5656
Kernel build dir is set to /lib/modules/4.19.91-183.git.5b6c906.an7.aarch64/build
set env: KBUILD_DIR=/lib/modules/4.19.91-183.git.5b6c906.an7.aarch64/build
unset env: KBUILD_OPTS
include option is set to  -nostdinc -isystem /usr/lib/gcc/aarch64-redhat-linux/4.8.5/include -I./arch/arm64/include -I./arch/arm64/include/generated  -I./include -I./arch/arm64/include/uapi -I./arch/arm64/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h
set env: NR_CPUS=4
set env: LINUX_VERSION_CODE=0x4135b
set env: CLANG_EXEC=/usr/bin/clang
set env: CLANG_OPTIONS=-xc
set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/aarch64-redhat-linux/4.8.5/include -I./arch/arm64/include -I./arch/arm64/include/generated  -I./include -I./arch/arm64/include/uapi -I./arch/arm64/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h
set env: PERF_BPF_INC_OPTIONS=-I/usr/lib/perf/include/bpf
set env: WORKING_DIR=/lib/modules/4.19.91-183.git.5b6c906.an7.aarch64/build
set env: CLANG_SOURCE=-
llvm compiling command template: echo '/*
 * bpf-script-example.c
 * Test basic LLVM building
 */
#ifndef LINUX_VERSION_CODE
# error Need LINUX_VERSION_CODE
# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
#endif
#define BPF_ANY 0
#define BPF_MAP_TYPE_ARRAY 2
#define BPF_FUNC_map_lookup_elem 1
#define BPF_FUNC_map_update_elem 2

static void *(*bpf_map_lookup_elem)(void *map, void *key) =
        (void *) BPF_FUNC_map_lookup_elem;
static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
        (void *) BPF_FUNC_map_update_elem;

struct bpf_map_def {
        unsigned int type;
        unsigned int key_size;
        unsigned int value_size;
        unsigned int max_entries;
};

#define SEC(NAME) __attribute__((section(NAME), used))
struct bpf_map_def SEC("maps") flip_table = {
        .type = BPF_MAP_TYPE_ARRAY,
        .key_size = sizeof(int),
        .value_size = sizeof(int),
        .max_entries = 1,
};

SEC("func=do_epoll_wait")
int bpf_func__SyS_epoll_pwait(void *ctx)
{
        int ind =0;
        int *flag = bpf_map_lookup_elem(&flip_table, &ind);
        int new_flag;
        if (!flag)
                return 0;
        /* flip flag and store back */
        new_flag = !*flag;
        bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
        return new_flag;
}
char _license[] SEC("license") = "GPL";
int _version SEC("version") = LINUX_VERSION_CODE;
' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE
llvm compiling command : echo '/*
 * bpf-script-example.c
 * Test basic LLVM building
 */
#ifndef LINUX_VERSION_CODE
# error Need LINUX_VERSION_CODE
# error Example: for 4.2 kernel, put 'clang-opt=-DLINUX_VERSION_CODE=0x40200 into llvm section of ~/.perfconfig'
#endif
#define BPF_ANY 0
#define BPF_MAP_TYPE_ARRAY 2
#define BPF_FUNC_map_lookup_elem 1
#define BPF_FUNC_map_update_elem 2

static void *(*bpf_map_lookup_elem)(void *map, void *key) =
        (void *) BPF_FUNC_map_lookup_elem;
static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
        (void *) BPF_FUNC_map_update_elem;

struct bpf_map_def {
        unsigned int type;
        unsigned int key_size;
        unsigned int value_size;
        unsigned int max_entries;
};

#define SEC(NAME) __attribute__((section(NAME), used))
struct bpf_map_def SEC(maps) flip_table = {
        .type = BPF_MAP_TYPE_ARRAY,
        .key_size = sizeof(int),
        .value_size = sizeof(int),
        .max_entries = 1,
};

SEC(func=do_epoll_wait)
int bpf_func__SyS_epoll_pwait(void *ctx)
{
        int ind =0;
        int *flag = bpf_map_lookup_elem(&flip_table, &ind);
        int new_flag;
        if (!flag)
                return 0;
        /* flip flag and store back */
        new_flag = !*flag;
        bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
        return new_flag;
}
char _license[] SEC(license) = GPL;
int _version SEC(version) = LINUX_VERSION_CODE;
' | /usr/bin/clang -D__KERNEL__ -D__NR_CPUS__=4 -DLINUX_VERSION_CODE=0x4135b -xc   -nostdinc -isystem /usr/lib/gcc/aarch64-redhat-linux/4.8.5/include -I./arch/arm64/include -I./arch/arm64/include/generated  -I./include -I./arch/arm64/include/uapi -I./arch/arm64/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h  -I/usr/lib/perf/include/bpf -Wno-unused-value -Wno-pointer-sign -working-directory /lib/modules/4.19.91-183.git.5b6c906.an7.aarch64/build -c - -target bpf  -O2 -o -
error: unknown target triple 'bpf', please use -triple or -arch
ERROR:  unable to compile -
Hint:   Check error message shown above.
Hint:   You can also pre-compile it into .o using:
                clang -target bpf -O2 -c -
        with proper -I and -D options.
Failed to compile test case: 'Basic BPF llvm compile'
test child finished with -1
---- end ----
LLVM search and compile subtest 1: FAILED!
38.2: kbuild searching                                    :
--- force skipped ---
LLVM search and compile subtest 2: Skip
38.3: Compile source for BPF prologue generation          :
--- force skipped ---
LLVM search and compile subtest 3: Skip
38.4: Compile source for BPF relocation                   :
--- force skipped ---
LLVM search and compile subtest 4: Skip


Version-Release number of selected component (if applicable):
# perf --version
perf version 4.19.91-183.git.5b6c906.an7.aarch64.debug

Steps to Reproduce:
1.安装和内核同版本的perf包
2.perf test 38 -v 

Actual results:
安装clang后,Basic-BPF-llvm-compile用例失败

Expected results:
Basic-BPF-llvm-compile用例成功

Additional info: