| 1 |
/* |
| 2 |
* SPDX-License-Identifier: BSD-3-Clause |
| 3 |
* Copyright © 2009 CNRS |
| 4 |
* Copyright © 2009-2024 Inria. All rights reserved. |
| 5 |
* Copyright © 2009-2012 Université Bordeaux |
| 6 |
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved. |
| 7 |
* See COPYING in top-level directory. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "private/autogen/config.h" |
| 11 |
#include "hwloc.h" |
| 12 |
|
| 13 |
#include <stdlib.h> |
| 14 |
#include <stdio.h> |
| 15 |
#include <string.h> |
| 16 |
#include <errno.h> |
| 17 |
|
| 18 |
#ifdef HWLOC_WIN_SYS |
| 19 |
#include <hwloc/windows.h> |
| 20 |
#endif |
| 21 |
|
| 22 |
#include "lstopo.h" |
| 23 |
#include "misc.h" |
| 24 |
|
| 25 |
#define indent(output, i) \ |
| 26 |
fprintf (output, "%*s", (int) i, ""); |
| 27 |
|
| 28 |
/* |
| 29 |
* Console fashion text output |
| 30 |
*/ |
| 31 |
|
| 32 |
static void |
| 33 |
output_console_obj (struct lstopo_output *loutput, hwloc_obj_t l, int collapse) |
| 34 |
{ |
| 35 |
FILE *output = loutput->file; |
| 36 |
enum lstopo_index_type_e index_type = loutput->index_type; |
| 37 |
int verbose_mode = loutput->verbose_mode; |
| 38 |
char pidxstr[16]; |
| 39 |
char lidxstr[32]; |
| 40 |
char busidstr[32]; |
| 41 |
|
| 42 |
if (collapse > 1 && l->type == HWLOC_OBJ_PCI_DEVICE) { |
| 43 |
strcpy(pidxstr, "P#[collapsed]"); /* shouldn't be used, os_index should be -1 except if importing old XMLs */ |
| 44 |
snprintf(lidxstr, sizeof(lidxstr), "%s%u-%u", loutput->logical_index_prefix, l->logical_index, l->logical_index+collapse-1); |
| 45 |
} else { |
| 46 |
snprintf(pidxstr, sizeof(pidxstr), "%s%u", loutput->os_index_prefix, l->os_index); |
| 47 |
snprintf(lidxstr, sizeof(lidxstr), "%s%u", loutput->logical_index_prefix, l->logical_index); |
| 48 |
} |
| 49 |
if (l->type == HWLOC_OBJ_PCI_DEVICE) |
| 50 |
lstopo_busid_snprintf(loutput, busidstr, sizeof(busidstr), l, collapse, loutput->need_pci_domain); |
| 51 |
|
| 52 |
if (loutput->show_cpuset < 2) { |
| 53 |
char type[64], *attr, phys[32] = ""; |
| 54 |
int len; |
| 55 |
hwloc_obj_type_snprintf (type, sizeof(type), l, verbose_mode-1); |
| 56 |
if (l->subtype) |
| 57 |
fprintf(output, "%s(%s)", type, l->subtype); |
| 58 |
else |
| 59 |
fprintf(output, "%s", type); |
| 60 |
if (l->depth != 0 && (verbose_mode >= 2 || (hwloc_obj_type_is_normal(l->type) || hwloc_obj_type_is_memory(l->type)))) { |
| 61 |
if (index_type != LSTOPO_INDEX_TYPE_PHYSICAL) |
| 62 |
/* print logical index in logical and default case */ |
| 63 |
fprintf(output, "%s", lidxstr); |
| 64 |
else if (index_type == LSTOPO_INDEX_TYPE_PHYSICAL && l->os_index != HWLOC_UNKNOWN_INDEX) |
| 65 |
/* print physical index in physical case */ |
| 66 |
fprintf(output, "%s", pidxstr); |
| 67 |
} |
| 68 |
if (l->name && (l->type == HWLOC_OBJ_MISC || l->type == HWLOC_OBJ_GROUP)) |
| 69 |
fprintf(output, " %s", l->name); |
| 70 |
if (index_type == LSTOPO_INDEX_TYPE_DEFAULT |
| 71 |
&& l->os_index != HWLOC_UNKNOWN_INDEX |
| 72 |
&& (verbose_mode >= 2 || l->type == HWLOC_OBJ_PU || l->type == HWLOC_OBJ_NUMANODE)) |
| 73 |
/* print physical index too if default index */ |
| 74 |
snprintf(phys, sizeof(phys), |
| 75 |
"%s", |
| 76 |
pidxstr[0] == ' ' ? pidxstr+1 : pidxstr /* skip the starting space if any */ |
| 77 |
); |
| 78 |
if (l->type == HWLOC_OBJ_PCI_DEVICE && verbose_mode <= 1) |
| 79 |
fprintf(output, " %s (%s)", |
| 80 |
busidstr, hwloc_pci_class_string(l->attr->pcidev.class_id)); |
| 81 |
/* display attributes */ |
| 82 |
len = hwloc_obj_attr_snprintf (NULL, 0, l, " ", verbose_mode-1); |
| 83 |
attr = malloc(len+1); |
| 84 |
*attr = '\0'; |
| 85 |
hwloc_obj_attr_snprintf (attr, len+1, l, " ", verbose_mode-1); |
| 86 |
if (*phys || *attr) { |
| 87 |
fprintf(output, " ("); |
| 88 |
if (*phys) |
| 89 |
fprintf(output, "%s", phys); |
| 90 |
if (*phys && *attr) |
| 91 |
fprintf(output, " "); |
| 92 |
if (*attr) { |
| 93 |
if (collapse > 1 && l->type == HWLOC_OBJ_PCI_DEVICE) { |
| 94 |
assert(!strncmp(attr, "busid=", 6)); |
| 95 |
assert(!strncmp(attr+18, " id=", 4)); |
| 96 |
fprintf(output, "busid=%s%s", busidstr, attr+18); |
| 97 |
} else |
| 98 |
fprintf(output, "%s", attr); |
| 99 |
} |
| 100 |
fprintf(output, ")"); |
| 101 |
} |
| 102 |
free(attr); |
| 103 |
/* display the root total_memory if not verbose (already shown) |
| 104 |
* (cannot be local_memory since root cannot be a NUMA node) */ |
| 105 |
if (verbose_mode == 1 && !l->parent && l->total_memory) |
| 106 |
fprintf(output, " (%lu%s total)", |
| 107 |
(unsigned long) hwloc_memory_size_printf_value(l->total_memory, 0), |
| 108 |
hwloc_memory_size_printf_unit(l->total_memory, 0)); |
| 109 |
/* append the name */ |
| 110 |
if (l->name && (l->type == HWLOC_OBJ_OS_DEVICE || verbose_mode >= 2) |
| 111 |
&& l->type != HWLOC_OBJ_MISC && l->type != HWLOC_OBJ_GROUP) |
| 112 |
fprintf(output, " \"%s\"", l->name); |
| 113 |
} |
| 114 |
if (!l->cpuset) |
| 115 |
return; |
| 116 |
if (loutput->show_cpuset == 1) |
| 117 |
fprintf(output, " cpuset="); |
| 118 |
if (loutput->show_cpuset) { |
| 119 |
char *cpusetstr; |
| 120 |
hwloc_utils_cpuset_format_asprintf(&cpusetstr, l->cpuset, loutput->cpuset_output_format); |
| 121 |
fprintf(output, "%s", cpusetstr); |
| 122 |
free(cpusetstr); |
| 123 |
} |
| 124 |
|
| 125 |
/* annotate if the PU/NUMA is disallowed/binding */ |
| 126 |
if (verbose_mode >= 2) { |
| 127 |
if (l->type == HWLOC_OBJ_PU) { |
| 128 |
if (lstopo_pu_disallowed(loutput, l)) |
| 129 |
fprintf(output, " (disallowed)"); |
| 130 |
else if (lstopo_pu_binding(loutput, l)) |
| 131 |
fprintf(output, " (binding)"); |
| 132 |
} else if (l->type == HWLOC_OBJ_NUMANODE) { |
| 133 |
if (lstopo_numa_disallowed(loutput, l)) |
| 134 |
fprintf(output, " (disallowed)"); |
| 135 |
else if (lstopo_numa_binding(loutput, l)) |
| 136 |
fprintf(output, " (binding)"); |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
/* Recursively output topology in a console fashion */ |
| 142 |
static void |
| 143 |
output_topology (struct lstopo_output *loutput, hwloc_obj_t l, hwloc_obj_t parent, int i) |
| 144 |
{ |
| 145 |
FILE *output = loutput->file; |
| 146 |
int verbose_mode = loutput->verbose_mode; |
| 147 |
hwloc_obj_t child; |
| 148 |
int group_identical = (verbose_mode <= 1) && !loutput->show_cpuset; |
| 149 |
int collapse = loutput->pci_collapse_enabled ? ((struct lstopo_obj_userdata *) l->userdata)->pci_collapsed : 0; |
| 150 |
|
| 151 |
if (l->type == HWLOC_OBJ_PCI_DEVICE && collapse == -1) |
| 152 |
return; |
| 153 |
|
| 154 |
if (group_identical |
| 155 |
&& parent && parent->arity == 1 |
| 156 |
&& !parent->memory_arity && !parent->io_arity && !parent->misc_arity |
| 157 |
&& l->cpuset && parent->cpuset && hwloc_bitmap_isequal(l->cpuset, parent->cpuset)) { |
| 158 |
/* in non-verbose mode, merge objects with their parent is they are exactly identical */ |
| 159 |
fprintf(output, " + "); |
| 160 |
} else { |
| 161 |
if (parent) |
| 162 |
fprintf(output, "\n"); |
| 163 |
indent (output, 2*i); |
| 164 |
i++; |
| 165 |
} |
| 166 |
|
| 167 |
if (collapse > 1) |
| 168 |
fprintf(output, "%d x { ", collapse); |
| 169 |
output_console_obj(loutput, l, collapse); |
| 170 |
if (collapse > 1) |
| 171 |
fprintf(output, " }"); |
| 172 |
|
| 173 |
for_each_memory_child(child, l) |
| 174 |
if (child->type != HWLOC_OBJ_PU || !loutput->ignore_numanodes) |
| 175 |
output_topology (loutput, child, l, i); |
| 176 |
for_each_child(child, l) |
| 177 |
if (child->type != HWLOC_OBJ_PU || !loutput->ignore_pus) |
| 178 |
output_topology (loutput, child, l, i); |
| 179 |
for_each_io_child(child, l) |
| 180 |
output_topology (loutput, child, l, i); |
| 181 |
for_each_misc_child(child, l) |
| 182 |
output_topology (loutput, child, l, i); |
| 183 |
} |
| 184 |
|
| 185 |
/* Recursive so that multiple depth types are properly shown */ |
| 186 |
static void |
| 187 |
output_only (struct lstopo_output *loutput, hwloc_obj_t l) |
| 188 |
{ |
| 189 |
FILE *output = loutput->file; |
| 190 |
hwloc_obj_t child; |
| 191 |
if (loutput->show_only.type == l->type |
| 192 |
|| loutput->show_only.depth == l->depth) { |
| 193 |
if (!hwloc_calc_check_object_filtered(l, &loutput->show_only)) { |
| 194 |
output_console_obj (loutput, l, 0); |
| 195 |
fprintf (output, "\n"); |
| 196 |
} |
| 197 |
} |
| 198 |
/* there can be anything below normal children */ |
| 199 |
for_each_child(child, l) |
| 200 |
output_only (loutput, child); |
| 201 |
/* there can be only memory or Misc below memory children */ |
| 202 |
if (loutput->show_only.type == HWLOC_OBJ_TYPE_NONE || hwloc_obj_type_is_memory(loutput->show_only.type) || loutput->show_only.type == HWLOC_OBJ_MISC) { |
| 203 |
for(child = l->memory_first_child; child; child = child->next_sibling) |
| 204 |
output_only (loutput, child); |
| 205 |
} |
| 206 |
/* there can be only I/O or Misc below I/O children */ |
| 207 |
if (loutput->show_only.type == HWLOC_OBJ_TYPE_NONE || hwloc_obj_type_is_io(loutput->show_only.type) || loutput->show_only.type == HWLOC_OBJ_MISC) { |
| 208 |
for_each_io_child(child, l) |
| 209 |
output_only (loutput, child); |
| 210 |
} |
| 211 |
/* there can be only Misc below Misc children */ |
| 212 |
if (loutput->show_only.type == HWLOC_OBJ_TYPE_NONE || loutput->show_only.type == HWLOC_OBJ_MISC) { |
| 213 |
/* Misc can only contain other Misc, no need to recurse otherwise */ |
| 214 |
for_each_misc_child(child, l) |
| 215 |
output_only (loutput, child); |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
static void output_distances(struct lstopo_output *loutput) |
| 220 |
{ |
| 221 |
hwloc_topology_t topology = loutput->topology; |
| 222 |
enum lstopo_index_type_e index_type = loutput->index_type; |
| 223 |
FILE *output = loutput->file; |
| 224 |
struct hwloc_distances_s **dist; |
| 225 |
unsigned nr = 0, j; |
| 226 |
int err = hwloc_distances_get(topology, &nr, NULL, 0, 0); |
| 227 |
if (err < 0 || !nr) |
| 228 |
return; |
| 229 |
dist = malloc(nr * sizeof(*dist)); |
| 230 |
if (!dist) |
| 231 |
return; |
| 232 |
err = hwloc_distances_get(topology, &nr, dist, 0, 0); |
| 233 |
if (!err) { |
| 234 |
for(j=0; j<nr; j++) { |
| 235 |
const char *kindmeans = (dist[j]->kind & HWLOC_DISTANCES_KIND_MEANS_LATENCY) ? "latency" : (dist[j]->kind & HWLOC_DISTANCES_KIND_MEANS_BANDWIDTH) ? "bandwidth" : "distance"; |
| 236 |
const char *name = hwloc_distances_get_name(topology, dist[j]); |
| 237 |
if (!name) |
| 238 |
name = "(null)"; |
| 239 |
if (loutput->transform_distances != -1) |
| 240 |
hwloc_distances_transform(topology, dist[j], loutput->transform_distances, NULL, 0); |
| 241 |
if (dist[j]->kind & HWLOC_DISTANCES_KIND_HETEROGENEOUS_TYPES) { |
| 242 |
fprintf(output, "Relative %s matrix (name %s kind %lu) between %u heterogeneous objects by %s indexes:\n", |
| 243 |
kindmeans, name, dist[j]->kind, |
| 244 |
dist[j]->nbobjs, |
| 245 |
index_type != LSTOPO_INDEX_TYPE_PHYSICAL ? "logical" : "physical"); |
| 246 |
} else { |
| 247 |
fprintf(output, "Relative %s matrix (name %s kind %lu) between %u %ss (depth %d) by %s indexes:\n", |
| 248 |
kindmeans, name, dist[j]->kind, |
| 249 |
dist[j]->nbobjs, |
| 250 |
hwloc_obj_type_string(dist[j]->objs[0]->type), |
| 251 |
dist[j]->objs[0]->depth, |
| 252 |
index_type != LSTOPO_INDEX_TYPE_PHYSICAL ? "logical" : "physical"); |
| 253 |
} |
| 254 |
hwloc_utils_print_distance_matrix(output, dist[j]->nbobjs, dist[j]->objs, dist[j]->values, index_type != LSTOPO_INDEX_TYPE_PHYSICAL, dist[j]->kind & HWLOC_DISTANCES_KIND_HETEROGENEOUS_TYPES); |
| 255 |
hwloc_distances_release(topology, dist[j]); |
| 256 |
} |
| 257 |
} |
| 258 |
free(dist); |
| 259 |
} |
| 260 |
|
| 261 |
static void output_memattr_obj(struct lstopo_output *loutput, |
| 262 |
hwloc_obj_t obj) |
| 263 |
{ |
| 264 |
enum lstopo_index_type_e index_type = loutput->index_type; |
| 265 |
unsigned idx = (index_type == LSTOPO_INDEX_TYPE_PHYSICAL ? obj->os_index : obj->logical_index); |
| 266 |
char objtype[16]; |
| 267 |
|
| 268 |
hwloc_obj_type_snprintf(objtype, sizeof(objtype), obj, 0); |
| 269 |
if (idx == (unsigned) -1) |
| 270 |
printf("%s %c#-1", objtype, |
| 271 |
index_type == LSTOPO_INDEX_TYPE_PHYSICAL ? 'P' : 'L'); |
| 272 |
else |
| 273 |
printf("%s %c#%u", objtype, |
| 274 |
index_type == LSTOPO_INDEX_TYPE_PHYSICAL ? 'P' : 'L', |
| 275 |
idx); |
| 276 |
|
| 277 |
if (obj->name) |
| 278 |
printf(" \"%s\"", obj->name); |
| 279 |
} |
| 280 |
|
| 281 |
static void output_memattr_initiator(struct lstopo_output *loutput, |
| 282 |
struct hwloc_location *initiator) |
| 283 |
{ |
| 284 |
hwloc_topology_t topology = loutput->topology; |
| 285 |
|
| 286 |
if (initiator->type == HWLOC_LOCATION_TYPE_CPUSET) { |
| 287 |
hwloc_obj_t obj; |
| 288 |
char *c; |
| 289 |
|
| 290 |
assert(initiator->location.cpuset); |
| 291 |
hwloc_bitmap_asprintf(&c, initiator->location.cpuset); |
| 292 |
printf(" from cpuset %s", c); |
| 293 |
free(c); |
| 294 |
|
| 295 |
obj = hwloc_get_obj_covering_cpuset(topology, initiator->location.cpuset); |
| 296 |
if (obj && !hwloc_bitmap_isequal(obj->cpuset, initiator->location.cpuset)) |
| 297 |
obj = NULL; |
| 298 |
if (obj) { |
| 299 |
while (obj->parent && hwloc_bitmap_isequal(obj->cpuset, obj->parent->cpuset)) |
| 300 |
obj = obj->parent; |
| 301 |
printf(" ("); |
| 302 |
output_memattr_obj(loutput, obj); |
| 303 |
printf(")"); |
| 304 |
} |
| 305 |
|
| 306 |
} else if (initiator->type == HWLOC_LOCATION_TYPE_OBJECT) { |
| 307 |
printf(" from "); |
| 308 |
output_memattr_obj(loutput, initiator->location.object); |
| 309 |
|
| 310 |
} else { |
| 311 |
printf(" from initiator with unexpected type %d", |
| 312 |
(int) initiator->type); |
| 313 |
} |
| 314 |
|
| 315 |
} |
| 316 |
|
| 317 |
static int output_memattr(struct lstopo_output *loutput, unsigned id) |
| 318 |
{ |
| 319 |
hwloc_topology_t topology = loutput->topology; |
| 320 |
int verbose_mode = loutput->verbose_mode; |
| 321 |
int show_all = (loutput->show_memattrs_only || (verbose_mode >= 3)); |
| 322 |
const char *name; |
| 323 |
unsigned long flags; |
| 324 |
unsigned nr_targets; |
| 325 |
hwloc_obj_t *targets; |
| 326 |
unsigned i; |
| 327 |
int err; |
| 328 |
|
| 329 |
if (!show_all |
| 330 |
&& (id == HWLOC_MEMATTR_ID_CAPACITY || id == HWLOC_MEMATTR_ID_LOCALITY)) |
| 331 |
return 0; |
| 332 |
|
| 333 |
err = hwloc_memattr_get_name(topology, id, &name); |
| 334 |
if (err < 0) |
| 335 |
return -1; |
| 336 |
err = hwloc_memattr_get_flags(topology, id, &flags); |
| 337 |
assert(!err); |
| 338 |
|
| 339 |
nr_targets = 0; |
| 340 |
err = hwloc_memattr_get_targets(topology, id, NULL, 0, &nr_targets, NULL, NULL); |
| 341 |
assert(!err); |
| 342 |
|
| 343 |
if (!show_all && !nr_targets) |
| 344 |
return 0; |
| 345 |
|
| 346 |
printf("Memory attribute #%u name `%s' flags %lu\n", id, name, flags); |
| 347 |
|
| 348 |
targets = malloc(nr_targets * sizeof(*targets)); |
| 349 |
if (!targets) |
| 350 |
return 0; |
| 351 |
|
| 352 |
err = hwloc_memattr_get_targets(topology, id, NULL, 0, &nr_targets, targets, NULL); |
| 353 |
assert(!err); |
| 354 |
|
| 355 |
for(i=0; i<nr_targets; i++) { |
| 356 |
|
| 357 |
if (!(flags & HWLOC_MEMATTR_FLAG_NEED_INITIATOR)) { |
| 358 |
hwloc_uint64_t value; |
| 359 |
err = hwloc_memattr_get_value(topology, id, targets[i], NULL, 0, &value); |
| 360 |
if (!err) { |
| 361 |
printf(" "); |
| 362 |
output_memattr_obj(loutput, targets[i]); |
| 363 |
printf(" = %llu\n", (unsigned long long) value); |
| 364 |
} |
| 365 |
|
| 366 |
} else { |
| 367 |
unsigned nr_initiators = 0; |
| 368 |
err = hwloc_memattr_get_initiators(topology, id, targets[i], 0, &nr_initiators, NULL, NULL); |
| 369 |
if (!err) { |
| 370 |
struct hwloc_location *initiators = malloc(nr_initiators * sizeof(*initiators)); |
| 371 |
hwloc_uint64_t *values = malloc(nr_initiators * sizeof(*values)); |
| 372 |
if (initiators && values) { |
| 373 |
err = hwloc_memattr_get_initiators(topology, id, targets[i], 0, &nr_initiators, initiators, values); |
| 374 |
if (!err) { |
| 375 |
unsigned j; |
| 376 |
for(j=0; j<nr_initiators; j++) { |
| 377 |
printf(" "); |
| 378 |
output_memattr_obj(loutput, targets[i]); |
| 379 |
printf(" = %llu", |
| 380 |
(unsigned long long) values[j]); |
| 381 |
output_memattr_initiator(loutput, &initiators[j]); |
| 382 |
printf("\n"); |
| 383 |
} |
| 384 |
} |
| 385 |
} |
| 386 |
free(initiators); |
| 387 |
free(values); |
| 388 |
} |
| 389 |
} |
| 390 |
} |
| 391 |
free(targets); |
| 392 |
|
| 393 |
return 0; |
| 394 |
} |
| 395 |
|
| 396 |
static void output_memattrs(struct lstopo_output *loutput) |
| 397 |
{ |
| 398 |
unsigned id; |
| 399 |
/* output in a convenient instead of the native ID order */ |
| 400 |
output_memattr(loutput, HWLOC_MEMATTR_ID_CAPACITY); |
| 401 |
output_memattr(loutput, HWLOC_MEMATTR_ID_LOCALITY); |
| 402 |
output_memattr(loutput, HWLOC_MEMATTR_ID_BANDWIDTH); |
| 403 |
output_memattr(loutput, HWLOC_MEMATTR_ID_READ_BANDWIDTH); |
| 404 |
output_memattr(loutput, HWLOC_MEMATTR_ID_WRITE_BANDWIDTH); |
| 405 |
output_memattr(loutput, HWLOC_MEMATTR_ID_LATENCY); |
| 406 |
output_memattr(loutput, HWLOC_MEMATTR_ID_READ_LATENCY); |
| 407 |
output_memattr(loutput, HWLOC_MEMATTR_ID_WRITE_LATENCY); |
| 408 |
/* output others */ |
| 409 |
for(id=HWLOC_MEMATTR_ID_WRITE_LATENCY+1; ; id++) |
| 410 |
if (output_memattr(loutput, id) < 0) |
| 411 |
break; |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
static void output_windows_processor_groups(struct lstopo_output *loutput __hwloc_attribute_unused, |
| 416 |
int force __hwloc_attribute_unused) |
| 417 |
{ |
| 418 |
#ifdef HWLOC_WIN_SYS |
| 419 |
hwloc_topology_t topology = loutput->topology; |
| 420 |
int err = hwloc_windows_get_nr_processor_groups(topology, 0); |
| 421 |
if (err > 0) { |
| 422 |
unsigned nr = (unsigned) err; |
| 423 |
if (nr > 1 || force) { |
| 424 |
hwloc_bitmap_t set = hwloc_bitmap_alloc(); |
| 425 |
if (set) { |
| 426 |
unsigned i; |
| 427 |
for(i=0; i<nr; i++) { |
| 428 |
err = hwloc_windows_get_processor_group_cpuset(topology, i, set, 0); |
| 429 |
if (!err) { |
| 430 |
char *s; |
| 431 |
hwloc_bitmap_asprintf(&s, set); |
| 432 |
printf("Processor Group #%u = %s\n", i, s); |
| 433 |
free(s); |
| 434 |
} |
| 435 |
} |
| 436 |
hwloc_bitmap_free(set); |
| 437 |
} |
| 438 |
} |
| 439 |
} |
| 440 |
#endif |
| 441 |
} |
| 442 |
|
| 443 |
static void output_cpukinds(struct lstopo_output *loutput) |
| 444 |
{ |
| 445 |
hwloc_topology_t topology = loutput->topology; |
| 446 |
unsigned i, j, nr; |
| 447 |
hwloc_bitmap_t cpuset = hwloc_bitmap_alloc(); |
| 448 |
|
| 449 |
nr = hwloc_cpukinds_get_nr(topology, 0); |
| 450 |
|
| 451 |
for(i=0; i<nr; i++) { |
| 452 |
int efficiency; |
| 453 |
struct hwloc_info_s *infos; |
| 454 |
unsigned nr_infos; |
| 455 |
int err; |
| 456 |
|
| 457 |
err = hwloc_cpukinds_get_info(topology, i, cpuset, &efficiency, &nr_infos, &infos, 0); |
| 458 |
if (!err) { |
| 459 |
char *cpusets; |
| 460 |
hwloc_bitmap_asprintf(&cpusets, cpuset); |
| 461 |
printf("CPU kind #%u efficiency %d cpuset %s\n", i, efficiency, cpusets); |
| 462 |
free(cpusets); |
| 463 |
for(j=0; j<nr_infos; j++) |
| 464 |
printf(" %s = %s\n", infos[j].name, infos[j].value); |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
hwloc_bitmap_free(cpuset); |
| 469 |
} |
| 470 |
|
| 471 |
int |
| 472 |
output_console(struct lstopo_output *loutput, const char *filename) |
| 473 |
{ |
| 474 |
hwloc_topology_t topology = loutput->topology; |
| 475 |
int verbose_mode = loutput->verbose_mode; |
| 476 |
FILE *output; |
| 477 |
|
| 478 |
output = open_output(filename, loutput->overwrite); |
| 479 |
if (!output) { |
| 480 |
fprintf(stderr, "Failed to open %s for writing (%s)\n", filename, strerror(errno)); |
| 481 |
return -1; |
| 482 |
} |
| 483 |
loutput->file = output; |
| 484 |
|
| 485 |
if (loutput->show_distances_only) { |
| 486 |
output_distances(loutput); |
| 487 |
return 0; |
| 488 |
} |
| 489 |
if (loutput->show_memattrs_only) { |
| 490 |
output_memattrs(loutput); |
| 491 |
return 0; |
| 492 |
} |
| 493 |
if (loutput->show_cpukinds_only) { |
| 494 |
output_cpukinds(loutput); |
| 495 |
return 0; |
| 496 |
} |
| 497 |
if (loutput->show_windows_processor_groups_only) { |
| 498 |
output_windows_processor_groups(loutput, 1); |
| 499 |
return 0; |
| 500 |
} |
| 501 |
|
| 502 |
/* |
| 503 |
* if verbose_mode == 0, only print the summary. |
| 504 |
* if verbose_mode == 1, only print the topology tree. |
| 505 |
* if verbose_mode > 1, print both. |
| 506 |
*/ |
| 507 |
|
| 508 |
if (loutput->show_only.depth != HWLOC_TYPE_DEPTH_UNKNOWN) { |
| 509 |
if (verbose_mode > 1) { |
| 510 |
if (loutput->show_only.type != HWLOC_OBJ_TYPE_NONE) |
| 511 |
fprintf(output, "Only showing some %s objects\n", hwloc_obj_type_string(loutput->show_only.type)); |
| 512 |
else |
| 513 |
fprintf(output, "Only showing some objects at depth %d\n", loutput->show_only.depth); |
| 514 |
} |
| 515 |
output_only (loutput, hwloc_get_root_obj(topology)); |
| 516 |
} else if (verbose_mode >= 1) { |
| 517 |
output_topology (loutput, hwloc_get_root_obj(topology), NULL, 0); |
| 518 |
fprintf(output, "\n"); |
| 519 |
} |
| 520 |
|
| 521 |
if ((verbose_mode > 1 || !verbose_mode) && loutput->show_only.depth == HWLOC_TYPE_DEPTH_UNKNOWN) { |
| 522 |
hwloc_lstopo_show_summary(output, topology); |
| 523 |
} |
| 524 |
|
| 525 |
if (verbose_mode > 1 && loutput->show_only.depth == HWLOC_TYPE_DEPTH_UNKNOWN) { |
| 526 |
output_distances(loutput); |
| 527 |
output_memattrs(loutput); |
| 528 |
output_cpukinds(loutput); |
| 529 |
output_windows_processor_groups(loutput, verbose_mode > 2); |
| 530 |
} |
| 531 |
|
| 532 |
if (verbose_mode > 1 && loutput->show_only.depth == HWLOC_TYPE_DEPTH_UNKNOWN) { |
| 533 |
hwloc_const_bitmap_t complete = hwloc_topology_get_complete_cpuset(topology); |
| 534 |
hwloc_const_bitmap_t topo = hwloc_topology_get_topology_cpuset(topology); |
| 535 |
hwloc_const_bitmap_t allowed = hwloc_topology_get_allowed_cpuset(topology); |
| 536 |
|
| 537 |
if (!hwloc_bitmap_isequal(topo, complete)) { |
| 538 |
hwloc_bitmap_t unknown = hwloc_bitmap_alloc(); |
| 539 |
char *unknownstr; |
| 540 |
hwloc_bitmap_copy(unknown, complete); |
| 541 |
hwloc_bitmap_andnot(unknown, unknown, topo); |
| 542 |
hwloc_bitmap_asprintf(&unknownstr, unknown); |
| 543 |
fprintf (output, "%d processors not represented in topology: %s\n", hwloc_bitmap_weight(unknown), unknownstr); |
| 544 |
free(unknownstr); |
| 545 |
hwloc_bitmap_free(unknown); |
| 546 |
} |
| 547 |
if (!hwloc_bitmap_isequal(topo, allowed)) { |
| 548 |
hwloc_bitmap_t disallowed = hwloc_bitmap_alloc(); |
| 549 |
char *disallowedstr; |
| 550 |
hwloc_bitmap_copy(disallowed, topo); |
| 551 |
hwloc_bitmap_andnot(disallowed, disallowed, allowed); |
| 552 |
hwloc_bitmap_asprintf(&disallowedstr, disallowed); |
| 553 |
fprintf(output, "%d processors represented but not allowed: %s\n", hwloc_bitmap_weight(disallowed), disallowedstr); |
| 554 |
free(disallowedstr); |
| 555 |
hwloc_bitmap_free(disallowed); |
| 556 |
} |
| 557 |
if (!hwloc_topology_is_thissystem(topology)) |
| 558 |
fprintf (output, "Topology not from this system\n"); |
| 559 |
} |
| 560 |
|
| 561 |
if (output != stdout) |
| 562 |
fclose(output); |
| 563 |
|
| 564 |
return 0; |
| 565 |
} |
| 566 |
|
| 567 |
int |
| 568 |
output_synthetic(struct lstopo_output *loutput, const char *filename) |
| 569 |
{ |
| 570 |
hwloc_topology_t topology = loutput->topology; |
| 571 |
FILE *output; |
| 572 |
int length; |
| 573 |
char sbuffer[1024]; |
| 574 |
char * dbuffer = NULL; |
| 575 |
unsigned nb1, nb2, nb3; |
| 576 |
|
| 577 |
if (!hwloc_get_root_obj(topology)->symmetric_subtree) { |
| 578 |
fprintf(stderr, "Cannot output assymetric topology in synthetic format.\n"); |
| 579 |
goto out; |
| 580 |
} |
| 581 |
|
| 582 |
nb1 = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_MISC); |
| 583 |
if (nb1) { |
| 584 |
fprintf(stderr, "# Ignoring %u Misc objects.\n", nb1); |
| 585 |
fprintf(stderr, "# (pass --filter Misc:none to hide this message).\n"); |
| 586 |
} |
| 587 |
nb1 = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_BRIDGE); |
| 588 |
nb2 = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_PCI_DEVICE); |
| 589 |
nb3 = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_OS_DEVICE); |
| 590 |
if (nb1 || nb2 || nb3) { |
| 591 |
fprintf(stderr, "# Ignoring %u Bridge, %u PCI device and %u OS device objects\n", nb1, nb2, nb3); |
| 592 |
fprintf(stderr, "# (pass --no-io to hide this message).\n"); |
| 593 |
} |
| 594 |
|
| 595 |
length = hwloc_topology_export_synthetic(topology, sbuffer, sizeof(sbuffer), loutput->export_synthetic_flags); |
| 596 |
if (length < 0) { |
| 597 |
fprintf(stderr, "Failed to export a synthetic description (%s)\n", strerror(errno)); |
| 598 |
goto out; |
| 599 |
} |
| 600 |
|
| 601 |
if (length >= (int) sizeof(sbuffer)) { |
| 602 |
dbuffer = malloc(length+1 /* \0 */); |
| 603 |
if (!dbuffer) |
| 604 |
goto out; |
| 605 |
|
| 606 |
length = hwloc_topology_export_synthetic(topology, dbuffer, length+1, loutput->export_synthetic_flags); |
| 607 |
if (length < 0) |
| 608 |
goto out_with_dbuffer; |
| 609 |
} |
| 610 |
|
| 611 |
output = open_output(filename, loutput->overwrite); |
| 612 |
if (!output) { |
| 613 |
fprintf(stderr, "Failed to open %s for writing (%s)\n", filename, strerror(errno)); |
| 614 |
goto out_with_dbuffer; |
| 615 |
} |
| 616 |
|
| 617 |
fprintf(output, "%s\n", dbuffer ? dbuffer : sbuffer); |
| 618 |
|
| 619 |
if (output != stdout) |
| 620 |
fclose(output); |
| 621 |
|
| 622 |
free(dbuffer); |
| 623 |
return 0; |
| 624 |
|
| 625 |
out_with_dbuffer: |
| 626 |
free(dbuffer); |
| 627 |
out: |
| 628 |
return -1; |
| 629 |
} |