Skip to content

Commit

Permalink
Create new plugin API abstractions
Browse files Browse the repository at this point in the history
Develop better plugin API abstractions.

Make read-only ldmsd's access to the API function pointer structs: struct ldmsd_plugin,
struct ldmsd_store, and struct ldmsd_sampler. The plugins now own those structs.

Introduce the ldmsd_plug_api.[ch] files, which most importantly include the accessor
functions for the new ldmsd_plug_handle_t, which is a opaque to the plugins.

ldmsd passes an opaque ldmsd_plug_handle_t to the plugins in each plugin API call.

Plugins may use the accessor functions to get and set things through the handle.

In particular, a plugin may use ldmsd_plug_context_set() to record its local context
pointer in one call, and use ldmsd_plug_context_get() to retrieve its local context
pointer.

Functions calls constructor() and destructor() are added to the plugin API to simplify
plugin multi-instance support.

The filesingle sampler is upgraded to multi-instance support.
  • Loading branch information
morrone committed Feb 21, 2025
1 parent 2c353ed commit 71feec8
Show file tree
Hide file tree
Showing 126 changed files with 1,444 additions and 1,287 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ OPTION_DEFAULT_ENABLE([lnet_stats], [ENABLE_LNET_STATS])
OPTION_DEFAULT_ENABLE([meminfo], [ENABLE_MEMINFO])
OPTION_DEFAULT_DISABLE([gpumetrics], [ENABLE_GPU_METRICS])
OPTION_DEFAULT_ENABLE([coretemp], [ENABLE_CORETEMP])
OPTION_DEFAULT_DISABLE([filesingle], [ENABLE_FILESINGLE])
OPTION_DEFAULT_ENABLE([filesingle], [ENABLE_FILESINGLE])
OPTION_DEFAULT_DISABLE([msr_interlagos], [ENABLE_MSR_INTERLAGOS])
OPTION_DEFAULT_ENABLE([array_example], [ENABLE_ARRAY_EXAMPLE])
OPTION_DEFAULT_ENABLE([hello_stream], [ENABLE_HELLO_STREAM])
Expand Down
8 changes: 4 additions & 4 deletions ldms/src/contrib/sampler/daos/daos.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int dao_log(int level, const char *fmt, ...)
return rc;
}

static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct attr_value_list *avl)
static int config(ldmsd_plug_handle_t handle, struct attr_value_list *kwl, struct attr_value_list *avl)
{
char *ival;
int rc;
Expand Down Expand Up @@ -168,7 +168,7 @@ int get_daos_rank(struct d_tm_context *ctx, uint32_t *rank)
return 0;
}

static int sample(struct ldmsd_sampler *self)
static int sample(ldmsd_plug_handle_t handle)
{
struct d_tm_context *ctx = NULL;
uint32_t rank = -1;
Expand Down Expand Up @@ -214,7 +214,7 @@ static int sample(struct ldmsd_sampler *self)
return rc;
}

static void term(struct ldmsd_plugin *self)
static void term(ldmsd_plug_handle_t handle)
{
dao_log(OVIS_LDEBUG, "term() called\n");
rank_targets_destroy();
Expand All @@ -226,7 +226,7 @@ static void term(struct ldmsd_plugin *self)
ovis_log_destroy(mylog);
}

static const char *usage(struct ldmsd_plugin *self)
static const char *usage(ldmsd_plug_handle_t handle)
{
dao_log(OVIS_LDEBUG, "usage() called\n");
return "config name=" SAMP " " BASE_CONFIG_USAGE;
Expand Down
10 changes: 5 additions & 5 deletions ldms/src/contrib/sampler/geopm_sampler/ldms_geopm_sampler.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,12 @@ static int config_check(struct attr_value_list *avl)
return access(g_geopm_request_path, R_OK);
}

static const char *usage(struct ldmsd_plugin *self)
static const char *usage(ldmsd_plug_handle_t handle)
{
return "config geopm_request_path=<absolute-path-to-file> name=" SAMP " " BASE_CONFIG_USAGE;
}

