2
2
* Copyright © 2009 CNRS
3
* Copyright © 2009-2012 Inria. All rights reserved.
3
* Copyright © 2009-2013 Inria. All rights reserved.
4
4
* Copyright © 2009-2012 Université Bordeaux 1
5
5
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
6
6
* See COPYING in top-level directory.
34
34
#include "lstopo.h"
38
hwloc_obj_type_t show_only = (hwloc_obj_type_t) -1;
37
int lstopo_pid_number = -1;
38
hwloc_pid_t lstopo_pid;
39
hwloc_obj_type_t lstopo_show_only = (hwloc_obj_type_t) -1;
40
int lstopo_show_cpuset = 0;
41
int lstopo_show_taskset = 0;
42
int lstopo_ignore_pus = 0;
44
char **lstopo_append_legends = NULL;
45
unsigned lstopo_append_legends_nr = 0;
41
47
unsigned int fontsize = 10;
42
48
unsigned int gridsize = 10;
43
49
enum lstopo_orient_e force_orient[HWLOC_OBJ_TYPE_MAX];
44
unsigned int legend = 1;
51
static int logical = -1;
52
static unsigned int legend = 1;
53
static unsigned int top = 0;
49
55
FILE *open_file(const char *filename, const char *mode)
263
269
fprintf (where, " --restrict <cpuset> Restrict the topology to processors listed in <cpuset>\n");
264
270
fprintf (where, " --restrict binding Restrict the topology to the current process binding\n");
265
#ifdef HWLOC_HAVE_LIBPCI
266
271
fprintf (where, " --no-io Do not show any I/O device or bridge\n");
267
272
fprintf (where, " --no-bridges Do not any I/O bridge except hostbridges\n");
268
273
fprintf (where, " --whole-io Show all I/O devices and bridges\n");
270
274
fprintf (where, "Input options:\n");
271
275
hwloc_utils_input_format_usage(where, 6);
272
276
fprintf (where, " --thissystem Assume that the input topology provides the topology\n"
279
283
fprintf (where, " --horiz[=<type,...>] Horizontal graphical layout instead of nearly 4/3 ratio\n");
280
284
fprintf (where, " --vert[=<type,...>] Vertical graphical layout instead of nearly 4/3 ratio\n");
281
285
fprintf (where, " --no-legend Remove the text legend at the bottom\n");
286
fprintf (where, " --append-legend <s> Append a new line of text at the bottom of the legend\n");
282
287
fprintf (where, "Miscellaneous options:\n");
283
288
fprintf (where, " --ps --top Display processes within the hierarchy\n");
284
289
fprintf (where, " --version Report version and exit\n");
388
393
else if (!strcmp (argv[0], "-p") || !strcmp (argv[0], "--physical"))
390
395
else if (!strcmp (argv[0], "-c") || !strcmp (argv[0], "--cpuset"))
396
lstopo_show_cpuset = 1;
392
397
else if (!strcmp (argv[0], "-C") || !strcmp (argv[0], "--cpuset-only"))
398
lstopo_show_cpuset = 2;
394
399
else if (!strcmp (argv[0], "--taskset")) {
400
lstopo_show_taskset = 1;
401
if (!lstopo_show_cpuset)
402
lstopo_show_cpuset = 1;
398
403
} else if (!strcmp (argv[0], "--only")) {
400
405
usage (callname, stderr);
401
406
exit(EXIT_FAILURE);
403
show_only = hwloc_obj_type_of_string(argv[1]);
408
lstopo_show_only = hwloc_obj_type_of_string(argv[1]);
409
if (lstopo_show_only == (hwloc_obj_type_t) -1)
410
fprintf(stderr, "Unsupported type `%s' passed to --only, ignoring.\n", argv[1]);
406
413
else if (!strcmp (argv[0], "--ignore")) {
414
hwloc_obj_type_t type;
408
416
usage (callname, stderr);
409
417
exit(EXIT_FAILURE);
411
hwloc_topology_ignore_type(topology, hwloc_obj_type_of_string(argv[1]));
419
type = hwloc_obj_type_of_string(argv[1]);
420
if (type == (hwloc_obj_type_t) -1)
421
fprintf(stderr, "Unsupported type `%s' passed to --ignore, ignoring.\n", argv[1]);
422
else if (type == HWLOC_OBJ_PU)
423
lstopo_ignore_pus = 1;
425
hwloc_topology_ignore_type(topology, type);
414
428
else if (!strcmp (argv[0], "--no-caches"))
456
470
type = hwloc_obj_type_of_string(tmp);
457
471
if (type != (hwloc_obj_type_t) -1)
458
472
force_orient[type] = orient;
474
fprintf(stderr, "Unsupported type `%s' passed to %s, ignoring.\n", tmp, argv[0]);
481
497
else if (!strcmp (argv[0], "--no-legend")) {
500
else if (!strcmp (argv[0], "--append-legend")) {
502
usage (callname, stderr);
505
lstopo_append_legends = realloc(lstopo_append_legends, (lstopo_append_legends_nr+1) * sizeof(*lstopo_append_legends));
506
lstopo_append_legends[lstopo_append_legends_nr] = strdup(argv[1]);
507
lstopo_append_legends_nr++;
485
511
else if (hwloc_utils_lookup_input_option(argv, argc, &opt,
486
512
&input, &input_format,
492
518
usage (callname, stderr);
493
519
exit(EXIT_FAILURE);
495
pid_number = atoi(argv[1]); opt = 1;
521
lstopo_pid_number = atoi(argv[1]); opt = 1;
496
522
} else if (!strcmp (argv[0], "--ps") || !strcmp (argv[0], "--top"))
498
524
else if (!strcmp (argv[0], "--version")) {
539
if (pid_number != -1 && pid_number != 0) {
540
pid = hwloc_pid_from_number(pid_number, 0);
541
if (hwloc_topology_set_pid(topology, pid)) {
565
if (lstopo_pid_number != -1 && lstopo_pid_number != 0) {
566
lstopo_pid = hwloc_pid_from_number(lstopo_pid_number, 0);
567
if (hwloc_topology_set_pid(topology, lstopo_pid)) {
542
568
perror("Setting target pid");
543
569
return EXIT_FAILURE;
547
573
err = hwloc_topology_load (topology);
575
fprintf(stderr, "hwloc_topology_load() failed (%s).\n", strerror(errno));
549
576
return EXIT_FAILURE;
552
580
add_process_objects(topology);
554
582
if (restrictstring) {
555
583
hwloc_bitmap_t restrictset = hwloc_bitmap_alloc();
556
584
if (!strcmp (restrictstring, "binding")) {
557
if (pid_number != -1 && pid_number != 0)
558
hwloc_get_proc_cpubind(topology, pid, restrictset, HWLOC_CPUBIND_PROCESS);
585
if (lstopo_pid_number != -1 && lstopo_pid_number != 0)
586
hwloc_get_proc_cpubind(topology, lstopo_pid, restrictset, HWLOC_CPUBIND_PROCESS);
560
588
hwloc_get_cpubind(topology, restrictset, HWLOC_CPUBIND_PROCESS);
570
598
free(restrictstring);
573
if (!filename && !strcmp(callname,"hwloc-info")) {
574
/* behave kind-of plpa-info */
579
601
/* if the output format wasn't enforced, look at the filename */
580
602
if (filename && output_format == LSTOPO_OUTPUT_DEFAULT) {
581
603
if (!strcmp(filename, "-")
585
607
char *dot = strrchr(filename, '.');
587
609
output_format = parse_output_format(dot+1, callname);
611
fprintf(stderr, "Cannot infer output type for file `%s' without any extension, using default output.\n", filename);
591
617
/* if the output format wasn't enforced, think a bit about what the user probably want */
592
618
if (output_format == LSTOPO_OUTPUT_DEFAULT) {
594
|| show_only != (hwloc_obj_type_t)-1
619
if (lstopo_show_cpuset
620
|| lstopo_show_only != (hwloc_obj_type_t)-1
595
621
|| verbose_mode != LSTOPO_VERBOSE_MODE_DEFAULT)
596
622
output_format = LSTOPO_OUTPUT_CONSOLE;