Skip to content

Commit c24290f

Browse files
committed
utils: factorize the filtering of objects using the new level structure with filters
Signed-off-by: Brice Goglin <[email protected]>
1 parent a323bf3 commit c24290f

File tree

2 files changed

+41
-42
lines changed

2 files changed

+41
-42
lines changed

utils/hwloc/hwloc-calc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ hwloc_calc_hierarch_output(hwloc_topology_t topology, const char *prefix, const
123123
unsigned idx = logicalo ? logi : obj->os_index;
124124
if (!hwloc_bitmap_intersects(set, obj->cpuset))
125125
goto next;
126+
if (hwloc_calc_check_object_filtered(obj, &hierlevels[level]))
127+
goto next;
126128
hwloc_obj_type_snprintf(type, sizeof(type), obj, HWLOC_OBJ_SNPRINTF_FLAG_LONG_NAMES);
127129
if (idx == (unsigned)-1)
128130
snprintf(string, sizeof(string), "%s%s%s:-1", prefix, level ? "." : "", type);
@@ -192,8 +194,7 @@ hwloc_calc_output(hwloc_topology_t topology, const char *sep, hwloc_bitmap_t set
192194
unsigned nb = 0;
193195
hwloc_obj_t obj = NULL;
194196
while ((obj = hwloc_calc_get_next_obj_covering_set_by_depth(topology, set, nodeseto, numberof.depth, obj)) != NULL) {
195-
if (numberof.depth == HWLOC_TYPE_DEPTH_OS_DEVICE
196-
&& (obj->attr->osdev.type & numberof.attr.osdev.type) != numberof.attr.osdev.type)
197+
if (hwloc_calc_check_object_filtered(obj, &numberof))
197198
continue;
198199
nb++;
199200
}
@@ -205,8 +206,7 @@ hwloc_calc_output(hwloc_topology_t topology, const char *sep, hwloc_bitmap_t set
205206
sep = ",";
206207
while ((obj = hwloc_calc_get_next_obj_covering_set_by_depth(topology, set, nodeseto, intersect.depth, obj)) != NULL) {
207208
unsigned idx;
208-
if (intersect.depth == HWLOC_TYPE_DEPTH_OS_DEVICE
209-
&& (obj->attr->osdev.type & intersect.attr.osdev.type) != intersect.attr.osdev.type)
209+
if (hwloc_calc_check_object_filtered(obj, &intersect))
210210
continue;
211211
if (!first)
212212
printf("%s", sep);

utils/hwloc/hwloc-calc.h

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,43 @@ hwloc_calc_append_set(hwloc_bitmap_t set, hwloc_const_bitmap_t newset,
8989
return 0;
9090
}
9191

92+
/* return 1 if obj is filtered out */
93+
static __hwloc_inline int
94+
hwloc_calc_check_object_filtered(hwloc_obj_t obj, struct hwloc_calc_level *level)
95+
{
96+
if (level->subtype[0]) {
97+
if (!obj->subtype || strcasecmp(level->subtype, obj->subtype))
98+
return 1;
99+
}
100+
101+
if (level->type == HWLOC_OBJ_NUMANODE) {
102+
if (level->only_hbm >= 0) {
103+
/* filter on hbm */
104+
int obj_is_hbm = obj->subtype && !strcmp(obj->subtype, "MCDRAM");
105+
if (level->only_hbm != obj_is_hbm)
106+
return 1;
107+
}
108+
109+
} else if (level->type == HWLOC_OBJ_PCI_DEVICE) {
110+
if (level->pci_vendor != -1 && (int) obj->attr->pcidev.vendor_id != level->pci_vendor)
111+
return 1;
112+
if (level->pci_device != -1 && (int) obj->attr->pcidev.device_id != level->pci_device)
113+
return 1;
114+
115+
} else if (level->type == HWLOC_OBJ_OS_DEVICE) {
116+
if (level->attr.osdev.type != 0 && !(obj->attr->osdev.type & level->attr.osdev.type))
117+
return 1;
118+
}
119+
120+
return 0;
121+
}
122+
92123
static __hwloc_inline unsigned
93124
hwloc_calc_get_nbobjs_inside_sets_by_depth(struct hwloc_calc_location_context_s *lcontext,
94125
hwloc_const_bitmap_t cpuset, hwloc_const_bitmap_t nodeset,
95126
struct hwloc_calc_level *level)
96127
{
97128
hwloc_topology_t topology = lcontext->topology;
98-
int only_hbm = level->only_hbm;
99129
hwloc_obj_t obj = NULL;
100130
unsigned n = 0;
101131
while ((obj = hwloc_get_next_obj_by_depth(topology, level->depth, obj)) != NULL) {
@@ -106,16 +136,8 @@ hwloc_calc_get_nbobjs_inside_sets_by_depth(struct hwloc_calc_location_context_s
106136
if (hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_iszero(obj->nodeset))
107137
/* ignore objects with empty sets (both can be empty when outside of cgroup) */
108138
continue;
109-
if (only_hbm >= 0 && obj->type == HWLOC_OBJ_NUMANODE) {
110-
/* filter on hbm */
111-
int obj_is_hbm = obj->subtype && !strcmp(obj->subtype, "MCDRAM");
112-
if (only_hbm != obj_is_hbm)
113-
continue;
114-
}
115-
if (level->subtype[0]) {
116-
if (!obj->subtype || strcasecmp(level->subtype, obj->subtype))
117-
continue;
118-
}
139+
if (hwloc_calc_check_object_filtered(obj, level))
140+
continue;
119141
n++;
120142
}
121143
return n;
@@ -127,7 +149,6 @@ hwloc_calc_get_obj_inside_sets_by_depth(struct hwloc_calc_location_context_s *lc
127149
struct hwloc_calc_level *level, unsigned ind)
128150
{
129151
hwloc_topology_t topology = lcontext->topology;
130-
int only_hbm = level->only_hbm;
131152
int logical = lcontext->logical;
132153
hwloc_obj_t obj = NULL;
133154
unsigned i = 0;
@@ -139,16 +160,8 @@ hwloc_calc_get_obj_inside_sets_by_depth(struct hwloc_calc_location_context_s *lc
139160
if (hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_iszero(obj->nodeset))
140161
/* ignore objects with empty sets (both can be empty when outside of cgroup) */
141162
continue;
142-
if (only_hbm >= 0 && obj->type == HWLOC_OBJ_NUMANODE) {
143-
/* filter on hbm */
144-
int obj_is_hbm = obj->subtype && !strcmp(obj->subtype, "MCDRAM");
145-
if (only_hbm != obj_is_hbm)
146-
continue;
147-
}
148-
if (level->subtype[0]) {
149-
if (!obj->subtype || strcasecmp(level->subtype, obj->subtype))
150-
continue;
151-
}
163+
if (hwloc_calc_check_object_filtered(obj, level))
164+
continue;
152165
if (logical) {
153166
if (i == ind)
154167
return obj;
@@ -544,22 +557,8 @@ hwloc_calc_append_iodev_by_index(struct hwloc_calc_location_context_s *lcontext,
544557
if (obj == prev) /* already used that object, stop wrapping around */
545558
break;
546559

547-
if (level->type == HWLOC_OBJ_PCI_DEVICE) {
548-
if (level->pci_vendor != -1 && (int) obj->attr->pcidev.vendor_id != level->pci_vendor)
549-
continue;
550-
if (level->pci_device != -1 && (int) obj->attr->pcidev.device_id != level->pci_device)
551-
continue;
552-
}
553-
554-
if (level->type == HWLOC_OBJ_OS_DEVICE) {
555-
if ((obj->attr->osdev.type & level->attr.osdev.type) != level->attr.osdev.type)
556-
continue;
557-
}
558-
559-
if (level->subtype[0]) {
560-
if (!obj->subtype || strcasecmp(level->subtype, obj->subtype))
561-
continue;
562-
}
560+
if (hwloc_calc_check_object_filtered(obj, level))
561+
continue;
563562

564563
if (first--)
565564
continue;

0 commit comments

Comments
 (0)