static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct attr_value_list *avl)
static int config(ldmsd_plug_handle_t handle, struct attr_value_list *kwl, struct attr_value_list *avl)
{
int rc = 0;

Expand Down Expand Up @@ -481,7 +481,7 @@ static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct
* This makes call into core LDMS functions for initializing the sampler
*/
errno = 0;
g_base = base_config(avl, self->cfg_name, SAMP, mylog);
g_base = base_config(avl, SAMP, SAMP, mylog);
ovis_log(mylog, OVIS_LDEBUG, SAMP": Base config() called.\n");
if (g_base == NULL) {
rc = errno ? errno : -1;
Expand All @@ -506,7 +506,7 @@ static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct
return rc;
}

static int sample(struct ldmsd_sampler *self)
static int sample(ldmsd_plug_handle_t handle)
{
int rc = 0;
union ldms_value value;
Expand Down Expand Up @@ -547,7 +547,7 @@ static int sample(struct ldmsd_sampler *self)
}


static void term(struct ldmsd_plugin *self)
static void term(ldmsd_plug_handle_t handle)
{
if (g_base) {
base_del(g_base);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,18 @@ static int config_check(struct attr_value_list *keyword_list, struct attr_value_

/**
* Provides usage information. Note that BASE_CONFIG_USAGE is defined in sampler_base.h.
* @param self this plugin instance.
* @param context this plugin instance.
* @return usage string.
*/
static const char *usage(struct ldmsd_plugin *self) {
static const char *usage(ldmsd_plug_handle_t handle) {
return "config name=" SAMP " "
BASE_CONFIG_USAGE;
}

/**
* Plugin instance constructor. Base is an instance of the sampler base "class".
*/
static int config(struct ldmsd_plugin *self,
static int config(ldmsd_plug_handle_t handle,
struct attr_value_list *keyword_list,
struct attr_value_list *attribute_value_list) {
#ifdef ENABLE_AUTO_SIMULATION
Expand Down Expand Up @@ -254,7 +254,7 @@ static int config(struct ldmsd_plugin *self,

// Create an instance from the base "class". This is effectively calling
// the base class constructor.
base = base_config(attribute_value_list, self->cfg_name, SAMP, __gpu_metrics_log);
base = base_config(attribute_value_list, SAMP, SAMP, __gpu_metrics_log);
if (!base) {
rc = errno;
goto err;
Expand All @@ -278,10 +278,10 @@ static int config(struct ldmsd_plugin *self,

/**
* LDMS calls this function to sample GPU metrics and store them in the metrics set.
* @param self
* @param context
* @return 0 if successful; otherwise returns EINVAL.
*/
static int sample(struct ldmsd_sampler *self) {
static int sample(ldmsd_plug_handle_t handle) {
if (!set) {
ovis_log(__gpu_metrics_log, OVIS_LDEBUG, SAMP ": plugin not initialized\n");
return EINVAL;
Expand Down Expand Up @@ -318,9 +318,9 @@ static int sample(struct ldmsd_sampler *self) {
/**
* Release any opened resource. Note that we have to call OneAPI C++ destructor to
* close any opened handles.
* @param self this plugin instance.
* @param context this plugin instance's context.
*/
static void term(struct ldmsd_plugin *self) {
static void term(ldmsd_plug_handle_t handle) {
// No longer need to free device handle array here.

size_t mallocCount = getMallocCount();
Expand All @@ -345,7 +345,7 @@ static struct ldmsd_sampler gpu_metrics_plugin = {
.name = SAMP,
.type = LDMSD_PLUGIN_SAMPLER,
.term = term, // destructor
.config = config, // constructor
.config = config,
.usage = usage,
},
.sample = sample,
Expand Down
16 changes: 7 additions & 9 deletions ldms/src/contrib/sampler/ipmireader/ipmireader.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ static int config_check(struct attr_value_list *kwl, struct attr_value_list *avl
return 0;
}

static const char *usage(struct ldmsd_plugin *self)
static const char *usage(ldmsd_plug_handle_t handle)
{
return "config name=" SAMP " address=<address> username=<username> password=<password> sdrcache=<cachefile> retry=<sec> " BASE_CONFIG_USAGE
" address address of the host to contact. H flag in the ipmitool command (e.g., cn1-ipmi).\n"
Expand All @@ -344,7 +344,7 @@ static const char *usage(struct ldmsd_plugin *self)
//FIXME: make an optional command to refresh the cache file.
}

static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct attr_value_list *avl)
static int config(ldmsd_plug_handle_t handle, struct attr_value_list *kwl, struct attr_value_list *avl)
{
char *hostname, *username, *password, *sdrcache, *retrycmd;
int rc;
Expand Down Expand Up @@ -385,7 +385,6 @@ static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct
retry = IPMIRETRYDEFAULT;
else
retry = atoi(retrycmd);


rc = 0;
do {
Expand All @@ -395,18 +394,18 @@ static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct

rc = create_commands(hostname, username, password, sdrcache);
ovis_log(mylog, OVIS_LERROR, SAMP "cannot create command. sleeping and retrying\n");
if (rc == EINVAL)
if (rc == EINVAL)
goto err;
} while (rc != 0);


rc = 0;
do {
//if cannot create metric set, retry indefinitely
if (rc != 0)
if (rc != 0)
sleep(retry);

base = base_config(avl, self->cfg_name, SAMP, mylog);
base = base_config(avl, SAMP, SAMP, mylog);
if (!base) {
rc = errno;
goto err;
Expand All @@ -429,7 +428,7 @@ static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct
return rc;
}

static int sample(struct ldmsd_sampler *self)
static int sample(ldmsd_plug_handle_t handle)
{
int metric_no;
char *s;
Expand Down Expand Up @@ -513,10 +512,9 @@ static int sample(struct ldmsd_sampler *self)
base_sample_end(base);

return 0;

}

static void term(struct ldmsd_plugin *self)
static void term(ldmsd_plug_handle_t handle)
{

cmd[0] = '\0';
Expand Down
10 changes: 5 additions & 5 deletions ldms/src/contrib/sampler/ipmireader/ipmisensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ static int config_check(struct attr_value_list *kwl, struct attr_value_list *avl
return 0;
}

static const char *usage(struct ldmsd_plugin *self)
static const char *usage(ldmsd_plug_handle_t handle)
{
return "config name=" SAMP " address=<address> username=<username> password=<password> " BASE_CONFIG_USAGE
" address address of the host to contact. h flag in the ipmi-sensors command (e.g., cn1-ipmi).\n"
" username username for the ipmi query. u flag in the ipmi-sensors command (default 'admin').\n"
" password password for the ipmi query. p flag in the ipmi-sensors command (default 'password').\n";
}

static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct attr_value_list *avl)
static int config(ldmsd_plug_handle_t handle, struct attr_value_list *kwl, struct attr_value_list *avl)
{
char *hostname, *username, *password;
int rc;
Expand Down Expand Up @@ -286,7 +286,7 @@ static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct
goto err;


base = base_config(avl, self->cfg_name, SAMP, mylog);
base = base_config(avl, SAMP, SAMP, mylog);
if (!base) {
rc = errno;
goto err;
Expand All @@ -305,7 +305,7 @@ static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct
return rc;
}

static int sample(struct ldmsd_sampler *self)
static int sample(ldmsd_plug_handle_t handle)
{
int metric_no;
char *s;
Expand Down Expand Up @@ -374,7 +374,7 @@ static int sample(struct ldmsd_sampler *self)
return 0;
}

static void term(struct ldmsd_plugin *self)
static void term(ldmsd_plug_handle_t handle)
{

cmd[0] = '\0';
Expand Down
11 changes: 5 additions & 6 deletions ldms/src/contrib/sampler/tutorial/tutorial_sampler.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ static int create_metric_set(struct tutorial_set* tset)
}


static const char *usage(struct ldmsd_plugin *self)
static const char *usage(ldmsd_plug_handle_t handle)
{
return "config name=" BASE_CONFIG_USAGE SAMP " schema=<schemaname> num_metrics=<N>\n";
}

static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct attr_value_list *avl)
static int config(ldmsd_plug_handle_t handle, struct attr_value_list *kwl, struct attr_value_list *avl)
{
char *value;
int rc;
Expand All @@ -173,7 +173,7 @@ static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct
}

//producer, component_id, instance, schema etc all in base_config
tsets[num_sets].base = base_config(avl, self->cfg_name, SAMP, mylog);
tsets[num_sets].base = base_config(avl, SAMP, SAMP, mylog);
if (!tsets[num_sets].base) {
rc = errno;
goto err;
Expand All @@ -196,7 +196,7 @@ static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct
return rc;
}

static int sample(struct ldmsd_sampler *self)
static int sample(ldmsd_plug_handle_t handle)
{
int metric_no;
int i,j;
Expand Down Expand Up @@ -228,9 +228,8 @@ static int sample(struct ldmsd_sampler *self)
return 0;
}

static void term(struct ldmsd_plugin *self)
static void term(ldmsd_plug_handle_t handle)
{

int i;

for (i = 0; i < num_sets; i++){
Expand Down
10 changes: 5 additions & 5 deletions ldms/src/contrib/sampler/variorum_sampler/variorum_sampler.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static int create_metric_set(base_data_t base)

}

static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct attr_value_list *avl)
static int config(ldmsd_plug_handle_t handle, struct attr_value_list *kwl, struct attr_value_list *avl)
{

int rc;
Expand All @@ -133,7 +133,7 @@ static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct
nsockets = variorum_get_num_sockets();

// prepare the base for metric collection
base = base_config(avl, self->cfg_name, SAMP, mylog);
base = base_config(avl, SAMP, SAMP, mylog);
if (!base) {
rc = errno;
goto err;
Expand All @@ -151,7 +151,7 @@ static int config(struct ldmsd_plugin *self, struct attr_value_list *kwl, struct
return rc;
}

static int sample(struct ldmsd_sampler *self)
static int sample(ldmsd_plug_handle_t handle)
{
json_t *power_obj = NULL;
int ret, socket;
Expand Down Expand Up @@ -195,7 +195,7 @@ static int sample(struct ldmsd_sampler *self)

}

static void term(struct ldmsd_plugin *self)
static void term(ldmsd_plug_handle_t handle)
{
int metric;

Expand All @@ -220,7 +220,7 @@ static void term(struct ldmsd_plugin *self)
set = NULL;
}

static const char *usage(struct ldmsd_plugin *self)
static const char *usage(ldmsd_plug_handle_t handle)
{
return "config name=" SAMP " " BASE_CONFIG_USAGE;
}
Expand Down
Loading

0 comments on commit 71feec8

Please sign in to comment.