Skip to content

Commit 0444ef7

Browse files
Not-so-pretty fix for logical numbering output. Needs improvement
Signed-off-by: Guillaume Mercier <[email protected]>
1 parent de1c932 commit 0444ef7

7 files changed

+90
-12
lines changed

src/qvi-bbuff-rmi.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ qvi_bbuff_rmi_pack_item_impl(
459459
}
460460
// Non-null data.
461461
char *datas = nullptr;
462-
int rc = qvi_hwloc_bitmap_asprintf(data, &datas);
462+
int rc = qvi_hwloc_bitmap_asprintf(NULL, data, &datas);
463463
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
464464
// We are sending the string representation of the cpuset.
465465
rc = buff->append(datas, strlen(datas) + 1);

src/qvi-hwloc.cc

+80-7
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,16 @@ qvi_hwloc_obj_type_is_host_resource(
180180

181181
int
182182
qvi_hwloc_bitmap_string(
183+
hwloc_topology_t topo,
183184
hwloc_const_bitmap_t bitmap,
184185
qv_bind_string_format_t format,
185186
char **result
186187
) {
187188
switch (format) {
188189
case QV_BIND_STRING_AS_BITMAP:
189-
return qvi_hwloc_bitmap_asprintf(bitmap, result);
190+
return qvi_hwloc_bitmap_asprintf(topo, bitmap, result);
190191
case QV_BIND_STRING_AS_LIST:
191-
return qvi_hwloc_bitmap_list_asprintf(bitmap, result);
192+
return qvi_hwloc_bitmap_list_asprintf(topo, bitmap, result);
192193
default:
193194
*result = nullptr;
194195
return QV_ERR_INVLD_ARG;
@@ -816,11 +817,11 @@ qvi_hwloc_emit_cpubind(
816817
if (rc != QV_SUCCESS) return rc;
817818

818819
char *cpusets = nullptr;
819-
rc = qvi_hwloc_bitmap_asprintf(cpuset, &cpusets);
820+
rc = qvi_hwloc_bitmap_asprintf(hwl->topo, cpuset, &cpusets);
820821
if (rc != QV_SUCCESS) goto out;
821822

822823
qvi_log_info(
823-
"[pid={} tid={}] cpubind={}",
824+
"[pid={} tid={}] cpubind (physical)=[{}",
824825
getpid(), task_id, cpusets
825826
);
826827
out:
@@ -831,6 +832,7 @@ qvi_hwloc_emit_cpubind(
831832

832833
int
833834
qvi_hwloc_bitmap_asprintf(
835+
hwloc_topology_t topo,
834836
hwloc_const_cpuset_t cpuset,
835837
char **result
836838
) {
@@ -840,12 +842,48 @@ qvi_hwloc_bitmap_asprintf(
840842
qvi_log_error("hwloc_bitmap_asprintf() failed");
841843
return QV_ERR_OOR;
842844
}
845+
846+
if (topo) {
847+
hwloc_obj_t obj_pu = nullptr;
848+
849+
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));
862+
for(int idx = 0; idx < num_pus ; idx++){
863+
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));
867+
}
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);
875+
free(iresult);
876+
877+
iresult = newstr;
878+
}
879+
843880
*result = iresult;
844881
return QV_SUCCESS;
845882
}
846883

