Skip to content

Commit

Permalink
Logical binding ouptut
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Mercier <[email protected]>
  • Loading branch information
GuillaumeMercier committed Feb 14, 2025
1 parent de1c932 commit a65a6de
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/qvi-bbuff-rmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ qvi_bbuff_rmi_pack_item_impl(
}
// Non-null data.
char *datas = nullptr;
int rc = qvi_hwloc_bitmap_asprintf(data, &datas);
int rc = qvi_hwloc_bitmap_asprintf(NULL, data, &datas);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
// We are sending the string representation of the cpuset.
rc = buff->append(datas, strlen(datas) + 1);
Expand Down
79 changes: 72 additions & 7 deletions src/qvi-hwloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,16 @@ qvi_hwloc_obj_type_is_host_resource(

int
qvi_hwloc_bitmap_string(
hwloc_topology_t topo,
hwloc_const_bitmap_t bitmap,
qv_bind_string_format_t format,
char **result
) {
switch (format) {
case QV_BIND_STRING_AS_BITMAP:
return qvi_hwloc_bitmap_asprintf(bitmap, result);
return qvi_hwloc_bitmap_asprintf(topo, bitmap, result);
case QV_BIND_STRING_AS_LIST:
return qvi_hwloc_bitmap_list_asprintf(bitmap, result);
return qvi_hwloc_bitmap_list_asprintf(topo, bitmap, result);
default:
*result = nullptr;
return QV_ERR_INVLD_ARG;
Expand Down Expand Up @@ -816,11 +817,11 @@ qvi_hwloc_emit_cpubind(
if (rc != QV_SUCCESS) return rc;

char *cpusets = nullptr;
rc = qvi_hwloc_bitmap_asprintf(cpuset, &cpusets);
rc = qvi_hwloc_bitmap_asprintf(hwl->topo, cpuset, &cpusets);
if (rc != QV_SUCCESS) goto out;

qvi_log_info(
"[pid={} tid={}] cpubind={}",
"[pid={} tid={}] cpubind (physical) = {}",
getpid(), task_id, cpusets
);
out:
Expand All @@ -831,6 +832,7 @@ qvi_hwloc_emit_cpubind(

int
qvi_hwloc_bitmap_asprintf(
hwloc_topology_t topo,
hwloc_const_cpuset_t cpuset,
char **result
) {
Expand All @@ -840,12 +842,44 @@ qvi_hwloc_bitmap_asprintf(
qvi_log_error("hwloc_bitmap_asprintf() failed");
return QV_ERR_OOR;
}

if (topo) {
hwloc_bitmap_t cpuset_logical = hwloc_bitmap_alloc();
hwloc_obj_t obj_pu = nullptr;

int num_pus = hwloc_get_nbobjs_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU);
for(int idx = 0; idx < num_pus ; idx++){
obj_pu = hwloc_get_next_obj_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU, obj_pu);
(void)hwloc_bitmap_set(cpuset_logical,obj_pu->logical_index);
}

char *iresult_logical = nullptr;
(void)hwloc_bitmap_list_asprintf(&iresult_logical, cpuset_logical);
if (qvi_unlikely(!iresult_logical)) {
qvi_log_error("hwloc_bitmap_list_asprintf() failed");
return QV_ERR_OOR;
}
(void)hwloc_bitmap_free(cpuset_logical);

char head[] = " | (logical) = ";
char *final_result = (char*)calloc(strlen(iresult)+
strlen(head)+
strlen(iresult_logical)+1,sizeof(char));
memcpy(final_result,iresult,strlen(iresult));
strcat(final_result,head);
strcat(final_result,iresult_logical);
free(iresult_logical);
free(iresult);
iresult = final_result;
}

*result = iresult;
return QV_SUCCESS;
}

int
qvi_hwloc_bitmap_list_asprintf(
hwloc_topology_t topo,
hwloc_const_cpuset_t cpuset,
char **result
) {
Expand All @@ -855,6 +889,37 @@ qvi_hwloc_bitmap_list_asprintf(
qvi_log_error("hwloc_bitmap_list_asprintf() failed");
return QV_ERR_OOR;
}

if (topo) {
hwloc_bitmap_t cpuset_logical = hwloc_bitmap_alloc();
hwloc_obj_t obj_pu = nullptr;

int num_pus = hwloc_get_nbobjs_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU);
for(int idx = 0; idx < num_pus ; idx++){
obj_pu = hwloc_get_next_obj_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU, obj_pu);
(void)hwloc_bitmap_set(cpuset_logical,obj_pu->logical_index);
}

char *iresult_logical = nullptr;
(void)hwloc_bitmap_list_asprintf(&iresult_logical, cpuset_logical);
if (qvi_unlikely(!iresult_logical)) {
qvi_log_error("hwloc_bitmap_list_asprintf() failed");
return QV_ERR_OOR;
}
(void)hwloc_bitmap_free(cpuset_logical);

char head[] = " | (logical) = ";
char *final_result = (char*)calloc(strlen(iresult)+
strlen(head)+
strlen(iresult_logical)+1,sizeof(char));
memcpy(final_result,iresult,strlen(iresult));
strcat(final_result,head);
strcat(final_result,iresult_logical);
free(iresult_logical);
free(iresult);
iresult = final_result;
}

*result = iresult;
return QV_SUCCESS;
}
Expand All @@ -869,7 +934,7 @@ qvi_hwloc_cpuset_debug(
#endif
assert(cpuset);
char *cpusets = nullptr;
int rc = qvi_hwloc_bitmap_asprintf(cpuset, &cpusets);
int rc = qvi_hwloc_bitmap_asprintf(nullptr, cpuset, &cpusets);
if (rc != QV_SUCCESS) {
qvi_abort();
}
Expand Down Expand Up @@ -957,7 +1022,7 @@ qvi_hwloc_task_get_cpubind_as_string(
int rc = qvi_hwloc_task_get_cpubind(hwl, task_id, &cpuset);
if (rc != QV_SUCCESS) return rc;

rc = qvi_hwloc_bitmap_asprintf(cpuset, cpusets);
rc = qvi_hwloc_bitmap_asprintf(hwl->topo, cpuset, cpusets);
qvi_hwloc_bitmap_delete(&cpuset);
return rc;
}
Expand Down Expand Up @@ -1185,7 +1250,7 @@ qvi_hwloc_devices_emit(
}
for (auto &dev : *devlist) {
char *cpusets = nullptr;
int rc = qvi_hwloc_bitmap_asprintf(dev->affinity.cdata(), &cpusets);
int rc = qvi_hwloc_bitmap_asprintf(hwl->topo, dev->affinity.cdata(), &cpusets);
if (rc != QV_SUCCESS) return rc;

qvi_log_info(" Device Name: {}", dev->name);
Expand Down
3 changes: 3 additions & 0 deletions src/qvi-hwloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ qvi_hwloc_emit_cpubind(
*/
int
qvi_hwloc_bitmap_asprintf(
hwloc_topology_t topo,
hwloc_const_cpuset_t cpuset,
char **result
);
Expand All @@ -196,6 +197,7 @@ qvi_hwloc_bitmap_asprintf(
*/
int
qvi_hwloc_bitmap_list_asprintf(
hwloc_topology_t topo,
hwloc_const_cpuset_t cpuset,
char **result
);
Expand Down Expand Up @@ -537,6 +539,7 @@ qvi_hwloc_get_devices_in_bitmap(

int
qvi_hwloc_bitmap_string(
hwloc_topology_t topo,
hwloc_const_bitmap_t bitmap,
qv_bind_string_format_t format,
char **result
Expand Down
4 changes: 3 additions & 1 deletion src/qvi-scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ qv_scope::bind_string(
int rc = m_group->task()->bind_top(&bitmap);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;

rc = qvi_hwloc_bitmap_string(bitmap, format, result);
hwloc_topology_t topo = qvi_hwloc_get_topo_obj(m_group->hwloc());

rc = qvi_hwloc_bitmap_string(topo, bitmap, format, result);
qvi_hwloc_bitmap_delete(&bitmap);
return rc;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/common-test-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ctu_emit_task_bind(
ers = "qv_bind_string() failed";
ctu_panic("%s (rc=%s)", ers, qv_strerr(rc));
}
printf("[%d] cpubind=%s\n", pid, binds);
printf("[%d] cpubind (physical) = %s\n", pid, binds);
free(binds);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/internal/test-hwloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ main(void)
ctu_panic("%s (rc=%s)", ers, qv_strerr(rc));
}

rc = qvi_hwloc_bitmap_asprintf(bitmap, &binds);
rc = qvi_hwloc_bitmap_asprintf(NULL, bitmap, &binds);
if (rc != QV_SUCCESS) {
ers = "qvi_hwloc_bitmap_asprintf() failed";
ctu_panic("%s (rc=%s)", ers, qv_strerr(rc));
Expand Down
2 changes: 1 addition & 1 deletion tests/internal/test-rmi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ client(
}

char *res;
qvi_hwloc_bitmap_asprintf(bitmap, &res);
qvi_hwloc_bitmap_asprintf(NULL, bitmap, &res);
printf("# [%d] cpubind = %s\n", who, res);
hwloc_bitmap_free(bitmap);
free(res);
Expand Down

0 comments on commit a65a6de

Please sign in to comment.