Skip to content

Commit

Permalink
Add the worker_threads command
Browse files Browse the repository at this point in the history
The `worker_threads` command is designed for integration into
configuration files, serving as a replacement of the `-P` command-line
option.

Usage:
   worker_threads num=<number of threads>
  • Loading branch information
nichamon authored and tom95858 committed Mar 5, 2024
1 parent e7e5fe6 commit 8af9586
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ldms/src/ldmsd/ldmsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,11 @@ int main(int argc, char *argv[])
"The option `-n` is obsolete. "
"Please specify `daemon_name name=<DAEMON_NAME> in a configuration file.\n");
cleanup(EINVAL, "Received an obsolete command-line option");
case 'P':
ovis_log(NULL, OVIS_LCRIT,
"The option `-P` is obsolete. "
"Please specify `worker_threads num=<NUMBER OF THREADS> in a configuration file.\n");
cleanup(EINVAL, "Received an obsolete command-line option");
default:
ret = ldmsd_process_cmd_line_arg(op, optarg);
if (ret) {
Expand Down
29 changes: 29 additions & 0 deletions ldms/src/ldmsd/ldmsd_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ static int set_memory_handler(ldmsd_req_ctxt_t reqc);
static int log_file_handler(ldmsd_req_ctxt_t reqc);
static int publish_kernel_handler(ldmsd_req_ctxt_t reqc);
static int daemon_name_set_handler(ldmsd_req_ctxt_t reqc);
static int worker_threads_set_handler(ldmsd_req_ctxt_t reqc);

/* executable for all */
#define XALL 0111
Expand Down Expand Up @@ -671,6 +672,9 @@ static struct request_handler_entry request_handler[] = {
[LDMSD_DAEMON_NAME_SET_REQ] = {
LDMSD_DAEMON_NAME_SET_REQ, daemon_name_set_handler, XUG
},
[LDMSD_WORKER_THR_SET_REQ] = {
LDMSD_WORKER_THR_SET_REQ, worker_threads_set_handler, XUG
},
};

int is_req_id_priority(enum ldmsd_request req_id)
Expand All @@ -687,6 +691,7 @@ int is_req_id_priority(enum ldmsd_request req_id)
case LDMSD_LOG_FILE_REQ:
case LDMSD_PUBLISH_KERNEL_REQ:
case LDMSD_DAEMON_NAME_SET_REQ:
case LDMSD_WORKER_THR_SET_REQ:
return 1;
default:
return 0;
Expand Down Expand Up @@ -9209,3 +9214,27 @@ static int daemon_name_set_handler(ldmsd_req_ctxt_t reqc)
free(name);
return rc;
}

static int worker_threads_set_handler(ldmsd_req_ctxt_t reqc)
{
int rc = 0;
char *value = NULL;

value = ldmsd_req_attr_str_value_get_by_id(reqc, LDMSD_ATTR_SIZE);
if (!value) {
reqc->errcode = EINVAL;
reqc->line_off = snprintf(reqc->line_buf, reqc->line_len,
"The attribute 'num' is missing.");
goto send_reply;
}
reqc->errcode = ldmsd_process_cmd_line_arg('P', value);
if (reqc->errcode) {
reqc->line_off = snprintf(reqc->line_buf, reqc->line_len,
"Failed to process the 'worker_threads' command");
goto send_reply;
}
send_reply:
ldmsd_send_req_response(reqc, reqc->line_buf);
free(value);
return rc;
}
1 change: 1 addition & 0 deletions ldms/src/ldmsd/ldmsd_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ enum ldmsd_request {
LDMSD_LOG_FILE_REQ,
LDMSD_PUBLISH_KERNEL_REQ,
LDMSD_DAEMON_NAME_SET_REQ,
LDMSD_WORKER_THR_SET_REQ,

/* failover requests by user */
LDMSD_FAILOVER_CONFIG_REQ = 0x700, /* "failover_config" user command */
Expand Down
2 changes: 2 additions & 0 deletions ldms/src/ldmsd/ldmsd_request_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const struct req_str_id req_str_id_table[] = {
{ "updtr_task", LDMSD_UPDTR_TASK_REQ },
{ "usage", LDMSD_PLUGN_LIST_REQ },
{ "version", LDMSD_VERSION_REQ },
{ "worker_threads", LDMSD_WORKER_THR_SET_REQ },
{ "xprt_stats", LDMSD_XPRT_STATS_REQ },
};

Expand All @@ -176,6 +177,7 @@ const struct req_str_id attr_str_id_table[] = {
{ "match", LDMSD_ATTR_MATCH },
{ "metric", LDMSD_ATTR_METRIC },
{ "name", LDMSD_ATTR_NAME },
{ "num", LDMSD_ATTR_SIZE },
{ "offset", LDMSD_ATTR_OFFSET },
{ "path", LDMSD_ATTR_PATH },
{ "peer_name", LDMSD_ATTR_PEER_NAME },
Expand Down

0 comments on commit 8af9586

Please sign in to comment.