847884
int
848885
qvi_hwloc_bitmap_list_asprintf(
886+
hwloc_topology_t topo,
849887
hwloc_const_cpuset_t cpuset,
850888
char **result
851889
) {
@@ -855,6 +893,41 @@ qvi_hwloc_bitmap_list_asprintf(
855893
qvi_log_error("hwloc_bitmap_list_asprintf() failed");
856894
return QV_ERR_OOR;
857895
}
896+
897+
if (topo) {
898+
hwloc_obj_t obj_pu = nullptr;
899+
900+
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));
913+
for(int idx = 0; idx < num_pus ; idx++){
914+
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));
918+
}
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);
926+
free(iresult);
927+
928+
iresult = newstr;
929+
}
930+
858931
*result = iresult;
859932
return QV_SUCCESS;
860933
}
@@ -869,7 +942,7 @@ qvi_hwloc_cpuset_debug(
869942
#endif
870943
assert(cpuset);
871944
char *cpusets = nullptr;
872-
int rc = qvi_hwloc_bitmap_asprintf(cpuset, &cpusets);
945+
int rc = qvi_hwloc_bitmap_asprintf(nullptr, cpuset, &cpusets);
873946
if (rc != QV_SUCCESS) {
874947
qvi_abort();
875948
}
@@ -957,7 +1030,7 @@ qvi_hwloc_task_get_cpubind_as_string(
9571030
int rc = qvi_hwloc_task_get_cpubind(hwl, task_id, &cpuset);
9581031
if (rc != QV_SUCCESS) return rc;
9591032

960-
rc = qvi_hwloc_bitmap_asprintf(cpuset, cpusets);
1033+
rc = qvi_hwloc_bitmap_asprintf(hwl->topo, cpuset, cpusets);
9611034
qvi_hwloc_bitmap_delete(&cpuset);
9621035
return rc;
9631036
}
@@ -1185,7 +1258,7 @@ qvi_hwloc_devices_emit(
11851258
}
11861259
for (auto &dev : *devlist) {
11871260
char *cpusets = nullptr;
1188-
int rc = qvi_hwloc_bitmap_asprintf(dev->affinity.cdata(), &cpusets);
1261+
int rc = qvi_hwloc_bitmap_asprintf(hwl->topo, dev->affinity.cdata(), &cpusets);
11891262
if (rc != QV_SUCCESS) return rc;
11901263

11911264
qvi_log_info(" Device Name: {}", dev->name);

src/qvi-hwloc.h

+3
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ qvi_hwloc_emit_cpubind(
187187
*/
188188
int
189189
qvi_hwloc_bitmap_asprintf(
190+
hwloc_topology_t topo,
190191
hwloc_const_cpuset_t cpuset,
191192
char **result
192193
);
@@ -196,6 +197,7 @@ qvi_hwloc_bitmap_asprintf(
196197
*/
197198
int
198199
qvi_hwloc_bitmap_list_asprintf(
200+
hwloc_topology_t topo,
199201
hwloc_const_cpuset_t cpuset,
200202
char **result
201203
);
@@ -537,6 +539,7 @@ qvi_hwloc_get_devices_in_bitmap(
537539

538540
int
539541
qvi_hwloc_bitmap_string(
542+
hwloc_topology_t topo,
540543
hwloc_const_bitmap_t bitmap,
541544
qv_bind_string_format_t format,
542545
char **result

src/qvi-scope.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ qv_scope::bind_string(
213213
int rc = m_group->task()->bind_top(&bitmap);
214214
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
215215

216-
rc = qvi_hwloc_bitmap_string(bitmap, format, result);
216+
hwloc_topology_t topo = qvi_hwloc_get_topo_obj(m_group->hwloc());
217+
218+
rc = qvi_hwloc_bitmap_string(topo, bitmap, format, result);
217219
qvi_hwloc_bitmap_delete(&bitmap);
218220
return rc;
219221
}

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=%s\n", pid, binds);
65+
printf("[%d] cpubind (physical)=[%s\n", pid, binds);
6666
free(binds);
6767
}
6868

tests/internal/test-hwloc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ main(void)
208208
ctu_panic("%s (rc=%s)", ers, qv_strerr(rc));
209209
}
210210

211-
rc = qvi_hwloc_bitmap_asprintf(bitmap, &binds);
211+
rc = qvi_hwloc_bitmap_asprintf(NULL, bitmap, &binds);
212212
if (rc != QV_SUCCESS) {
213213
ers = "qvi_hwloc_bitmap_asprintf() failed";
214214
ctu_panic("%s (rc=%s)", ers, qv_strerr(rc));

tests/internal/test-rmi.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ client(
112112
}
113113

114114
char *res;
115-
qvi_hwloc_bitmap_asprintf(bitmap, &res);
115+
qvi_hwloc_bitmap_asprintf(NULL, bitmap, &res);
116116
printf("# [%d] cpubind = %s\n", who, res);
117117
hwloc_bitmap_free(bitmap);
118118
free(res);

0 commit comments

Comments
 (0)