modprobe_remove_kernel_modules();
}
+ close(thread_quit_pipe[0]);
+ close(thread_quit_pipe[1]);
++
+ /* OUTPUT BENCHMARK RESULTS */
+ bench_init();
+
+ if (getenv("BENCH_UST_NOTIFY")) {
+ bench_print_ust_notification();
+ }
+
+ if (getenv("BENCH_UST_REGISTER")) {
+ bench_print_ust_register();
+ }
+
+ if (getenv("BENCH_BOOT_PROCESS")) {
+ bench_print_boot_process();
+ }
+
+ bench_close();
+ /* END BENCHMARK */
}
/*
*/
static void *thread_manage_kernel(void *data)
{
- int ret, i, nb_fd = 0;
+ int ret, i, pollfd, update_poll_flag = 1;
+ uint32_t revents, nb_fd;
char tmp;
- int update_poll_flag = 1;
+ struct lttng_poll_event events;
+ tracepoint(sessiond_th_kern_start);
+
DBG("Thread manage kernel started");
+ ret = create_thread_poll_set(&events, 2);
+ if (ret < 0) {
+ goto error;
+ }
+
+ ret = lttng_poll_add(&events, kernel_poll_pipe[0], LPOLLIN);
+ if (ret < 0) {
+ goto error;
+ }
+
while (1) {
if (update_poll_flag == 1) {
- nb_fd = update_kernel_pollfd();
- if (nb_fd < 0) {
+ ret = update_kernel_poll(&events);
+ if (ret < 0) {
goto error;
}
update_poll_flag = 0;
}
- DBG("Polling on %d fds", nb_fd);
+ nb_fd = LTTNG_POLL_GETNB(&events);
+
+ DBG("Thread kernel polling on %d fds", nb_fd);
+
+ /* Zeroed the poll events */
+ lttng_poll_reset(&events);
+ tracepoint(sessiond_th_kern_poll);
+
/* Poll infinite value of time */
- ret = poll(kernel_pollfd, nb_fd, -1);
+ ret = lttng_poll_wait(&events, -1);
if (ret < 0) {
- perror("poll kernel thread");
goto error;
} else if (ret == 0) {
/* Should not happen since timeout is infinite */
*/
static void *thread_manage_kconsumerd(void *data)
{
- int sock = 0, ret;
+ int sock = 0, i, ret, pollfd;
+ uint32_t revents, nb_fd;
enum lttcomm_return_code code;
- struct pollfd pollfd[2];
+ struct lttng_poll_event events;
+ tracepoint(sessiond_th_kcon_start);
+
DBG("[thread] Manage kconsumerd started");
ret = lttcomm_listen_unix_sock(kconsumerd_err_sock);
goto error;
}
- /* First fd is always the quit pipe */
- pollfd[0].fd = thread_quit_pipe[0];
+ /*
+ * Pass 2 as size here for the thread quit pipe and kconsumerd_err_sock.
+ * Nothing more will be added to this poll set.
+ */
+ ret = create_thread_poll_set(&events, 2);
+ if (ret < 0) {
+ goto error;
+ }
+
+ ret = lttng_poll_add(&events, kconsumerd_err_sock, LPOLLIN | LPOLLRDHUP);
+ if (ret < 0) {
+ goto error;
+ }
- /* Apps socket */
- pollfd[1].fd = kconsumerd_err_sock;
- pollfd[1].events = POLLIN;
+ nb_fd = LTTNG_POLL_GETNB(&events);
+ tracepoint(sessiond_th_kcon_poll);
+
/* Inifinite blocking call, waiting for transmission */
- ret = poll(pollfd, 2, -1);
+ ret = lttng_poll_wait(&events, -1);
if (ret < 0) {
- perror("poll kconsumerd thread");
goto error;
}
*/
static void *thread_manage_apps(void *data)
{
- int i, ret, current_nb_fd;
- unsigned int nb_fd = 2;
- int update_poll_flag = 1;
- struct pollfd *pollfd = NULL;
+ int i, ret, pollfd;
+ uint32_t revents, nb_fd;
struct ust_command ust_cmd;
+ struct lttng_poll_event events;
+ tracepoint(sessiond_th_apps_start);
+
DBG("[thread] Manage application started");
- ust_cmd.sock = -1;
- current_nb_fd = nb_fd;
+ ret = create_thread_poll_set(&events, 2);
+ if (ret < 0) {
+ goto error;
+ }
- while (1) {
- /* See if we have a valid socket to add to pollfd */
- if (ust_cmd.sock != -1) {
- nb_fd++;
- update_poll_flag = 1;
- }
+ ret = lttng_poll_add(&events, apps_cmd_pipe[0], LPOLLIN | LPOLLRDHUP);
+ if (ret < 0) {
+ goto error;
+ }
- /* The pollfd struct must be updated */
- if (update_poll_flag) {
- ret = update_apps_cmd_pollfd(nb_fd, current_nb_fd, &pollfd);
- if (ret < 0) {
- /* malloc failed so we quit */
- goto error;
- }
+ while (1) {
+ /* Zeroed the events structure */
+ lttng_poll_reset(&events);
- if (ust_cmd.sock != -1) {
- /* Update pollfd with the new UST socket */
- DBG("Adding sock %d to apps cmd pollfd", ust_cmd.sock);
- pollfd[nb_fd - 1].fd = ust_cmd.sock;
- pollfd[nb_fd - 1].events = POLLHUP | POLLNVAL | POLLERR;
- ust_cmd.sock = -1;
- }
- }
+ nb_fd = LTTNG_POLL_GETNB(&events);
DBG("Apps thread polling on %d fds", nb_fd);
+ tracepoint(sessiond_th_apps_poll);
+
/* Inifinite blocking call, waiting for transmission */
- ret = poll(pollfd, nb_fd, -1);
+ ret = lttng_poll_wait(&events, -1);
if (ret < 0) {
- perror("poll apps thread");
goto error;
}
- /* Thread quit pipe has been closed. Killing thread. */
- if (pollfd[0].revents == POLLNVAL) {
- goto error;
- } else {
- /* apps_cmd_pipe pipe events */
- switch (pollfd[1].revents) {
- case POLLERR:
- ERR("Apps command pipe poll error");
+ for (i = 0; i < nb_fd; i++) {
+ /* Fetch once the poll data */
+ revents = LTTNG_POLL_GETEV(&events, i);
+ pollfd = LTTNG_POLL_GETFD(&events, i);
+
+ /* Thread quit pipe has been closed. Killing thread. */
+ ret = check_thread_quit_pipe(pollfd, revents);
+ if (ret) {
goto error;
- case POLLIN:
- tracepoint(ust_register_read_start);
+ }
- /* Empty pipe */
- ret = read(apps_cmd_pipe[0], &ust_cmd, sizeof(ust_cmd));
- if (ret < 0 || ret < sizeof(ust_cmd)) {
- perror("read apps cmd pipe");
+ /* Inspect the apps cmd pipe */
+ if (pollfd == apps_cmd_pipe[0]) {
+ if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
+ ERR("Apps command pipe error");
goto error;
- }
+ } else if (revents & LPOLLIN) {
++ tracepoint(ust_register_read_start);
+ /* Empty pipe */
+ ret = read(apps_cmd_pipe[0], &ust_cmd, sizeof(ust_cmd));
+ if (ret < 0 || ret < sizeof(ust_cmd)) {
+ perror("read apps cmd pipe");
+ goto error;
+ }
- tracepoint(ust_register_read_stop);
+ /* Register applicaton to the session daemon */
+ ret = register_traceable_app(&ust_cmd.reg_msg, ust_cmd.sock);
+ if (ret < 0) {
+ /* Only critical ENOMEM error can be returned here */
+ goto error;
+ }
- tracepoint(ust_register_add_start);
- /* Register applicaton to the session daemon */
- ret = register_traceable_app(&ust_cmd.reg_msg, ust_cmd.sock);
- if (ret < 0) {
- /* Only critical ENOMEM error can be returned here */
- goto error;
+ ret = ustctl_register_done(ust_cmd.sock);
+ if (ret < 0) {
+ /*
+ * If the registration is not possible, we simply
+ * unregister the apps and continue
+ */
+ unregister_traceable_app(ust_cmd.sock);
+ } else {
+ /*
+ * We just need here to monitor the close of the UST
+ * socket and poll set monitor those by default.
+ */
+ ret = lttng_poll_add(&events, ust_cmd.sock, 0);
+ if (ret < 0) {
+ goto error;
+ }
+
+ DBG("Apps with sock %d added to poll set", ust_cmd.sock);
+ }
+ break;
}
- tracepoint(ust_register_add_stop);
+ } else {
+ /*
+ * At this point, we know that a registered application made the
+ * event at poll_wait.
+ */
+ if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
+ /* Removing from the poll set */
+ ret = lttng_poll_del(&events, pollfd);
+ if (ret < 0) {
+ goto error;
+ }
- tracepoint(ust_register_done_start);
- ret = ustctl_register_done(ust_cmd.sock);
- if (ret < 0) {
- /*
- * If the registration is not possible, we simply unregister
- * the apps and continue
- */
- unregister_traceable_app(ust_cmd.sock);
+ /* Socket closed */
+ unregister_traceable_app(pollfd);
+ break;
}
-
- tracepoint(ust_register_done_stop);
- break;
}
}
-
- current_nb_fd = nb_fd;
- for (i = 2; i < current_nb_fd; i++) {
- /* Apps socket is closed/hungup */
- switch (pollfd[i].revents) {
- case POLLERR:
- case POLLHUP:
- case POLLNVAL:
- /* Pipe closed */
- unregister_traceable_app(pollfd[i].fd);
- /* Indicate to remove this fd from the pollfd */
- pollfd[i].fd = -1;
- nb_fd--;
- break;
- }
- }
-
- if (nb_fd != current_nb_fd) {
- update_poll_flag = 1;
- }
}
error:
while (1) {
DBG("Accepting application registration");
+ tracepoint(sessiond_th_reg_poll);
+
+ nb_fd = LTTNG_POLL_GETNB(&events);
+
/* Inifinite blocking call, waiting for transmission */
- ret = poll(pollfd, 2, -1);
+ ret = lttng_poll_wait(&events, -1);
if (ret < 0) {
- perror("poll register apps thread");
goto error;
}
- /* Thread quit pipe has been closed. Killing thread. */
- if (pollfd[0].revents == POLLNVAL) {
- goto error;
- } else if (pollfd[1].revents == POLLERR) {
- ERR("Register apps socket poll error");
- goto error;
- }
+ for (i = 0; i < nb_fd; i++) {
+ /* Fetch once the poll data */
+ revents = LTTNG_POLL_GETEV(&events, i);
+ pollfd = LTTNG_POLL_GETFD(&events, i);
- /* Registration starts here. Recording cycles */
- tracepoint(ust_register_start);
+ /* Thread quit pipe has been closed. Killing thread. */
+ ret = check_thread_quit_pipe(pollfd, revents);
+ if (ret) {
+ goto error;
+ }
- sock = lttcomm_accept_unix_sock(apps_sock);
- if (sock < 0) {
- goto error;
- }
+ /* Event on the registration socket */
+ if (pollfd == apps_sock) {
+ if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
+ ERR("Register apps socket poll error");
+ goto error;
+ } else if (revents & LPOLLIN) {
++ /* Registration starts here. Recording cycles */
++ tracepoint(ust_register_start);
+
- /* Create UST registration command for enqueuing */
- ust_cmd = malloc(sizeof(struct ust_command));
- if (ust_cmd == NULL) {
- perror("ust command malloc");
- goto error;
- }
+ sock = lttcomm_accept_unix_sock(apps_sock);
+ if (sock < 0) {
+ goto error;
+ }
- /*
- * Using message-based transmissions to ensure we don't have to deal
- * with partially received messages.
- */
- ret = lttcomm_recv_unix_sock(sock, &ust_cmd->reg_msg,
- sizeof(struct ust_register_msg));
- if (ret < 0 || ret < sizeof(struct ust_register_msg)) {
- if (ret < 0) {
- perror("lttcomm_recv_unix_sock register apps");
- } else {
- ERR("Wrong size received on apps register");
- }
- free(ust_cmd);
- close(sock);
- continue;
- }
+ /* Create UST registration command for enqueuing */
+ ust_cmd = malloc(sizeof(struct ust_command));
+ if (ust_cmd == NULL) {
+ perror("ust command malloc");
+ goto error;
+ }
- ust_cmd->sock = sock;
+ /*
+ * Using message-based transmissions to ensure we don't
+ * have to deal with partially received messages.
+ */
+ ret = lttcomm_recv_unix_sock(sock, &ust_cmd->reg_msg,
+ sizeof(struct ust_register_msg));
+ if (ret < 0 || ret < sizeof(struct ust_register_msg)) {
+ if (ret < 0) {
+ perror("lttcomm_recv_unix_sock register apps");
+ } else {
+ ERR("Wrong size received on apps register");
+ }
+ free(ust_cmd);
+ close(sock);
+ continue;
+ }
- DBG("UST registration received with pid:%d ppid:%d uid:%d"
- " gid:%d sock:%d name:%s (version %d.%d)",
- ust_cmd->reg_msg.pid, ust_cmd->reg_msg.ppid,
- ust_cmd->reg_msg.uid, ust_cmd->reg_msg.gid,
- ust_cmd->sock, ust_cmd->reg_msg.name,
- ust_cmd->reg_msg.major, ust_cmd->reg_msg.minor);
- /*
- * Lock free enqueue the registration request.
- * The red pill has been taken! This apps will be part of the *system*
- */
- cds_wfq_enqueue(&ust_cmd_queue.queue, &ust_cmd->node);
+ ust_cmd->sock = sock;
- /*
- * Wake the registration queue futex.
- * Implicit memory barrier with the exchange in cds_wfq_enqueue.
- */
- futex_nto1_wake(&ust_cmd_queue.futex);
+ DBG("UST registration received with pid:%d ppid:%d uid:%d"
+ " gid:%d sock:%d name:%s (version %d.%d)",
+ ust_cmd->reg_msg.pid, ust_cmd->reg_msg.ppid,
+ ust_cmd->reg_msg.uid, ust_cmd->reg_msg.gid,
+ ust_cmd->sock, ust_cmd->reg_msg.name,
+ ust_cmd->reg_msg.major, ust_cmd->reg_msg.minor);
+ /*
+ * Lock free enqueue the registration request. The red pill
+ * has been taken! This apps will be part of the *system* :)
+ */
+ cds_wfq_enqueue(&ust_cmd_queue.queue, &ust_cmd->node);
- tracepoint(ust_register_stop);
+ /*
+ * Wake the registration queue futex. Implicit memory
+ * barrier with the exchange in cds_wfq_enqueue.
+ */
+ futex_nto1_wake(&ust_cmd_queue.futex);
++
++ tracepoint(ust_register_stop);
+ }
+ }
+ }
}
error:
*/
static void *thread_manage_clients(void *data)
{
- int sock = 0, ret;
+ int sock = 0, ret, i, pollfd;
+ uint32_t revents, nb_fd;
struct command_ctx *cmd_ctx = NULL;
- struct pollfd pollfd[2];
+ struct lttng_poll_event events;
+ tracepoint(sessiond_th_cli_start);
+
DBG("[thread] Manage client started");
ret = lttcomm_listen_unix_sock(client_sock);
while (1) {
DBG("Accepting client command ...");
+ tracepoint(sessiond_th_cli_poll);
+
+ nb_fd = LTTNG_POLL_GETNB(&events);
+
/* Inifinite blocking call, waiting for transmission */
- ret = poll(pollfd, 2, -1);
+ ret = lttng_poll_wait(&events, -1);
if (ret < 0) {
- perror("poll client thread");
goto error;
}