Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*
0002  * Copyright © 2009-2018 Inria.  All rights reserved.
0003  * Copyright © 2009-2012 Université Bordeaux
0004  * Copyright © 2009-2011 Cisco Systems, Inc.  All rights reserved.
0005  * See COPYING in top-level directory.
0006  */
0007 
0008 /** \file
0009  * \brief Exporting Topologies to XML or to Synthetic strings.
0010  */
0011 
0012 #ifndef HWLOC_EXPORT_H
0013 #define HWLOC_EXPORT_H
0014 
0015 #ifndef HWLOC_H
0016 #error Please include the main hwloc.h instead
0017 #endif
0018 
0019 
0020 #ifdef __cplusplus
0021 extern "C" {
0022 #elif 0
0023 }
0024 #endif
0025 
0026 
0027 /** \defgroup hwlocality_xmlexport Exporting Topologies to XML
0028  * @{
0029  */
0030 
0031 /** \brief Flags for exporting XML topologies.
0032  *
0033  * Flags to be given as a OR'ed set to hwloc_topology_export_xml().
0034  */
0035 enum hwloc_topology_export_xml_flags_e {
0036  /** \brief Export XML that is loadable by hwloc v1.x.
0037   * However, the export may miss some details about the topology.
0038   * \hideinitializer
0039   */
0040  HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1 = (1UL<<0)
0041 };
0042 
0043 /** \brief Export the topology into an XML file.
0044  *
0045  * This file may be loaded later through hwloc_topology_set_xml().
0046  *
0047  * By default, the latest export format is used, which means older hwloc
0048  * releases (e.g. v1.x) will not be able to import it.
0049  * Exporting to v1.x specific XML format is possible using flag
0050  * ::HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1 but it may miss some details
0051  * about the topology.
0052  * If there is any chance that the exported file may ever be imported
0053  * back by a process using hwloc 1.x, one should consider detecting
0054  * it at runtime and using the corresponding export format.
0055  *
0056  * \p flags is a OR'ed set of ::hwloc_topology_export_xml_flags_e.
0057  *
0058  * \return 0 on success, or -1 on error.
0059  *
0060  * \note See also hwloc_topology_set_userdata_export_callback()
0061  * for exporting application-specific object userdata.
0062  *
0063  * \note The topology-specific userdata pointer is ignored when exporting to XML.
0064  *
0065  * \note Only printable characters may be exported to XML string attributes.
0066  * Any other character, especially any non-ASCII character, will be silently
0067  * dropped.
0068  *
0069  * \note If \p name is "-", the XML output is sent to the standard output.
0070  */
0071 HWLOC_DECLSPEC int hwloc_topology_export_xml(hwloc_topology_t topology, const char *xmlpath, unsigned long flags);
0072 
0073 /** \brief Export the topology into a newly-allocated XML memory buffer.
0074  *
0075  * \p xmlbuffer is allocated by the callee and should be freed with
0076  * hwloc_free_xmlbuffer() later in the caller.
0077  *
0078  * This memory buffer may be loaded later through hwloc_topology_set_xmlbuffer().
0079  *
0080  * By default, the latest export format is used, which means older hwloc
0081  * releases (e.g. v1.x) will not be able to import it.
0082  * Exporting to v1.x specific XML format is possible using flag
0083  * ::HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1 but it may miss some details
0084  * about the topology.
0085  * If there is any chance that the exported buffer may ever be imported
0086  * back by a process using hwloc 1.x, one should consider detecting
0087  * it at runtime and using the corresponding export format.
0088  *
0089  * The returned buffer ends with a \0 that is included in the returned
0090  * length.
0091  *
0092  * \p flags is a OR'ed set of ::hwloc_topology_export_xml_flags_e.
0093  *
0094  * \return 0 on success, or -1 on error.
0095  *
0096  * \note See also hwloc_topology_set_userdata_export_callback()
0097  * for exporting application-specific object userdata.
0098  *
0099  * \note The topology-specific userdata pointer is ignored when exporting to XML.
0100  *
0101  * \note Only printable characters may be exported to XML string attributes.
0102  * Any other character, especially any non-ASCII character, will be silently
0103  * dropped.
0104  */
0105 HWLOC_DECLSPEC int hwloc_topology_export_xmlbuffer(hwloc_topology_t topology, char **xmlbuffer, int *buflen, unsigned long flags);
0106 
0107 /** \brief Free a buffer allocated by hwloc_topology_export_xmlbuffer() */
0108 HWLOC_DECLSPEC void hwloc_free_xmlbuffer(hwloc_topology_t topology, char *xmlbuffer);
0109 
0110 /** \brief Set the application-specific callback for exporting object userdata
0111  *
0112  * The object userdata pointer is not exported to XML by default because hwloc
0113  * does not know what it contains.
0114  *
0115  * This function lets applications set \p export_cb to a callback function
0116  * that converts this opaque userdata into an exportable string.
0117  *
0118  * \p export_cb is invoked during XML export for each object whose
0119  * \p userdata pointer is not \c NULL.
0120  * The callback should use hwloc_export_obj_userdata() or
0121  * hwloc_export_obj_userdata_base64() to actually export
0122  * something to XML (possibly multiple times per object).
0123  *
0124  * \p export_cb may be set to \c NULL if userdata should not be exported to XML.
0125  *
0126  * \note The topology-specific userdata pointer is ignored when exporting to XML.
0127  */
0128 HWLOC_DECLSPEC void hwloc_topology_set_userdata_export_callback(hwloc_topology_t topology,
0129                                 void (*export_cb)(void *reserved, hwloc_topology_t topology, hwloc_obj_t obj));
0130 
0131 /** \brief Export some object userdata to XML
0132  *
0133  * This function may only be called from within the export() callback passed
0134  * to hwloc_topology_set_userdata_export_callback().
0135  * It may be invoked one of multiple times to export some userdata to XML.
0136  * The \p buffer content of length \p length is stored with optional name
0137  * \p name.
0138  *
0139  * When importing this XML file, the import() callback (if set) will be
0140  * called exactly as many times as hwloc_export_obj_userdata() was called
0141  * during export(). It will receive the corresponding \p name, \p buffer
0142  * and \p length arguments.
0143  *
0144  * \p reserved, \p topology and \p obj must be the first three parameters
0145  * that were given to the export callback.
0146  *
0147  * Only printable characters may be exported to XML string attributes.
0148  *
0149  * If exporting binary data, the application should first encode into
0150  * printable characters only (or use hwloc_export_obj_userdata_base64()).
0151  * It should also take care of portability issues if the export may
0152  * be reimported on a different architecture.
0153  *
0154  * \return 0 on success.
0155  * \return -1 with errno set to \c EINVAL if a non-printable character is
0156  * passed in \p name or \b buffer.
0157  */
0158 HWLOC_DECLSPEC int hwloc_export_obj_userdata(void *reserved, hwloc_topology_t topology, hwloc_obj_t obj, const char *name, const void *buffer, size_t length);
0159 
0160 /** \brief Encode and export some object userdata to XML
0161  *
0162  * This function is similar to hwloc_export_obj_userdata() but it encodes
0163  * the input buffer into printable characters before exporting.
0164  * On import, decoding is automatically performed before the data is given
0165  * to the import() callback if any.
0166  *
0167  * This function may only be called from within the export() callback passed
0168  * to hwloc_topology_set_userdata_export_callback().
0169  *
0170  * The name must be made of printable characters for export to XML string attributes.
0171  *
0172  * The function does not take care of portability issues if the export
0173  * may be reimported on a different architecture.
0174  *
0175  * \return 0 on success.
0176  * \return -1 with errno set to \c EINVAL if a non-printable character is
0177  * passed in \p name.
0178  */
0179 HWLOC_DECLSPEC int hwloc_export_obj_userdata_base64(void *reserved, hwloc_topology_t topology, hwloc_obj_t obj, const char *name, const void *buffer, size_t length);
0180 
0181 /** \brief Set the application-specific callback for importing userdata
0182  *
0183  * On XML import, userdata is ignored by default because hwloc does not know
0184  * how to store it in memory.
0185  *
0186  * This function lets applications set \p import_cb to a callback function
0187  * that will get the XML-stored userdata and store it in the object as expected
0188  * by the application.
0189  *
0190  * \p import_cb is called during hwloc_topology_load() as many times as
0191  * hwloc_export_obj_userdata() was called during export. The topology
0192  * is not entirely setup yet. Object attributes are ready to consult,
0193  * but links between objects are not.
0194  *
0195  * \p import_cb may be \c NULL if userdata should be ignored during import.
0196  *
0197  * \note \p buffer contains \p length characters followed by a null byte ('\0').
0198  *
0199  * \note This function should be called before hwloc_topology_load().
0200  *
0201  * \note The topology-specific userdata pointer is ignored when importing from XML.
0202  */
0203 HWLOC_DECLSPEC void hwloc_topology_set_userdata_import_callback(hwloc_topology_t topology,
0204                                 void (*import_cb)(hwloc_topology_t topology, hwloc_obj_t obj, const char *name, const void *buffer, size_t length));
0205 
0206 /** @} */
0207 
0208 
0209 /** \defgroup hwlocality_syntheticexport Exporting Topologies to Synthetic
0210  * @{
0211  */
0212 
0213 /** \brief Flags for exporting synthetic topologies.
0214  *
0215  * Flags to be given as a OR'ed set to hwloc_topology_export_synthetic().
0216  */
0217 enum hwloc_topology_export_synthetic_flags_e {
0218  /** \brief Export extended types such as L2dcache as basic types such as Cache.
0219   *
0220   * This is required if loading the synthetic description with hwloc < 1.9.
0221   * \hideinitializer
0222   */
0223  HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_EXTENDED_TYPES = (1UL<<0),
0224 
0225  /** \brief Do not export level attributes.
0226   *
0227   * Ignore level attributes such as memory/cache sizes or PU indexes.
0228   * This is required if loading the synthetic description with hwloc < 1.10.
0229   * \hideinitializer
0230   */
0231  HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_ATTRS = (1UL<<1),
0232 
0233  /** \brief Export the memory hierarchy as expected in hwloc 1.x.
0234   *
0235   * Instead of attaching memory children to levels, export single NUMA node child
0236   * as normal intermediate levels, when possible.
0237   * This is required if loading the synthetic description with hwloc 1.x.
0238   * However this may fail if some objects have multiple local NUMA nodes.
0239   * \hideinitializer
0240   */
0241  HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_V1 = (1UL<<2),
0242 
0243  /** \brief Do not export memory information.
0244   *
0245   * Only export the actual hierarchy of normal CPU-side objects and ignore
0246   * where memory is attached.
0247   * This is useful for when the hierarchy of CPUs is what really matters,
0248   * but it behaves as if there was a single machine-wide NUMA node.
0249   * \hideinitializer
0250   */
0251  HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_IGNORE_MEMORY = (1UL<<3)
0252 };
0253 
0254 /** \brief Export the topology as a synthetic string.
0255  *
0256  * At most \p buflen characters will be written in \p buffer,
0257  * including the terminating \0.
0258  *
0259  * This exported string may be given back to hwloc_topology_set_synthetic().
0260  *
0261  * \p flags is a OR'ed set of ::hwloc_topology_export_synthetic_flags_e.
0262  *
0263  * \return The number of characters that were written,
0264  * not including the terminating \0.
0265  *
0266  * \return -1 if the topology could not be exported,
0267  * for instance if it is not symmetric.
0268  *
0269  * \note I/O and Misc children are ignored, the synthetic string only
0270  * describes normal children.
0271  *
0272  * \note A 1024-byte buffer should be large enough for exporting
0273  * topologies in the vast majority of cases.
0274  */
0275   HWLOC_DECLSPEC int hwloc_topology_export_synthetic(hwloc_topology_t topology, char *buffer, size_t buflen, unsigned long flags);
0276 
0277 /** @} */
0278 
0279 
0280 
0281 #ifdef __cplusplus
0282 } /* extern "C" */
0283 #endif
0284 
0285 
0286 #endif /* HWLOC_EXPORT_H */