From 0fa0df62e559ed1036fabedeaa9fa7d92f556f10 Mon Sep 17 00:00:00 2001 From: "Samuel K. Gutierrez" Date: Fri, 5 Jul 2024 20:05:13 -0600 Subject: [PATCH] Rework scope bind string code with cleanups. The task should return the top of its bind stack. Move the generation of the bind string to the scope level. Signed-off-by: Samuel K. Gutierrez --- src/qvi-hwloc.h | 1 - src/qvi-rmi.h | 2 -- src/qvi-scope.cc | 23 ++++++++++++++++++++--- src/qvi-task.cc | 43 +++++++++---------------------------------- src/qvi-task.h | 14 +++++--------- 5 files changed, 34 insertions(+), 49 deletions(-) diff --git a/src/qvi-hwloc.h b/src/qvi-hwloc.h index 7b9c123..0a96e9b 100644 --- a/src/qvi-hwloc.h +++ b/src/qvi-hwloc.h @@ -18,7 +18,6 @@ #define QVI_HWLOC_H #include "qvi-common.h" -#include "qvi-task.h" #ifdef __cplusplus extern "C" { diff --git a/src/qvi-rmi.h b/src/qvi-rmi.h index 5d631c5..6ec340c 100644 --- a/src/qvi-rmi.h +++ b/src/qvi-rmi.h @@ -23,8 +23,6 @@ #include "qvi-hwloc.h" #include "qvi-hwpool.h" -// TODO(skg) Just pass a pointer to the task in the interfaces here. - #ifdef __cplusplus struct qvi_rmi_config_s { diff --git a/src/qvi-scope.cc b/src/qvi-scope.cc index cc019c6..c3bbfb1 100644 --- a/src/qvi-scope.cc +++ b/src/qvi-scope.cc @@ -1385,9 +1385,26 @@ qvi_scope_bind_string( qv_bind_string_format_t format, char **str ) { - return qvi_task_bind_string( - scope->group->task(), format, str - ); + char *istr = nullptr; + + hwloc_cpuset_t cpuset = nullptr; + int rc = qvi_task_bind_top(scope->group->task(), &cpuset); + if (rc != QV_SUCCESS) return rc; + + switch (format) { + case QV_BIND_STRING_AS_BITMAP: + rc = qvi_hwloc_bitmap_asprintf(&istr, cpuset); + break; + case QV_BIND_STRING_AS_LIST: + rc = qvi_hwloc_bitmap_list_asprintf(&istr, cpuset); + break; + default: + rc = QV_ERR_INVLD_ARG; + break; + } + qvi_hwloc_bitmap_free(&cpuset); + *str = istr; + return rc; } /* diff --git a/src/qvi-task.cc b/src/qvi-task.cc index 6c9e8ed..a0419d0 100644 --- a/src/qvi-task.cc +++ b/src/qvi-task.cc @@ -25,15 +25,13 @@ struct qvi_task_s { qvi_rmi_client_t *rmi = nullptr; /** The task's bind stack. */ qvi_task_bind_stack_t stack; - /** - * Returns the caller's thread ID. - */ + /** Returns the caller's thread ID. */ static pid_t me(void) { return qvi_gettid(); } - + /** Connects to the RMI server. */ int connect_to_server(void) { @@ -108,34 +106,12 @@ struct qvi_task_s { rmi, me(), stack.top().cdata() ); } - /** */ + /** Returns the task's current cpuset. */ int - bind_string( - qv_bind_string_format_t format, - char **str + bind_top( + hwloc_cpuset_t *dest ) { - char *istr = nullptr; - - hwloc_cpuset_t cpuset = nullptr; - int rc = qvi_rmi_task_get_cpubind( - rmi, me(), &cpuset - ); - if (rc != QV_SUCCESS) goto out; - - switch (format) { - case QV_BIND_STRING_AS_BITMAP: - rc = qvi_hwloc_bitmap_asprintf(&istr, cpuset); - break; - case QV_BIND_STRING_AS_LIST: - rc = qvi_hwloc_bitmap_list_asprintf(&istr, cpuset); - break; - default: - rc = QV_ERR_INVLD_ARG; - } - out: - hwloc_bitmap_free(cpuset); - *str = istr; - return rc; + return qvi_hwloc_bitmap_dup(stack.top().cdata(), dest); } }; @@ -182,12 +158,11 @@ qvi_task_bind_pop( } int -qvi_task_bind_string( +qvi_task_bind_top( qvi_task_t *task, - qv_bind_string_format_t format, - char **str + hwloc_cpuset_t *dest ) { - return task->bind_string(format, str); + return task->bind_top(dest); } /* diff --git a/src/qvi-task.h b/src/qvi-task.h index cb4312b..c540ccf 100644 --- a/src/qvi-task.h +++ b/src/qvi-task.h @@ -23,9 +23,9 @@ extern "C" { #endif -/** - * - */ +pid_t +qvi_task_id(void); + int qvi_task_new( qvi_task_t **task @@ -41,9 +41,6 @@ qvi_task_rmi( qvi_task_t *task ); -pid_t -qvi_task_id(void); - int qvi_task_bind_push( qvi_task_t *task, @@ -56,10 +53,9 @@ qvi_task_bind_pop( ); int -qvi_task_bind_string( +qvi_task_bind_top( qvi_task_t *task, - qv_bind_string_format_t format, - char **str + hwloc_cpuset_t *dest ); #ifdef __cplusplus