Fix: lttng_poll_mod calls compat_(e)poll_add
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v5 1/8 Fix: lttng_poll_mod calls compat_(e)poll_add
lttng_poll_mod should call compat_(e)poll_mod.
--- src/common/compat/poll.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/common/compat/poll.h +2 -2
@@ -177,7 +177,7 @@ extern int compat_epoll_del(struct lttng_poll_event *events, int fd);extern int compat_epoll_mod (struct lttng_poll_event *events,int fd,uint32_t req_events);#define lttng_poll_mod (events, fd, req_events) \ - compat_epoll_add(events, fd, req_events) + compat_epoll_mod(events, fd, req_events)/* * Set up the poll set limits variable poll_max_size
@@ -361,7 +361,7 @@ extern int compat_poll_del(struct lttng_poll_event *events, int fd);extern int compat_poll_mod (struct lttng_poll_event *events,int fd,uint32_t req_events);#define lttng_poll_mod (events, fd, req_events) \ - compat_poll_add(events, fd, req_events) + compat_poll_mod(events, fd, req_events)/* * Set up the poll set limits variable poll_max_size
Signature · 1 line
2.11.0
PATCH v5 2/8 Add Unit test to poll compatibility layer
In reply to a message not in the archive---
File uses space indentation instead.
Added space between operator and operand (for typecasting). Empty line in variables declaration removed. Replaced reset by init for lttng_poll_init test. Removed empty line at the end of function.
.gitignore | 1 + tests/unit/Makefile.am | 9 +- tests/unit/test_utils_compat_poll.c | 234 ++++++++++++++++++++++++++++++++++++ 3 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 tests/unit/test_utils_compat_poll.c
.gitignore +1 -0
@@ -73,6 +73,7 @@ TAGS /tests/unit/test_session /tests/unit/test_uri /tests/unit/test_ust_data +/tests/unit/test_utils_compat_poll /tests/unit/test_utils_parse_size_suffix /tests/unit/test_utils_parse_time_suffix /tests/unit/test_utils_expand_path
tests/unit/Makefile.am +8 -1
@@ -12,6 +12,7 @@ TESTS = test_kernel_data \ test_utils_parse_size_suffix \ test_utils_parse_time_suffix \ test_utils_expand_path \ + test_utils_compat_poll \ test_string_utils \ test_notification \ ini_config/test_ini_config
@@ -28,7 +29,8 @@ LIBLTTNG_CTL=$(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la # Define test programs noinst_PROGRAMS = test_uri test_session test_kernel_data \ test_utils_parse_size_suffix test_utils_parse_time_suffix \ - test_utils_expand_path test_string_utils test_notification + test_utils_expand_path test_utils_compat_poll \ + test_string_utils test_notification if HAVE_LIBLTTNG_UST_CTL noinst_PROGRAMS += test_ust_data
@@ -145,6 +147,11 @@ test_utils_parse_size_suffix_LDADD = $(LIBTAP) $(LIBHASHTABLE) $(LIBCOMMON) $(DL test_utils_parse_time_suffix_SOURCES = test_utils_parse_time_suffix.c test_utils_parse_time_suffix_LDADD = $(LIBTAP) $(LIBHASHTABLE) $(LIBCOMMON) +# compat_poll unit test +test_utils_compat_poll_SOURCES = test_utils_compat_poll.c +test_utils_compat_poll_LDADD = $(LIBTAP) $(LIBHASHTABLE) $(DL_LIBS) \ + $(top_builddir)/src/common/compat/libcompat.la $(LIBCOMMON) + # expand_path unit test test_utils_expand_path_SOURCES = test_utils_expand_path.c test_utils_expand_path_LDADD = $(LIBTAP) $(LIBHASHTABLE) $(LIBCOMMON) $(DL_LIBS)
tests/unit/test_utils_compat_poll.c new file +233 -0
233 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v5 3/8 Change LTTNG_POLL_GETNB behaviour for poll flavor
In reply to a message not in the archiveModify LTTNG_POLL_GETNB to provide compatibility with the epoll flavor. Since it is only used after a lttng_poll_wait call with no modification (add, del, mod) between, this change does not modify the behaviour in its current usage while ensuring similar API behavior between compatibility layer implementations.
--- src/common/compat/poll.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
src/common/compat/poll.h +3 -1
@@ -315,10 +315,12 @@ static inline int __lttng_poll_get_prev_fd(struct lttng_poll_event *events,/* * For the following calls, consider 'e' to be a lttng_poll_event pointer and i * being the index of the events array. +* LTTNG_POLL_GETNB is always used after lttng_poll_wait, thus we can use the +* current list for test compatibility purposes. */ #define LTTNG_POLL_GETFD (e, i) LTTNG_REF(e)->wait.events[i].fd#define LTTNG_POLL_GETEV (e, i) LTTNG_REF(e)->wait.events[i].revents -#define LTTNG_POLL_GETNB (e) LTTNG_REF(e)->wait.nb_fd +#define LTTNG_POLL_GETNB (e) LTTNG_REF(e)->current.nb_fd#define LTTNG_POLL_GETSZ (e) LTTNG_REF(e)->wait.events_size#define LTTNG_POLL_GET_PREV_FD (e, i, nb_fd) \ __lttng_poll_get_prev_fd(LTTNG_REF(e), i, nb_fd)
Signature · 1 line
2.11.0
PATCH v5 4/8 Adapt poll layer behaviour to match the epoll layer
In reply to a message not in the archive---
Removed trailing trailing whitespace in comments.
src/common/compat/compat-poll.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
src/common/compat/compat-poll.c +20 -10
@@ -1,5 +1,6 @@/* * Copyright (C) 2011 - David Goulet <[email protected]> +* Copyright (C) 2019 - Yannick Lamarre <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 only,
@@ -204,10 +205,10 @@ int compat_poll_mod(struct lttng_poll_event *events, int fd, uint32_t req_events) {int i; -bool fd_found = false;struct compat_poll_event_array *current; -if (events ==NULL || events->current.events ==NULL || fd <0 ) { +if (events ==NULL || events->current.nb_fd ==0 || + events->current.events ==NULL || fd <0 ) {ERR ("Bad compat poll mod arguments" ); goto error; }
@@ -216,16 +217,16 @@ int compat_poll_mod(struct lttng_poll_event *events, int fd,for (i =0 ; i < current->nb_fd; i++) {if (current->events[i].fd == fd) { - fd_found = true; current->events[i].events = req_events; events->need_update =1 ;break ; } } -if (!fd_found) { - goto error; - } +/* +* The epoll flavor doesn't flag modifying a non-included FD as an +* error. +*/ return 0 ;
@@ -238,11 +239,12 @@ error:*/ int compat_poll_del (struct lttng_poll_event *events,int fd) { -int new_size, i, count =0 , ret; +int i, count =0 , ret; +uint32_t new_size;struct compat_poll_event_array *current; -if (events ==NULL || events->current.events ==NULL || fd <0 ) { -ERR ("Wrong arguments for poll del" ); +if (events ==NULL || events->current.nb_fd ==0 || + events->current.events ==NULL || fd <0 ) { goto error; }
@@ -257,13 +259,20 @@ int compat_poll_del(struct lttng_poll_event *events, int fd) count++; } } + +/* The fd was not in our set, return no error as with epoll. */ +if (current->nb_fd == count) { + goto end; + } +/* No fd duplicate should be ever added into array. */ assert (current->nb_fd -1 == count); current->nb_fd = count;/* Resize array if needed. */ new_size =1U <<utils_get_count_order_u32 (current->nb_fd); -if (new_size != current->alloc_size && new_size >= current->init_size) { +if (new_size != current->alloc_size && new_size >= current->init_size + && current->nb_fd !=0 ) { ret =resize_poll_event (current, new_size);if (ret <0 ) { goto error;
@@ -272,6 +281,7 @@ int compat_poll_del(struct lttng_poll_event *events, int fd) events->need_update =1 ; +end:return 0 ; error:
Signature · 1 line
2.11.0
PATCH v5 5/8 Fix hang in thread_rotation when using compat-poll
In reply to a message not in the archiveAdd missing verification to prevent a blocking read on an empty fd.
--- src/bin/lttng-sessiond/rotation-thread.c | 4 ++++ 1 file changed, 4 insertions(+)
src/bin/lttng-sessiond/rotation-thread.c +4 -0
@@ -974,6 +974,10 @@ void *thread_rotation(void *data)int fd =LTTNG_POLL_GETFD (&thread.events, i);uint32_t revents =LTTNG_POLL_GETEV (&thread.events, i); +if (!revents) { +/* No activity for this FD (poll implementation). */ +continue ; + }DBG ("[rotation-thread] Handling fd (%i) activity (%u)" , fd, revents);
Signature · 1 line
2.11.0
PATCH v5 6/8 Change lttng_poll_wait behaviour of compat-poll to match compat-epoll
In reply to a message not in the archiveThis removes the need to verify for idle file descriptors and mitigates risks of bug due to behaviour mismatch.
---
Iterator declaration moved to the begining of function.
src/common/compat/compat-poll.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-)
src/common/compat/compat-poll.c +34 -4
@@ -293,7 +293,9 @@ error:*/ int compat_poll_wait (struct lttng_poll_event *events,int timeout) { -int ret; +int ret, active_fd_count; +int idle_pfd_index =0 ; +size_t i;if (events ==NULL || events->current.events ==NULL ) {ERR ("poll wait arguments error" );
@@ -325,11 +327,39 @@ int compat_poll_wait(struct lttng_poll_event *events, int timeout) goto error; } + active_fd_count = ret; +/* -* poll() should always iterate on all FDs since we handle the pollset in -* user space and after poll returns, we have to try every fd for a match. +* Swap all active pollfd structs to the beginning of the +* array to emulate compat-epoll behaviour. This algorithm takes +* advantage of poll's returned value and the burst nature of active +* events on the file descriptors. The while loop guarantees that +* idle_pfd will always point to an idle fd. */ -return events->wait.nb_fd; +if (active_fd_count == events->wait.nb_fd) { + goto end; + } +while (idle_pfd_index < active_fd_count && + events->wait.events[idle_pfd_index].revents !=0 ) { + idle_pfd_index++; + } + +for (i = idle_pfd_index +1 ; idle_pfd_index < active_fd_count; + i++) { +struct pollfd swap_pfd; +struct pollfd *idle_pfd = &events->wait.events[idle_pfd_index]; +struct pollfd *current_pfd = &events->wait.events[i]; + +if (ipfd->revents !=0 ) { + swap_pfd = *current_pfd; + *current_pfd = *idle_pfd; + *idle_pfd = swap_pfd; + idle_pfd_index++; + } + } + +end: +return ret; error:return -1 ;
Signature · 1 line
2.11.0
PATCH v5 7/8 Clean code base from redundant verification
In reply to a message not in the archiveRemove redundant verification for file descriptors with 0 revents in code base.
--- src/bin/lttng-consumerd/health-consumerd.c | 5 ----- src/bin/lttng-relayd/health-relayd.c | 5 ----- src/bin/lttng-relayd/live.c | 10 ---------- src/bin/lttng-relayd/main.c | 16 ---------------- src/bin/lttng-sessiond/agent-thread.c | 5 ----- src/bin/lttng-sessiond/client.c | 5 ----- src/bin/lttng-sessiond/dispatch.c | 5 ----- src/bin/lttng-sessiond/health.c | 5 ----- src/bin/lttng-sessiond/ht-cleanup.c | 5 ----- src/bin/lttng-sessiond/manage-apps.c | 5 ----- src/bin/lttng-sessiond/manage-consumer.c | 10 ---------- src/bin/lttng-sessiond/manage-kernel.c | 5 ----- src/bin/lttng-sessiond/notification-thread.c | 3 --- src/bin/lttng-sessiond/notify-apps.c | 5 ----- src/bin/lttng-sessiond/register.c | 5 ----- src/bin/lttng-sessiond/rotation-thread.c | 4 ---- src/common/consumer/consumer.c | 10 ---------- 17 files changed, 108 deletions(-)
src/bin/lttng-consumerd/health-consumerd.c +0 -5
@@ -259,11 +259,6 @@ restart: revents =LTTNG_POLL_GETEV (&events, i); pollfd =LTTNG_POLL_GETFD (&events, i); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -/* Thread quit pipe has been closed. Killing thread. */ ret =check_health_quit_pipe (pollfd, revents);if (ret) {
src/bin/lttng-relayd/health-relayd.c +0 -5
@@ -329,11 +329,6 @@ restart: revents =LTTNG_POLL_GETEV (&events, i); pollfd =LTTNG_POLL_GETFD (&events, i); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -/* Thread quit pipe has been closed. Killing thread. */ ret =check_health_quit_pipe (pollfd, revents);if (ret) {
src/bin/lttng-relayd/live.c +0 -10
@@ -543,11 +543,6 @@ restart: revents =LTTNG_POLL_GETEV (&events, i); pollfd =LTTNG_POLL_GETFD (&events, i); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -/* Thread quit pipe has been closed. Killing thread. */ ret =check_thread_quit_pipe (pollfd, revents);if (ret) {
@@ -2000,11 +1995,6 @@ restart:health_code_update (); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -/* Thread quit pipe has been closed. Killing thread. */ ret =check_thread_quit_pipe (pollfd, revents);if (ret) {
src/bin/lttng-relayd/main.c +0 -16
@@ -858,14 +858,6 @@ restart: revents =LTTNG_POLL_GETEV (&events, i); pollfd =LTTNG_POLL_GETFD (&events, i); -if (!revents) { -/* -* No activity for this FD (poll -* implementation). -*/ -continue ; - } -/* Thread quit pipe has been closed. Killing thread. */ ret =check_thread_quit_pipe (pollfd, revents);if (ret) {
@@ -3813,14 +3805,6 @@ restart:health_code_update (); -if (!revents) { -/* -* No activity for this FD (poll -* implementation). -*/ -continue ; - } -/* Thread quit pipe has been closed. Killing thread. */ ret =check_thread_quit_pipe (pollfd, revents);if (ret) {
src/bin/lttng-sessiond/agent-thread.c +0 -5
@@ -404,11 +404,6 @@ restart: revents =LTTNG_POLL_GETEV (&events, i); pollfd =LTTNG_POLL_GETFD (&events, i); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -/* Thread quit pipe has been closed. Killing thread. */ if (pollfd == quit_pipe_read_fd) { goto exit;
src/bin/lttng-sessiond/client.c +0 -5
@@ -2090,11 +2090,6 @@ static void *thread_manage_clients(void *data)health_code_update (); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -if (pollfd == thread_quit_pipe_fd) { err =0 ; goto exit;
src/bin/lttng-sessiond/dispatch.c +0 -5
@@ -144,11 +144,6 @@ static void sanitize_wait_queue(struct ust_reg_wait_queue *wait_queue)uint32_t revents =LTTNG_POLL_GETEV (&events, i);int pollfd =LTTNG_POLL_GETFD (&events, i); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -cds_list_for_each_entry_safe (wait_node, tmp_wait_node, &wait_queue->head, head) { if (pollfd == wait_node->app->sock &&
src/bin/lttng-sessiond/health.c +0 -5
@@ -158,11 +158,6 @@ restart: revents =LTTNG_POLL_GETEV (&events, i); pollfd =LTTNG_POLL_GETFD (&events, i); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -/* Event on the registration socket */ if (pollfd == sock) {if (revents &LPOLLIN ) {
src/bin/lttng-sessiond/ht-cleanup.c +0 -5
@@ -155,11 +155,6 @@ static void *thread_ht_cleanup(void *data) revents =LTTNG_POLL_GETEV (&events, i); pollfd =LTTNG_POLL_GETFD (&events, i); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -if (pollfd != ht_cleanup_pipe[0 ]) {continue ; }
src/bin/lttng-sessiond/manage-apps.c +0 -5
@@ -123,11 +123,6 @@ static void *thread_application_management(void *data)health_code_update (); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -if (pollfd == quit_pipe_read_fd) { err =0 ; goto exit;
src/bin/lttng-sessiond/manage-consumer.c +0 -10
@@ -134,11 +134,6 @@ void *thread_consumer_management(void *data)health_code_update (); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -/* Thread quit pipe has been closed. Killing thread. */ if (pollfd == quit_pipe_read_fd) { err =0 ;
@@ -298,11 +293,6 @@ void *thread_consumer_management(void *data)health_code_update (); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -/* * Thread quit pipe has been triggered, flag that we should stop * but continue the current loop to handle potential data from
src/bin/lttng-sessiond/manage-kernel.c +0 -5
@@ -267,11 +267,6 @@ static void *thread_kernel_management(void *data)health_code_update (); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -if (pollfd == quit_pipe_read_fd) { err =0 ; goto exit;
src/bin/lttng-sessiond/notification-thread.c +0 -3
@@ -562,9 +562,6 @@ void *thread_notification(void *data)int fd =LTTNG_POLL_GETFD (&state.events, i);uint32_t revents =LTTNG_POLL_GETEV (&state.events, i); -if (!revents) { -continue ; - }DBG ("[notification-thread] Handling fd (%i) activity (%u)" , fd, revents);if (fd == state.notification_channel_socket) {
src/bin/lttng-sessiond/notify-apps.c +0 -5
@@ -109,11 +109,6 @@ restart: revents =LTTNG_POLL_GETEV (&events, i); pollfd =LTTNG_POLL_GETFD (&events, i); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -/* Thread quit pipe has been closed. Killing thread. */ if (pollfd == quit_pipe_read_fd) { err =0 ;
src/bin/lttng-sessiond/register.c +0 -5
@@ -239,11 +239,6 @@ static void *thread_application_registration(void *data) revents =LTTNG_POLL_GETEV (&events, i); pollfd =LTTNG_POLL_GETFD (&events, i); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -/* Thread quit pipe has been closed. Killing thread. */ if (pollfd == quit_pipe_read_fd) { err =0 ;
src/bin/lttng-sessiond/rotation-thread.c +0 -4
@@ -974,10 +974,6 @@ void *thread_rotation(void *data)int fd =LTTNG_POLL_GETFD (&thread.events, i);uint32_t revents =LTTNG_POLL_GETEV (&thread.events, i); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - }DBG ("[rotation-thread] Handling fd (%i) activity (%u)" , fd, revents);
src/common/consumer/consumer.c +0 -10
@@ -2396,11 +2396,6 @@ restart: revents =LTTNG_POLL_GETEV (&events, i); pollfd =LTTNG_POLL_GETFD (&events, i); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -if (pollfd ==lttng_pipe_get_readfd (ctx->consumer_metadata_pipe)) {if (revents &LPOLLIN ) {ssize_t pipe_len;
@@ -2990,11 +2985,6 @@ restart: revents =LTTNG_POLL_GETEV (&events, i); pollfd =LTTNG_POLL_GETFD (&events, i); -if (!revents) { -/* No activity for this FD (poll implementation). */ -continue ; - } -if (pollfd == ctx->consumer_channel_pipe[0 ]) {if (revents &LPOLLIN ) {enum consumer_channel_action action;
Signature · 1 line
2.11.0
PATCH v5 8/8 Fix typo
In reply to a message not in the archive--- src/common/compat/poll.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/common/compat/poll.h +1 -1
@@ -358,7 +358,7 @@ extern int compat_poll_del(struct lttng_poll_event *events, int fd);compat_poll_del (events, fd)/* -* Modify an fd's events in the epoll set. +* Modify an fd's events in the poll set. */extern int compat_poll_mod (struct lttng_poll_event *events,int fd,uint32_t req_events);
Signature · 1 line
2.11.0