Skip to content

Commit

Permalink
Rework scope bind string code with cleanups.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
samuelkgutierrez committed Jul 6, 2024
1 parent 9e5f104 commit 0fa0df6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 49 deletions.
1 change: 0 additions & 1 deletion src/qvi-hwloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define QVI_HWLOC_H

#include "qvi-common.h"
#include "qvi-task.h"

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 0 additions & 2 deletions src/qvi-rmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 20 additions & 3 deletions src/qvi-scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
Expand Down
43 changes: 9 additions & 34 deletions src/qvi-task.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -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);
}

/*
Expand Down
14 changes: 5 additions & 9 deletions src/qvi-task.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
extern "C" {
#endif

/**
*
*/
pid_t
qvi_task_id(void);

int
qvi_task_new(
qvi_task_t **task
Expand All @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 0fa0df6

Please sign in to comment.