d942f231af
Enable vDSO getcpu & gettimeofday test for riscv. But only riscv64 supports __vdso_gettimeofday and riscv32 is under development. VERSION { LINUX_4.15 { global: __vdso_rt_sigreturn; __vdso_gettimeofday; __vdso_clock_gettime; __vdso_clock_getres; __vdso_getcpu; __vdso_flush_icache; local: *; }; } Co-developed-by: haocheng.zy <haocheng.zy@linux.alibaba.com> Signed-off-by: haocheng.zy <haocheng.zy@linux.alibaba.com> Suggested-by: Mao Han <han_mao@linux.alibaba.com> Reviewed-by: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: Guo Ren <guoren@linux.alibaba.com> Signed-off-by: Guo Ren <guoren@kernel.org> Cc: Paul Walmsley <paul.walmsley@sifive.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Elliott Hughes <enh@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
59 lines
1.1 KiB
C
59 lines
1.1 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* vdso_test_getcpu.c: Sample code to test parse_vdso.c and vDSO getcpu()
|
|
*
|
|
* Copyright (c) 2020 Arm Ltd
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
#include <elf.h>
|
|
#include <stdio.h>
|
|
#include <sys/auxv.h>
|
|
#include <sys/time.h>
|
|
|
|
#include "../kselftest.h"
|
|
#include "parse_vdso.h"
|
|
|
|
#if defined(__riscv)
|
|
const char *version = "LINUX_4.15";
|
|
#else
|
|
const char *version = "LINUX_2.6";
|
|
#endif
|
|
const char *name = "__vdso_getcpu";
|
|
|
|
struct getcpu_cache;
|
|
typedef long (*getcpu_t)(unsigned int *, unsigned int *,
|
|
struct getcpu_cache *);
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
unsigned long sysinfo_ehdr;
|
|
unsigned int cpu, node;
|
|
getcpu_t get_cpu;
|
|
long ret;
|
|
|
|
sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
|
|
if (!sysinfo_ehdr) {
|
|
printf("AT_SYSINFO_EHDR is not present!\n");
|
|
return KSFT_SKIP;
|
|
}
|
|
|
|
vdso_init_from_sysinfo_ehdr(getauxval(AT_SYSINFO_EHDR));
|
|
|
|
get_cpu = (getcpu_t)vdso_sym(version, name);
|
|
if (!get_cpu) {
|
|
printf("Could not find %s\n", name);
|
|
return KSFT_SKIP;
|
|
}
|
|
|
|
ret = get_cpu(&cpu, &node, 0);
|
|
if (ret == 0) {
|
|
printf("Running on CPU %u node %u\n", cpu, node);
|
|
} else {
|
|
printf("%s failed\n", name);
|
|
return KSFT_FAIL;
|
|
}
|
|
|
|
return 0;
|
|
}
|