Skip to content

Commit

Permalink
Checkpoint hardware pool work with cleanups. (#250)
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov>
  • Loading branch information
samuelkgutierrez authored Jul 26, 2024
1 parent 4a65370 commit 4c3ef21
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 85 deletions.
77 changes: 6 additions & 71 deletions src/qvi-bbuff-rmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ qvi_bbuff_rmi_get_picture
(
std::string &picture,
T&& arg,
Types&&... args
Types &&...args
) {
qvi_bbuff_rmi_pack_type_picture(picture, std::forward<T>(arg));
qvi_bbuff_rmi_get_picture(picture, std::forward<Types>(args)...);
Expand Down Expand Up @@ -523,24 +523,7 @@ qvi_bbuff_rmi_pack_item(
qvi_bbuff_t *buff,
qvi_hwpool_dev_s *data
) {
// TODO(skg) Move to device code.
// Pack device hints.
int rc = qvi_bbuff_rmi_pack_item(buff, data->hints);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
// Pack device affinity.
rc = qvi_bbuff_rmi_pack_item(buff, data->affinity);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
// Pack device type.
rc = qvi_bbuff_rmi_pack_item(buff, data->type);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
// Pack device ID.
rc = qvi_bbuff_rmi_pack_item(buff, data->m_id);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
// Pack device PCI bus ID.
rc = qvi_bbuff_rmi_pack_item(buff, data->pci_bus_id);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
// Pack device UUID.
return qvi_bbuff_rmi_pack_item(buff, data->uuid);
return data->packinto(buff);
}

/**
Expand All @@ -551,7 +534,7 @@ qvi_bbuff_rmi_pack_item_impl(
qvi_bbuff_t *buff,
const qvi_hwpool_s *data
) {
return data->packto(buff);
return data->packinto(buff);
}

/**
Expand All @@ -578,7 +561,7 @@ inline int
qvi_bbuff_rmi_pack(
qvi_bbuff_t *buff,
T&& arg,
Types&&... args
Types &&...args
) {
const int rc = qvi_bbuff_rmi_pack_item(buff, std::forward<T>(arg));
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
Expand Down Expand Up @@ -873,55 +856,7 @@ qvi_bbuff_rmi_unpack_item(
byte_t *buffpos,
size_t *bytes_written
) {
// TODO(skg) Move to dev code.
size_t bw = 0, total_bw = 0;

int rc = qvi_bbuff_rmi_unpack_item(
&dev->hints, buffpos, &bw
);
if (rc != QV_SUCCESS) goto out;
total_bw += bw;
buffpos += bw;

rc = qvi_bbuff_rmi_unpack_item(
dev->affinity, buffpos, &bw
);
if (rc != QV_SUCCESS) goto out;
total_bw += bw;
buffpos += bw;

rc = qvi_bbuff_rmi_unpack_item(
&dev->type, buffpos, &bw
);
if (rc != QV_SUCCESS) goto out;
total_bw += bw;
buffpos += bw;

rc = qvi_bbuff_rmi_unpack_item(
&dev->m_id, buffpos, &bw
);
if (rc != QV_SUCCESS) goto out;
total_bw += bw;
buffpos += bw;

rc = qvi_bbuff_rmi_unpack_item(
dev->pci_bus_id, buffpos, &bw
);
if (rc != QV_SUCCESS) goto out;
total_bw += bw;
buffpos += bw;

rc = qvi_bbuff_rmi_unpack_item(
dev->uuid, buffpos, &bw
);
if (rc != QV_SUCCESS) goto out;
total_bw += bw;
out:
if (rc != QV_SUCCESS) {
total_bw = 0;
}
*bytes_written = total_bw;
return rc;
return qvi_hwpool_dev_s::unpack(buffpos, bytes_written, dev);
}

/**
Expand Down Expand Up @@ -951,7 +886,7 @@ inline int
qvi_bbuff_rmi_unpack(
void *data,
T&& arg,
Types&&... args
Types &&...args
) {
byte_t *pos = (byte_t *)data;
size_t bytes_written = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/qvi-bbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ struct qvi_bbuff_s {
);
/** Destructor. */
~qvi_bbuff_s(void);
/** Assignment operator. */
void
operator=(const qvi_bbuff_s &src) = delete;
/** Returns the size of the data stored in the byte buffer. */
size_t
size(void) const;
Expand Down
102 changes: 100 additions & 2 deletions src/qvi-hwpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,25 @@ pool_release_cpus_by_cpuset(
}
#endif

qvi_hwpool_dev_s::qvi_hwpool_dev_s(
const qvi_hwloc_device_s &dev
) : type(dev.type)
, affinity(dev.affinity)
, m_id(dev.id)
, pci_bus_id(dev.pci_bus_id)
, uuid(dev.uuid) { }

qvi_hwpool_dev_s::qvi_hwpool_dev_s(
const std::shared_ptr<qvi_hwloc_device_s> &shdev
) : qvi_hwpool_dev_s(*shdev.get()) { }

bool
qvi_hwpool_dev_s::operator==(
const qvi_hwpool_dev_s &x
) const {
return uuid == x.uuid;
}

int
qvi_hwpool_dev_s::id(
qv_device_id_type_t format,
Expand Down Expand Up @@ -162,6 +181,85 @@ qvi_hwpool_dev_s::id(
return rc;
}

int
qvi_hwpool_dev_s::packinto(
qvi_bbuff_t *buff
) const {
// Pack device hints.
int rc = qvi_bbuff_rmi_pack_item(buff, hints);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
// Pack device affinity.
rc = qvi_bbuff_rmi_pack_item(buff, affinity);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
// Pack device type.
rc = qvi_bbuff_rmi_pack_item(buff, type);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
// Pack device ID.
rc = qvi_bbuff_rmi_pack_item(buff, m_id);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
// Pack device PCI bus ID.
rc = qvi_bbuff_rmi_pack_item(buff, pci_bus_id);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
// Pack device UUID.
return qvi_bbuff_rmi_pack_item(buff, uuid);
}

int
qvi_hwpool_dev_s::unpack(
byte_t *buffpos,
size_t *bytes_written,
qvi_hwpool_dev_s *dev
) {
size_t bw = 0, total_bw = 0;

int rc = qvi_bbuff_rmi_unpack_item(
&dev->hints, buffpos, &bw
);
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
total_bw += bw;
buffpos += bw;

rc = qvi_bbuff_rmi_unpack_item(
dev->affinity, buffpos, &bw
);
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
total_bw += bw;
buffpos += bw;

rc = qvi_bbuff_rmi_unpack_item(
&dev->type, buffpos, &bw
);
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
total_bw += bw;
buffpos += bw;

rc = qvi_bbuff_rmi_unpack_item(
&dev->m_id, buffpos, &bw
);
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
total_bw += bw;
buffpos += bw;

rc = qvi_bbuff_rmi_unpack_item(
dev->pci_bus_id, buffpos, &bw
);
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
total_bw += bw;
buffpos += bw;

rc = qvi_bbuff_rmi_unpack_item(
dev->uuid, buffpos, &bw
);
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
total_bw += bw;
out:
if (qvi_unlikely(rc != QV_SUCCESS)) {
total_bw = 0;
}
*bytes_written = total_bw;
return rc;
}

int
qvi_hwpool_s::add_devices_with_affinity(
qvi_hwloc_t *hwloc
Expand Down Expand Up @@ -256,7 +354,7 @@ qvi_hwpool_s::release_devices(void)
}

int
qvi_hwpool_s::packto(
qvi_hwpool_s::packinto(
qvi_bbuff_t *buff
) const {
// Pack the CPU.
Expand Down Expand Up @@ -309,7 +407,7 @@ qvi_hwpool_s::unpack(
if (qvi_unlikely(rc != QV_SUCCESS)) break;
total_bw += bw;
buffpos += bw;
//
// Add the unpacked device.
rc = ihwp->add_device(dev);
if (qvi_unlikely(rc != QV_SUCCESS)) break;
}
Expand Down
30 changes: 20 additions & 10 deletions src/qvi-hwpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,40 @@ struct qvi_hwpool_dev_s : qvi_hwpool_res_s {
/** Constructor using qvi_hwloc_device_s. */
explicit qvi_hwpool_dev_s(
const qvi_hwloc_device_s &dev
) : type(dev.type)
, affinity(dev.affinity)
, m_id(dev.id)
, pci_bus_id(dev.pci_bus_id)
, uuid(dev.uuid) { }
);
/** Constructor using std::shared_ptr<qvi_hwloc_device_s>. */
explicit qvi_hwpool_dev_s(
const std::shared_ptr<qvi_hwloc_device_s> &shdev
) : qvi_hwpool_dev_s(*shdev.get()) { }
);
/** Destructor. */
virtual ~qvi_hwpool_dev_s(void) = default;
/** Equality operator. */
bool
operator==(
const qvi_hwpool_dev_s &x
) const {
return uuid == x.uuid;
}
) const;
/** Returns the device's ID string formatted as specified. */
int
id(
qv_device_id_type_t format,
char **result
);
/**
* Packs the instance into the provided buffer.
*/
int
packinto(
qvi_bbuff_t *buff
) const;
/**
* Unpacks the buffer and creates a new hardware pool device instance.
*/
static int
unpack(
byte_t *buffpos,
size_t *bytes_written,
qvi_hwpool_dev_s *dev
);
};

/**
Expand Down Expand Up @@ -158,7 +168,7 @@ struct qvi_hwpool_s {
* Packs the instance into the provided buffer.
*/
int
packto(
packinto(
qvi_bbuff_t *buff
) const;
/**
Expand Down
4 changes: 2 additions & 2 deletions src/qvi-scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ gather_hwpools(
const uint_t group_size = group->size();
// Pack the hardware pool into a buffer.
qvi_bbuff_t txbuff;
int rc = txpool->packto(&txbuff);
int rc = txpool->packinto(&txbuff);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
// Gather the values to the root.
bool shared = false;
Expand Down Expand Up @@ -416,7 +416,7 @@ scatter_hwpools(
rc = qvi_bbuff_new(&txbuffs[i]);
if (rc != QV_SUCCESS) break;

rc = pools[i]->packto(txbuffs[i]);
rc = pools[i]->packinto(txbuffs[i]);
if (rc != QV_SUCCESS) break;
}
if (rc != QV_SUCCESS) goto out;
Expand Down

0 comments on commit 4c3ef21

Please sign in to comment.