Skip to contentSkip to conversation

Fix: various compat poll/epoll issues

PATCH New Mathieu Desnoyers 2 participants 6 messages Jan 5, 2015 – Jan 8, 2015 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 2/6 Fix: various compat poll/epoll issues

poll:
- fix two nb_fd off by one in "add",
- simplify array size calculation,
- add error checking,
- compress the content of array before resizing it on "del" (out-of-bound memory access issue),
- set wait.nb_fd = 0 when no FD are present in array on wait,
- remove need_realloc flag: this can be checked internally by comparing current->alloc_size and wait->alloc_size. Minimize the number of duplicated state.

epoll:
- add error checking,
- simplify array size calculation (make it similar to poll),
- Set default size when poll_max_size is 0 within compat_epoll_set_max_size(), which allow better error checking elsewhere in epoll compat code.

---
 src/common/compat/compat-epoll.c | 62 ++++++++++++++++-------------------
 src/common/compat/compat-poll.c  | 70 +++++++++++++++++-----------------------
 src/common/compat/poll.h         |  7 ++--
 3 files changed, 61 insertions(+), 78 deletions(-)
src/common/compat/compat-epoll.c +28 -34
index 29bd2f8..5d6153b 100644
@@ -77,8 +77,13 @@ int compat_epoll_create(struct lttng_poll_event *events, int size, int flags)
 		goto error;
 	}
 
+	if (!poll_max_size) {
+		ERR("poll_max_size not initialized yet");
+		goto error;
+	}
+
 	/* Don't bust the limit here */
