~ubuntu-branches/ubuntu/vivid/mpich/vivid-proposed

« back to all changes in this revision

Viewing changes to src/pm/hydra/tools/topo/hwloc/hwloc/utils/hwloc-info.c

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2014-04-01 20:24:20 UTC
  • mfrom: (5.2.4 sid)
  • Revision ID: package-import@ubuntu.com-20140401202420-t5ey1ia2klt5dkq3
Tags: 3.1-4
* [c3e3398] Disable test_primitives, which is unreliable on some platforms.
            (Closes: #743047)
* [265a699] Add minimal autotest.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
7
 */
 
8
 
 
9
#include <private/autogen/config.h>
 
10
#include <hwloc.h>
 
11
 
 
12
#include <stdlib.h>
 
13
#include <stdio.h>
 
14
#include <string.h>
 
15
#include <fcntl.h>
 
16
#include <assert.h>
 
17
 
 
18
#include "misc.h"
 
19
#include "hwloc-calc.h"
 
20
 
 
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;
 
31
 
 
32
void usage(const char *name, FILE *where)
 
33
{
 
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");
 
57
}
 
58
 
 
59
static void
 
60
hwloc_info_show_obj(hwloc_obj_t obj, const char *type, const char *prefix, int verbose)
 
61
{
 
62
  char s[128];
 
63
  unsigned i;
 
64
  if (verbose < 0)
 
65
    return;
 
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);
 
71
  if (obj->name)
 
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);
 
81
 
 
82
  if (obj->cpuset) {
 
83
    hwloc_bitmap_snprintf(s, sizeof(s), obj->cpuset);
 
84
    printf("%s cpuset = %s\n", prefix, s);
 
85
  }
 
86
  if (obj->complete_cpuset) {
 
87
    hwloc_bitmap_snprintf(s, sizeof(s), obj->complete_cpuset);
 
88
    printf("%s complete cpuset = %s\n", prefix, s);
 
89
  }
 
90
  if (obj->online_cpuset) {
 
91
    hwloc_bitmap_snprintf(s, sizeof(s), obj->online_cpuset);
 
92
    printf("%s online cpuset = %s\n", prefix, s);
 
93
  }
 
94
  if (obj->allowed_cpuset) {
 
95
    hwloc_bitmap_snprintf(s, sizeof(s), obj->allowed_cpuset);
 
96
    printf("%s allowed cpuset = %s\n", prefix, s);
 
97
  }
 
98
 
 
99
  if (obj->nodeset) {
 
100
    hwloc_bitmap_snprintf(s, sizeof(s), obj->nodeset);
 
101
    printf("%s nodeset = %s\n", prefix, s);
 
102
  }
 
103
  if (obj->complete_nodeset) {
 
104
    hwloc_bitmap_snprintf(s, sizeof(s), obj->complete_nodeset);
 
105
    printf("%s complete nodeset = %s\n", prefix, s);
 
106
  }
 
107
  if (obj->allowed_nodeset) {
 
108
    hwloc_bitmap_snprintf(s, sizeof(s), obj->allowed_nodeset);
 
109
    printf("%s allowed nodeset = %s\n", prefix, s);
 
110
  }
 
111
 
 
112
  switch (obj->type) {
 
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;
 
119
    }
 
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);
 
126
    break;
 
127
  case HWLOC_OBJ_GROUP:
 
128
    printf("%s attr group depth = %u\n", prefix, obj->attr->group.depth);
 
129
    break;
 
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);
 
134
      break;
 
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);
 
145
      break;
 
146
    }
 
147
    switch (obj->attr->bridge.downstream_type) {
 
148
    case HWLOC_OBJ_BRIDGE_HOST:
 
149
      assert(0);
 
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);
 
156
      break;
 
157
    }
 
158
    break;
 
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);
 
168
    break;
 
169
  case HWLOC_OBJ_OS_DEVICE:
 
170
    printf("%s attr osdev type = %s\n", prefix, type);
 
171
    break;
 
172
  default:
 
173
    /* nothing to show */
 
174
    break;
 
175
  }
 
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);
 
178
  }
 
179
}
 
180
 
 
181
static void
 
182
hwloc_calc_process_arg_info_cb(void *_data __hwloc_attribute_unused,
 
183
                               hwloc_obj_t obj,
 
184
                               int verbose)
 
