Re: 2.5 and delay pools

From: Adrian Chadd <adrian@dont-contact.us>
Date: Sun, 7 Mar 2004 23:35:51 -0700

On Thu, Mar 04, 2004, Adrian Chadd wrote:

> I can't leave that in - pinger/unlinkd use an fd_set.
> Gah, I'll have to do a little bit of tidying up to deal with
> the nreadfds and nwritefds in a more efficient fashion.
> Thanks.

Right. Here's what I have. Its a bit evil, but broken fdset manipulation
doesn't crash when using poll+delay pools.

Comments?

adrian

:styx:/usr/local/src/squid-2/squid-2.5/src# cat /tmp/diff
Index: comm_select.c
===================================================================
RCS file: /squid/squid/src/comm_select.c,v
retrieving revision 1.53.2.7
diff -u -r1.53.2.7 comm_select.c
--- comm_select.c 11 May 2003 17:30:13 -0000 1.53.2.7
+++ comm_select.c 8 Mar 2004 06:34:58 -0000
@@ -63,11 +63,14 @@
 static void comm_select_dns_incoming(void);
 #endif

-#if !HAVE_POLL
+#if HAVE_POLL
+static char global_readfds[SQUID_MAXFD];
+static char global_writefds[SQUID_MAXFD];
+#else
 static struct timeval zero_tv;
-#endif
 static fd_set global_readfds;
 static fd_set global_writefds;
+#endif
 static int nreadfds;
 static int nwritefds;

@@ -310,7 +313,7 @@
 {
     struct pollfd pfds[SQUID_MAXFD];
 #if DELAY_POOLS
- fd_set slowfds;
+ char slowfds[SQUID_MAXFD];
 #endif
     PF *hdl = NULL;
     int fd;
@@ -332,7 +335,7 @@
        /* Handle any fs callbacks that need doing */
        storeDirCallback();
 #if DELAY_POOLS
- FD_ZERO(&slowfds);
+ bzero(&slowfds, sizeof(slowfds));
 #endif
        if (commCheckICPIncoming)
            comm_poll_icp_incoming();
@@ -358,7 +361,7 @@
 #if DELAY_POOLS
                case -1:
                    events |= POLLRDNORM;
- FD_SET(i, &slowfds);
+ slowfds[i] = 1;
                    break;
 #endif
                default:
@@ -437,7 +440,7 @@
                if (NULL == (hdl = F->read_handler))
                    (void) 0;
 #if DELAY_POOLS
- else if (FD_ISSET(fd, &slowfds))
+ else if (slowfds[i])
                    commAddSlowFd(fd);
 #endif
                else {
@@ -950,8 +953,13 @@
     cachemgrRegister("comm_incoming",
        "comm_incoming() stats",
        commIncomingStats, 0, 1);
+#if HAVE_POLL
+ bzero(&global_readfds, sizeof(global_readfds));
+ bzero(&global_writefds, sizeof(global_writefds));
+#else
     FD_ZERO(&global_readfds);
     FD_ZERO(&global_writefds);
+#endif
     nreadfds = nwritefds = 0;
 }

@@ -1082,6 +1090,32 @@
     statHistDump(&f->comm_http_incoming, sentry, statHistIntDumper);
 }

+#if HAVE_POLL
+void
+commUpdateReadBits(int fd, PF * handler)
+{
+ if (handler && !global_readfds[fd]) {
+ global_readfds[fd] = 1;
+ nreadfds++;
+ } else if (! handler && global_readfds[fd]) {
+ global_readfds[fd] = 0;
+ nreadfds--;
+ }
+}
+
+void
+commUpdateWriteBits(int fd, PF * handler)
+{
+ if (handler && !global_writefds[fd]) {
+ global_writefds[fd] = 1;
+ nwritefds++;
+ } else if (! handler && global_writefds[fd]) {
+ global_writefds[fd] = 0;
+ nwritefds--;
+ }
+}
+
+#else
 void
 commUpdateReadBits(int fd, PF * handler)
 {
@@ -1105,6 +1139,7 @@
        nwritefds--;
     }
 }
+#endif

 /* Called by async-io or diskd to speed up the polling */
 void
Index: delay_pools.c
===================================================================
RCS file: /squid/squid/src/delay_pools.c,v
retrieving revision 1.19.2.8
diff -u -r1.19.2.8 delay_pools.c
--- delay_pools.c 18 Jun 2003 23:53:35 -0000 1.19.2.8
+++ delay_pools.c 8 Mar 2004 06:34:58 -0000
@@ -89,7 +89,7 @@
 typedef union _delayPool delayPool;

 static delayPool *delay_data = NULL;
-static fd_set delay_no_delay;
+static int delay_no_delay[SQUID_MAXFD];
 static time_t delay_pools_last_update = 0;
 static hash_table *delay_id_ptr_hash = NULL;
 static long memory_used = 0;
@@ -134,7 +134,7 @@
 delayPoolsInit(void)
 {
     delay_pools_last_update = getCurrentTime();
- FD_ZERO(&delay_no_delay);
+ bzero(&delay_no_delay, sizeof(delay_no_delay));
     cachemgrRegister("delay", "Delay Pool Levels", delayPoolStats, 0, 1);
 }

@@ -283,19 +283,19 @@
 void
 delaySetNoDelay(int fd)
 {
- FD_SET(fd, &delay_no_delay);
+ delay_no_delay[fd] = 1;
 }

 void
 delayClearNoDelay(int fd)
 {
- FD_CLR(fd, &delay_no_delay);
+ delay_no_delay[fd] = 0;
 }

 int
 delayIsNoDelay(int fd)
 {
- return FD_ISSET(fd, &delay_no_delay);
+ return (delay_no_delay[fd] == 1);
 }

 static delay_id
Received on Sun Mar 07 2004 - 23:35:52 MST

This archive was generated by hypermail pre-2.1.9 : Thu Apr 01 2004 - 12:00:04 MST