1 /*
2 * Copyright © 2009 CNRS
3 * Copyright © 2009-2016 Inria. All rights reserved.
4 * Copyright © 2009-2011 Université Bordeaux
5 * See COPYING in top-level directory.
6 */
7
8 /** \file
9 * \brief Macros to help interaction between hwloc and Linux.
10 *
11 * Applications that use hwloc on Linux may want to include this file
12 * if using some low-level Linux features.
13 */
14
15 #ifndef HWLOC_LINUX_H
16 #define HWLOC_LINUX_H
17
18 #include <hwloc.h>
19 #include <stdio.h>
20
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26
27 /** \defgroup hwlocality_linux Linux-specific helpers
28 *
29 * This includes helpers for manipulating Linux kernel cpumap files, and hwloc
30 * equivalents of the Linux sched_setaffinity and sched_getaffinity system calls.
31 *
32 * @{
33 */
34
35 /** \brief Bind a thread \p tid on cpus given in cpuset \p set
36 *
37 * The behavior is exactly the same as the Linux sched_setaffinity system call,
38 * but uses a hwloc cpuset.
39 *
40 * \note This is equivalent to calling hwloc_set_proc_cpubind() with
41 * HWLOC_CPUBIND_THREAD as flags.
42 */
43 HWLOC_DECLSPEC int hwloc_linux_set_tid_cpubind(hwloc_topology_t topology, pid_t tid, hwloc_const_cpuset_t set);
44
45 /** \brief Get the current binding of thread \p tid
46 *
47 * The behavior is exactly the same as the Linux sched_getaffinity system call,
48 * but uses a hwloc cpuset.
49 *
50 * \note This is equivalent to calling hwloc_get_proc_cpubind() with
51 * ::HWLOC_CPUBIND_THREAD as flags.
52 */
53 HWLOC_DECLSPEC int hwloc_linux_get_tid_cpubind(hwloc_topology_t topology, pid_t tid, hwloc_cpuset_t set);
54
55 /** \brief Get the last physical CPU where thread \p tid ran.
56 *
57 * \note This is equivalent to calling hwloc_get_proc_last_cpu_location() with
58 * ::HWLOC_CPUBIND_THREAD as flags.
59 */
60 HWLOC_DECLSPEC int hwloc_linux_get_tid_last_cpu_location(hwloc_topology_t topology, pid_t tid, hwloc_bitmap_t set);
61
62 /** \brief Convert a linux kernel cpumask file \p path into a hwloc bitmap \p set.
63 *
64 * Might be used when reading CPU set from sysfs attributes such as topology
65 * and caches for processors, or local_cpus for devices.
66 *
67 * \note This function ignores the HWLOC_FSROOT environment variable.
68 */
69 HWLOC_DECLSPEC int hwloc_linux_read_path_as_cpumask(const char *path, hwloc_bitmap_t set);
70
71 /** @} */
72
73
74 #ifdef __cplusplus
75 } /* extern "C" */
76 #endif
77
78
79 #endif /* HWLOC_LINUX_H */