Skip to content

Commit 814b493

Browse files
PSRCodejgalar
authored andcommitted
Use pipe instead of eventfd() for notification command queue
Signed-off-by: Jonathan Rajotte <[email protected]> Signed-off-by: Jérémie Galarneau <[email protected]>
1 parent 4a171f3 commit 814b493

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/bin/lttng-sessiond/notification-thread-commands.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int run_command_wait(struct notification_thread_handle *handle,
4444
cds_list_add_tail(&cmd->cmd_list_node,
4545
&handle->cmd_queue.list);
4646
/* Wake-up thread. */
47-
ret = write(handle->cmd_queue.event_fd,
47+
ret = write(lttng_pipe_get_writefd(handle->cmd_queue.event_pipe),
4848
&notification_counter, sizeof(notification_counter));
4949
if (ret < 0) {
5050
PERROR("write to notification thread's queue event fd");

src/bin/lttng-sessiond/notification-thread-events.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ int handle_notification_thread_command(
12751275
struct notification_thread_command *cmd;
12761276

12771277
/* Read event_fd to put it back into a quiescent state. */
1278-
ret = read(handle->cmd_queue.event_fd, &counter, sizeof(counter));
1278+
ret = read(lttng_pipe_get_readfd(handle->cmd_queue.event_pipe), &counter, sizeof(counter));
12791279
if (ret == -1) {
12801280
goto error;
12811281
}

src/bin/lttng-sessiond/notification-thread.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,12 @@ void notification_thread_handle_destroy(
5454
goto end;
5555
}
5656

57-
if (handle->cmd_queue.event_fd < 0) {
58-
goto end;
59-
}
60-
ret = close(handle->cmd_queue.event_fd);
61-
if (ret < 0) {
62-
PERROR("close notification command queue event_fd");
63-
}
64-
6557
assert(cds_list_empty(&handle->cmd_queue.list));
6658
pthread_mutex_destroy(&handle->cmd_queue.lock);
6759

60+
if (handle->cmd_queue.event_pipe) {
61+
lttng_pipe_destroy(handle->cmd_queue.event_pipe);
62+
}
6863
if (handle->channel_monitoring_pipes.ust32_consumer >= 0) {
6964
ret = close(handle->channel_monitoring_pipes.ust32_consumer);
7065
if (ret) {
@@ -94,18 +89,22 @@ struct notification_thread_handle *notification_thread_handle_create(
9489
{
9590
int ret;
9691
struct notification_thread_handle *handle;
92+
struct lttng_pipe *event_pipe = NULL;
9793

9894
handle = zmalloc(sizeof(*handle));
9995
if (!handle) {
10096
goto end;
10197
}
10298

103-
/* FIXME Replace eventfd by a pipe to support older kernels. */
104-
handle->cmd_queue.event_fd = eventfd(0, EFD_CLOEXEC | EFD_SEMAPHORE);
105-
if (handle->cmd_queue.event_fd < 0) {
106-
PERROR("eventfd notification command queue");
99+
event_pipe = lttng_pipe_open(O_CLOEXEC);
100+
if (!event_pipe) {
101+
ERR("event_pipe creation");
107102
goto error;
108103
}
104+
105+
handle->cmd_queue.event_pipe = event_pipe;
106+
event_pipe = NULL;
107+
109108
CDS_INIT_LIST_HEAD(&handle->cmd_queue.list);
110109
ret = pthread_mutex_init(&handle->cmd_queue.lock, NULL);
111110
if (ret) {
@@ -145,6 +144,7 @@ struct notification_thread_handle *notification_thread_handle_create(
145144
end:
146145
return handle;
147146
error:
147+
lttng_pipe_destroy(event_pipe);
148148
notification_thread_handle_destroy(handle);
149149
return NULL;
150150
}
@@ -282,7 +282,7 @@ int init_poll_set(struct lttng_poll_event *poll_set,
282282
ERR("[notification-thread] Failed to add notification channel socket to pollset");
283283
goto error;
284284
}
285-
ret = lttng_poll_add(poll_set, handle->cmd_queue.event_fd,
285+
ret = lttng_poll_add(poll_set, lttng_pipe_get_readfd(handle->cmd_queue.event_pipe),
286286
LPOLLIN | LPOLLERR);
287287
if (ret < 0) {
288288
ERR("[notification-thread] Failed to add notification command queue event fd to pollset");
@@ -544,7 +544,7 @@ void *thread_notification(void *data)
544544
ERR("[notification-thread] Unexpected poll events %u for notification socket %i", revents, fd);
545545
goto error;
546546
}
547-
} else if (fd == handle->cmd_queue.event_fd) {
547+
} else if (fd == lttng_pipe_get_readfd(handle->cmd_queue.event_pipe)) {
548548
ret = handle_notification_thread_command(handle,
549549
&state);
550550
if (ret < 0) {

src/bin/lttng-sessiond/notification-thread.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
struct notification_thread_handle {
3131
/*
3232
* Queue of struct notification command.
33-
* event_fd must be WRITE(2) to signal that a new command
33+
* event_pipe must be WRITE(2) to signal that a new command
3434
* has been enqueued.
3535
*/
3636
struct {
37-
int event_fd;
37+
struct lttng_pipe *event_pipe;
3838
struct cds_list_head list;
3939
pthread_mutex_t lock;
4040
} cmd_queue;

0 commit comments

Comments
 (0)