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 0444ef7 commit e1cc7e4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 53 deletions.
94 changes: 42 additions & 52 deletions src/qvi-hwloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ qvi_hwloc_emit_cpubind(
if (rc != QV_SUCCESS) goto out;

qvi_log_info(
"[pid={} tid={}] cpubind (physical)=[{}",
"[pid={} tid={}] cpubind (physical) = {}",
getpid(), task_id, cpusets
);
out:
Expand All @@ -844,37 +844,32 @@ qvi_hwloc_bitmap_asprintf(
}

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);
int num_pus_cp = num_pus;

int num_digits = 1;
while(num_pus_cp /= 10) num_digits++;

char head[] = "] | (logical)=[";
int str_size = strlen(head)+num_pus*(num_digits+1)+1;
char *str = (char *)calloc(str_size,sizeof(char));

strcpy(str,head);

char *core_str = (char *)calloc(num_digits+2,sizeof(char));
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);
sprintf(core_str,"%i%s",obj_pu->logical_index, idx == (num_pus-1) ? "]" :",");
strcat(str,core_str);
memset(core_str,0,strlen(core_str));
(void)hwloc_bitmap_set(cpuset_logical,obj_pu->logical_index);
}

char *newstr = (char *)calloc(strlen(str)+strlen(iresult)+1,sizeof(char));
strcpy(newstr,iresult);
strcat(newstr,str);

free(core_str);
free(str);

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);

iresult = newstr;
iresult = final_result;
}

*result = iresult;
Expand All @@ -893,39 +888,34 @@ 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);
int num_pus_cp = num_pus;

int num_digits = 1;
while(num_pus_cp /= 10) num_digits++;

char head[] = "] | (logical)=[";
int str_size = strlen(head)+num_pus*(num_digits+1)+1;
char *str = (char *)calloc(str_size,sizeof(char));

strcpy(str,head);

char *core_str = (char *)calloc(num_digits+2,sizeof(char));
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);
sprintf(core_str,"%i%s",obj_pu->logical_index, idx == (num_pus-1) ? "]" :",");
strcat(str,core_str);
memset(core_str,0,strlen(core_str));
(void)hwloc_bitmap_set(cpuset_logical,obj_pu->logical_index);
}

char *newstr = (char *)calloc(strlen(str)+strlen(iresult)+1,sizeof(char));
strcpy(newstr,iresult);
strcat(newstr,str);

free(core_str);
free(str);

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);

iresult = newstr;
iresult = final_result;
}

*result = iresult;
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 (physical)=[%s\n", pid, binds);
printf("[%d] cpubind (physical) = %s\n", pid, binds);
free(binds);
}

Expand Down

0 comments on commit e1cc7e4

Please sign in to comment.