Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:16

0001 /*
0002  * Copyright © 2009 CNRS
0003  * Copyright © 2009-2018 Inria.  All rights reserved.
0004  * Copyright © 2009-2012 Université Bordeaux
0005  * Copyright © 2009-2010 Cisco Systems, Inc.  All rights reserved.
0006  * See COPYING in top-level directory.
0007  */
0008 
0009 /**
0010  * This file contains the inline code of functions declared in hwloc.h
0011  */
0012 
0013 #ifndef HWLOC_INLINES_H
0014 #define HWLOC_INLINES_H
0015 
0016 #ifndef HWLOC_H
0017 #error Please include the main hwloc.h instead
0018 #endif
0019 
0020 #include <stdlib.h>
0021 #include <errno.h>
0022 
0023 
0024 #ifdef __cplusplus
0025 extern "C" {
0026 #endif
0027 
0028 static __hwloc_inline int
0029 hwloc_get_type_or_below_depth (hwloc_topology_t topology, hwloc_obj_type_t type)
0030 {
0031   int depth = hwloc_get_type_depth(topology, type);
0032 
0033   if (depth != HWLOC_TYPE_DEPTH_UNKNOWN)
0034     return depth;
0035 
0036   /* find the highest existing level with type order >= */
0037   for(depth = hwloc_get_type_depth(topology, HWLOC_OBJ_PU); ; depth--)
0038     if (hwloc_compare_types(hwloc_get_depth_type(topology, depth), type) < 0)
0039       return depth+1;
0040 
0041   /* Shouldn't ever happen, as there is always a Machine level with lower order and known depth.  */
0042   /* abort(); */
0043 }
0044 
0045 static __hwloc_inline int
0046 hwloc_get_type_or_above_depth (hwloc_topology_t topology, hwloc_obj_type_t type)
0047 {
0048   int depth = hwloc_get_type_depth(topology, type);
0049 
0050   if (depth != HWLOC_TYPE_DEPTH_UNKNOWN)
0051     return depth;
0052 
0053   /* find the lowest existing level with type order <= */
0054   for(depth = 0; ; depth++)
0055     if (hwloc_compare_types(hwloc_get_depth_type(topology, depth), type) > 0)
0056       return depth-1;
0057 
0058   /* Shouldn't ever happen, as there is always a PU level with higher order and known depth.  */
0059   /* abort(); */
0060 }
0061 
0062 static __hwloc_inline int
0063 hwloc_get_nbobjs_by_type (hwloc_topology_t topology, hwloc_obj_type_t type)
0064 {
0065   int depth = hwloc_get_type_depth(topology, type);
0066   if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
0067     return 0;
0068   if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
0069     return -1; /* FIXME: agregate nbobjs from different levels? */
0070   return (int) hwloc_get_nbobjs_by_depth(topology, depth);
0071 }
0072 
0073 static __hwloc_inline hwloc_obj_t
0074 hwloc_get_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx)
0075 {
0076   int depth = hwloc_get_type_depth(topology, type);
0077   if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
0078     return NULL;
0079   if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
0080     return NULL;
0081   return hwloc_get_obj_by_depth(topology, depth, idx);
0082 }
0083 
0084 static __hwloc_inline hwloc_obj_t
0085 hwloc_get_next_obj_by_depth (hwloc_topology_t topology, int depth, hwloc_obj_t prev)
0086 {
0087   if (!prev)
0088     return hwloc_get_obj_by_depth (topology, depth, 0);
0089   if (prev->depth != depth)
0090     return NULL;
0091   return prev->next_cousin;
0092 }
0093 
0094 static __hwloc_inline hwloc_obj_t
0095 hwloc_get_next_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type,
0096                 hwloc_obj_t prev)
0097 {
0098   int depth = hwloc_get_type_depth(topology, type);
0099   if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
0100     return NULL;
0101   return hwloc_get_next_obj_by_depth (topology, depth, prev);
0102 }
0103 
0104 static __hwloc_inline hwloc_obj_t
0105 hwloc_get_root_obj (hwloc_topology_t topology)
0106 {
0107   return hwloc_get_obj_by_depth (topology, 0, 0);
0108 }
0109 
0110 static __hwloc_inline const char *
0111 hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name)
0112 {
0113   unsigned i;
0114   for(i=0; i<obj->infos_count; i++) {
0115     struct hwloc_info_s *info = &obj->infos[i];
0116     if (!strcmp(info->name, name))
0117       return info->value;
0118   }
0119   return NULL;
0120 }
0121 
0122 static __hwloc_inline void *
0123 hwloc_alloc_membind_policy(hwloc_topology_t topology, size_t len, hwloc_const_cpuset_t set, hwloc_membind_policy_t policy, int flags)
0124 {
0125   void *p = hwloc_alloc_membind(topology, len, set, policy, flags);
0126   if (p)
0127     return p;
0128 
0129   if (hwloc_set_membind(topology, set, policy, flags) < 0)
0130     /* hwloc_set_membind() takes care of ignoring errors if non-STRICT */
0131     return NULL;
0132 
0133   p = hwloc_alloc(topology, len);
0134   if (p && policy != HWLOC_MEMBIND_FIRSTTOUCH)
0135     /* Enforce the binding by touching the data */
0136     memset(p, 0, len);
0137   return p;
0138 }
0139 
0140 
0141 #ifdef __cplusplus
0142 } /* extern "C" */
0143 #endif
0144 
0145 
0146 #endif /* HWLOC_INLINES_H */