Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-09 09:12:34

0001 /*
0002  * SPDX-License-Identifier: BSD-3-Clause
0003  * Copyright © 2009 CNRS
0004  * Copyright © 2009-2023 Inria.  All rights reserved.
0005  * Copyright © 2009-2011 Université Bordeaux
0006  * See COPYING in top-level directory.
0007  */
0008 
0009 /** \file
0010  * \brief Macros to help interaction between hwloc and Linux.
0011  *
0012  * Applications that use hwloc on Linux may want to include this file
0013  * if using some low-level Linux features.
0014  */
0015 
0016 #ifndef HWLOC_LINUX_H
0017 #define HWLOC_LINUX_H
0018 
0019 #include "hwloc.h"
0020 
0021 #include <stdio.h>
0022 
0023 
0024 #ifdef __cplusplus
0025 extern "C" {
0026 #endif
0027 
0028 
0029 /** \defgroup hwlocality_linux Linux-specific helpers
0030  *
0031  * This includes helpers for manipulating Linux kernel cpumap files, and hwloc
0032  * equivalents of the Linux sched_setaffinity and sched_getaffinity system calls.
0033  *
0034  * @{
0035  */
0036 
0037 /** \brief Bind a thread \p tid on cpus given in cpuset \p set
0038  *
0039  * The behavior is exactly the same as the Linux sched_setaffinity system call,
0040  * but uses a hwloc cpuset.
0041  *
0042  * \return 0 on success, -1 on error.
0043  *
0044  * \note This is equivalent to calling hwloc_set_proc_cpubind() with
0045  * HWLOC_CPUBIND_THREAD as flags.
0046  */
0047 HWLOC_DECLSPEC int hwloc_linux_set_tid_cpubind(hwloc_topology_t topology, pid_t tid, hwloc_const_cpuset_t set);
0048 
0049 /** \brief Get the current binding of thread \p tid
0050  *
0051  * The CPU-set \p set (previously allocated by the caller)
0052  * is filled with the list of PUs which the thread
0053  * was last bound to.
0054  *
0055  * The behavior is exactly the same as the Linux sched_getaffinity system call,
0056  * but uses a hwloc cpuset.
0057  *
0058  * \return 0 on success, -1 on error.
0059  *
0060  * \note This is equivalent to calling hwloc_get_proc_cpubind() with
0061  * ::HWLOC_CPUBIND_THREAD as flags.
0062  */
0063 HWLOC_DECLSPEC int hwloc_linux_get_tid_cpubind(hwloc_topology_t topology, pid_t tid, hwloc_cpuset_t set);
0064 
0065 /** \brief Get the last physical CPU where thread \p tid ran.
0066  *
0067  * The CPU-set \p set (previously allocated by the caller)
0068  * is filled with the PU which the thread last ran on.
0069  *
0070  * \return 0 on success, -1 on error.
0071  *
0072  * \note This is equivalent to calling hwloc_get_proc_last_cpu_location() with
0073  * ::HWLOC_CPUBIND_THREAD as flags.
0074  */
0075 HWLOC_DECLSPEC int hwloc_linux_get_tid_last_cpu_location(hwloc_topology_t topology, pid_t tid, hwloc_bitmap_t set);
0076 
0077 /** \brief Convert a linux kernel cpumask file \p path into a hwloc bitmap \p set.
0078  *
0079  * Might be used when reading CPU set from sysfs attributes such as topology
0080  * and caches for processors, or local_cpus for devices.
0081  *
0082  * \return 0 on success, -1 on error.
0083  *
0084  * \note This function ignores the HWLOC_FSROOT environment variable.
0085  */
0086 HWLOC_DECLSPEC int hwloc_linux_read_path_as_cpumask(const char *path, hwloc_bitmap_t set);
0087 
0088 /** @} */
0089 
0090 
0091 #ifdef __cplusplus
0092 } /* extern "C" */
0093 #endif
0094 
0095 
0096 #endif /* HWLOC_LINUX_H */