Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 09:24:48

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