185
{
 
186
  char prefix[32];
 
187
  char objs[128];
 
188
 
 
189
  prefix[0] = '\0';
 
190
  if (show_index_prefix)
 
191
    snprintf(prefix, sizeof(prefix), "%u: ", current_obj);
 
192
 
 
193
  hwloc_obj_type_snprintf(objs, sizeof(objs), obj, 1);
 
194
 
 
195
  if (show_ancestors) {
 
196
    char parents[128];
 
197
    unsigned level = 0;
 
198
    hwloc_obj_t parent = obj;
 
199
    while (parent) {
 
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);
 
203
      if (verbose < 0)
 
204
        printf("%s%s:%u\n", prefix, parents, parent->logical_index);
 
205
      else if (level)
 
206
        printf("%s%s L#%u = parent #%u of %s L#%u\n",
 
207
               prefix, parents, parent->logical_index, level, objs, obj->logical_index);
 
208
      else
 
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;
 
212
      level++;
 
213
    }
 
214
  } else if (show_ancestor_type != (hwloc_obj_type_t) -1) {
 
215
    char parents[128];
 
216
    hwloc_obj_t parent = obj;
 
217
    while (parent) {
 
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)
 
222
          goto next;
 
223
        if (parent->type == HWLOC_OBJ_CACHE
 
224
            && show_ancestor_attrdepth != -1
 
225
            && show_ancestor_attrdepth != (int) parent->attr->cache.depth)
 
226
          goto next;
 
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)
 
230
          goto next;
 
231
        hwloc_obj_type_snprintf(parents, sizeof(parents), parent, 1);
 
232
        if (verbose < 0)
 
233
          printf("%s%s:%u\n", prefix, parents, parent->logical_index);
 
234
        else
 
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);
 
238
      }
 
239
next:
 
240
      parent = parent->parent;
 
241
    }
 
242
  } else {
 
243
    if (verbose < 0)
 
244
      printf("%s%s:%u\n", prefix, objs, obj->logical_index);
 
245
    else
 
246
      printf("%s%s L#%u\n", prefix, objs, obj->logical_index);
 
247
    hwloc_info_show_obj(obj, objs, prefix, verbose);
 
248
  }
 
249
 
 
250
  current_obj++;
 
251
}
 
252
 
 
253
int
 
254
main (int argc, char *argv[])
 
