Skip to content

Commit 4c3ef21

Browse files
Checkpoint hardware pool work with cleanups. (#250)
Signed-off-by: Samuel K. Gutierrez <[email protected]>
1 parent 4a65370 commit 4c3ef21

File tree

5 files changed

+131
-85
lines changed

5 files changed

+131
-85
lines changed

src/qvi-bbuff-rmi.h

+6-71
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ qvi_bbuff_rmi_get_picture
277277
(
278278
std::string &picture,
279279
T&& arg,
280-
Types&&... args
280+
Types &&...args
281281
) {
282282
qvi_bbuff_rmi_pack_type_picture(picture, std::forward<T>(arg));
283283
qvi_bbuff_rmi_get_picture(picture, std::forward<Types>(args)...);
@@ -523,24 +523,7 @@ qvi_bbuff_rmi_pack_item(
523523
qvi_bbuff_t *buff,
524524
qvi_hwpool_dev_s *data
525525
) {
526-
// TODO(skg) Move to device code.
527-
// Pack device hints.
528-
int rc = qvi_bbuff_rmi_pack_item(buff, data->hints);
529-
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
530-
// Pack device affinity.
531-
rc = qvi_bbuff_rmi_pack_item(buff, data->affinity);
532-
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
533-
// Pack device type.
534-
rc = qvi_bbuff_rmi_pack_item(buff, data->type);
535-
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
536-
// Pack device ID.
537-
rc = qvi_bbuff_rmi_pack_item(buff, data->m_id);
538-
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
539-
// Pack device PCI bus ID.
540-
rc = qvi_bbuff_rmi_pack_item(buff, data->pci_bus_id);
541-
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
542-
// Pack device UUID.
543-
return qvi_bbuff_rmi_pack_item(buff, data->uuid);
526+
return data->packinto(buff);
544527
}
545528

546529
/**
@@ -551,7 +534,7 @@ qvi_bbuff_rmi_pack_item_impl(
551534
qvi_bbuff_t *buff,
552535
const qvi_hwpool_s *data
553536
) {
554-
return data->packto(buff);
537+
return data->packinto(buff);
555538
}
556539

557540
/**
@@ -578,7 +561,7 @@ inline int
578561
qvi_bbuff_rmi_pack(
579562
qvi_bbuff_t *buff,
580563
T&& arg,
581-
Types&&... args
564+
Types &&...args
582565
) {
583566
const int rc = qvi_bbuff_rmi_pack_item(buff, std::forward<T>(arg));
584567
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
@@ -873,55 +856,7 @@ qvi_bbuff_rmi_unpack_item(
873856
byte_t *buffpos,
874857
size_t *bytes_written
875858
) {
876-
// TODO(skg) Move to dev code.
877-
size_t bw = 0, total_bw = 0;
878-
879-
int rc = qvi_bbuff_rmi_unpack_item(
880-
&dev->hints, buffpos, &bw
881-
);
882-
if (rc != QV_SUCCESS) goto out;
883-
total_bw += bw;
884-
buffpos += bw;
885-
886-
rc = qvi_bbuff_rmi_unpack_item(
887-
dev->affinity, buffpos, &bw
888-
);
889-
if (rc != QV_SUCCESS) goto out;
890-
total_bw += bw;
891-
buffpos += bw;
892-
893-
rc = qvi_bbuff_rmi_unpack_item(
894-
&dev->type, buffpos, &bw
895-
);
896-
if (rc != QV_SUCCESS) goto out;
897-
total_bw += bw;
898-
buffpos += bw;
899-
900-
rc = qvi_bbuff_rmi_unpack_item(
901-
&dev->m_id, buffpos, &bw
902-
);
903-
if (rc != QV_SUCCESS) goto out;
904-
total_bw += bw;
905-
buffpos += bw;
906-
907-
rc = qvi_bbuff_rmi_unpack_item(
908-
dev->pci_bus_id, buffpos, &bw
909-
);
910-
if (rc != QV_SUCCESS) goto out;
911-
total_bw += bw;
912-
buffpos += bw;
913-
914-
rc = qvi_bbuff_rmi_unpack_item(
915-
dev->uuid, buffpos, &bw
916-
);
917-
if (rc != QV_SUCCESS) goto out;
918-
total_bw += bw;
919-
out:
920-
if (rc != QV_SUCCESS) {
921-
total_bw = 0;
922-
}
923-
*bytes_written = total_bw;
924-
return rc;
859+
return qvi_hwpool_dev_s::unpack(buffpos, bytes_written, dev);
925860
}
926861

927862
/**
@@ -951,7 +886,7 @@ inline int
951886
qvi_bbuff_rmi_unpack(
952887
void *data,
953888
T&& arg,
954-
Types&&... args
889+
Types &&...args
955890
) {
956891
byte_t *pos = (byte_t *)data;
957892
size_t bytes_written = 0;

src/qvi-bbuff.h

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ struct qvi_bbuff_s {
4040
);
4141
/** Destructor. */
4242
~qvi_bbuff_s(void);
43+
/** Assignment operator. */
44+
void
45+
operator=(const qvi_bbuff_s &src) = delete;
4346
/** Returns the size of the data stored in the byte buffer. */
4447
size_t
4548
size(void) const;

src/qvi-hwpool.cc

+100-2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ pool_release_cpus_by_cpuset(
134134
}
135135
#endif
136136

137+
qvi_hwpool_dev_s::qvi_hwpool_dev_s(
138+
const qvi_hwloc_device_s &dev
139+
) : type(dev.type)
140+
, affinity(dev.affinity)
141+
, m_id(dev.id)
142+
, pci_bus_id(dev.pci_bus_id)
143+
, uuid(dev.uuid) { }
144+
145+
qvi_hwpool_dev_s::qvi_hwpool_dev_s(
146+
const std::shared_ptr<qvi_hwloc_device_s> &shdev
147+
) : qvi_hwpool_dev_s(*shdev.get()) { }
148+
149+
bool
150+
qvi_hwpool_dev_s::operator==(
151+
const qvi_hwpool_dev_s &x
152+
) const {
153+
return uuid == x.uuid;
154+
}
155+
137156
int
138157
qvi_hwpool_dev_s::id(
139158
qv_device_id_type_t format,
@@ -162,6 +181,85 @@ qvi_hwpool_dev_s::id(
162181
return rc;
163182
}
164183

184+
int
185+
qvi_hwpool_dev_s::packinto(
186+
qvi_bbuff_t *buff
187+
) const {
188+
// Pack device hints.
189+
int rc = qvi_bbuff_rmi_pack_item(buff, hints);
190+
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
191+
// Pack device affinity.
192+
rc = qvi_bbuff_rmi_pack_item(buff, affinity);
193+
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
194+
// Pack device type.
195+
rc = qvi_bbuff_rmi_pack_item(buff, type);
196+
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
197+
// Pack device ID.
198+
rc = qvi_bbuff_rmi_pack_item(buff, m_id);
199+
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
200+
// Pack device PCI bus ID.
201+
rc = qvi_bbuff_rmi_pack_item(buff, pci_bus_id);
202+
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
203+
// Pack device UUID.
204+
return qvi_bbuff_rmi_pack_item(buff, uuid);
205+
}
206+
207+
int
208+
qvi_hwpool_dev_s::unpack(
209+
byte_t *buffpos,
210+
size_t *bytes_written,
211+
qvi_hwpool_dev_s *dev
212+
) {
213+
size_t bw = 0, total_bw = 0;
214+
215+
int rc = qvi_bbuff_rmi_unpack_item(
216+
&dev->hints, buffpos, &bw
217+
);
218+
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
219+
total_bw += bw;
220+
buffpos += bw;
221+
222+
rc = qvi_bbuff_rmi_unpack_item(
223+
dev->affinity, buffpos, &bw
224+
);
225+
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
226+
total_bw += bw;
227+
buffpos += bw;
228+
229+
rc = qvi_bbuff_rmi_unpack_item(
230+
&dev->type, buffpos, &bw
231+
);
232+
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
233+
total_bw += bw;
234+
buffpos += bw;
235+
236+
rc = qvi_bbuff_rmi_unpack_item(
237+
&dev->m_id, buffpos, &bw
238+
);
239+
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
240+
total_bw += bw;
241+
buffpos += bw;
242+
243+
rc = qvi_bbuff_rmi_unpack_item(
244+
dev->pci_bus_id, buffpos, &bw
245+
);
246+
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
247+
total_bw += bw;
248+
buffpos += bw;
249+
250+
rc = qvi_bbuff_rmi_unpack_item(
251+
dev->uuid, buffpos, &bw
252+
);
253+
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
254+
total_bw += bw;
255+
out:
256+
if (qvi_unlikely(rc != QV_SUCCESS)) {
257+
total_bw = 0;
258+
}
259+
*bytes_written = total_bw;
260+
return rc;
261+
}
262+
165263
int
166264
qvi_hwpool_s::add_devices_with_affinity(
167265
qvi_hwloc_t *hwloc
@@ -256,7 +354,7 @@ qvi_hwpool_s::release_devices(void)
256354
}
257355

258356
int
259-
qvi_hwpool_s::packto(
357+
qvi_hwpool_s::packinto(
260358
qvi_bbuff_t *buff
261359
) const {
262360
// Pack the CPU.
@@ -309,7 +407,7 @@ qvi_hwpool_s::unpack(
309407
if (qvi_unlikely(rc != QV_SUCCESS)) break;
310408
total_bw += bw;
311409
buffpos += bw;
312-
//
410+
// Add the unpacked device.
313411
rc = ihwp->add_device(dev);
314412
if (qvi_unlikely(rc != QV_SUCCESS)) break;
315413
}

src/qvi-hwpool.h

+20-10
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,40 @@ struct qvi_hwpool_dev_s : qvi_hwpool_res_s {
5656
/** Constructor using qvi_hwloc_device_s. */
5757
explicit qvi_hwpool_dev_s(
5858
const qvi_hwloc_device_s &dev
59-
) : type(dev.type)
60-
, affinity(dev.affinity)
61-
, m_id(dev.id)
62-
, pci_bus_id(dev.pci_bus_id)
63-
, uuid(dev.uuid) { }
59+
);
6460
/** Constructor using std::shared_ptr<qvi_hwloc_device_s>. */
6561
explicit qvi_hwpool_dev_s(
6662
const std::shared_ptr<qvi_hwloc_device_s> &shdev
67-
) : qvi_hwpool_dev_s(*shdev.get()) { }
63+
);
6864
/** Destructor. */
6965
virtual ~qvi_hwpool_dev_s(void) = default;
7066
/** Equality operator. */
7167
bool
7268
operator==(
7369
const qvi_hwpool_dev_s &x
74-
) const {
75-
return uuid == x.uuid;
76-
}
70+
) const;
7771
/** Returns the device's ID string formatted as specified. */
7872
int
7973
id(
8074
qv_device_id_type_t format,
8175
char **result
8276
);
77+
/**
78+
* Packs the instance into the provided buffer.
79+
*/
80+
int
81+
packinto(
82+
qvi_bbuff_t *buff
83+
) const;
84+
/**
85+
* Unpacks the buffer and creates a new hardware pool device instance.
86+
*/
87+
static int
88+
unpack(
89+
byte_t *buffpos,
90+
size_t *bytes_written,
91+
qvi_hwpool_dev_s *dev
92+
);
8393
};
8494

8595
/**
@@ -158,7 +168,7 @@ struct qvi_hwpool_s {
158168
* Packs the instance into the provided buffer.
159169
*/
160170
int
161-
packto(
171+
packinto(
162172
qvi_bbuff_t *buff
163173
) const;
164174
/**

src/qvi-scope.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ gather_hwpools(
319319
const uint_t group_size = group->size();
320320
// Pack the hardware pool into a buffer.
321321
qvi_bbuff_t txbuff;
322-
int rc = txpool->packto(&txbuff);
322+
int rc = txpool->packinto(&txbuff);
323323
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
324324
// Gather the values to the root.
325325
bool shared = false;
@@ -416,7 +416,7 @@ scatter_hwpools(
416416
rc = qvi_bbuff_new(&txbuffs[i]);
417417
if (rc != QV_SUCCESS) break;
418418

419-
rc = pools[i]->packto(txbuffs[i]);
419+
rc = pools[i]->packinto(txbuffs[i]);
420420
if (rc != QV_SUCCESS) break;
421421
}
422422
if (rc != QV_SUCCESS) goto out;

0 commit comments

Comments
 (0)