2 * Copyright 2013-2015, Michael Ellerman, IBM Corp.
3 * Licensed under GPLv2.
6 #define _GNU_SOURCE /* For CPU_ZERO etc. */
15 #include <sys/types.h>
20 static char auxv
[4096];
22 void *get_auxv_entry(int type
)
29 fd
= open("/proc/self/auxv", O_RDONLY
);
37 num
= read(fd
, auxv
, sizeof(auxv
));
43 if (num
> sizeof(auxv
)) {
44 printf("Overflowed auxv buffer\n");
48 p
= (ElfW(auxv_t
) *)auxv
;
50 while (p
->a_type
!= AT_NULL
) {
51 if (p
->a_type
== type
) {
52 result
= (void *)p
->a_un
.a_val
;
63 int pick_online_cpu(void)
70 if (sched_getaffinity(0, sizeof(mask
), &mask
)) {
71 perror("sched_getaffinity");
75 /* We prefer a primary thread, but skip 0 */
76 for (cpu
= 8; cpu
< CPU_SETSIZE
; cpu
+= 8)
77 if (CPU_ISSET(cpu
, &mask
))
80 /* Search for anything, but in reverse */
81 for (cpu
= CPU_SETSIZE
- 1; cpu
>= 0; cpu
--)
82 if (CPU_ISSET(cpu
, &mask
))
85 printf("No cpus in affinity mask?!\n");
This page took 0.043828 seconds and 5 git commands to generate.