Skip to content

Commit e1cc7e4

Browse files
Logical binding ouptut
Signed-off-by: Guillaume Mercier <[email protected]>
1 parent 0444ef7 commit e1cc7e4

File tree

2 files changed

+43
-53
lines changed

2 files changed

+43
-53
lines changed

src/qvi-hwloc.cc

+42-52
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ qvi_hwloc_emit_cpubind(
821821
if (rc != QV_SUCCESS) goto out;
822822

823823
qvi_log_info(
824-
"[pid={} tid={}] cpubind (physical)=[{}",
824+
"[pid={} tid={}] cpubind (physical) = {}",
825825
getpid(), task_id, cpusets
826826
);
827827
out:
@@ -844,37 +844,32 @@ qvi_hwloc_bitmap_asprintf(
844844
}
845845

846846
if (topo) {
847+
hwloc_bitmap_t cpuset_logical = hwloc_bitmap_alloc();
847848
hwloc_obj_t obj_pu = nullptr;
848-
849+
849850
int num_pus = hwloc_get_nbobjs_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU);
850-
int num_pus_cp = num_pus;
851-
852-
int num_digits = 1;
853-
while(num_pus_cp /= 10) num_digits++;
854-
855-
char head[] = "] | (logical)=[";
856-
int str_size = strlen(head)+num_pus*(num_digits+1)+1;
857-
char *str = (char *)calloc(str_size,sizeof(char));
858-
859-
strcpy(str,head);
860-
861-
char *core_str = (char *)calloc(num_digits+2,sizeof(char));
862851
for(int idx = 0; idx < num_pus ; idx++){
863852
obj_pu = hwloc_get_next_obj_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU, obj_pu);
864-
sprintf(core_str,"%i%s",obj_pu->logical_index, idx == (num_pus-1) ? "]" :",");
865-
strcat(str,core_str);
866-
memset(core_str,0,strlen(core_str));
853+
(void)hwloc_bitmap_set(cpuset_logical,obj_pu->logical_index);
867854
}
868-
869-
char *newstr = (char *)calloc(strlen(str)+strlen(iresult)+1,sizeof(char));
870-
strcpy(newstr,iresult);
871-
strcat(newstr,str);
872-
873-
free(core_str);
874-
free(str);
855+
856+
char *iresult_logical = nullptr;
857+
(void)hwloc_bitmap_list_asprintf(&iresult_logical, cpuset_logical);
858+
if (qvi_unlikely(!iresult_logical)) {
859+
qvi_log_error("hwloc_bitmap_list_asprintf() failed");
860+
return QV_ERR_OOR;
861+
}
862+
(void)hwloc_bitmap_free(cpuset_logical);
863+
864+
char head[] = " | (logical) = ";
865+
char *final_result = (char*)calloc(strlen(iresult)+
866+
strlen(head)+
867+
strlen(iresult_logical)+1,sizeof(char));
868+
memcpy(final_result,iresult,strlen(iresult));
869+
strcat(final_result,head);
870+
strcat(final_result,iresult_logical);
875871
free(iresult);
876-
877-
iresult = newstr;
872+
iresult = final_result;
878873
}
879874

880875
*result = iresult;
@@ -893,39 +888,34 @@ qvi_hwloc_bitmap_list_asprintf(
893888
qvi_log_error("hwloc_bitmap_list_asprintf() failed");
894889
return QV_ERR_OOR;
895890
}
896-
891+
897892
if (topo) {
893+
hwloc_bitmap_t cpuset_logical = hwloc_bitmap_alloc();
898894
hwloc_obj_t obj_pu = nullptr;
899-
895+
900896
int num_pus = hwloc_get_nbobjs_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU);
901-
int num_pus_cp = num_pus;
902-
903-
int num_digits = 1;
904-
while(num_pus_cp /= 10) num_digits++;
905-
906-
char head[] = "] | (logical)=[";
907-
int str_size = strlen(head)+num_pus*(num_digits+1)+1;
908-
char *str = (char *)calloc(str_size,sizeof(char));
909-
910-
strcpy(str,head);
911-
912-
char *core_str = (char *)calloc(num_digits+2,sizeof(char));
913897
for(int idx = 0; idx < num_pus ; idx++){
914898
obj_pu = hwloc_get_next_obj_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU, obj_pu);
915-
sprintf(core_str,"%i%s",obj_pu->logical_index, idx == (num_pus-1) ? "]" :",");
916-
strcat(str,core_str);
917-
memset(core_str,0,strlen(core_str));
899+
(void)hwloc_bitmap_set(cpuset_logical,obj_pu->logical_index);
918900
}
919-
920-
char *newstr = (char *)calloc(strlen(str)+strlen(iresult)+1,sizeof(char));
921-
strcpy(newstr,iresult);
922-
strcat(newstr,str);
923-
924-
free(core_str);
925-
free(str);
901+
902+
char *iresult_logical = nullptr;
903+
(void)hwloc_bitmap_list_asprintf(&iresult_logical, cpuset_logical);
904+
if (qvi_unlikely(!iresult_logical)) {
905+
qvi_log_error("hwloc_bitmap_list_asprintf() failed");
906+
return QV_ERR_OOR;
907+
}
908+
(void)hwloc_bitmap_free(cpuset_logical);
909+
910+
char head[] = " | (logical) = ";
911+
char *final_result = (char*)calloc(strlen(iresult)+
912+
strlen(head)+
913+
strlen(iresult_logical)+1,sizeof(char));
914+
memcpy(final_result,iresult,strlen(iresult));
915+
strcat(final_result,head);
916+
strcat(final_result,iresult_logical);
926917
free(iresult);
927-
928-
iresult = newstr;
918+
iresult = final_result;
929919
}
930920

931921
*result = iresult;

tests/common-test-utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ ctu_emit_task_bind(
6262
ers = "qv_bind_string() failed";
6363
ctu_panic("%s (rc=%s)", ers, qv_strerr(rc));
6464
}
65-
printf("[%d] cpubind (physical)=[%s\n", pid, binds);
65+
printf("[%d] cpubind (physical) = %s\n", pid, binds);
6666
free(binds);
6767
}
6868

0 commit comments

Comments
 (0)