• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List

hwloc.h

00001 /*
00002  * Copyright © 2009 CNRS
00003  * Copyright © 2009-2010 INRIA
00004  * Copyright © 2009-2011 Université Bordeaux 1
00005  * Copyright © 2009-2011 Cisco Systems, Inc.  All rights reserved.
00006  * See COPYING in top-level directory.
00007  */
00008 
00016 #ifndef HWLOC_H
00017 #define HWLOC_H
00018 
00019 #include <hwloc/config.h>
00020 #include <sys/types.h>
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <limits.h>
00024 #ifdef HWLOC_HAVE_STDINT_H
00025 #include <stdint.h>
00026 #endif
00027 
00028 /*
00029  * Symbol transforms
00030  */
00031 #include <hwloc/rename.h>
00032 
00033 /*
00034  * Bitmap definitions
00035  */
00036 
00037 #include <hwloc/bitmap.h>
00038 #include <hwloc/cpuset.h>
00039 
00040 
00041 #ifdef __cplusplus
00042 extern "C" {
00043 #endif
00044 
00045 
00051 #define HWLOC_API_VERSION 0x00010100
00052 
00054  unsigned hwloc_get_api_version(void);
00055 
00064 struct hwloc_topology;
00069 typedef struct hwloc_topology * hwloc_topology_t;
00070 
00101 typedef hwloc_bitmap_t hwloc_cpuset_t;
00103 typedef hwloc_const_bitmap_t hwloc_const_cpuset_t;
00104 
00118 typedef hwloc_bitmap_t hwloc_nodeset_t;
00121 typedef hwloc_const_bitmap_t hwloc_const_nodeset_t;
00122 
00137 typedef enum {
00138   HWLOC_OBJ_SYSTEM,     
00143   HWLOC_OBJ_MACHINE,    
00148   HWLOC_OBJ_NODE,       
00152   HWLOC_OBJ_SOCKET,     
00156   HWLOC_OBJ_CACHE,      
00159   HWLOC_OBJ_CORE,       
00163   HWLOC_OBJ_PU,         
00172   HWLOC_OBJ_GROUP,      
00184   HWLOC_OBJ_MISC        
00188 } hwloc_obj_type_t;
00189 
00207  int hwloc_compare_types (hwloc_obj_type_t type1, hwloc_obj_type_t type2) ;
00208 
00209 enum hwloc_compare_types_e {
00210     HWLOC_TYPE_UNORDERED = INT_MAX      
00211 };
00212 
00221 union hwloc_obj_attr_u;
00222 
00224 struct hwloc_obj_memory_s {
00225   uint64_t total_memory; 
00226   uint64_t local_memory; 
00228   unsigned page_types_len; 
00234   struct hwloc_obj_memory_page_type_s {
00235     uint64_t size;      
00236     uint64_t count;     
00237   } * page_types;
00238 };
00239 
00244 struct hwloc_obj {
00245   /* physical information */
00246   hwloc_obj_type_t type;                
00247   unsigned os_index;                    
00248   char *name;                           
00250   struct hwloc_obj_memory_s memory;     
00252   union hwloc_obj_attr_u *attr;         
00255   /* global position */
00256   unsigned depth;                       
00257   unsigned logical_index;               
00259   signed os_level;                      
00261   struct hwloc_obj *next_cousin;        
00262   struct hwloc_obj *prev_cousin;        
00264   /* parent */
00265   struct hwloc_obj *parent;             
00266   unsigned sibling_rank;                
00267   struct hwloc_obj *next_sibling;       
00268   struct hwloc_obj *prev_sibling;       
00270   /* children */
00271   unsigned arity;                       
00272   struct hwloc_obj **children;          
00273   struct hwloc_obj *first_child;        
00274   struct hwloc_obj *last_child;         
00276   /* misc */
00277   void *userdata;                       
00279   /* cpusets and nodesets */
00280   hwloc_cpuset_t cpuset;                
00293   hwloc_cpuset_t complete_cpuset;       
00304   hwloc_cpuset_t online_cpuset;         
00312   hwloc_cpuset_t allowed_cpuset;        
00323   hwloc_nodeset_t nodeset;              
00340   hwloc_nodeset_t complete_nodeset;     
00354   hwloc_nodeset_t allowed_nodeset;      
00367   struct hwloc_obj_info_s *infos;       
00368   unsigned infos_count;                 
00369 };
00373 typedef struct hwloc_obj * hwloc_obj_t;
00374 
00376 union hwloc_obj_attr_u {
00378   struct hwloc_cache_attr_s {
00379     uint64_t size;                        
00380     unsigned depth;                       
00381     unsigned linesize;                    
00382   } cache;
00384   struct hwloc_group_attr_s {
00385     unsigned depth;                       
00386   } group;
00387 };
00388 
00390 struct hwloc_obj_info_s {
00391   char *name;   
00392   char *value;  
00393 };
00394 
00409  int hwloc_topology_init (hwloc_topology_t *topologyp);
00410 
00423  int hwloc_topology_load(hwloc_topology_t topology);
00424 
00429  void hwloc_topology_destroy (hwloc_topology_t topology);
00430 
00435  void hwloc_topology_check(hwloc_topology_t topology);
00436 
00469  int hwloc_topology_ignore_type(hwloc_topology_t topology, hwloc_obj_type_t type);
00470 
00477  int hwloc_topology_ignore_type_keep_structure(hwloc_topology_t topology, hwloc_obj_type_t type);
00478 
00484  int hwloc_topology_ignore_all_keep_structure(hwloc_topology_t topology);
00485 
00490 enum hwloc_topology_flags_e {
00491   HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM = (1<<0),
00500   HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM = (1<<1)
00519 };
00520 
00525  int hwloc_topology_set_flags (hwloc_topology_t topology, unsigned long flags);
00526 
00540  int hwloc_topology_set_fsroot(hwloc_topology_t restrict topology, const char * restrict fsroot_path);
00541 
00555  int hwloc_topology_set_pid(hwloc_topology_t restrict topology, hwloc_pid_t pid);
00556 
00570  int hwloc_topology_set_synthetic(hwloc_topology_t restrict topology, const char * restrict description);
00571 
00583  int hwloc_topology_set_xml(hwloc_topology_t restrict topology, const char * restrict xmlpath);
00584 
00590  int hwloc_topology_set_xmlbuffer(hwloc_topology_t restrict topology, const char * restrict buffer, int size);
00591 
00593 struct hwloc_topology_discovery_support {
00595   unsigned char pu;
00596 };
00597 
00599 struct hwloc_topology_cpubind_support {
00601   unsigned char set_thisproc_cpubind;
00603   unsigned char get_thisproc_cpubind;
00605   unsigned char set_proc_cpubind;
00607   unsigned char get_proc_cpubind;
00609   unsigned char set_thisthread_cpubind;
00611   unsigned char get_thisthread_cpubind;
00613   unsigned char set_thread_cpubind;
00615   unsigned char get_thread_cpubind;
00616 };
00617 
00619 struct hwloc_topology_membind_support {
00621   unsigned char set_thisproc_membind;
00623   unsigned char get_thisproc_membind;
00625   unsigned char set_proc_membind;
00627   unsigned char get_proc_membind;
00629   unsigned char set_thisthread_membind;
00631   unsigned char get_thisthread_membind;
00633   unsigned char set_area_membind;
00635   unsigned char get_area_membind;
00637   unsigned char alloc_membind;
00639   unsigned char firsttouch_membind;
00641   unsigned char bind_membind;
00643   unsigned char interleave_membind;
00645   unsigned char replicate_membind;
00647   unsigned char nexttouch_membind;
00648 
00650   unsigned char migrate_membind;
00651 };
00652 
00659 struct hwloc_topology_support {
00660   struct hwloc_topology_discovery_support *discovery;
00661   struct hwloc_topology_cpubind_support *cpubind;
00662   struct hwloc_topology_membind_support *membind;
00663 };
00664 
00666  const struct hwloc_topology_support *hwloc_topology_get_support(hwloc_topology_t restrict topology);
00667 
00680  void hwloc_topology_export_xml(hwloc_topology_t topology, const char *xmlpath);
00681 
00688  void hwloc_topology_export_xmlbuffer(hwloc_topology_t topology, char **xmlbuffer, int *buflen);
00689 
00699  hwloc_obj_t hwloc_topology_insert_misc_object_by_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset, const char *name);
00700 
00710  hwloc_obj_t hwloc_topology_insert_misc_object_by_parent(hwloc_topology_t topology, hwloc_obj_t parent, const char *name);
00711 
00724  unsigned hwloc_topology_get_depth(hwloc_topology_t restrict topology) ;
00725 
00735  int hwloc_get_type_depth (hwloc_topology_t topology, hwloc_obj_type_t type);
00736 
00737 enum hwloc_get_type_depth_e {
00738     HWLOC_TYPE_DEPTH_UNKNOWN = -1, 
00739     HWLOC_TYPE_DEPTH_MULTIPLE = -2 
00740 };
00741 
00746  hwloc_obj_type_t hwloc_get_depth_type (hwloc_topology_t topology, unsigned depth) ;
00747 
00749  unsigned hwloc_get_nbobjs_by_depth (hwloc_topology_t topology, unsigned depth) ;
00750 
00756 static inline int 
00757 hwloc_get_nbobjs_by_type (hwloc_topology_t topology, hwloc_obj_type_t type)
00758 {
00759         int depth = hwloc_get_type_depth(topology, type);
00760         if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
00761                 return 0;
00762         if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
00763                 return -1; /* FIXME: agregate nbobjs from different levels? */
00764         return hwloc_get_nbobjs_by_depth(topology, depth);
00765 }
00766 
00774  int hwloc_topology_is_thissystem(hwloc_topology_t  restrict topology) ;
00775 
00785  hwloc_obj_t hwloc_get_obj_by_depth (hwloc_topology_t topology, unsigned depth, unsigned idx) ;
00786 
00793 static inline hwloc_obj_t 
00794 hwloc_get_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx)
00795 {
00796   int depth = hwloc_get_type_depth(topology, type);
00797   if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
00798     return NULL;
00799   if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
00800     return NULL;
00801   return hwloc_get_obj_by_depth(topology, depth, idx);
00802 }
00803 
00813  const char * hwloc_obj_type_string (hwloc_obj_type_t type) ;
00814 
00819  hwloc_obj_type_t hwloc_obj_type_of_string (const char * string) ;
00820 
00831  int hwloc_obj_type_snprintf(char * restrict string, size_t size, hwloc_obj_t obj,
00832                                    int verbose);
00833 
00845  int hwloc_obj_attr_snprintf(char * restrict string, size_t size, hwloc_obj_t obj, const char * restrict separator,
00846                                    int verbose);
00847 
00868  int hwloc_obj_snprintf(char * restrict string, size_t size,
00869                              hwloc_topology_t topology, hwloc_obj_t obj,
00870                              const char * restrict indexprefix, int verbose);
00871 
00879  int hwloc_obj_cpuset_snprintf(char * restrict str, size_t size, size_t nobj, const hwloc_obj_t * restrict objs);
00880 
00885 static inline char * 
00886 hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name)
00887 {
00888   unsigned i;
00889   for(i=0; i<obj->infos_count; i++)
00890     if (!strcmp(obj->infos[i].name, name))
00891       return obj->infos[i].value;
00892   return NULL;
00893 }
00894 
00949 typedef enum {
00950   HWLOC_CPUBIND_PROCESS = (1<<0), 
00953   HWLOC_CPUBIND_THREAD = (1<<1),  
00955   HWLOC_CPUBIND_STRICT = (1<<2),  
00983   HWLOC_CPUBIND_NOMEMBIND = (1<<3)
00997 } hwloc_cpubind_flags_t;
00998 
01004  int hwloc_set_cpubind(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags);
01005 
01008  int hwloc_get_cpubind(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
01009 
01017  int hwloc_set_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_cpuset_t set, int flags);
01018 
01026  int hwloc_get_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
01027 
01028 #ifdef hwloc_thread_t
01029 
01036  int hwloc_set_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t tid, hwloc_const_cpuset_t set, int flags);
01037 #endif
01038 
01039 #ifdef hwloc_thread_t
01040 
01047  int hwloc_get_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t tid, hwloc_cpuset_t set, int flags);
01048 #endif
01049 
01108 typedef enum {
01109   HWLOC_MEMBIND_DEFAULT =       0,      
01111   HWLOC_MEMBIND_FIRSTTOUCH =    1,      
01122   HWLOC_MEMBIND_BIND =          2,      
01124   HWLOC_MEMBIND_INTERLEAVE =    3,      
01139   HWLOC_MEMBIND_REPLICATE =     4,      
01161   HWLOC_MEMBIND_NEXTTOUCH =     5,      
01171   HWLOC_MEMBIND_MIXED = -1              
01176 } hwloc_membind_policy_t;
01177 
01189 typedef enum {
01190   HWLOC_MEMBIND_PROCESS =       (1<<0), 
01197   HWLOC_MEMBIND_THREAD =        (1<<1), 
01203   HWLOC_MEMBIND_STRICT =        (1<<2), 
01214   HWLOC_MEMBIND_MIGRATE =       (1<<3), 
01222   HWLOC_MEMBIND_NOCPUBIND =     (1<<4)  
01245 } hwloc_membind_flags_t;
01246 
01259  int hwloc_set_membind_nodeset(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
01260 
01274  int hwloc_set_membind(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset, hwloc_membind_policy_t policy, int flags);
01275 
01316  int hwloc_get_membind_nodeset(hwloc_topology_t topology, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
01317 
01363  int hwloc_get_membind(hwloc_topology_t topology, hwloc_cpuset_t cpuset, hwloc_membind_policy_t * policy, int flags);
01364 
01371  int hwloc_set_proc_membind_nodeset(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
01372 
01379  int hwloc_set_proc_membind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_cpuset_t cpuset, hwloc_membind_policy_t policy, int flags);
01380 
01414  int hwloc_get_proc_membind_nodeset(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
01415 
01452  int hwloc_get_proc_membind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t cpuset, hwloc_membind_policy_t * policy, int flags);
01453 
01460  int hwloc_set_area_membind_nodeset(hwloc_topology_t topology, const void *addr, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
01461 
01468  int hwloc_set_area_membind(hwloc_topology_t topology, const void *addr, size_t len, hwloc_const_cpuset_t cpuset, hwloc_membind_policy_t policy, int flags);
01469 
01492  int hwloc_get_area_membind_nodeset(hwloc_topology_t topology, const void *addr, size_t len, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
01493 
01518  int hwloc_get_area_membind(hwloc_topology_t topology, const void *addr, size_t len, hwloc_cpuset_t cpuset, hwloc_membind_policy_t * policy, int flags);
01519 
01527  void *hwloc_alloc(hwloc_topology_t topology, size_t len);
01528 
01538  void *hwloc_alloc_membind_nodeset(hwloc_topology_t topology, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags) ;
01539 
01549  void *hwloc_alloc_membind(hwloc_topology_t topology, size_t len, hwloc_const_cpuset_t cpuset, hwloc_membind_policy_t policy, int flags) ;
01550 
01554  int hwloc_free(hwloc_topology_t topology, void *addr, size_t len);
01555 
01559 #ifdef __cplusplus
01560 } /* extern "C" */
01561 #endif
01562 
01563 
01564 /* high-level helpers */
01565 #include <hwloc/helper.h>
01566 
01567 
01568 #endif /* HWLOC_H */

Generated on Mon Jan 24 2011 17:12:07 for Hardware Locality (hwloc) by  doxygen 1.7.2