2
* Copyright © 2009 CNRS
3
* Copyright © 2009-2013 Inria. All rights reserved.
4
* Copyright © 2009-2012 Université Bordeaux 1
5
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
6
* See COPYING in top-level directory.
9
#include <private/autogen/config.h>
19
#include "hwloc-calc.h"
21
static int pid_number = -1;
22
static hwloc_pid_t pid;
23
static int verbose_mode = 0;
24
static int logical = 1;
25
static int show_ancestors = 0;
26
static hwloc_obj_type_t show_ancestor_type = (hwloc_obj_type_t) -1;
27
static int show_ancestor_attrdepth = -1;
28
static hwloc_obj_cache_type_t show_ancestor_attrcachetype = (hwloc_obj_cache_type_t) -1;
29
static int show_index_prefix = 0;
30
static int current_obj;
32
void usage(const char *name, FILE *where)
34
fprintf (where, "Usage: %s [ options ] [ locations ]\n", name);
35
fprintf (where, "\nOutput options:\n");
36
fprintf (where, " -v --verbose Include additional details\n");
37
fprintf (where, " -s --silent Reduce the amount of details to show\n");
38
fprintf (where, " --ancestors Display the chain of ancestor objects up to the root\n");
39
fprintf (where, " --ancestor <type> Only display the ancestor of the given type\n");
40
fprintf (where, " -n Prefix each line with the index of the considered object\n");
41
fprintf (where, "Object filtering options:\n");
42
fprintf (where, " --restrict <cpuset> Restrict the topology to processors listed in <cpuset>\n");
43
fprintf (where, " --restrict binding Restrict the topology to the current process binding\n");
44
fprintf (where, " --no-io Do not show any I/O device or bridge\n");
45
fprintf (where, " --no-bridges Do not any I/O bridge except hostbridges\n");
46
fprintf (where, " --whole-io Show all I/O devices and bridges\n");
47
fprintf (where, "Input options:\n");
48
hwloc_utils_input_format_usage(where, 6);
49
fprintf (where, " --thissystem Assume that the input topology provides the topology\n"
50
" for the system on which we are running\n");
51
fprintf (where, " --pid <pid> Detect topology as seen by process <pid>\n");
52
fprintf (where, " --whole-system Do not consider administration limitations\n");
53
fprintf (where, " -l --logical Use logical object indexes for input (default)\n");
54
fprintf (where, " -p --physical Use physical object indexes for input\n");
55
fprintf (where, "Miscellaneous options:\n");
56
fprintf (where, " --version Report version and exit\n");
60
hwloc_info_show_obj(hwloc_obj_t obj, const char *type, const char *prefix, int verbose)
66
printf("%s type = %s\n", prefix, hwloc_obj_type_string(obj->type));
67
printf("%s full type = %s\n", prefix, type);
68
printf("%s logical index = %u\n", prefix, obj->logical_index);
69
if (obj->os_index != (unsigned) -1)
70
printf("%s os index = %u\n", prefix, obj->os_index);
72
printf("%s name = %s\n", prefix, obj->name);
73
if (obj->depth != (unsigned) -1)
74
printf("%s depth = %u\n", prefix, obj->depth);
75
printf("%s sibling rank = %u\n", prefix, obj->sibling_rank);
76
printf("%s children = %u\n", prefix, obj->arity);
77
if (obj->memory.local_memory)
78
printf("%s local memory = %llu\n", prefix, (unsigned long long) obj->memory.local_memory);
79
if (obj->memory.total_memory)
80
printf("%s total memory = %llu\n", prefix, (unsigned long long) obj->memory.total_memory);
83
hwloc_bitmap_snprintf(s, sizeof(s), obj->cpuset);
84
printf("%s cpuset = %s\n", prefix, s);
86
if (obj->complete_cpuset) {
87
hwloc_bitmap_snprintf(s, sizeof(s), obj->complete_cpuset);
88
printf("%s complete cpuset = %s\n", prefix, s);
90
if (obj->online_cpuset) {
91
hwloc_bitmap_snprintf(s, sizeof(s), obj->online_cpuset);
92
printf("%s online cpuset = %s\n", prefix, s);
94
if (obj->allowed_cpuset) {
95
hwloc_bitmap_snprintf(s, sizeof(s), obj->allowed_cpuset);
96
printf("%s allowed cpuset = %s\n", prefix, s);
100
hwloc_bitmap_snprintf(s, sizeof(s), obj->nodeset);
101
printf("%s nodeset = %s\n", prefix, s);
103
if (obj->complete_nodeset) {
104
hwloc_bitmap_snprintf(s, sizeof(s), obj->complete_nodeset);
105
printf("%s complete nodeset = %s\n", prefix, s);
107
if (obj->allowed_nodeset) {
108
hwloc_bitmap_snprintf(s, sizeof(s), obj->allowed_nodeset);
109
printf("%s allowed nodeset = %s\n", prefix, s);
113
case HWLOC_OBJ_CACHE:
114
printf("%s attr cache depth = %u\n", prefix, obj->attr->cache.depth);
115
switch (obj->attr->cache.type) {
116
case HWLOC_OBJ_CACHE_UNIFIED: printf("%s attr cache type = Unified\n", prefix); break;
117
case HWLOC_OBJ_CACHE_DATA: printf("%s attr cache type = Data\n", prefix); break;
118
case HWLOC_OBJ_CACHE_INSTRUCTION: printf("%s attr cache type = Instruction\n", prefix); break;
120
printf("%s attr cache size = %llu\n", prefix, (unsigned long long) obj->attr->cache.size);
121
printf("%s attr cache line size = %u\n", prefix, obj->attr->cache.linesize);
122
if (obj->attr->cache.associativity == -1)
123
printf("%s attr cache ways = Fully-associative\n", prefix);
124
else if (obj->attr->cache.associativity != 0)
125
printf("%s attr cache ways = %d\n", prefix, obj->attr->cache.associativity);
127
case HWLOC_OBJ_GROUP:
128
printf("%s attr group depth = %u\n", prefix, obj->attr->group.depth);
130
case HWLOC_OBJ_BRIDGE:
131
switch (obj->attr->bridge.upstream_type) {
132
case HWLOC_OBJ_BRIDGE_HOST:
133
printf("%s attr bridge upstream type = Host\n", prefix);
135
case HWLOC_OBJ_BRIDGE_PCI:
136
printf("%s attr bridge upstream type = PCI\n", prefix);
137
printf("%s attr PCI bus id = %04x:%02x:%02x.%01x\n",
138
prefix, obj->attr->pcidev.domain, obj->attr->pcidev.bus, obj->attr->pcidev.dev, obj->attr->pcidev.func);
139
printf("%s attr PCI class = %04x\n",
140
prefix, obj->attr->pcidev.class_id);
141
printf("%s attr PCI id = %04x:%04x\n",
142
prefix, obj->attr->pcidev.vendor_id, obj->attr->pcidev.device_id);
143
if (obj->attr->pcidev.linkspeed)
144
printf("%s attr PCI linkspeed = %f GB/s\n", prefix, obj->attr->pcidev.linkspeed);
147
switch (obj->attr->bridge.downstream_type) {
148
case HWLOC_OBJ_BRIDGE_HOST:
150
case HWLOC_OBJ_BRIDGE_PCI:
151
printf("%s attr bridge downstream type = PCI\n", prefix);
152
printf("%s attr PCI secondary bus = %02x\n",
153
prefix, obj->attr->bridge.downstream.pci.secondary_bus);
154
printf("%s attr PCI subordinate bus = %02x\n",
155
prefix, obj->attr->bridge.downstream.pci.subordinate_bus);
159
case HWLOC_OBJ_PCI_DEVICE:
160
printf("%s attr PCI bus id = %04x:%02x:%02x.%01x\n",
161
prefix, obj->attr->pcidev.domain, obj->attr->pcidev.bus, obj->attr->pcidev.dev, obj->attr->pcidev.func);
162
printf("%s attr PCI class = %04x\n",
163
prefix, obj->attr->pcidev.class_id);
164
printf("%s attr PCI id = %04x:%04x\n",
165
prefix, obj->attr->pcidev.vendor_id, obj->attr->pcidev.device_id);
166
if (obj->attr->pcidev.linkspeed)
167
printf("%s attr PCI linkspeed = %f GB/s\n", prefix, obj->attr->pcidev.linkspeed);
169
case HWLOC_OBJ_OS_DEVICE:
170
printf("%s attr osdev type = %s\n", prefix, type);
173
/* nothing to show */
176
for(i=0; i<obj->infos_count; i++) {
177
printf("%s info %s = %s\n", prefix, obj->infos[i].name, obj->infos[i].value);
182
hwloc_calc_process_arg_info_cb(void *_data __hwloc_attribute_unused,
190
if (show_index_prefix)
191
snprintf(prefix, sizeof(prefix), "%u: ", current_obj);
193
hwloc_obj_type_snprintf(objs, sizeof(objs), obj, 1);
195
if (show_ancestors) {
198
hwloc_obj_t parent = obj;
200
if (show_index_prefix)
201
snprintf(prefix, sizeof(prefix), "%u.%u: ", current_obj, level);
202
hwloc_obj_type_snprintf(parents, sizeof(parents), parent, 1);
204
printf("%s%s:%u\n", prefix, parents, parent->logical_index);
206
printf("%s%s L#%u = parent #%u of %s L#%u\n",
207
prefix, parents, parent->logical_index, level, objs, obj->logical_index);
209
printf("%s%s L#%u\n", prefix, parents, parent->logical_index);
210
hwloc_info_show_obj(parent, parents, prefix, verbose);
211
parent = parent->parent;
214
} else if (show_ancestor_type != (hwloc_obj_type_t) -1) {
216
hwloc_obj_t parent = obj;
218
if (parent->type == show_ancestor_type) {
219
if (parent->type == HWLOC_OBJ_GROUP
220
&& show_ancestor_attrdepth != -1
221
&& show_ancestor_attrdepth != (int) parent->attr->group.depth)
223
if (parent->type == HWLOC_OBJ_CACHE
224
&& show_ancestor_attrdepth != -1
225
&& show_ancestor_attrdepth != (int) parent->attr->cache.depth)
227
if (parent->type == HWLOC_OBJ_CACHE
228
&& show_ancestor_attrcachetype != (hwloc_obj_cache_type_t) -1
229
&& show_ancestor_attrcachetype != parent->attr->cache.type)
231
hwloc_obj_type_snprintf(parents, sizeof(parents), parent, 1);
233
printf("%s%s:%u\n", prefix, parents, parent->logical_index);
235
printf("%s%s L#%u = parent of %s L#%u\n",
236
prefix, parents, parent->logical_index, objs, obj->logical_index);
237
hwloc_info_show_obj(parent, parents, prefix, verbose);
240
parent = parent->parent;
244
printf("%s%s:%u\n", prefix, objs, obj->logical_index);
246
printf("%s%s L#%u\n", prefix, objs, obj->logical_index);
247
hwloc_info_show_obj(obj, objs, prefix, verbose);
254
main (int argc, char *argv[])
257
hwloc_topology_t topology;
259
unsigned long flags = HWLOC_TOPOLOGY_FLAG_IO_DEVICES | HWLOC_TOPOLOGY_FLAG_IO_BRIDGES | HWLOC_TOPOLOGY_FLAG_ICACHES;
262
enum hwloc_utils_input_format input_format = HWLOC_UTILS_INPUT_DEFAULT;
263
char *restrictstring = NULL;
267
/* enable verbose backends */
268
putenv("HWLOC_XML_VERBOSE=1");
269
putenv("HWLOC_SYNTHETIC_VERBOSE=1");
271
callname = strrchr(argv[0], '/');
276
/* skip argv[0], handle options */
280
err = hwloc_topology_init (&topology);
284
hwloc_topology_set_flags(topology, flags);
288
if (*argv[0] == '-') {
289
if (!strcmp (argv[0], "-v") || !strcmp (argv[0], "--verbose"))
291
else if (!strcmp (argv[0], "-s") || !strcmp (argv[0], "--silent"))
293
else if (!strcmp (argv[0], "-h") || !strcmp (argv[0], "--help")) {
294
usage(callname, stdout);
297
else if (!strcmp (argv[0], "-n"))
298
show_index_prefix = 1;
299
else if (!strcmp (argv[0], "--ancestors"))
301
else if (!strcmp (argv[0], "--ancestor")) {
303
usage (callname, stderr);
306
err = hwloc_obj_type_sscanf(argv[1], &show_ancestor_type, &show_ancestor_attrdepth, &show_ancestor_attrcachetype);
308
fprintf(stderr, "unrecognized --ancestor type %s\n", argv[1]);
309
usage(callname, stderr);
314
else if (!strcmp (argv[0], "--no-icaches"))
315
flags &= ~HWLOC_TOPOLOGY_FLAG_ICACHES;
316
else if (!strcmp (argv[0], "--whole-system"))
317
flags |= HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM;
318
else if (!strcmp (argv[0], "--no-io"))
319
flags &= ~(HWLOC_TOPOLOGY_FLAG_IO_DEVICES | HWLOC_TOPOLOGY_FLAG_IO_BRIDGES);
320
else if (!strcmp (argv[0], "--no-bridges"))
321
flags &= ~(HWLOC_TOPOLOGY_FLAG_IO_BRIDGES);
322
else if (!strcmp (argv[0], "--whole-io"))
323
flags |= HWLOC_TOPOLOGY_FLAG_WHOLE_IO;
324
else if (!strcmp (argv[0], "--thissystem"))
325
flags |= HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM;
326
else if (!strcmp (argv[0], "--restrict")) {
328
usage (callname, stderr);
331
restrictstring = strdup(argv[1]);
335
else if (hwloc_utils_lookup_input_option(argv, argc, &opt,
336
&input, &input_format,
338
/* we'll enable later */
340
else if (!strcmp (argv[0], "--pid")) {
342
usage (callname, stderr);
345
pid_number = atoi(argv[1]); opt = 1;
347
else if (!strcmp(argv[0], "-l") || !strcmp(argv[0], "--logical"))
349
else if (!strcmp(argv[0], "-p") || !strcmp(argv[0], "--physical"))
351
else if (!strcmp (argv[0], "--version")) {
352
printf("%s %s\n", callname, VERSION);
356
fprintf (stderr, "Unrecognized option: %s\n", argv[0]);
357
usage(callname, stderr);
368
hwloc_topology_set_flags(topology, flags);
371
err = hwloc_utils_enable_input_format(topology, input, input_format, verbose_mode, callname);
376
if (pid_number != -1 && pid_number != 0) {
377
pid = hwloc_pid_from_number(pid_number, 0);
378
if (hwloc_topology_set_pid(topology, pid)) {
379
perror("Setting target pid");
384
err = hwloc_topology_load (topology);
388
topodepth = hwloc_topology_get_depth(topology);
390
if (restrictstring) {
391
hwloc_bitmap_t restrictset = hwloc_bitmap_alloc();
392
if (!strcmp (restrictstring, "binding")) {
393
if (pid_number != -1 && pid_number != 0)
394
hwloc_get_proc_cpubind(topology, pid, restrictset, HWLOC_CPUBIND_PROCESS);
396
hwloc_get_cpubind(topology, restrictset, HWLOC_CPUBIND_PROCESS);
398
hwloc_bitmap_sscanf(restrictset, restrictstring);
400
err = hwloc_topology_restrict (topology, restrictset, 0);
402
perror("Restricting the topology");
405
hwloc_bitmap_free(restrictset);
406
free(restrictstring);
410
hwloc_lstopo_show_summary(stdout, topology);
415
if (!strcmp(argv[0], "all") || !strcmp(argv[0], "root")) {
416
hwloc_calc_process_arg_info_cb(NULL, hwloc_get_root_obj(topology), verbose_mode);
418
/* try to match a type/depth followed by a special character */
419
typelen = strspn(argv[0], "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
420
if (typelen && (argv[0][typelen] == ':' || argv[0][typelen] == '=')) {
421
err = hwloc_calc_process_type_arg(topology, topodepth, argv[0], typelen, logical,
422
hwloc_calc_process_arg_info_cb, NULL,
430
hwloc_topology_destroy (topology);