Skip to content

Commit

Permalink
xml: add support for 3.0 xml format
Browse files Browse the repository at this point in the history
For now, it only changes the XML header to <topology version="3.0">

We still use hwloc2.dtd, we'll fork it later into a hwloc3.dtd if needed.

2.0 is still enabled internally for now,
but 2.0 and 3.0 import/export is supported.

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Jan 25, 2023
1 parent d1029c3 commit 5e004cc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
3 changes: 3 additions & 0 deletions NEWS
Expand Up @@ -43,6 +43,9 @@ Version 3.0.0
- hwloc_cpuset_from_nodeset_strict()
+ HWLOC_PCI_<domain>_<bus>_LOCALCPUS environment variables,
superseded with a single HWLOC_PCI_LOCALITY since 2.0.
* Misc
+ XML format switches to 3.0 by default. Exporting to 2.x is
possible with the new V2 XML export flag.


Version 2.9.0
Expand Down
11 changes: 8 additions & 3 deletions hwloc/topology-xml-libxml.c
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2018 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2011, 2020 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
Expand Down Expand Up @@ -438,6 +438,7 @@ hwloc__libxml2_prepare_export(hwloc_topology_t topology, struct hwloc__xml_expor
struct hwloc__xml_export_state_s state;
hwloc__libxml_export_state_data_t data = (void *) state.data;
int v1export = flags & HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1;
int v2export = flags & HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V2;
xmlDocPtr doc = NULL; /* document pointer */
xmlNodePtr root_node = NULL; /* root pointer */

Expand All @@ -449,8 +450,12 @@ hwloc__libxml2_prepare_export(hwloc_topology_t topology, struct hwloc__xml_expor
/* Creates a new document, a node and set it as a root node. */
doc = xmlNewDoc(BAD_CAST "1.0");
root_node = xmlNewNode(NULL, BAD_CAST "topology");
if (!(flags & HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1))
xmlNewProp(root_node, BAD_CAST "version", BAD_CAST "2.0");
if (!v1export) {
if (v2export)
xmlNewProp(root_node, BAD_CAST "version", BAD_CAST "2.0");
else
xmlNewProp(root_node, BAD_CAST "version", BAD_CAST "3.0");
}
xmlDocSetRootElement(doc, root_node);

/* Creates a DTD declaration. Isn't mandatory. */
Expand Down
11 changes: 8 additions & 3 deletions hwloc/topology-xml-nolibxml.c
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2020 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2011 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
Expand Down Expand Up @@ -676,6 +676,7 @@ hwloc___nolibxml_prepare_export(hwloc_topology_t topology, struct hwloc__xml_exp
struct hwloc__xml_export_state_s state, childstate;
hwloc__nolibxml_export_state_data_t ndata = (void *) &state.data;
int v1export = flags & HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1;
int v2export = flags & HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V2;
int res;

HWLOC_BUILD_ASSERT(sizeof(*ndata) <= sizeof(state.data));
Expand All @@ -699,8 +700,12 @@ hwloc___nolibxml_prepare_export(hwloc_topology_t topology, struct hwloc__xml_exp
"<!DOCTYPE topology SYSTEM \"%s\">\n", v1export ? "hwloc.dtd" : "hwloc2.dtd");
hwloc__nolibxml_export_update_buffer(ndata, res);
hwloc__nolibxml_export_new_child(&state, &childstate, "topology");
if (!(flags & HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1))
hwloc__nolibxml_export_new_prop(&childstate, "version", "2.0");
if (!v1export) {
if (v2export)
hwloc__nolibxml_export_new_prop(&childstate, "version", "2.0");
else
hwloc__nolibxml_export_new_prop(&childstate, "version", "3.0");
}
hwloc__xml_export_topology (&childstate, topology, flags);
hwloc__nolibxml_export_end_object(&childstate, "topology");

Expand Down
2 changes: 1 addition & 1 deletion hwloc/topology-xml.c
Expand Up @@ -2081,7 +2081,7 @@ hwloc_look_xml(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus)
if (ret < 0)
goto failed;

if (data->version_major > 2) {
if (data->version_major > 3) {
if (hwloc__xml_verbose())
fprintf(stderr, "%s: cannot import XML version %u.%u > 2\n",
data->msgprefix, data->version_major, data->version_minor);
Expand Down
2 changes: 1 addition & 1 deletion utils/lstopo/lstopo-no-graphics.1in
Expand Up @@ -69,7 +69,7 @@ Enforce flags when exporting to the XML format.
Flags may be given as numeric values or as a comma-separated list of flag names
that are passed to \fIhwloc_topology_export_xml()\fR.
Those names may be substrings of actual flag names as long as a single one matches.
A value of \fB1\fR (or \fBv1\fR) reverts to the format of hwloc v1.x.
A value of \fB2\fR (or \fBv2\fR) reverts to the format of hwloc v2.x.
The default is \fB0\fR (or \fBnone\fR).
.TP
\fB\-\-export\-synthetic\-flags\fR <flags>
Expand Down

0 comments on commit 5e004cc

Please sign in to comment.