Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v1.3.3

  |   Home   |   Support   |   FAQ   |  
openfabrics-verbs.h
1 /*
2  * Copyright © 2009 CNRS
3  * Copyright © 2009-2010 inria. All rights reserved.
4  * Copyright © 2009-2010 Université Bordeaux 1
5  * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
6  * See COPYING in top-level directory.
7  */
8 
19 #ifndef HWLOC_OPENFABRICS_VERBS_H
20 #define HWLOC_OPENFABRICS_VERBS_H
21 
22 #include <hwloc.h>
23 #include <hwloc/autogen/config.h>
24 #include <hwloc/linux.h>
25 
26 #include <infiniband/verbs.h>
27 
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 
46 static inline int
48  struct ibv_device *ibdev, hwloc_cpuset_t set)
49 {
50 #ifdef HWLOC_LINUX_SYS
51  /* If we're on Linux, use the verbs-provided sysfs mechanism to
52  get the local cpus */
53 #define HWLOC_OPENFABRICS_VERBS_SYSFS_PATH_MAX 128
54  char path[HWLOC_OPENFABRICS_VERBS_SYSFS_PATH_MAX];
55  FILE *sysfile = NULL;
56 
57  sprintf(path, "/sys/class/infiniband/%s/device/local_cpus",
58  ibv_get_device_name(ibdev));
59  sysfile = fopen(path, "r");
60  if (!sysfile)
61  return -1;
62 
63  hwloc_linux_parse_cpumap_file(sysfile, set);
64 
65  fclose(sysfile);
66 #else
67  /* Non-Linux systems simply get a full cpuset */
69 #endif
70  return 0;
71 }
72 
76 #ifdef __cplusplus
77 } /* extern "C" */
78 #endif
79 
80 
81 #endif /* HWLOC_OPENFABRICS_VERBS_H */