Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add qvi_hwloc_bitmap_dup() and use it. #93

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/qvi-hwloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -705,17 +705,32 @@ qvi_hwloc_bitmap_copy(
hwloc_const_cpuset_t src,
hwloc_cpuset_t dest
) {
if (!src || !dest) {
assert(false);
return QV_ERR_INTERNAL;
}
assert(src && dest);

if (hwloc_bitmap_copy(dest, src) != 0) {
return QV_ERR_HWLOC;
}
return QV_SUCCESS;
}

int
qvi_hwloc_bitmap_dup(
hwloc_const_cpuset_t src,
hwloc_cpuset_t *dest
) {
hwloc_cpuset_t idest = nullptr;
int rc = qvi_hwloc_bitmap_calloc(&idest);
if (rc != QV_SUCCESS) goto out;

rc = qvi_hwloc_bitmap_copy(src, idest);
out:
if (rc != QV_SUCCESS) {
qvi_hwloc_bitmap_free(&idest);
}
*dest = idest;
return rc;
}

int
qvi_hwloc_bitmap_nbits(
hwloc_const_cpuset_t cpuset,
Expand Down Expand Up @@ -1545,8 +1560,7 @@ qvi_hwloc_get_device_affinity(
// lists tend to be small, so just perform a linear search for the given ID.
for (const auto &dev : *devlist) {
if (dev->visdev_id != device_id) continue;
qvi_hwloc_bitmap_calloc(&icpuset);
rc = qvi_hwloc_bitmap_copy(dev->cpuset, icpuset);
rc = qvi_hwloc_bitmap_dup(dev->cpuset, &icpuset);
if (rc != QV_SUCCESS) goto out;
}
if (!icpuset) rc = QV_ERR_NOT_FOUND;
Expand Down
9 changes: 9 additions & 0 deletions src/qvi-hwloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ qvi_hwloc_bitmap_copy(
hwloc_cpuset_t dest
);

/**
*
*/
int
qvi_hwloc_bitmap_dup(
hwloc_const_cpuset_t src,
hwloc_cpuset_t *dest
);

/**
* Returns the number of bits required to represent a given cpuset.
*/
Expand Down
16 changes: 5 additions & 11 deletions src/qvi-hwpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,8 @@ qvi_hwpool_new_line_from_hwpool(
qvi_line_hwpool_t *iline = nullptr;
rc = qvi_line_hwpool_new(&iline);
if (rc != QV_SUCCESS) goto out;
// Initialize and copy the cpuset.
rc = qvi_hwloc_bitmap_calloc(&iline->cpuset);
if (rc != QV_SUCCESS) goto out;
rc = qvi_hwloc_bitmap_copy(rpool->cpus.cpuset, iline->cpuset);
// Duplicate the cpuset.
rc = qvi_hwloc_bitmap_dup(rpool->cpus.cpuset, &iline->cpuset);
if (rc != QV_SUCCESS) goto out;
// Initialize and fill in the device information.
iline->ndevinfos = ndevinfos;
Expand All @@ -192,14 +190,10 @@ qvi_hwpool_new_line_from_hwpool(
for (const auto &dinfo : rpool->devinfos) {
iline->devinfos[idx].type = dinfo.second->type;
iline->devinfos[idx].id = dinfo.second->id;
// Initialize and copy cpuset
rc = qvi_hwloc_bitmap_calloc(
&iline->devinfos[idx].affinity
);
if (rc != QV_SUCCESS) break;
rc = qvi_hwloc_bitmap_copy(
// Duplicate the cpuset
rc = qvi_hwloc_bitmap_dup(
dinfo.second->affinity,
iline->devinfos[idx].affinity
&iline->devinfos[idx].affinity
);
if (rc != QV_SUCCESS) break;
nw = asprintf(
Expand Down
Loading