diff --git a/src/qvi-bbuff-rmi.h b/src/qvi-bbuff-rmi.h index f044dc0..4839523 100644 --- a/src/qvi-bbuff-rmi.h +++ b/src/qvi-bbuff-rmi.h @@ -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(arg)); qvi_bbuff_rmi_get_picture(picture, std::forward(args)...); @@ -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); } /** @@ -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); } /** @@ -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(arg)); if (qvi_unlikely(rc != QV_SUCCESS)) return rc; @@ -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); } /** @@ -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; diff --git a/src/qvi-bbuff.h b/src/qvi-bbuff.h index c6e0814..b936209 100644 --- a/src/qvi-bbuff.h +++ b/src/qvi-bbuff.h @@ -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; diff --git a/src/qvi-hwpool.cc b/src/qvi-hwpool.cc index b98d3ac..c3c939e 100644 --- a/src/qvi-hwpool.cc +++ b/src/qvi-hwpool.cc @@ -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 &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, @@ -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 @@ -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. @@ -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; } diff --git a/src/qvi-hwpool.h b/src/qvi-hwpool.h index e026bdb..70fa82f 100644 --- a/src/qvi-hwpool.h +++ b/src/qvi-hwpool.h @@ -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. */ explicit qvi_hwpool_dev_s( const std::shared_ptr &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 + ); }; /** @@ -158,7 +168,7 @@ struct qvi_hwpool_s { * Packs the instance into the provided buffer. */ int - packto( + packinto( qvi_bbuff_t *buff ) const; /** diff --git a/src/qvi-scope.cc b/src/qvi-scope.cc index 6bfb6e4..266ad45 100644 --- a/src/qvi-scope.cc +++ b/src/qvi-scope.cc @@ -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; @@ -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;