Marat Dukhan | d9f76e0 | 2017-09-24 22:46:08 -0700 | [diff] [blame^] | 1 | #include <stdbool.h> |
| 2 | #include <stdint.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <string.h> |
| 5 | #include <errno.h> |
| 6 | |
| 7 | #include <sched.h> |
| 8 | |
| 9 | #include <cpuinfo.h> |
| 10 | #include <linux/api.h> |
| 11 | |
| 12 | |
| 13 | const struct cpuinfo_processor** cpuinfo_linux_cpu_to_processor_map; |
| 14 | const struct cpuinfo_core** cpuinfo_linux_cpu_to_core_map; |
| 15 | |
| 16 | |
| 17 | const struct cpuinfo_processor* cpuinfo_current_processor(void) { |
| 18 | const int cpu = sched_getcpu(); |
| 19 | if (cpu >= 0) { |
| 20 | return cpuinfo_linux_cpu_to_processor_map[cpu]; |
| 21 | } else { |
| 22 | return &cpuinfo_processors[0]; |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | const struct cpuinfo_core* cpuinfo_current_core(void) { |
| 27 | const int cpu = sched_getcpu(); |
| 28 | if (cpu >= 0) { |
| 29 | return cpuinfo_linux_cpu_to_core_map[cpu]; |
| 30 | } else { |
| 31 | return &cpuinfo_cores[0]; |
| 32 | } |
| 33 | } |