drm/atomic-helper: document drm_atomic_helper_check() restrictions
[drm/drm-misc.git] / tools / testing / selftests / vDSO / vdso_test_getcpu.c
blobcdeaed45fb26c61f6314c58fe1b71fa0be3c0108
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * vdso_test_getcpu.c: Sample code to test parse_vdso.c and vDSO getcpu()
5 * Copyright (c) 2020 Arm Ltd
6 */
8 #include <stdint.h>
9 #include <elf.h>
10 #include <stdio.h>
11 #include <sys/auxv.h>
12 #include <sys/time.h>
14 #include "../kselftest.h"
15 #include "parse_vdso.h"
16 #include "vdso_config.h"
17 #include "vdso_call.h"
19 struct getcpu_cache;
20 typedef long (*getcpu_t)(unsigned int *, unsigned int *,
21 struct getcpu_cache *);
23 int main(int argc, char **argv)
25 const char *version = versions[VDSO_VERSION];
26 const char **name = (const char **)&names[VDSO_NAMES];
27 unsigned long sysinfo_ehdr;
28 unsigned int cpu, node;
29 getcpu_t get_cpu;
30 long ret;
32 sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
33 if (!sysinfo_ehdr) {
34 printf("AT_SYSINFO_EHDR is not present!\n");
35 return KSFT_SKIP;
38 vdso_init_from_sysinfo_ehdr(getauxval(AT_SYSINFO_EHDR));
40 get_cpu = (getcpu_t)vdso_sym(version, name[4]);
41 if (!get_cpu) {
42 printf("Could not find %s\n", name[4]);
43 return KSFT_SKIP;
46 ret = VDSO_CALL(get_cpu, 3, &cpu, &node, 0);
47 if (ret == 0) {
48 printf("Running on CPU %u node %u\n", cpu, node);
49 } else {
50 printf("%s failed\n", name[4]);
51 return KSFT_FAIL;
54 return 0;