Skip to content

Commit 8a5f8bc

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

File tree

6 files changed

+58
-10
lines changed

6 files changed

+58
-10
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

+49-6
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,7 +817,7 @@ 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(
@@ -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,33 @@ qvi_hwloc_bitmap_asprintf(
840842
qvi_log_error("hwloc_bitmap_asprintf() failed");
841843
return QV_ERR_OOR;
842844
}
845+
846+
if (topo) {
847+
int num_pus = hwloc_get_nbobjs_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU);
848+
hwloc_obj_t obj_pu = NULL;
849+
char str[128] = {0};
850+
sprintf(str,"%s"," | cpubind (logical)=[");
851+
for(int idx = 0; idx < num_pus ; idx++){
852+
char str2[64] = {0};
853+
obj_pu = hwloc_get_next_obj_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU, obj_pu);
854+
sprintf(str2,"%i%s",obj_pu->logical_index, idx == (num_pus-1) ? "]" :",");
855+
strcat(str,str2);
856+
}
857+
858+
char *newstr = (char *)malloc(sizeof(char)*(strlen(str)+strlen(iresult)+1));
859+
strcpy(newstr,iresult);
860+
strcat(newstr,str);
861+
free(iresult);
862+
iresult = newstr;
863+
}
864+
843865
*result = iresult;
844866
return QV_SUCCESS;
845867
}
846868

847869
int
848870
qvi_hwloc_bitmap_list_asprintf(
871+
hwloc_topology_t topo,
849872
hwloc_const_cpuset_t cpuset,
850873
char **result
851874
) {
@@ -855,6 +878,26 @@ qvi_hwloc_bitmap_list_asprintf(
855878
qvi_log_error("hwloc_bitmap_list_asprintf() failed");
856879
return QV_ERR_OOR;
857880
}
881+
882+
if (topo) {
883+
int num_pus = hwloc_get_nbobjs_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU);
884+
hwloc_obj_t obj_pu = NULL;
885+
char str[128] = {0};
886+
sprintf(str,"%s"," | cpubind (logical)=[");
887+
for(int idx = 0; idx < num_pus ; idx++){
888+
char str2[64] = {0};
889+
obj_pu = hwloc_get_next_obj_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU, obj_pu);
890+
sprintf(str2,"%i%s",obj_pu->logical_index, idx == (num_pus-1) ? "]" :",");
891+
strcat(str,str2);
892+
}
893+
894+
char *newstr = (char *)malloc(sizeof(char)*(strlen(str)+strlen(iresult)+1));
895+
strcpy(newstr,iresult);
896+
strcat(newstr,str);
897+
free(iresult);
898+
iresult = newstr;
899+
}
900+
858901
*result = iresult;
859902
return QV_SUCCESS;
860903
}
@@ -869,7 +912,7 @@ qvi_hwloc_cpuset_debug(
869912
#endif
870913
assert(cpuset);
871914
char *cpusets = nullptr;
872-
int rc = qvi_hwloc_bitmap_asprintf(cpuset, &cpusets);
915+
int rc = qvi_hwloc_bitmap_asprintf(NULL, cpuset, &cpusets);
873916
if (rc != QV_SUCCESS) {
874917
qvi_abort();
875918
}
@@ -957,7 +1000,7 @@ qvi_hwloc_task_get_cpubind_as_string(
9571000
int rc = qvi_hwloc_task_get_cpubind(hwl, task_id, &cpuset);
9581001
if (rc != QV_SUCCESS) return rc;
9591002

960-
rc = qvi_hwloc_bitmap_asprintf(cpuset, cpusets);
1003+
rc = qvi_hwloc_bitmap_asprintf(hwl->topo, cpuset, cpusets);
9611004
qvi_hwloc_bitmap_delete(&cpuset);
9621005
return rc;
9631006
}
@@ -1185,7 +1228,7 @@ qvi_hwloc_devices_emit(
11851228
}
11861229
for (auto &dev : *devlist) {
11871230
char *cpusets = nullptr;
1188-
int rc = qvi_hwloc_bitmap_asprintf(dev->affinity.cdata(), &cpusets);
1231+
int rc = qvi_hwloc_bitmap_asprintf(hwl->topo, dev->affinity.cdata(), &cpusets);
11891232
if (rc != QV_SUCCESS) return rc;
11901233

11911234
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/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)