This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master in repository sanlock.
commit 025fbb828a7fda53d3db905c96e5c8299b286738 Author: David Teigland teigland@redhat.com AuthorDate: Wed Aug 21 16:38:58 2024 -0500
sanlock: include worker thread info in status
'sanlock status -D' will show worker thread info. --- src/client_cmd.c | 14 +++++ src/cmd.c | 34 +++++++++++- src/main.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++- src/sanlock_internal.h | 14 +++++ src/sanlock_sock.h | 1 + 5 files changed, 198 insertions(+), 2 deletions(-)
diff --git a/src/client_cmd.c b/src/client_cmd.c index e06d0f7..43a3da8 100644 --- a/src/client_cmd.c +++ b/src/client_cmd.c @@ -180,6 +180,17 @@ static void status_host(struct sanlk_state *st, char *str, int debug) print_debug(str, st->str_len); }
+static void status_worker(struct sanlk_state *st, char *str, int debug) +{ + if (!debug) + return; + + printf("worker %u\n", st->data32); + + if (st->str_len) + print_debug(str, st->str_len); +} + static void print_st(struct sanlk_state *st, char *str, char *bin, int debug) { switch (st->type) { @@ -195,6 +206,9 @@ static void print_st(struct sanlk_state *st, char *str, char *bin, int debug) case SANLK_STATE_RESOURCE: status_resource(st, str, bin, debug); break; + case SANLK_STATE_WORKER: + status_worker(st, str, debug); + break; } }
diff --git a/src/cmd.c b/src/cmd.c index 01ebb9d..e91da9d 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -2302,6 +2302,7 @@ static int print_state_daemon(char *str) "max_sectors_kb_align=%d " "max_sectors_kb_num=%d " "max_worker_threads=%d " + "num_worker_threads=%d " "use_hugepages=%s " "write_init_io_timeout=%u " "use_aio=%d " @@ -2334,6 +2335,7 @@ static int print_state_daemon(char *str) com.max_sectors_kb_align, com.max_sectors_kb_num, com.max_worker_threads, + daemon_status_num_workers, com.use_hugepages ? "all" : "none", com.write_init_io_timeout, main_task.use_aio, @@ -2531,6 +2533,30 @@ static void send_state_daemon(int fd) send_all(fd, str, str_len, MSG_NOSIGNAL); }
+int print_state_worker(int i, char *str); + +static void send_state_worker(int fd, int i) +{ + struct sanlk_state st; + char str[SANLK_STATE_MAXSTR]; + int str_len; + + memset(&st, 0, sizeof(st)); + st.type = SANLK_STATE_WORKER; + st.data32 = i; + + str_len = print_state_worker(i, str); + + if (!str_len) + return; + + st.str_len = str_len; + + send_all(fd, &st, sizeof(st), MSG_NOSIGNAL); + if (str_len) + send_all(fd, str, str_len, MSG_NOSIGNAL); +} + static void send_state_client(int fd, struct client *cl, int ci) { struct sanlk_state st; @@ -2660,7 +2686,7 @@ static void cmd_status(int ci, int fd, struct sm_header *h_recv, int client_maxi struct sm_header h; struct client *cl; struct space *sp; - int ci_iter; + int ci_iter, i;
log_cmd(cmd, "cmd_status %d,%d", ci, fd);
@@ -2677,6 +2703,12 @@ static void cmd_status(int ci, int fd, struct sm_header *h_recv, int client_maxi if (h_recv->data == SANLK_STATE_DAEMON) return;
+ for (i = 0; i < com.max_worker_threads; i++) + send_state_worker(fd, i); + + if (h_recv->data == SANLK_STATE_WORKER) + return; + for (ci_iter = 0; ci_iter <= client_maxi; ci_iter++) { cl = &client[ci_iter]; if (!cl->used) diff --git a/src/main.c b/src/main.c index e8bf7c4..82872fa 100644 --- a/src/main.c +++ b/src/main.c @@ -69,6 +69,7 @@ struct thread_pool { pthread_mutex_t mutex; pthread_cond_t cond; pthread_cond_t quit_wait; + struct worker_info *info; };
/* priorities are LOG_* from syslog.h */ @@ -941,14 +942,43 @@ static int main_loop(void) return 0; }
+int print_state_worker(int i, char *str); + +int print_state_worker(int i, char *str) +{ + if (!pool.info[i].work_count) + return 0; + + memset(str, 0, SANLK_STATE_MAXSTR); + + snprintf(str, SANLK_STATE_MAXSTR-1, + "cmd_last=%s " + "busy=%u " + "work_count=%u " + "io_count=%u " + "to_count=%u " + "paxos_hugebuf_created=%u " + "paxos_hugebuf_used=%u", + cmd_num_to_str(pool.info[i].cmd_last), + pool.info[i].busy, + pool.info[i].work_count, + pool.info[i].io_count, + pool.info[i].to_count, + pool.info[i].paxos_hugebuf_created, + pool.info[i].paxos_hugebuf_used); + + return strlen(str) + 1; +} + static void *thread_pool_worker(void *data) { struct task task; struct cmd_args *ca; + long workerid = (long)data;
memset(&task, 0, sizeof(struct task)); setup_task_aio(&task, main_task.use_aio, WORKER_AIO_CB_SIZE); - snprintf(task.name, NAME_ID_SIZE, "worker%ld", (long)data); + snprintf(task.name, NAME_ID_SIZE, "worker%ld", workerid);
pthread_mutex_lock(&pool.mutex);
@@ -962,12 +992,20 @@ static void *thread_pool_worker(void *data) while (!list_empty(&pool.work_data)) { ca = list_first_entry(&pool.work_data, struct cmd_args, list); list_del(&ca->list); + pool.info[workerid].busy = 1; + pool.info[workerid].cmd_last = ca->header.cmd; pthread_mutex_unlock(&pool.mutex);
call_cmd_thread(&task, ca); free(ca);
pthread_mutex_lock(&pool.mutex); + pool.info[workerid].busy = 0; + pool.info[workerid].work_count++; + pool.info[workerid].io_count = task.io_count; + pool.info[workerid].to_count = task.to_count; + pool.info[workerid].paxos_hugebuf_created = task.paxos_hugebuf_created; + pool.info[workerid].paxos_hugebuf_used = task.paxos_hugebuf_used; }
if (pool.quit) @@ -975,6 +1013,7 @@ static void *thread_pool_worker(void *data) }
pool.num_workers--; + daemon_status_num_workers--; /* for status reporting */ if (!pool.num_workers) pthread_cond_signal(&pool.quit_wait); pthread_mutex_unlock(&pool.mutex); @@ -1007,6 +1046,7 @@ static int thread_pool_add_work(struct cmd_args *ca) return rv; } pool.num_workers++; + daemon_status_num_workers++; /* for status reporting */ }
pthread_cond_signal(&pool.cond); @@ -1036,6 +1076,12 @@ static int thread_pool_create(int min_workers, int max_workers) pthread_cond_init(&pool.cond, NULL); pthread_cond_init(&pool.quit_wait, NULL); pool.max_workers = max_workers; + pool.info = malloc(max_workers * sizeof(struct worker_info)); + + if (!pool.info) + return -ENOMEM; + + memset(pool.info, 0, max_workers * sizeof(struct worker_info));
for (i = 0; i < min_workers; i++) { rv = pthread_create(&th, NULL, thread_pool_worker, @@ -1046,6 +1092,7 @@ static int thread_pool_create(int min_workers, int max_workers) break; } pool.num_workers++; + daemon_status_num_workers++; /* for status reporting */ }
if (rv < 0) @@ -2731,6 +2778,94 @@ static int read_command_line(int argc, char *argv[]) return 0; }
+const char *cmd_num_to_str(int cmd) +{ + switch (cmd) { + case SM_CMD_INQ_LOCKSPACE: + return "inq_lockspace"; + case SM_CMD_READ_RESOURCE_OWNERS: + return "read_resource_owners"; + case SM_CMD_GET_LOCKSPACES: + return "get_lockspaces"; + case SM_CMD_GET_HOSTS: + return "get_hosts"; + case SM_CMD_REGISTER: + return "register"; + case SM_CMD_ADD_LOCKSPACE: + return "add_lockspace"; + case SM_CMD_REM_LOCKSPACE: + return "rem_lockspace"; + case SM_CMD_SHUTDOWN: + return "shutdown"; + case SM_CMD_STATUS: + return "status"; + case SM_CMD_ACQUIRE: + return "acquire"; + case SM_CMD_RELEASE: + return "release"; + case SM_CMD_INQUIRE: + return "inquire"; + case SM_CMD_RESTRICT: + return "restrict"; + case SM_CMD_REQUEST: + return "request"; + case SM_CMD_ALIGN: + return "align"; + case SM_CMD_EXAMINE_LOCKSPACE: + return "examine_lockspace"; + case SM_CMD_EXAMINE_RESOURCE: + return "examine_resource"; + case SM_CMD_HOST_STATUS: + return "host_status"; + case SM_CMD_KILLPATH: + return "killpath"; + case SM_CMD_WRITE_LOCKSPACE: + return "write_lockspace"; + case SM_CMD_WRITE_RESOURCE: + return "write_resource"; + case SM_CMD_READ_LOCKSPACE: + return "read_lockspace"; + case SM_CMD_READ_RESOURCE: + return "read_resource"; + case SM_CMD_SET_LVB: + return "set_lvb"; + case SM_CMD_GET_LVB: + return "get_lvb"; + case SM_CMD_CONVERT: + return "convert"; + case SM_CMD_VERSION: + return "version"; + case SM_CMD_SHUTDOWN_WAIT: + return "shutdown_wait"; + case SM_CMD_REG_EVENT: + return "reg_event"; + case SM_CMD_END_EVENT: + return "end_event"; + case SM_CMD_SET_EVENT: + return "set_event"; + case SM_CMD_SET_CONFIG: + return "set_config"; + case SM_CMD_RENEWAL: + return "renewal"; + case SM_CMD_FORMAT_RINDEX: + return "format_rindex"; + case SM_CMD_UPDATE_RINDEX: + return "update_rindex"; + case SM_CMD_LOOKUP_RINDEX: + return "lookup_rindex"; + case SM_CMD_CREATE_RESOURCE: + return "create_resource"; + case SM_CMD_DELETE_RESOURCE: + return "delete_resource"; + case SM_CMD_REBUILD_RINDEX: + return "rebuild_rindex"; + case SM_CMD_LOG_DUMP: + return "log_dump"; + default: + return "unknown"; + } +} + uint32_t cmd_str_to_num(const char *str) { if (!strcmp(str, "inq_lockspace")) diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h index 22b7698..ebb0a9c 100644 --- a/src/sanlock_internal.h +++ b/src/sanlock_internal.h @@ -291,6 +291,17 @@ struct task {
EXTERN struct task main_task;
+struct worker_info { + unsigned int busy; + unsigned int cmd_last; + unsigned int work_count; + unsigned int io_count; + unsigned int to_count; + unsigned int paxos_hugebuf_used; + unsigned int paxos_hugebuf_created; + unsigned int paxos_hugebuf_size; +}; + /* TODO: change used, suspend, need_free, pid_dead to flags */
#define CL_KILLPATH_PID 0x00000001 /* include pid as killpath arg */ @@ -418,6 +429,7 @@ struct command_line { EXTERN struct command_line com;
uint32_t cmd_str_to_num(const char *str); +const char *cmd_num_to_str(int cmd); uint64_t cmd_num_to_debug_flag(uint32_t cmd); int is_cmd_debug(uint32_t cmd); void set_cmd_debug(uint32_t cmd); @@ -474,6 +486,8 @@ EXTERN char our_host_name_global[SANLK_NAME_LEN+1]; EXTERN char our_product_uuid[SANLK_NAME_LEN+1]; EXTERN char our_product_uuid_compact[SANLK_NAME_LEN+1]; /* dash chars omitted from uuid */
+EXTERN int daemon_status_num_workers; /* replicate thread pool counter for status reporting */ + EXTERN int kill_count_max; EXTERN int is_helper; EXTERN int helper_ci; diff --git a/src/sanlock_sock.h b/src/sanlock_sock.h index 924468d..e252f83 100644 --- a/src/sanlock_sock.h +++ b/src/sanlock_sock.h @@ -83,6 +83,7 @@ struct sm_header { #define SANLK_STATE_RESOURCE 4 #define SANLK_STATE_HOST 5 #define SANLK_STATE_RENEWAL 6 +#define SANLK_STATE_WORKER 7
struct sanlk_state { uint32_t type; /* SANLK_STATE_ */
sanlock-devel@lists.fedorahosted.org