libtopology
topology.h
Go to the documentation of this file.
1 /*
2  * libtopology - a library for discovering Linux system topology
3  *
4  * Copyright 2008 Nathan Lynch, IBM Corporation
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * version 2.1 as published by the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301 USA
19  */
20 
27 #ifndef _TOPOLOGY_H_
28 #define _TOPOLOGY_H_
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #ifndef LIBTOPOLOGY_DOXYGEN_SKIP
35 
36 #include <sched.h> /* for cpu_set_t */
37 
38 #endif /* LIBTOPOLOGY_DOXYGEN_SKIP */
39 
40 typedef unsigned long topo_context_t;
41 typedef unsigned long topo_procent_t;
42 typedef unsigned long topo_device_t;
43 
44 typedef enum topology_level {
45  TOPOLOGY_THREAD = 1,
46  TOPOLOGY_CORE,
47  TOPOLOGY_PACKAGE,
48  TOPOLOGY_NODE,
49  TOPOLOGY_SYSTEM,
50 } topo_level_t;
51 
69 extern int topology_init_context(topo_context_t *ctx, topo_procent_t *system);
70 
84 extern void topology_free_context(topo_context_t ctx);
85 
106 extern size_t topology_sizeof_cpumask(topo_context_t ctx);
107 
125 extern topo_procent_t
126 topology_traverse(topo_procent_t start,
127  topo_procent_t iter,
128  topo_level_t to_level);
141 extern void topology_procent_cpumask(topo_procent_t ent, cpu_set_t *dest);
142 
159 extern topo_device_t
160 topology_find_device_by_type(topo_context_t ctx,
161  topo_device_t prev,
162  const char *type);
163 
164 
177 extern void topology_device_cpumask(topo_device_t dev, cpu_set_t *dest);
178 
191 extern const char *
192 topology_device_get_attribute(topo_device_t dev, const char *name);
193 
203 #define topology_for_each_device_of_type(ctx, dev, type) \
204  for ((dev) = topology_find_device_by_type((ctx), (topo_device_t)0, (type)); \
205  (dev) != 0; \
206  (dev) = topology_find_device_by_type((ctx), (dev), (type)))
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 
212 #endif /* _TOPOLOGY_H_ */