0001
0002
0003
0004
0005
0006
0007
0008 #include <stdint.h>
0009 #include <elf.h>
0010 #include <stdio.h>
0011 #include <sys/auxv.h>
0012 #include <sys/time.h>
0013
0014 #include "../kselftest.h"
0015 #include "parse_vdso.h"
0016
0017 const char *version = "LINUX_2.6";
0018 const char *name = "__vdso_getcpu";
0019
0020 struct getcpu_cache;
0021 typedef long (*getcpu_t)(unsigned int *, unsigned int *,
0022 struct getcpu_cache *);
0023
0024 int main(int argc, char **argv)
0025 {
0026 unsigned long sysinfo_ehdr;
0027 unsigned int cpu, node;
0028 getcpu_t get_cpu;
0029 long ret;
0030
0031 sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
0032 if (!sysinfo_ehdr) {
0033 printf("AT_SYSINFO_EHDR is not present!\n");
0034 return KSFT_SKIP;
0035 }
0036
0037 vdso_init_from_sysinfo_ehdr(getauxval(AT_SYSINFO_EHDR));
0038
0039 get_cpu = (getcpu_t)vdso_sym(version, name);
0040 if (!get_cpu) {
0041 printf("Could not find %s\n", name);
0042 return KSFT_SKIP;
0043 }
0044
0045 ret = get_cpu(&cpu, &node, 0);
0046 if (ret == 0) {
0047 printf("Running on CPU %u node %u\n", cpu, node);
0048 } else {
0049 printf("%s failed\n", name);
0050 return KSFT_FAIL;
0051 }
0052
0053 return 0;
0054 }