Skip to content

Commit ef9f9f7

Browse files
committed
utils: use the new hwloc_calc_parse_level() for parsing locations etc
Remove the old hwloc_calc_parse_depth_prefix() which was similar. Signed-off-by: Brice Goglin <[email protected]>
1 parent 56deb3b commit ef9f9f7

File tree

1 file changed

+36
-87
lines changed

1 file changed

+36
-87
lines changed

utils/hwloc/hwloc-calc.h

Lines changed: 36 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -192,60 +192,6 @@ hwloc_calc_parse_level(struct hwloc_calc_location_context_s *lcontext,
192192
return 0;
193193
}
194194

195-
static __hwloc_inline int
196-
hwloc_calc_parse_depth_prefix(struct hwloc_calc_location_context_s *lcontext,
197-
const char *string, size_t typelen,
198-
hwloc_obj_type_t *typep)
199-
{
200-
hwloc_topology_t topology = lcontext->topology;
201-
int topodepth = lcontext->topodepth;
202-
int verbose = lcontext->verbose;
203-
char typestring[20+1]; /* large enough to store all type names, even with a depth attribute */
204-
hwloc_obj_type_t type;
205-
union hwloc_obj_attr_u attr;
206-
int depth;
207-
char *end;
208-
int err;
209-
210-
if (typelen >= sizeof(typestring)) {
211-
if (verbose >= 0)
212-
fprintf(stderr, "invalid type name %s\n", string);
213-
return -1;
214-
}
215-
strncpy(typestring, string, typelen);
216-
typestring[typelen] = '\0';
217-
218-
/* try to match a type name */
219-
err = hwloc_type_sscanf(typestring, &type, &attr, sizeof(attr));
220-
if (!err) {
221-
*typep = type;
222-
return hwloc_get_type_depth_with_attr(topology, type, &attr, sizeof(attr));
223-
}
224-
225-
if (!strcasecmp(typestring, "HBM") || !strcasecmp(typestring, "MCDRAM")) {
226-
if (lcontext->only_hbm == -1)
227-
lcontext->only_hbm = 1;
228-
*typep = HWLOC_OBJ_NUMANODE;
229-
depth = HWLOC_TYPE_DEPTH_NUMANODE;
230-
return depth;
231-
}
232-
233-
/* try to match a numeric depth */
234-
depth = strtol(string, &end, 0);
235-
if (end != &string[typelen]) {
236-
if (verbose >= 0)
237-
fprintf(stderr, "invalid type name %s\n", string);
238-
return -1;
239-
}
240-
if (depth >= topodepth) {
241-
if (verbose >= 0)
242-
fprintf(stderr, "ignoring invalid depth %d\n", depth);
243-
return -1;
244-
}
245-
*typep = HWLOC_OBJ_TYPE_NONE;
246-
return depth;
247-
}
248-
249195
static __hwloc_inline int
250196
hwloc_calc_parse_range(const char *_string,
251197
int *firstp, int *amountp, int *stepp, int *wrapp,
@@ -351,6 +297,7 @@ hwloc_calc_append_object_range(struct hwloc_calc_location_context_s *lcontext,
351297
void (*cbfunc)(struct hwloc_calc_location_context_s *, void *, hwloc_obj_t), void *cbdata)
352298
{
353299
int verbose = lcontext->verbose;
300+
hwloc_topology_t topology = lcontext->topology;
354301
hwloc_obj_t obj;
355302
unsigned width;
356303
const char *dot, *nextsep = NULL;
@@ -374,7 +321,7 @@ hwloc_calc_append_object_range(struct hwloc_calc_location_context_s *lcontext,
374321
if (dot) {
375322
/* parse the next string before calling ourself recursively */
376323
size_t typelen;
377-
hwloc_obj_type_t type;
324+
struct hwloc_calc_level level;
378325
const char *nextstring = dot+1;
379326
typelen = strspn(nextstring, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
380327
if (!typelen || nextstring[typelen] != ':') {
@@ -384,19 +331,21 @@ hwloc_calc_append_object_range(struct hwloc_calc_location_context_s *lcontext,
384331
}
385332
nextsep = &nextstring[typelen];
386333

387-
nextdepth = hwloc_calc_parse_depth_prefix(lcontext,
388-
nextstring, typelen,
389-
&type);
390-
if (nextdepth == HWLOC_TYPE_DEPTH_UNKNOWN) {
391-
if (verbose >= 0)
392-
fprintf(stderr, "could not find level specified by location %s\n", nextstring);
393-
return -1;
394-
}
395-
if (nextdepth == HWLOC_TYPE_DEPTH_MULTIPLE) {
396-
if (verbose >= 0)
397-
fprintf(stderr, "found multiple levels for location %s\n", nextstring);
398-
return -1;
334+
err = hwloc_calc_parse_level(lcontext, topology, nextstring, typelen, &level);
335+
if (err < 0) {
336+
if (level.depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
337+
if (verbose >= 0)
338+
fprintf(stderr, "could not find level specified by location %s\n", nextstring);
339+
return -1;
340+
}
341+
if (level.depth == HWLOC_TYPE_DEPTH_MULTIPLE) {
342+
if (verbose >= 0)
343+
fprintf(stderr, "found multiple levels for location %s\n", nextstring);
344+
return -1;
345+
}
399346
}
347+
nextdepth = level.depth;
348+
400349
/* we need an object with a cpuset, that's depth>=0 or memory */
401350
if (nextdepth < 0 && nextdepth != HWLOC_TYPE_DEPTH_NUMANODE) {
402351
if (verbose >= 0)
@@ -615,33 +564,33 @@ hwloc_calc_process_location(struct hwloc_calc_location_context_s *lcontext,
615564
hwloc_topology_t topology = lcontext->topology;
616565
int verbose = lcontext->verbose;
617566
const char *sep = &arg[typelen];
618-
hwloc_obj_type_t type = HWLOC_OBJ_TYPE_NONE;
619-
int depth;
567+
struct hwloc_calc_level level;
568+
int err;
620569

621-
depth = hwloc_calc_parse_depth_prefix(lcontext,
622-
arg, typelen,
623-
&type);
624-
if (depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
625-
if (verbose >= 0)
626-
fprintf(stderr, "could not find level specified by location %s\n", arg);
627-
return -1;
628-
}
629-
if (depth == HWLOC_TYPE_DEPTH_MULTIPLE) {
630-
if (verbose >= 0)
631-
fprintf(stderr, "found multiple levels for location %s\n", arg);
632-
return -1;
570+
err = hwloc_calc_parse_level(lcontext, topology, arg, typelen, &level);
571+
if (err < 0) {
572+
if (level.depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
573+
if (verbose >= 0)
574+
fprintf(stderr, "could not find level specified by location %s\n", arg);
575+
return -1;
576+
}
577+
if (level.depth == HWLOC_TYPE_DEPTH_MULTIPLE) {
578+
if (verbose >= 0)
579+
fprintf(stderr, "found multiple levels for location %s\n", arg);
580+
return -1;
581+
}
633582
}
634583

635-
if (depth < 0 && depth != HWLOC_TYPE_DEPTH_NUMANODE) {
584+
if (level.depth < 0 && level.depth != HWLOC_TYPE_DEPTH_NUMANODE) {
636585
/* special object without cpusets */
637586

638587
/* if we didn't find a depth but found a type, handle special cases */
639588
hwloc_obj_t obj = NULL;
640589

641590
if (*sep == ':' || *sep == '[') {
642-
return hwloc_calc_append_iodev_by_index(lcontext, type, depth, sep, cbfunc, cbdata);
591+
return hwloc_calc_append_iodev_by_index(lcontext, level.type, level.depth, sep, cbfunc, cbdata);
643592

644-
} else if (*sep == '=' && type == HWLOC_OBJ_PCI_DEVICE) {
593+
} else if (*sep == '=' && level.type == HWLOC_OBJ_PCI_DEVICE) {
645594
/* try to match a busid */
646595
obj = hwloc_get_pcidev_by_busidstring(topology, sep+1);
647596
if (obj)
@@ -650,7 +599,7 @@ hwloc_calc_process_location(struct hwloc_calc_location_context_s *lcontext,
650599
fprintf(stderr, "invalid PCI device %s\n", sep+1);
651600
return -1;
652601

653-
} else if (*sep == '=' && type == HWLOC_OBJ_OS_DEVICE) {
602+
} else if (*sep == '=' && level.type == HWLOC_OBJ_OS_DEVICE) {
654603
/* try to match a OS device name */
655604
while ((obj = hwloc_get_next_osdev(topology, obj)) != NULL) {
656605
if (!strcmp(obj->name, sep+1))
@@ -660,7 +609,7 @@ hwloc_calc_process_location(struct hwloc_calc_location_context_s *lcontext,
660609
fprintf(stderr, "invalid OS device %s\n", sep+1);
661610
return -1;
662611

663-
} else if (*sep == '=' && type == HWLOC_OBJ_MISC) {
612+
} else if (*sep == '=' && level.type == HWLOC_OBJ_MISC) {
664613
/* try to match a Misc device name */
665614
obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_MISC, 0);
666615
while (obj) {
@@ -680,7 +629,7 @@ hwloc_calc_process_location(struct hwloc_calc_location_context_s *lcontext,
680629
return hwloc_calc_append_object_range(lcontext,
681630
hwloc_topology_get_complete_cpuset(topology),
682631
hwloc_topology_get_complete_nodeset(topology),
683-
depth, sep+1, cbfunc, cbdata);
632+
level.depth, sep+1, cbfunc, cbdata);
684633
}
685634

686635
struct hwloc_calc_set_context_s {

0 commit comments

Comments
 (0)