From a61a05990ac7d62614c0fdbea8b5c42329fc0a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20K=2E=20Guti=C3=A9rrez?= Date: Thu, 18 Apr 2024 15:56:22 -0600 Subject: [PATCH] Checkpoint new scope splitting work. (#108) Signed-off-by: Samuel K. Gutierrez --- src/qvi-hwloc.h | 7 +++++-- src/qvi-hwpool.cc | 25 ++++++++++++++++++++++ src/qvi-hwpool.h | 11 ++++++++++ src/qvi-scope.cc | 53 ++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 93 insertions(+), 3 deletions(-) diff --git a/src/qvi-hwloc.h b/src/qvi-hwloc.h index c79a0e92..0e7708ae 100644 --- a/src/qvi-hwloc.h +++ b/src/qvi-hwloc.h @@ -430,12 +430,15 @@ struct qvi_hwloc_bitmap_s { { qvi_hwloc_bitmap_free(&data); } - /** Assignment operator. */ + /** + * Assignment operator. + * + * Check qvim_rc on the LHS after assignment to verify status. + */ void operator=(const qvi_hwloc_bitmap_s &src) { qvim_rc = qvi_hwloc_bitmap_copy(src.data, data); - assert(qvim_rc == QV_SUCCESS); } }; diff --git a/src/qvi-hwpool.cc b/src/qvi-hwpool.cc index c2026441..f333eb0b 100644 --- a/src/qvi-hwpool.cc +++ b/src/qvi-hwpool.cc @@ -94,6 +94,31 @@ qvi_hwpool_free( qvi_delete(rpool); } +int +qvi_hwpool_dup( + const qvi_hwpool_t *const rpool, + qvi_hwpool_t **dup +) { + qvi_hwpool_t *idup = nullptr; + int rc = qvi_hwpool_new(&idup); + if (rc != QV_SUCCESS) goto out; + // This performs a deep copy of the underlying CPUs. + idup->cpus = rpool->cpus; + // Assignment here sets qvim_rc, so check it. + if (idup->qvim_rc != QV_SUCCESS) { + rc = idup->qvim_rc; + goto out; + } + // This performs a deep copy of the underlying device infos. + idup->devinfos = rpool->devinfos; +out: + if (rc != QV_SUCCESS) { + qvi_hwpool_free(&idup); + } + *dup = idup; + return rc; +} + int qvi_hwpool_new_from_line( qvi_line_hwpool_t *line, diff --git a/src/qvi-hwpool.h b/src/qvi-hwpool.h index 5bcc70cb..a0ab397d 100644 --- a/src/qvi-hwpool.h +++ b/src/qvi-hwpool.h @@ -88,6 +88,8 @@ struct qvi_hwpool_devinfo_s { std::string uuid; /** The bitmap encoding CPU affinity. */ qvi_hwloc_bitmap_t affinity; + /** No default constructor. */ + qvi_hwpool_devinfo_s(void) = delete; /** Constructor */ qvi_hwpool_devinfo_s( qv_hw_obj_type_t type, @@ -153,6 +155,15 @@ qvi_hwpool_free( qvi_hwpool_t **pool ); +/** + * + */ +int +qvi_hwpool_dup( + const qvi_hwpool_t *const rpool, + qvi_hwpool_t **dup +); + /** * */ diff --git a/src/qvi-scope.cc b/src/qvi-scope.cc index be7ef977..bfae8d88 100644 --- a/src/qvi-scope.cc +++ b/src/qvi-scope.cc @@ -105,7 +105,6 @@ struct qvi_scope_split_agg_s { qvi_hwloc_bitmap_free(&cpuset); } affinities.clear(); - } }; @@ -1144,6 +1143,58 @@ qvi_scope_split( return rc; } +#if 0 +int +qvi_scope_ksplit( + qv_scope_t *parent, + int npieces, + int *colors, + uint_t k, + qv_hw_obj_type_t maybe_obj_type, + qv_scope_t **children +) { + int rc = QV_SUCCESS, colorp = 0; + qvi_hwpool_t *hwpool = nullptr; + qvi_group_t *group = nullptr; + qv_scope_t *ichild = nullptr; + + qvi_scope_split_agg_s splitagg{}; + splitagg.rmi = parent->rmi; + splitagg.base_hwpool = parent->hwpool; + splitagg.split_size = npieces; + splitagg.group_size = k; + splitagg.split_at_type = maybe_obj_type; + splitagg.colors = std::vector(colors, colors + k); + for (uint_t i = 0; i < k; ++i) { + qvi_hwpool_t *hwp = nullptr; + rc = qvi_hwpool_dup(parent->hwpool, &hwp); + if (rc != QV_SUCCESS) goto out; + splitagg.hwpools.push_back(hwp); + } + // Split the hardware resources based on the provided split parameters. + rc = agg_split(splitagg); + if (rc != QV_SUCCESS) goto out; + // Split underlying group. Notice the use of colorp here. + rc = parent->group->split( + colorp, parent->group->id(), &group + ); + if (rc != QV_SUCCESS) goto out; + // Create and initialize the new scope. + rc = qvi_scope_new(&ichild); + if (rc != QV_SUCCESS) goto out; + + rc = scope_init(ichild, parent->rmi, group, hwpool); +out: + if (rc != QV_SUCCESS) { + qvi_scope_free(&ichild); + qvi_group_free(&group); + qvi_hwpool_free(&hwpool); + } + *children = ichild; + return rc; +} +#endif + int qvi_scope_split_at( qv_scope_t *parent,