14
14
#endif /* HWLOC_LINUX_SYS */
15
15
#include "hwloc/shmem.h"
16
16
17
+ #include "private/debug.h" /* for HWLOC_BUILD_ASSERT() */
18
+
17
19
#include <stdlib.h>
18
20
#include <stdio.h>
19
21
#include <string.h>
@@ -562,6 +564,63 @@ parse_output_format(const char *name, char *callname __hwloc_attribute_unused)
562
564
return LSTOPO_OUTPUT_ERROR ;
563
565
}
564
566
567
+ /****************************************************
568
+ * Store filters during parsing and apply them later
569
+ */
570
+
571
+ struct lstopo_type_filter { enum hwloc_type_filter_e filter ; int changed ; };
572
+
573
+ /* if these assert fails, some types were added,
574
+ * assumptions in macros below must be rechecked
575
+ */
576
+ #define init_type_filters () do { \
577
+ unsigned _i; \
578
+ HWLOC_BUILD_ASSERT(HWLOC_OBJ_TYPE_MIN == 0); \
579
+ HWLOC_BUILD_ASSERT(HWLOC_OBJ_TYPE_MAX == 20); \
580
+ for(_i=HWLOC_OBJ_TYPE_MIN; _i<HWLOC_OBJ_TYPE_MAX; _i++) \
581
+ type_filter[_i].changed = 0; \
582
+ } while (0)
583
+
584
+ #define set_type_filter (_type , _filter ) do { \
585
+ type_filter[_type].filter = _filter; \
586
+ type_filter[_type].changed = 1; \
587
+ } while (0)
588
+
589
+ #define set_all_types_filter (_filter ) do { \
590
+ unsigned _i; \
591
+ for(_i=HWLOC_OBJ_TYPE_MIN; _i<HWLOC_OBJ_TYPE_MAX; _i++) \
592
+ set_type_filter(_i, _filter); \
593
+ } while (0)
594
+
595
+ /* must operate on same types as hwloc_topology_set_io_types_filter() */
596
+ #define set_io_types_filter (_filter ) do { \
597
+ set_type_filter(HWLOC_OBJ_BRIDGE, _filter); \
598
+ set_type_filter(HWLOC_OBJ_PCI_DEVICE, _filter); \
599
+ set_type_filter(HWLOC_OBJ_OS_DEVICE, _filter); \
600
+ } while (0)
601
+
602
+ /* must operate on same types as hwloc_topology_set_cache_types_filter() */
603
+ #define set_cache_types_filter (_filter ) do { \
604
+ unsigned _i; \
605
+ for(_i=HWLOC_OBJ_L1CACHE; _i<HWLOC_OBJ_L3ICACHE; _i++) \
606
+ set_type_filter(_i, _filter); \
607
+ } while (0)
608
+
609
+ /* must operate on same types as hwloc_topology_set_icache_types_filter() */
610
+ #define set_icache_types_filter (_filter ) do { \
611
+ unsigned _i; \
612
+ for(_i=HWLOC_OBJ_L1ICACHE; _i<HWLOC_OBJ_L3ICACHE; _i++) \
613
+ set_type_filter(_i, _filter); \
614
+ } while (0)
615
+
616
+ #define apply_type_filters (_topo ) do { \
617
+ unsigned _i; \
618
+ for(_i=HWLOC_OBJ_TYPE_MIN; _i<HWLOC_OBJ_TYPE_MAX; _i++) \
619
+ if (type_filter[_i].changed) \
620
+ hwloc_topology_set_type_filter(_topo, _i, type_filter[_i].filter); \
621
+ } while (0)
622
+
623
+
565
624
#define LSTOPO_VERBOSE_MODE_DEFAULT 1
566
625
567
626
int
@@ -578,6 +637,7 @@ main (int argc, char *argv[])
578
637
char * input = NULL ;
579
638
enum hwloc_utils_input_format input_format = HWLOC_UTILS_INPUT_DEFAULT ;
580
639
enum output_format output_format = LSTOPO_OUTPUT_DEFAULT ;
640
+ struct lstopo_type_filter type_filter [HWLOC_OBJ_TYPE_MAX ];
581
641
char * restrictstring = NULL ;
582
642
struct lstopo_output loutput ;
583
643
output_method * output_func ;
@@ -614,6 +674,8 @@ main (int argc, char *argv[])
614
674
loutput .pid = 0 ;
615
675
loutput .need_pci_domain = 0 ;
616
676
677
+ init_type_filters ();
678
+
617
679
loutput .factorize_enabled = 1 ;
618
680
for (i = HWLOC_OBJ_TYPE_MIN ; i < HWLOC_OBJ_TYPE_MAX ; i ++ )
619
681
loutput .factorize_min [i ] = FACTORIZE_MIN_DEFAULT ;
@@ -767,16 +829,16 @@ main (int argc, char *argv[])
767
829
loutput .ignore_numanodes = 1 ;
768
830
}
769
831
else if (all )
770
- hwloc_topology_set_all_types_filter ( topology , filter );
832
+ set_all_types_filter ( filter );
771
833
else if (allio )
772
- hwloc_topology_set_io_types_filter ( topology , filter );
834
+ set_io_types_filter ( filter );
773
835
else if (allcaches ) {
774
- hwloc_topology_set_cache_types_filter ( topology , filter );
775
- hwloc_topology_set_type_filter ( topology , HWLOC_OBJ_MEMCACHE , filter );
836
+ set_cache_types_filter ( filter );
837
+ set_type_filter ( HWLOC_OBJ_MEMCACHE , filter );
776
838
} else if (allicaches )
777
- hwloc_topology_set_icache_types_filter ( topology , filter );
839
+ set_icache_types_filter ( filter );
778
840
else
779
- hwloc_topology_set_type_filter ( topology , type , filter );
841
+ set_type_filter ( type , filter );
780
842
opt = 1 ;
781
843
}
782
844
else if (!strcmp (argv [0 ], "--ignore" )) {
@@ -794,22 +856,22 @@ main (int argc, char *argv[])
794
856
else if (type == HWLOC_OBJ_NUMANODE )
795
857
loutput .ignore_numanodes = 1 ;
796
858
else
797
- hwloc_topology_set_type_filter ( topology , type , HWLOC_TYPE_FILTER_KEEP_NONE );
859
+ set_type_filter ( type , HWLOC_TYPE_FILTER_KEEP_NONE );
798
860
opt = 1 ;
799
861
}
800
862
else if (!strcmp (argv [0 ], "--no-smt" )) {
801
863
loutput .ignore_pus = 1 ;
802
864
}
803
865
else if (!strcmp (argv [0 ], "--no-caches" )) {
804
- hwloc_topology_set_cache_types_filter ( topology , HWLOC_TYPE_FILTER_KEEP_NONE );
805
- hwloc_topology_set_type_filter ( topology , HWLOC_OBJ_MEMCACHE , HWLOC_TYPE_FILTER_KEEP_NONE );
866
+ set_cache_types_filter ( HWLOC_TYPE_FILTER_KEEP_NONE );
867
+ set_type_filter ( HWLOC_OBJ_MEMCACHE , HWLOC_TYPE_FILTER_KEEP_NONE );
806
868
}
807
869
else if (!strcmp (argv [0 ], "--no-useless-caches" )) {
808
- hwloc_topology_set_cache_types_filter ( topology , HWLOC_TYPE_FILTER_KEEP_STRUCTURE );
809
- hwloc_topology_set_type_filter ( topology , HWLOC_OBJ_MEMCACHE , HWLOC_TYPE_FILTER_KEEP_STRUCTURE );
870
+ set_cache_types_filter ( HWLOC_TYPE_FILTER_KEEP_STRUCTURE );
871
+ set_type_filter ( HWLOC_OBJ_MEMCACHE , HWLOC_TYPE_FILTER_KEEP_STRUCTURE );
810
872
}
811
873
else if (!strcmp (argv [0 ], "--no-icaches" )) {
812
- hwloc_topology_set_icache_types_filter ( topology , HWLOC_TYPE_FILTER_KEEP_NONE );
874
+ set_icache_types_filter ( HWLOC_TYPE_FILTER_KEEP_NONE );
813
875
}
814
876
else if (!strcmp (argv [0 ], "--disallowed" ) || !strcmp (argv [0 ], "--whole-system" ))
815
877
flags |= HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED ;
@@ -837,13 +899,13 @@ main (int argc, char *argv[])
837
899
flags |= HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED ;
838
900
839
901
} else if (!strcmp (argv [0 ], "--no-io" )) {
840
- hwloc_topology_set_io_types_filter ( topology , HWLOC_TYPE_FILTER_KEEP_NONE );
902
+ set_io_types_filter ( HWLOC_TYPE_FILTER_KEEP_NONE );
841
903
} else if (!strcmp (argv [0 ], "--no-bridges" )) {
842
- hwloc_topology_set_type_filter ( topology , HWLOC_OBJ_BRIDGE , HWLOC_TYPE_FILTER_KEEP_NONE );
904
+ set_type_filter ( HWLOC_OBJ_BRIDGE , HWLOC_TYPE_FILTER_KEEP_NONE );
843
905
} else if (!strcmp (argv [0 ], "--whole-io" )) {
844
- hwloc_topology_set_io_types_filter ( topology , HWLOC_TYPE_FILTER_KEEP_ALL );
906
+ set_io_types_filter ( HWLOC_TYPE_FILTER_KEEP_ALL );
845
907
} else if (!strcmp (argv [0 ], "--merge" )) {
846
- hwloc_topology_set_all_types_filter ( topology , HWLOC_TYPE_FILTER_KEEP_STRUCTURE );
908
+ set_all_types_filter ( HWLOC_TYPE_FILTER_KEEP_STRUCTURE );
847
909
}
848
910
else if (!strcmp (argv [0 ], "--no-collapse" ))
849
911
loutput .pci_collapse_enabled = 0 ;
@@ -1315,6 +1377,8 @@ main (int argc, char *argv[])
1315
1377
hwloc_topology_set_userdata_export_callback (topology , hwloc_utils_userdata_export_cb );
1316
1378
}
1317
1379
1380
+ apply_type_filters (topology );
1381
+
1318
1382
/*********************
1319
1383
* Build the topology
1320
1384
*/
0 commit comments