~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/lstopo.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
1
/*
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"
35
35
#include "misc.h"
36
36
 
37
 
int logical = -1;
38
 
hwloc_obj_type_t show_only = (hwloc_obj_type_t) -1;
39
 
int show_cpuset = 0;
40
 
int taskset = 0;
 
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;
 
43
 
 
44
char **lstopo_append_legends = NULL;
 
45
unsigned lstopo_append_legends_nr = 0;
 
46
 
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;
45
 
unsigned int top = 0;
46
 
int pid_number = -1;
47
 
hwloc_pid_t pid;
 
50
 
 
51
static int logical = -1;
 
52
static unsigned int legend = 1;
 
53
static unsigned int top = 0;
48
54
 
49
55
FILE *open_file(const char *filename, const char *mode)
50
56
{
262
268
                  "                        impact\n");
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");
269
 
#endif
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"))
389
394
        logical = 0;
390
395
      else if (!strcmp (argv[0], "-c") || !strcmp (argv[0], "--cpuset"))
391
 
        show_cpuset = 1;
 
396
        lstopo_show_cpuset = 1;
392
397
      else if (!strcmp (argv[0], "-C") || !strcmp (argv[0], "--cpuset-only"))
393
 
        show_cpuset = 2;
 
398
        lstopo_show_cpuset = 2;
394
399
      else if (!strcmp (argv[0], "--taskset")) {
395
 
        taskset = 1;
396
 
        if (!show_cpuset)
397
 
          show_cpuset = 1;
 
400
        lstopo_show_taskset = 1;
 
401
        if (!lstopo_show_cpuset)
 
402
          lstopo_show_cpuset = 1;
398
403
      } else if (!strcmp (argv[0], "--only")) {
399
404
        if (argc < 2) {
400
405
          usage (callname, stderr);
401
406
          exit(EXIT_FAILURE);
402
407
        }
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]);
404
411
        opt = 1;
405
412
      }
406
413
      else if (!strcmp (argv[0], "--ignore")) {
 
414
        hwloc_obj_type_t type;
407
415
        if (argc < 2) {
408
416
          usage (callname, stderr);
409
417
          exit(EXIT_FAILURE);
410
418
        }
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;
 
424
        else
 
425
          hwloc_topology_ignore_type(topology, type);
412
426
        opt = 1;
413
427
      }
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;
 
473
          else
 
474
            fprintf(stderr, "Unsupported type `%s' passed to %s, ignoring.\n", tmp, argv[0]);
459
475
          if (!end)
460
476
            break;
461
477
          tmp = end+1;
481
497
      else if (!strcmp (argv[0], "--no-legend")) {
482
498
        legend = 0;
483
499
      }
 
500
      else if (!strcmp (argv[0], "--append-legend")) {
 
501
        if (argc < 2) {
 
502
          usage (callname, stderr);
 
503
          exit(EXIT_FAILURE);
 
504
        }
 
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++;
 
508
        opt = 1;
 
509
      }
484
510
 
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);
494
520
        }
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"))
497
523
        top = 1;
498
524
      else if (!strcmp (argv[0], "--version")) {
517
543
      argv += opt+1;
518
544
    }
519
545
 
520
 
  if (show_only != (hwloc_obj_type_t)-1)
 
546
  if (lstopo_show_only != (hwloc_obj_type_t)-1)
521
547
    merge = 0;
522
548
 
523
549
  hwloc_topology_set_flags(topology, flags);
536
562
      return err;
537
563
  }
538
564
 
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;
544
570
    }
545
571
  }
546
572
 
547
573
  err = hwloc_topology_load (topology);
548
 
  if (err)
 
574
  if (err) {
 
575
    fprintf(stderr, "hwloc_topology_load() failed (%s).\n", strerror(errno));
549
576
    return EXIT_FAILURE;
 
577
  }
550
578
 
551
579
  if (top)
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);
559
587
      else
560
588
        hwloc_get_cpubind(topology, restrictset, HWLOC_CPUBIND_PROCESS);
561
589
    } else {
570
598
    free(restrictstring);
571
599
  }
572
600
 
573
 
  if (!filename && !strcmp(callname,"hwloc-info")) {
574
 
    /* behave kind-of plpa-info */
575
 
    filename = "-";
576
 
    verbose_mode--;
577
 
  }
578
 
 
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, '.');
586
608
      if (dot)
587
609
        output_format = parse_output_format(dot+1, callname);
 
610
      else {
 
611
        fprintf(stderr, "Cannot infer output type for file `%s' without any extension, using default output.\n", filename);
 
612
        filename = NULL;
 
613
      }
588
614
    }
589
615
  }
590
616
 
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) {
593
 
    if (show_cpuset
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;
597
623
  }
606
632
  switch (output_format) {
607
633
    case LSTOPO_OUTPUT_DEFAULT:
608
634
#ifdef LSTOPO_HAVE_GRAPHICS
609
 
#if CAIRO_HAS_XLIB_SURFACE && defined HWLOC_HAVE_X11
 
635
#if CAIRO_HAS_XLIB_SURFACE && defined HWLOC_HAVE_X11_KEYSYM
610
636
      if (getenv("DISPLAY")) {
611
637
        if (logical == -1)
612
638
          logical = 0;
675
701
 
676
702
  hwloc_topology_destroy (topology);
677
703
 
 
704
  for(i=0; i<lstopo_append_legends_nr; i++)
 
705
    free(lstopo_append_legends[i]);
 
706
  free(lstopo_append_legends);
 
707
 
678
708
  return EXIT_SUCCESS;
679
709
}