-	if (size > poll_max_size && poll_max_size != 0) {
+	if (size > poll_max_size) {
 		size = poll_max_size;
 	}
 
@@ -166,7 +171,7 @@ int compat_epoll_del(struct lttng_poll_event *events, int fd)
 {
 	int ret;
 
-	if (events == NULL || fd < 0) {
+	if (events == NULL || fd < 0 || events->nb_fd == 0) {
 		goto error;
 	}
 
@@ -205,6 +210,12 @@ int compat_epoll_wait(struct lttng_poll_event *events, int timeout)
 		ERR("Wrong arguments in compat_epoll_wait");
 		goto error;
 	}
+	assert(events->nb_fd >= 0);
+
+	if (events->nb_fd == 0) {
+		errno = EINVAL;
+		return -1;
+	}
 
 	/*
 	 * Resize if needed before waiting. We could either expand the array or
@@ -212,23 +223,8 @@ int compat_epoll_wait(struct lttng_poll_event *events, int timeout)
 	 * ensured that the events argument of the epoll_wait call will be large
 	 * enough to hold every possible returned events.
 	 */
-	if (events->nb_fd > events->alloc_size) {
-		/* Expand if the nb_fd is higher than the actual size. */
-		new_size = max_t(uint32_t,
-				1U << utils_get_count_order_u32(events->nb_fd),
-				events->alloc_size << 1UL);
-	} else if ((events->nb_fd << 1UL) <= events->alloc_size &&
-			events->nb_fd >= events->init_size) {
-		/* Shrink if nb_fd multiplied by two is <= than the actual size. */
-		new_size = max_t(uint32_t,
-				utils_get_count_order_u32(events->nb_fd) >> 1U,
-				events->alloc_size >> 1U);
-	} else {
-		/* Indicate that we don't want to resize. */
-		new_size = 0;
-	}
-
-	if (new_size) {
+	new_size = 1U << utils_get_count_order_u32(events->nb_fd);
+	if (new_size != events->alloc_size && new_size >= events->init_size) {
 		ret = resize_poll_event(events, new_size);
 		if (ret < 0) {
 			/* ENOMEM problem at this point. */
@@ -258,17 +254,16 @@ error:
 /*
  * Setup poll set maximum size.
  */
-void compat_epoll_set_max_size(void)
+int compat_epoll_set_max_size(void)
 {
-	int ret, fd;
+	int ret, fd, retval = 0;
 	ssize_t size_ret;
 	char buf[64];
 
-	poll_max_size = DEFAULT_POLL_SIZE;
-
 	fd = open(COMPAT_EPOLL_PROC_PATH, O_RDONLY);
 	if (fd < 0) {
-		return;
+		retval = -1;
+		goto end;
 	}
 
 	size_ret = lttng_read(fd, buf, sizeof(buf));
@@ -278,21 +273,20 @@ void compat_epoll_set_max_size(void)
 	 */
 	if (size_ret < 0 || size_ret >= sizeof(buf)) {
 		PERROR("read set max size");
-		goto error;
+		retval = -1;
+		goto end_read;
 	}
 	buf[size_ret] = '\0';
-
 	poll_max_size = atoi(buf);
-	if (poll_max_size == 0) {
-		/* Extra precaution */
-		poll_max_size = DEFAULT_POLL_SIZE;
-	}
-
-	DBG("epoll set max size is %d", poll_max_size);
-
-error:
+end_read:
 	ret = close(fd);
 	if (ret) {
 		PERROR("close");
 	}
+end:
+	if (!poll_max_size) {
+		poll_max_size = DEFAULT_POLL_SIZE;
+	}
+	DBG("epoll set max size is %d", poll_max_size);
+	return retval;
 }
src/common/compat/compat-poll.c +30 -40

154 lines not on this page · raw message

src/common/compat/poll.h +3 -4
index f892c83..30bdca7 100644
@@ -174,7 +174,7 @@ extern int compat_epoll_del(struct lttng_poll_event *events, int fd);
 /*
  * Set up the poll set limits variable poll_max_size
  */
-extern void compat_epoll_set_max_size(void);
+extern int compat_epoll_set_max_size(void);
 #define lttng_poll_set_max_size() \
 	compat_epoll_set_max_size()
 
@@ -285,8 +285,7 @@ struct compat_poll_event {
 	 * execution before a poll wait is done.
 	 */
 	struct compat_poll_event_array current;
-	/* Indicate if wait.events needs to be realloc. */
-	int need_realloc:1;
+
 	/* Indicate if wait.events need to be updated from current. */
 	int need_update:1;
 };
@@ -351,7 +350,7 @@ extern int compat_poll_del(struct lttng_poll_event *events, int fd);
 /*
  * Set up the poll set limits variable poll_max_size
  */
-extern void compat_poll_set_max_size(void);
+extern int compat_poll_set_max_size(void);
 #define lttng_poll_set_max_size() \
 	compat_poll_set_max_size()
 
Signature · 1 line
2.1.1
#2 lore raw

PATCH 3/6 Fix: compat poll: add missing empty revents checks

In reply to a message not in the archive

Poll returns the entire array, including entries that have no activity. We need to check them explicitly.

---
 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                | 71 ++++++++++++++++++------------
 src/bin/lttng-sessiond/agent-thread.c      |  5 +++
 src/bin/lttng-sessiond/ht-cleanup.c        | 10 +++++
 src/bin/lttng-sessiond/main.c              | 40 +++++++++++++++++
 src/bin/lttng-sessiond/ust-thread.c        |  5 +++
 src/common/consumer.c                      |  8 +++-
 9 files changed, 129 insertions(+), 30 deletions(-)
src/bin/lttng-consumerd/health-consumerd.c +5 -0
index bd47f0c..fc9a266 100644
@@ -261,6 +261,11 @@ 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 +5 -0
index af375e2..75149ba 100644
@@ -330,6 +330,11 @@ 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 +10 -0
index fd570e0..756efbe 100644
@@ -488,6 +488,11 @@ 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) {
@@ -1922,6 +1927,11 @@ 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 +42 -29

100 lines not on this page · raw message

src/bin/lttng-sessiond/agent-thread.c +5 -0
index d7d9c6c..a9cc6e7 100644
@@ -330,6 +330,11 @@ 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 = sessiond_check_thread_quit_pipe(pollfd, revents);
 			if (ret) {
src/bin/lttng-sessiond/ht-cleanup.c +10 -0
index ace41e5..373c913 100644
@@ -96,6 +96,11 @@ 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 != ht_cleanup_pipe[0]) {
 				continue;
 			}
@@ -140,6 +145,11 @@ 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 == ht_cleanup_pipe[0]) {
 				continue;
 			}
src/bin/lttng-sessiond/main.c +40 -0
index f418d74..2649b55 100644
@@ -1090,6 +1090,11 @@ static void *thread_manage_kernel(void *data)
 
 			health_code_update();
 
+			if (!revents) {
+				/* No activity for this FD (poll implementation). */
+				continue;
+			}
+
 			/* Thread quit pipe has been closed. Killing thread. */
 			ret = sessiond_check_thread_quit_pipe(pollfd, revents);
 			if (ret) {
@@ -1235,6 +1240,11 @@ restart:
 
 		health_code_update();
 
+		if (!revents) {
+			/* No activity for this FD (poll implementation). */
+			continue;
+		}
+
 		/* Thread quit pipe has been closed. Killing thread. */
 		ret = sessiond_check_thread_quit_pipe(pollfd, revents);
 		if (ret) {
@@ -1362,6 +1372,11 @@ restart_poll:
 
 			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
@@ -1538,6 +1553,11 @@ static void *thread_manage_apps(void *data)
 
 			health_code_update();
 
+			if (!revents) {
+				/* No activity for this FD (poll implementation). */
+				continue;
+			}
+
 			/* Thread quit pipe has been closed. Killing thread. */
 			ret = sessiond_check_thread_quit_pipe(pollfd, revents);
 			if (ret) {
@@ -1716,6 +1736,11 @@ 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 &&
@@ -2055,6 +2080,11 @@ static void *thread_registration_apps(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. */
 			ret = sessiond_check_thread_quit_pipe(pollfd, revents);
 			if (ret) {
@@ -3918,6 +3948,11 @@ 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 = sessiond_check_thread_quit_pipe(pollfd, revents);
 			if (ret) {
@@ -4090,6 +4125,11 @@ static void *thread_manage_clients(void *data)
 
 			health_code_update();
 
+			if (!revents) {
+				/* No activity for this FD (poll implementation). */
+				continue;
+			}
+
 			/* Thread quit pipe has been closed. Killing thread. */
 			ret = sessiond_check_thread_quit_pipe(pollfd, revents);
 			if (ret) {
src/bin/lttng-sessiond/ust-thread.c +5 -0
index d92c1f9..6f4295d 100644
@@ -92,6 +92,11 @@ 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 = sessiond_check_thread_quit_pipe(pollfd, revents);
 			if (ret) {
src/common/consumer.c +7 -1
index 3f72af3..1ece1d5 100644
@@ -2212,6 +2212,11 @@ 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 & (LPOLLERR | LPOLLHUP )) {
 					DBG("Metadata thread pipe hung up");
@@ -2782,10 +2787,11 @@ restart:
 			revents = LTTNG_POLL_GETEV(&events, i);
 			pollfd = LTTNG_POLL_GETFD(&events, i);
 
-			/* Just don't waste time if no returned events for the fd */
 			if (!revents) {
+				/* No activity for this FD (poll implementation). */
 				continue;
 			}
+
 			if (pollfd == ctx->consumer_channel_pipe[0]) {
 				if (revents & (LPOLLERR | LPOLLHUP)) {
 					DBG("Channel thread pipe hung up");
Signature · 1 line
2.1.1
#3 lore raw

PATCH 4/6 Fix: call lttng_poll_set_max_size before start threads

In reply to a message not in the archive

This changes the location of lttng_poll_set_max_size() call within sessiond main() to call it before creating the ht_cleanup thread. This fix is only needed on top of the main refactoring patch.

This fix also adds checks for lttng_poll_set_max_size() error values.

---
 src/bin/lttng-consumerd/lttng-consumerd.c |  5 ++++-
 src/bin/lttng-relayd/live.c               |  5 ++++-
 src/bin/lttng-relayd/main.c               |  5 ++++-
 src/bin/lttng-sessiond/main.c             | 10 +++++++---
 4 files changed, 19 insertions(+), 6 deletions(-)
src/bin/lttng-consumerd/lttng-consumerd.c +4 -1
index b43e8f1..7122d06 100644
@@ -346,7 +346,10 @@ int main(int argc, char **argv)
 	}
 
 	/* Set up max poll set size */
-	lttng_poll_set_max_size();
+	if (lttng_poll_set_max_size()) {
+		retval = -1;
+		goto exit_init_data;
+	}
 
 	if (*command_sock_path == '\0') {
 		switch (opt_type) {
src/bin/lttng-relayd/live.c +4 -1
index 756efbe..3728005 100644
@@ -2102,7 +2102,10 @@ int relayd_live_create(struct lttng_uri *uri,
 	cds_wfcq_init(&viewer_conn_queue.head, &viewer_conn_queue.tail);
 
 	/* Set up max poll set size */
-	lttng_poll_set_max_size();
+	if (lttng_poll_set_max_size()) {
+		retval = -1;
+		goto exit_init_data;
+	}
 
 	/* Setup the dispatcher thread */
 	ret = pthread_create(&live_dispatcher_thread, NULL,
src/bin/lttng-relayd/main.c +4 -1
index 94bb4cb..d09b0c6 100644
@@ -2850,7 +2850,10 @@ int main(int argc, char **argv)
 	cds_wfcq_init(&relay_conn_queue.head, &relay_conn_queue.tail);
 
 	/* Set up max poll set size */
-	lttng_poll_set_max_size();
+	if (lttng_poll_set_max_size()) {
+		retval = -1;
+		goto exit_init_data;
+	}
 
 	/* Initialize communication library */
 	lttcomm_init();
src/bin/lttng-sessiond/main.c +7 -3
index 2649b55..6bc7b1e 100644
@@ -5205,6 +5205,12 @@ int main(int argc, char **argv)
 		goto exit_ht_cleanup_pipe;
 	}
 
+	/* Set up max poll set size */
+	if (lttng_poll_set_max_size()) {
+		retval = -1;
+		goto exit_set_max_size;
+	}
+
 	/* Create thread to clean up RCU hash tables */
 	ret = pthread_create(&ht_cleanup_thread, NULL,
 			thread_ht_cleanup, (void *) NULL);
@@ -5539,9 +5545,6 @@ int main(int argc, char **argv)
 	 */
 	session_list_ptr = session_get_list();
 
-	/* Set up max poll set size */
-	lttng_poll_set_max_size();
-
 	cmd_init();
 
 	/* Check for the application socket timeout env variable. */
@@ -5771,6 +5774,7 @@ exit_init_data:
 		retval = -1;
 	}
 exit_ht_cleanup:
+exit_set_max_size:
 
 	utils_close_pipe(ht_cleanup_pipe);
 exit_ht_cleanup_pipe:
Signature · 1 line
2.1.1
#4 lore raw

PATCH 5/6 Fix: poll: show the correct number of fds

In reply to a message not in the archive

LTTNG_POLL_GETNB() uses wait nb_fd, which is only updated after lttng_poll_wait returns.

---
 src/bin/lttng-sessiond/agent-thread.c |  4 +++-
 src/bin/lttng-sessiond/ht-cleanup.c   |  5 +++--
 src/bin/lttng-sessiond/main.c         |  8 ++++++--
 src/bin/lttng-sessiond/ust-thread.c   |  5 +++--
 src/common/consumer.c                 | 10 ++++++++--
 5 files changed, 23 insertions(+), 9 deletions(-)
src/bin/lttng-sessiond/agent-thread.c +3 -1
index a9cc6e7..5f48151 100644
@@ -307,12 +307,14 @@ void *agent_thread_manage_registration(void *data)
 	}
 
 	while (1) {
-		DBG3("[agent-thread] Manage agent polling on %d fds",
+		DBG3("[agent-thread] Manage agent polling",
 				LTTNG_POLL_GETNB(&events));
 
 		/* Inifinite blocking call, waiting for transmission */
 restart:
 		ret = lttng_poll_wait(&events, -1);
+		DBG3("[agent-thread] Manage agent return from poll on %d fds",
+				LTTNG_POLL_GETNB(&events));
 		if (ret < 0) {
 			/*
 			 * Restart interrupted system call.
src/bin/lttng-sessiond/ht-cleanup.c +3 -2
index 373c913..e5a2916 100644
@@ -66,14 +66,15 @@ void *thread_ht_cleanup(void *data)
 	while (1) {
 		int handled_event;
 
-		DBG3("[ht-thread] Polling on %d fds.",
-			LTTNG_POLL_GETNB(&events));
+		DBG3("[ht-thread] Polling.");
 
 		/* Inifinite blocking call, waiting for transmission */
 restart:
 		handled_event = 0;
 		health_poll_entry();
 		ret = lttng_poll_wait(&events, -1);
+		DBG3("[ht-thread] Returning from poll on %d fds.",
+			LTTNG_POLL_GETNB(&events));
 		health_poll_exit();
 		if (ret < 0) {
 			/*
src/bin/lttng-sessiond/main.c +6 -2
index 6bc7b1e..6fd1d1e 100644
@@ -1059,12 +1059,14 @@ static void *thread_manage_kernel(void *data)
 			update_poll_flag = 0;
 		}
 
-		DBG("Thread kernel polling on %d fds", LTTNG_POLL_GETNB(&events));
+		DBG("Thread kernel polling");
 
 		/* Poll infinite value of time */
 	restart:
 		health_poll_entry();
 		ret = lttng_poll_wait(&events, -1);
+		DBG("Thread kernel return from poll on %d fds",
+				LTTNG_POLL_GETNB(&events));
 		health_poll_exit();
 		if (ret < 0) {
 			/*
@@ -1527,12 +1529,14 @@ static void *thread_manage_apps(void *data)
 	health_code_update();
 
 	while (1) {
-		DBG("Apps thread polling on %d fds", LTTNG_POLL_GETNB(&events));
+		DBG("Apps thread polling");
 
 		/* Inifinite blocking call, waiting for transmission */
 	restart:
 		health_poll_entry();
 		ret = lttng_poll_wait(&events, -1);
+		DBG("Apps thread return from poll on %d fds",
+				LTTNG_POLL_GETNB(&events));
 		health_poll_exit();
 		if (ret < 0) {
 			/*
src/bin/lttng-sessiond/ust-thread.c +3 -2
index 6f4295d..b421eb2 100644
@@ -65,13 +65,14 @@ void *ust_thread_manage_notify(void *data)
 	health_code_update();
 
 	while (1) {
-		DBG3("[ust-thread] Manage notify polling on %d fds",
-				LTTNG_POLL_GETNB(&events));
+		DBG3("[ust-thread] Manage notify polling");
 
 		/* Inifinite blocking call, waiting for transmission */
 restart:
 		health_poll_entry();
 		ret = lttng_poll_wait(&events, -1);
+		DBG3("[ust-thread] Manage notify return from poll on %d fds",
+				LTTNG_POLL_GETNB(&events));
 		health_poll_exit();
 		if (ret < 0) {
 			/*
src/common/consumer.c +8 -2
index 1ece1d5..ef5da12 100644
@@ -2190,9 +2190,12 @@ void *consumer_thread_metadata_poll(void *data)
 		}
 
 restart:
-		DBG("Metadata poll wait with %d fd(s)", LTTNG_POLL_GETNB(&events));
+		health_code_update();
 		health_poll_entry();
+		DBG("Metadata poll wait");
 		ret = lttng_poll_wait(&events, -1);
+		DBG("Metadata poll return from wait with %d fd(s)",
+				LTTNG_POLL_GETNB(&events));
 		health_poll_exit();
 		DBG("Metadata event catched in thread");
 		if (ret < 0) {
@@ -2765,9 +2768,12 @@ void *consumer_thread_channel_poll(void *data)
 		}
 
 restart:
-		DBG("Channel poll wait with %d fd(s)", LTTNG_POLL_GETNB(&events));
+		health_code_update();
+		DBG("Channel poll wait");
 		health_poll_entry();
 		ret = lttng_poll_wait(&events, -1);
+		DBG("Channel poll return from wait with %d fd(s)",
+				LTTNG_POLL_GETNB(&events));
 		health_poll_exit();
 		DBG("Channel event catched in thread");
 		if (ret < 0) {
Signature · 1 line
2.1.1
#5 lore raw

PATCH 6/6 Fix: exit threads not only on goto restart

In reply to a message not in the archive

Exit threads as soon as number of FD is 0, on every loop (no need for goto restart special case). Number of FD being 0 is a sufficient condition for exiting the thread: it means the quit pipe has been removed from the poll set.

---
 src/common/consumer.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
src/common/consumer.c +7 -17
index ef5da12..607116f 100644
@@ -2181,14 +2181,6 @@ void *consumer_thread_metadata_poll(void *data)
 	DBG("Metadata main loop started");
 
 	while (1) {
-		health_code_update();
-
-		/* Only the metadata pipe is set */
-		if (LTTNG_POLL_GETNB(&events) == 0 && consumer_quit == 1) {
-			err = 0;	/* All is OK */
-			goto end;
-		}
-
 restart:
 		health_code_update();
 		health_poll_entry();
@@ -2203,7 +2195,10 @@ restart:
 				ERR("Poll EINTR catched");
 				goto restart;
 			}
-			goto error;
+			if (LTTNG_POLL_GETNB(&events) == 0) {
+				err = 0;	/* All is OK */
+			}
+			goto end;
 		}
 
 		nb_fd = ret;
@@ -2759,14 +2754,6 @@ void *consumer_thread_channel_poll(void *data)
 	DBG("Channel main loop started");
 
 	while (1) {
-		health_code_update();
-
-		/* Only the channel pipe is set */
-		if (LTTNG_POLL_GETNB(&events) == 0 && consumer_quit == 1) {
-			err = 0;	/* All is OK */
-			goto end;
-		}
-
 restart:
 		health_code_update();
 		DBG("Channel poll wait");
@@ -2781,6 +2768,9 @@ restart:
 				ERR("Poll EINTR catched");
 				goto restart;
 			}
+			if (LTTNG_POLL_GETNB(&events) == 0) {
+				err = 0;	/* All is OK */
+			}
 			goto end;
 		}
 
Signature · 1 line
2.1.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Re: [PATCH lttng-tools 5/6] Fix: poll: show the correct number of fds

Quoted 17 lines · Mathieu Desnoyers

LTTNG_POLL_GETNB() uses wait nb_fd, which is only updated after lttng_poll_wait returns.

---
 src/bin/lttng-sessiond/agent-thread.c |  4 +++-
 src/bin/lttng-sessiond/ht-cleanup.c   |  5 +++--
 src/bin/lttng-sessiond/main.c         |  8 ++++++--
 src/bin/lttng-sessiond/ust-thread.c   |  5 +++--
 src/common/consumer.c                 | 10 ++++++++--
 5 files changed, 23 insertions(+), 9 deletions(-)
src/bin/lttng-sessiond/agent-thread.c +0 -0
index a9cc6e7..5f48151 100644

src/bin/lttng-sessiond/agent-thread.c void *agent_thread_manage_registration(void *data) · line 311

Quoted 6 lines
src/bin/lttng-sessiond/agent-thread.c +1 -1
@@ -307,12 +307,14 @@ void *agent_thread_manage_registration(void *data)
        }
 
        while (1) {
-               DBG3("[agent-thread] Manage agent polling on %d fds",
+               DBG3("[agent-thread] Manage agent polling",
                                LTTNG_POLL_GETNB(&events));

All merged with a small change here as "LTTNG_POLL_GETNB(&events)" is no longer referred to in the format string.

I also added a "Fixes #747" note in the appropriate commit messages.

Thanks!
Jérémie

Quoted 123 lines
src/bin/lttng-sessiond/agent-thread.c +2 -0
                /* Inifinite blocking call, waiting for transmission */
 restart:
                ret = lttng_poll_wait(&events, -1);
+               DBG3("[agent-thread] Manage agent return from poll on %d fds",
+                               LTTNG_POLL_GETNB(&events));
                if (ret < 0) {
                        /*
                         * Restart interrupted system call.
src/bin/lttng-sessiond/ht-cleanup.c +3 -2
index 373c913..e5a2916 100644
@@ -66,14 +66,15 @@ void *thread_ht_cleanup(void *data)
        while (1) {
                int handled_event;
 
-               DBG3("[ht-thread] Polling on %d fds.",
-                       LTTNG_POLL_GETNB(&events));
+               DBG3("[ht-thread] Polling.");
 
                /* Inifinite blocking call, waiting for transmission */
 restart:
                handled_event = 0;
                health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
+               DBG3("[ht-thread] Returning from poll on %d fds.",
+                       LTTNG_POLL_GETNB(&events));
                health_poll_exit();
                if (ret < 0) {
                        /*
src/bin/lttng-sessiond/main.c +6 -2
index 6bc7b1e..6fd1d1e 100644
@@ -1059,12 +1059,14 @@ static void *thread_manage_kernel(void *data)
                        update_poll_flag = 0;
                }
 
-               DBG("Thread kernel polling on %d fds", LTTNG_POLL_GETNB(&events));
+               DBG("Thread kernel polling");
 
                /* Poll infinite value of time */
        restart:
                health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
+               DBG("Thread kernel return from poll on %d fds",
+                               LTTNG_POLL_GETNB(&events));
                health_poll_exit();
                if (ret < 0) {
                        /*
@@ -1527,12 +1529,14 @@ static void *thread_manage_apps(void *data)
        health_code_update();
 
        while (1) {
-               DBG("Apps thread polling on %d fds", LTTNG_POLL_GETNB(&events));
+               DBG("Apps thread polling");
 
                /* Inifinite blocking call, waiting for transmission */
        restart:
                health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
+               DBG("Apps thread return from poll on %d fds",
+                               LTTNG_POLL_GETNB(&events));
                health_poll_exit();
                if (ret < 0) {
                        /*
src/bin/lttng-sessiond/ust-thread.c +3 -2
index 6f4295d..b421eb2 100644
@@ -65,13 +65,14 @@ void *ust_thread_manage_notify(void *data)
        health_code_update();
 
        while (1) {
-               DBG3("[ust-thread] Manage notify polling on %d fds",
-                               LTTNG_POLL_GETNB(&events));
+               DBG3("[ust-thread] Manage notify polling");
 
                /* Inifinite blocking call, waiting for transmission */
 restart:
                health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
+               DBG3("[ust-thread] Manage notify return from poll on %d fds",
+                               LTTNG_POLL_GETNB(&events));
                health_poll_exit();
                if (ret < 0) {
                        /*
src/common/consumer.c +8 -3
index 1ece1d5..ef5da12 100644
@@ -2190,9 +2190,12 @@ void *consumer_thread_metadata_poll(void *data)
                }
 
 restart:
-               DBG("Metadata poll wait with %d fd(s)", LTTNG_POLL_GETNB(&events));
+               health_code_update();
                health_poll_entry();
+               DBG("Metadata poll wait");
                ret = lttng_poll_wait(&events, -1);
+               DBG("Metadata poll return from wait with %d fd(s)",
+                               LTTNG_POLL_GETNB(&events));
                health_poll_exit();
                DBG("Metadata event catched in thread");
                if (ret < 0) {
@@ -2765,9 +2768,12 @@ void *consumer_thread_channel_poll(void *data)
                }
 
 restart:
-               DBG("Channel poll wait with %d fd(s)", LTTNG_POLL_GETNB(&events));
+               health_code_update();
+               DBG("Channel poll wait");
                health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
+               DBG("Channel poll return from wait with %d fd(s)",
+                               LTTNG_POLL_GETNB(&events));
                health_poll_exit();
                DBG("Channel event catched in thread");
                if (ret < 0) {
--

2.1.1

Signature · 8 lines
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev