X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fmain.c;h=e8f05cecf2694dc8048c4540950611d265097145;hp=f9b41d2707bd26aff4f95a72aa1885d2f2f09280;hb=66ea93b10c703e1b3dda1e17109eed9138e4ece2;hpb=bc4b3ff16b26d5430fe701fd0680a157c65e21f8 diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index f9b41d270..e8f05cecf 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -366,10 +366,21 @@ LTTNG_HIDDEN void sessiond_notify_ready(void) { /* - * The _return variant is used since the implied memory barriers are - * required. + * This memory barrier is paired with the one performed by + * the client thread after it has seen that 'lttng_sessiond_ready' is 0. + * + * The purpose of these memory barriers is to ensure that all + * initialization operations of the various threads that call this + * function to signal that they are ready are commited/published + * before the client thread can see the 'lttng_sessiond_ready' counter + * reach 0. + * + * Note that this could be a 'write' memory barrier, but a full barrier + * is used in case the code using this utility changes. The performance + * implications of this choice are minimal since this is a slow path. */ - (void) uatomic_sub_return(<tng_sessiond_ready, 1); + cmm_smp_mb(); + uatomic_sub(<tng_sessiond_ready, 1); } static @@ -847,7 +858,7 @@ error: * * Useful for CPU hotplug feature. */ -static int update_kernel_stream(struct consumer_data *consumer_data, int fd) +static int update_kernel_stream(int fd) { int ret = 0; struct ltt_session *session; @@ -1081,7 +1092,7 @@ static void *thread_manage_kernel(void *data) * New CPU detected by the kernel. Adding kernel stream to * kernel session and updating the kernel consumer */ - ret = update_kernel_stream(&kconsumer_data, pollfd); + ret = update_kernel_stream(pollfd); if (ret < 0) { continue; } @@ -2989,8 +3000,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, case LTTNG_ROTATION_GET_INFO: case LTTNG_SESSION_GET_CURRENT_OUTPUT: case LTTNG_ROTATION_SET_SCHEDULE: - case LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD: - case LTTNG_ROTATION_SCHEDULE_GET_SIZE: + case LTTNG_SESSION_LIST_ROTATION_SCHEDULES: need_domain = 0; break; default: @@ -3035,8 +3045,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, case LTTNG_DATA_PENDING: case LTTNG_ROTATE_SESSION: case LTTNG_ROTATION_GET_INFO: - case LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD: - case LTTNG_ROTATION_SCHEDULE_GET_SIZE: + case LTTNG_SESSION_LIST_ROTATION_SCHEDULES: break; default: /* Setup lttng message with no payload */ @@ -4215,15 +4224,24 @@ error_add_context: } case LTTNG_ROTATION_SET_SCHEDULE: { + bool set_schedule; + enum lttng_rotation_schedule_type schedule_type; + uint64_t value; + if (cmd_ctx->session->kernel_session && !check_rotate_compatible()) { DBG("Kernel tracer version does not support session rotations"); ret = LTTNG_ERR_ROTATION_WRONG_VERSION; goto error; } + set_schedule = cmd_ctx->lsm->u.rotation_set_schedule.set == 1; + schedule_type = (enum lttng_rotation_schedule_type) cmd_ctx->lsm->u.rotation_set_schedule.type; + value = cmd_ctx->lsm->u.rotation_set_schedule.value; + ret = cmd_rotation_set_schedule(cmd_ctx->session, - cmd_ctx->lsm->u.rotate_setup.timer_us, - cmd_ctx->lsm->u.rotate_setup.size, + set_schedule, + schedule_type, + value, notification_thread_handle); if (ret != LTTNG_OK) { goto error; @@ -4231,42 +4249,17 @@ error_add_context: break; } - case LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD: - { - struct lttng_rotation_schedule_get_timer_period *get_timer; - - get_timer = zmalloc(sizeof(struct lttng_rotation_schedule_get_timer_period)); - if (!get_timer) { - ret = ENOMEM; - goto error; - } - get_timer->rotate_timer = cmd_ctx->session->rotate_timer_period; - - ret = setup_lttng_msg_no_cmd_header(cmd_ctx, get_timer, - sizeof(struct lttng_rotation_schedule_get_timer_period)); - free(get_timer); - if (ret < 0) { - ret = -ret; - goto error; - } - - ret = LTTNG_OK; - break; - } - case LTTNG_ROTATION_SCHEDULE_GET_SIZE: + case LTTNG_SESSION_LIST_ROTATION_SCHEDULES: { - struct lttng_rotation_schedule_get_size *get_size; - - get_size = zmalloc(sizeof(struct lttng_rotation_schedule_get_size)); - if (!get_size) { - ret = ENOMEM; - goto error; - } - get_size->rotate_size = cmd_ctx->session->rotate_size; - - ret = setup_lttng_msg_no_cmd_header(cmd_ctx, get_size, - sizeof(struct lttng_rotation_schedule_get_size)); - free(get_size); + struct lttng_session_list_schedules_return schedules = { + .periodic.set = !!cmd_ctx->session->rotate_timer_period, + .periodic.value = cmd_ctx->session->rotate_timer_period, + .size.set = !!cmd_ctx->session->rotate_size, + .size.value = cmd_ctx->session->rotate_size, + }; + + ret = setup_lttng_msg_no_cmd_header(cmd_ctx, &schedules, + sizeof(schedules)); if (ret < 0) { ret = -ret; goto error; @@ -4563,8 +4556,17 @@ static void *thread_manage_clients(void *data) if (ret > 0 || (ret < 0 && errno != EINTR)) { goto exit; } - cmm_smp_rmb(); } + /* + * This barrier is paired with the one in sessiond_notify_ready() to + * ensure that loads accessing data initialized by the other threads, + * on which this thread was waiting, are not performed before this point. + * + * Note that this could be a 'read' memory barrier, but a full barrier + * is used in case the code changes. The performance implications of + * this choice are minimal since this is a slow path. + */ + cmm_smp_mb(); /* This testpoint is after we signal readiness to the parent. */ if (testpoint(sessiond_thread_manage_clients)) { @@ -4578,6 +4580,8 @@ static void *thread_manage_clients(void *data) health_code_update(); while (1) { + const struct cmd_completion_handler *cmd_completion_handler; + DBG("Accepting client command ..."); /* Inifinite blocking call, waiting for transmission */ @@ -4720,6 +4724,18 @@ static void *thread_manage_clients(void *data) continue; } + cmd_completion_handler = cmd_pop_completion_handler(); + if (cmd_completion_handler) { + enum lttng_error_code completion_code; + + completion_code = cmd_completion_handler->run( + cmd_completion_handler->data); + if (completion_code != LTTNG_OK) { + clean_command_ctx(&cmd_ctx); + continue; + } + } + health_code_update(); DBG("Sending response (size: %d, retcode: %s (%d))", @@ -5810,6 +5826,12 @@ int main(int argc, char **argv) goto exit_set_signal_handler; } + /* + * Init config from environment variables. + * Command line option override env configuration per-doc. Do env first. + */ + sessiond_config_apply_env_config(&config); + /* * Parse arguments and load the daemon configuration file. * @@ -5824,9 +5846,6 @@ int main(int argc, char **argv) goto exit_options; } - /* Init config from environment variables. */ - sessiond_config_apply_env_config(&config); - /* * Resolve all paths received as arguments, configuration option, or * through environment variable as absolute paths. This is necessary