255
{
 
256
  int err;
 
257
  hwloc_topology_t topology;
 
258
  unsigned topodepth;
 
259
  unsigned long flags = HWLOC_TOPOLOGY_FLAG_IO_DEVICES | HWLOC_TOPOLOGY_FLAG_IO_BRIDGES | HWLOC_TOPOLOGY_FLAG_ICACHES;
 
260
  char * callname;
 
261
  char * input = NULL;
 
262
  enum hwloc_utils_input_format input_format = HWLOC_UTILS_INPUT_DEFAULT;
 
263
  char *restrictstring = NULL;
 
264
  size_t typelen;
 
265
  int opt;
 
266
 
 
267
  /* enable verbose backends */
 
268
  putenv("HWLOC_XML_VERBOSE=1");
 
269
  putenv("HWLOC_SYNTHETIC_VERBOSE=1");
 
270
 
 
271
  callname = strrchr(argv[0], '/');
 
272
  if (!callname)
 
273
    callname = argv[0];
 
274
  else
 
275
    callname++;
 
276
  /* skip argv[0], handle options */
 
277
  argc--;
 
278
  argv++;
 
279
 
 
280
  err = hwloc_topology_init (&topology);
 
281
  if (err)
 
282
    return EXIT_FAILURE;
 
283
 
 
284
  hwloc_topology_set_flags(topology, flags);
 
285
 
 
286
  while (argc >= 1) {
 
287
    opt = 0;
 
288
    if (*argv[0] == '-') {
 
289
      if (!strcmp (argv[0], "-v") || !strcmp (argv[0], "--verbose"))
 
290
        verbose_mode++;
 
291
      else if (!strcmp (argv[0], "-s") || !strcmp (argv[0], "--silent"))
 
292
        verbose_mode--;
 
293
      else if (!strcmp (argv[0], "-h") || !strcmp (argv[0], "--help")) {
 
294
        usage(callname, stdout);
 
295
        exit(EXIT_SUCCESS);
 
296
      }
 
297
      else if (!strcmp (argv[0], "-n"))
 
298
        show_index_prefix = 1;
 
299
      else if (!strcmp (argv[0], "--ancestors"))
 
300
        show_ancestors = 1;
 
301
      else if (!strcmp (argv[0], "--ancestor")) {
 
302
        if (argc < 2) {
 
303
          usage (callname, stderr);
 
304
          exit(EXIT_FAILURE);
 
305
        }
 
306
        err = hwloc_obj_type_sscanf(argv[1], &show_ancestor_type, &show_ancestor_attrdepth, &show_ancestor_attrcachetype);
 
307
        if (err < 0) {
 
308
          fprintf(stderr, "unrecognized --ancestor type %s\n", argv[1]);
 
309
          usage(callname, stderr);
 
310
          return EXIT_SUCCESS;
 
311
        }
 
312
        opt = 1;
 
313
      }
 
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")) {
 
327
        if (argc < 2) {
 
328
          usage (callname, stderr);
 
329
          exit(EXIT_FAILURE);
 
330
        }
 
331
        restrictstring = strdup(argv[1]);
 
332
        opt = 1;
 
333
      }
 
334
 
 
335
      else if (hwloc_utils_lookup_input_option(argv, argc, &opt,
 
336
                                               &input, &input_format,
 
337
                                               callname)) {
 
338
        /* we'll enable later */
 
339
      }
 
340
      else if (!strcmp (argv[0], "--pid")) {
 
341
        if (argc < 2) {
 
342
          usage (callname, stderr);
 
343
          exit(EXIT_FAILURE);
 
344
        }
 
345
        pid_number = atoi(argv[1]); opt = 1;
 
346
      }
 
347
      else if (!strcmp(argv[0], "-l") || !strcmp(argv[0], "--logical"))
 
348
        logical = 1;
 
349
      else if (!strcmp(argv[0], "-p") || !strcmp(argv[0], "--physical"))
 
350
        logical = 0;
 
351
      else if (!strcmp (argv[0], "--version")) {
 
352
        printf("%s %s\n", callname, VERSION);
 
353
        exit(EXIT_SUCCESS);
 
354
      }
 
355
      else {
 
356
        fprintf (stderr, "Unrecognized option: %s\n", argv[0]);
 
357
        usage(callname, stderr);
 
358
        return EXIT_FAILURE;
 
359
      }
 
360
      argc -= opt+1;
 
361
      argv += opt+1;
 
362
    } else {
 
363
      /* not an option */
 
364
      break;
 
365
    }
 
366
  }
 
367
 
 
368
  hwloc_topology_set_flags(topology, flags);
 
369
 
 
370
  if (input) {
 
371
    err = hwloc_utils_enable_input_format(topology, input, input_format, verbose_mode, callname);
 
372
    if (err)
 
373
      return err;
 
374
  }
 
375
 
 
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");
 
380
      return EXIT_FAILURE;
 
381
    }
 
382
  }
 
383
 
 
384
  err = hwloc_topology_load (topology);
 
385
  if (err)
 
386
    return EXIT_FAILURE;
 
387
 
 
388
  topodepth = hwloc_topology_get_depth(topology);
 
389
 
 
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);
 
395
      else
 
396
        hwloc_get_cpubind(topology, restrictset, HWLOC_CPUBIND_PROCESS);
 
397
    } else {
 
398
      hwloc_bitmap_sscanf(restrictset, restrictstring);
 
399
    }
 
400
    err = hwloc_topology_restrict (topology, restrictset, 0);
 
401
    if (err) {
 
402
      perror("Restricting the topology");
 
403
      /* fallthrough */
 
404
    }
 
405
    hwloc_bitmap_free(restrictset);
 
406
    free(restrictstring);
 
407
  }
 
408
 
 
409
  if (!argc)
 
410
    hwloc_lstopo_show_summary(stdout, topology);
 
411
 
 
412
  else {
 
413
    current_obj = 0;
 
414
    while (argc >= 1) {
 
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);
 
417
      } else {
 
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,
 
423
                                            verbose_mode);
 
424
        }
 
425
      }
 
426
      argc--; argv++;
 
427
    }
 
428
  }
 
429
 
 
430
  hwloc_topology_destroy (topology);
 
431
 
 
432
  return EXIT_SUCCESS;
 
433
}