From: Pablo Neira Ayuso <pablo@netfilter.org>
To: heitzenberger@astaro.com
Cc: netfilter-devel@vger.kernel.org, holger@eitzenberger.org
Subject: Re: [ULOGD 10/15] Improve select performance
Date: Tue, 19 Feb 2008 20:58:00 +0100 [thread overview]
Message-ID: <47BB34C8.9080902@netfilter.org> (raw)
In-Reply-To: <20080202205108.605422040@astaro.com>
[-- Attachment #1: Type: text/plain, Size: 503 bytes --]
heitzenberger@astaro.com wrote:
> The previous code consumed quite lots of CPU cycles because of
> inefficiently handling fd_sets.
I have applied the following patch which is based on your improvement.
I'll check the other patches that are targeted to make plugins
reconfigurable as soon as I have some spare time, whatever help in the
merge process with current SVN would be appreciated and would surely
speed up the development. Thanks.
--
"Los honestos son inadaptados sociales" -- Les Luthiers
[-- Attachment #2: x --]
[-- Type: text/plain, Size: 2295 bytes --]
Index: src/select.c
===================================================================
--- src/select.c (revisión: 7377)
+++ src/select.c (copia de trabajo)
@@ -26,6 +26,7 @@
#include <ulogd/linuxlist.h>
static int maxfd = 0;
+static fd_set readset, writeset, exceptset;
static LLIST_HEAD(ulogd_fds);
int ulogd_register_fd(struct ulogd_fd *fd)
@@ -41,6 +42,15 @@
if (flags < 0)
return -1;
+ if (fd->when & ULOGD_FD_READ)
+ FD_SET(fd->fd, &readset);
+
+ if (fd->when & ULOGD_FD_WRITE)
+ FD_SET(fd->fd, &writeset);
+
+ if (fd->when & ULOGD_FD_EXCEPT)
+ FD_SET(fd->fd, &exceptset);
+
/* Register FD */
if (fd->fd > maxfd)
maxfd = fd->fd;
@@ -52,44 +62,48 @@
void ulogd_unregister_fd(struct ulogd_fd *fd)
{
+ if (fd->when & ULOGD_FD_READ)
+ FD_CLR(fd->fd, &readset);
+
+ if (fd->when & ULOGD_FD_WRITE)
+ FD_CLR(fd->fd, &writeset);
+
+ if (fd->when & ULOGD_FD_EXCEPT)
+ FD_CLR(fd->fd, &exceptset);
+
llist_del(&fd->list);
+
+ /* Improvement: recalculate maxfd iif fd->fd == maxfd */
+ maxfd = -1;
+ llist_for_each_entry(fd, &ulogd_fds, list) {
+ if (fd->fd > maxfd)
+ maxfd = fd->fd;
+ }
}
int ulogd_select_main(struct timeval *tv)
{
struct ulogd_fd *ufd;
- fd_set readset, writeset, exceptset;
+ fd_set rds_tmp, wrs_tmp, exs_tmp;
int i;
- FD_ZERO(&readset);
- FD_ZERO(&writeset);
- FD_ZERO(&exceptset);
+ rds_tmp = readset;
+ wrs_tmp = writeset;
+ exs_tmp = exceptset;
- /* prepare read and write fdsets */
- llist_for_each_entry(ufd, &ulogd_fds, list) {
- if (ufd->when & ULOGD_FD_READ)
- FD_SET(ufd->fd, &readset);
-
- if (ufd->when & ULOGD_FD_WRITE)
- FD_SET(ufd->fd, &writeset);
-
- if (ufd->when & ULOGD_FD_EXCEPT)
- FD_SET(ufd->fd, &exceptset);
- }
-
- i = select(maxfd+1, &readset, &writeset, &exceptset, tv);
+ i = select(maxfd+1, &rds_tmp, &wrs_tmp, &exs_tmp, tv);
if (i > 0) {
/* call registered callback functions */
llist_for_each_entry(ufd, &ulogd_fds, list) {
int flags = 0;
- if (FD_ISSET(ufd->fd, &readset))
+ if (FD_ISSET(ufd->fd, &rds_tmp))
flags |= ULOGD_FD_READ;
- if (FD_ISSET(ufd->fd, &writeset))
+ if (FD_ISSET(ufd->fd, &wrs_tmp))
flags |= ULOGD_FD_WRITE;
- if (FD_ISSET(ufd->fd, &exceptset))
+ if (FD_ISSET(ufd->fd, &exs_tmp))
flags |= ULOGD_FD_EXCEPT;
if (flags)
next prev parent reply other threads:[~2008-02-19 19:58 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-02 20:48 [ULOGD 00/15] ulogd V2 improvements, round 2 heitzenberger
2008-02-02 20:48 ` [ULOGD 01/15] Add NACCT output plugin heitzenberger
2008-02-02 21:24 ` Pablo Neira Ayuso
2008-02-02 20:48 ` [ULOGD 02/15] common.h: added heitzenberger
2008-02-02 21:30 ` Pablo Neira Ayuso
2008-02-02 20:48 ` [ULOGD 03/15] Replace timer code by working version heitzenberger
2008-02-02 22:45 ` Pablo Neira Ayuso
2008-02-02 20:48 ` [ULOGD 04/15] Add IFI list heitzenberger
2008-02-02 21:36 ` Pablo Neira Ayuso
2008-02-02 21:50 ` Holger Eitzenberger
2008-02-02 22:56 ` Pablo Neira Ayuso
2008-02-02 20:48 ` [ULOGD 05/15] Add signalling subsystem heitzenberger
2008-02-19 19:38 ` Pablo Neira Ayuso
2008-02-20 8:43 ` Holger Eitzenberger
2008-02-20 12:20 ` Patrick McHardy
2008-02-20 12:23 ` Pablo Neira Ayuso
2008-02-02 20:48 ` [ULOGD 06/15] Conffile cleanup, use common pr_debug() heitzenberger
2008-02-02 21:43 ` Pablo Neira Ayuso
2008-02-02 20:48 ` [ULOGD 07/15] Renice to -1 on startup heitzenberger
2008-02-02 21:47 ` Pablo Neira Ayuso
2008-02-02 20:48 ` [ULOGD 08/15] Initial round to make plugins reconfigurable heitzenberger
2008-02-02 20:48 ` [ULOGD 09/15] llist: add llist_for_each_prev_safe() heitzenberger
2008-02-02 20:48 ` [ULOGD 10/15] Improve select performance heitzenberger
2008-02-19 19:58 ` Pablo Neira Ayuso [this message]
2008-02-02 20:48 ` [ULOGD 11/15] Add set_sockbuf_len() heitzenberger
2008-02-19 19:57 ` Pablo Neira Ayuso
2008-02-02 20:48 ` [ULOGD 12/15] Introduce global state, skip some stacks during reconfiguration heitzenberger
2008-02-02 20:48 ` [ULOGD 13/15] llist: turn poisoning off by default heitzenberger
2008-02-02 20:48 ` [ULOGD 14/15] SQLITE3: port to ulogd 2.00, mostly a rewrite heitzenberger
2008-02-02 20:48 ` [ULOGD 15/15] NFCT: rework and let it scale heitzenberger
2008-02-02 22:52 ` [ULOGD 00/15] ulogd V2 improvements, round 2 Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47BB34C8.9080902@netfilter.org \
--to=pablo@netfilter.org \
--cc=heitzenberger@astaro.com \
--cc=holger@eitzenberger.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).