From 898f5d1d8512754eaf0d435f530585d78f89cb84 Mon Sep 17 00:00:00 2001 From: wessels <> Date: Tue, 9 Jul 1996 10:46:46 +0000 Subject: [PATCH] Async I/O from Pete Bentley --- ChangeLog | 1 + configure | 53 +++++++++++++++---------------- configure.in | 5 +-- include/autoconf.h.in | 3 ++ src/Makefile.in | 6 ++-- src/comm.cc | 16 +++++++++- src/disk.cc | 72 +++++++++++-------------------------------- src/main.cc | 5 ++- src/squid.h | 5 ++- 9 files changed, 78 insertions(+), 88 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7cde21279e..2ce607ddff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ Changes to squid-1.1.alpha2: - Added Support for RFC931/ident + - Added Asynchronous Disk I/O routines from Pete Bentley. Changes to squid-1.0.1 (July 8, 1996): diff --git a/configure b/configure index e00726abb8..ef7772ce92 100755 --- a/configure +++ b/configure @@ -517,7 +517,7 @@ fi -# From configure.in Revision: 1.18.2.31 +# From configure.in Revision: 1.21 ac_aux_dir= for ac_dir in aux $srcdir/aux; do if test -f $ac_dir/install-sh; then @@ -1282,6 +1282,7 @@ fi for ac_hdr in \ alloca.h \ + aio.h \ arpa/inet.h \ arpa/nameser.h \ bstring.h \ @@ -1330,7 +1331,7 @@ if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF @@ -1361,7 +1362,7 @@ done echo $ac_n "checking for tm->tm_gmtoff""... $ac_c" 1>&6 cat > conftest.$ac_ext < #include @@ -1387,7 +1388,7 @@ rm -f conftest* echo $ac_n "checking for extended mallinfo""... $ac_c" 1>&6 cat > conftest.$ac_ext < #include @@ -1419,7 +1420,7 @@ else { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < main() @@ -1453,7 +1454,7 @@ else { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < main() @@ -1487,7 +1488,7 @@ if eval "test \"`echo '$''{'ac_cv_header_alloca_h'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < int main() { return 0; } @@ -1519,7 +1520,7 @@ if eval "test \"`echo '$''{'ac_cv_func_alloca'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&6 else cat > conftest.$ac_ext <&6 else cat > conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext <&6 else cat > conftest.$ac_ext < conftest.$ac_ext < @@ -2166,7 +2167,7 @@ if test "$cross_compiling" = yes; then SQUID_UDP_SO_SNDBUF=8192 else cat > conftest.$ac_ext < @@ -2202,7 +2203,7 @@ if test "$cross_compiling" = yes; then SQUID_UDP_SO_RCVBUF=8192 else cat > conftest.$ac_ext < @@ -2238,7 +2239,7 @@ if test "$cross_compiling" = yes; then SQUID_TCP_SO_SNDBUF=8192 else cat > conftest.$ac_ext < @@ -2274,7 +2275,7 @@ if test "$cross_compiling" = yes; then SQUID_TCP_SO_RCVBUF=8192 else cat > conftest.$ac_ext < @@ -2307,7 +2308,7 @@ EOF echo $ac_n "checking if sys_errlist is already defined""... $ac_c" 1>&6 cat > conftest.$ac_ext < int main() { return 0; } diff --git a/configure.in b/configure.in index 23d12f526f..034eae283e 100644 --- a/configure.in +++ b/configure.in @@ -3,13 +3,13 @@ dnl Configuration input file for Squid dnl dnl Duane Wessels, wessels@nlanr.net, February 1996 (autoconf v2.9) dnl -dnl $Id: configure.in,v 1.21 1996/07/09 03:41:04 wessels Exp $ +dnl $Id: configure.in,v 1.22 1996/07/09 04:46:47 wessels Exp $ dnl dnl dnl AC_INIT(src/main.c) AC_CONFIG_HEADER(include/autoconf.h) -AC_REVISION($Revision: 1.21 $)dnl +AC_REVISION($Revision: 1.22 $)dnl AC_PREFIX_DEFAULT(/usr/local/squid) AC_CONFIG_AUX_DIR(aux) @@ -127,6 +127,7 @@ AC_HEADER_STDC AC_CHECK_HEADERS( \ alloca.h \ + aio.h \ arpa/inet.h \ arpa/nameser.h \ bstring.h \ diff --git a/include/autoconf.h.in b/include/autoconf.h.in index 8f9bd10272..e86925ac07 100644 --- a/include/autoconf.h.in +++ b/include/autoconf.h.in @@ -130,6 +130,9 @@ /* Define if you have the timegm function. */ #undef HAVE_TIMEGM +/* Define if you have the header file. */ +#undef HAVE_AIO_H + /* Define if you have the header file. */ #undef HAVE_ALLOCA_H diff --git a/src/Makefile.in b/src/Makefile.in index d288a4d8e5..a4eae948c3 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.in,v 1.26 1996/07/09 03:41:17 wessels Exp $ +# $Id: Makefile.in,v 1.27 1996/07/09 04:46:49 wessels Exp $ # # Uncomment and customize the following to suit your needs: # @@ -52,8 +52,8 @@ CLIENT_LIBS = -L../lib -lmiscutil $(XTRA_LIBS) PROGS = squid client UTILS = dnsserver ftpget CGIPROGS = cachemgr.cgi -OBJS = acl.o background.o cache_cf.o errorpage.o comm.o \ - debug.o disk.o dynamic_array.o \ +OBJS = acl.o async_io.o background.o cache_cf.o errorpage.o \ + comm.o debug.o disk.o dynamic_array.o \ fdstat.o filemap.o ftp.o gopher.o \ hash.o http.o icp.o ident.o ipcache.o \ main.o mime.o neighbors.o objcache.o \ diff --git a/src/comm.cc b/src/comm.cc index 8bdf4aea65..5049dce4aa 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.33 1996/07/09 03:41:20 wessels Exp $ + * $Id: comm.cc,v 1.34 1996/07/09 04:46:50 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -668,6 +668,11 @@ int comm_select(sec, failtime) nfds = 0; maxfd = fdstat_biggest_fd() + 1; for (i = 0; i < maxfd; i++) { +#if USE_ASYNC_IO + /* Using async IO for disk handle, so don't select on them */ + if (fdstat_type(i) == FD_FILE) + continue; +#endif /* Check each open socket for a handler. */ if (fd_table[i].read_handler && fd_table[i].stall_until <= squid_curtime) { nfds++; @@ -692,8 +697,14 @@ int comm_select(sec, failtime) if (shutdown_pending || reread_pending) debug(5, 2, "comm_select: Still waiting on %d FDs\n", nfds); while (1) { +#if USE_ASYNC_IO + /* Another CPU vs latency tradeoff for async IO */ + poll_time.tv_sec = 0; + poll_time.tv_usec = 250000; +#else poll_time.tv_sec = sec > 1 ? 1 : 0; poll_time.tv_usec = 0; +#endif num = select(maxfd, &readfds, &writefds, &exceptfds, &poll_time); if (num >= 0) break; @@ -705,6 +716,9 @@ int comm_select(sec, failtime) return COMM_ERROR; /* NOTREACHED */ } +#if USE_ASYNC_IO + aioExamine(); /* See if any IO completed */ +#endif if (num < 0) continue; debug(5, num ? 5 : 8, "comm_select: %d sockets ready at %d\n", diff --git a/src/disk.cc b/src/disk.cc index 08b4db484e..f4e1a5d963 100644 --- a/src/disk.cc +++ b/src/disk.cc @@ -1,5 +1,5 @@ /* - * $Id: disk.cc,v 1.13 1996/07/09 03:41:22 wessels Exp $ + * $Id: disk.cc,v 1.14 1996/07/09 04:46:51 wessels Exp $ * * DEBUG: section 6 Disk I/O Routines * AUTHOR: Harvest Derived @@ -106,19 +106,6 @@ #include "squid.h" #define DISK_LINE_LEN 1024 -#define MAX_FILE_NAME_LEN 256 - -typedef struct _dread_ctrl { - int fd; - off_t offset; - int req_len; - char *buf; - int cur_len; - int end_of_file; - int (*handler) _PARAMS((int fd, char *buf, int size, int errflag, void *data, - int offset)); - void *client_data; -} dread_ctrl; typedef struct _dwalk_ctrl { int fd; @@ -131,40 +118,6 @@ typedef struct _dwalk_ctrl { void *line_data; } dwalk_ctrl; -typedef struct _dwrite_q { - char *buf; - int len; - int cur_offset; - struct _dwrite_q *next; -} dwrite_q; - -typedef struct _FileEntry { - char filename[MAX_FILE_NAME_LEN]; - enum { - NO, YES - } at_eof; - enum { - NOT_OPEN, OPEN - } open_stat; - enum { - NOT_REQUEST, REQUEST - } close_request; - enum { - NOT_PRESENT, PRESENT - } write_daemon; - enum { - UNLOCK, LOCK - } write_lock; - int access_code; /* use to verify write lock */ - enum { - NO_WRT_PENDING, WRT_PENDING - } write_pending; - void (*wrt_handle) (); - void *wrt_handle_data; - dwrite_q *write_q; - dwrite_q *write_q_tail; -} FileEntry; - /* table for FILE variable, write lock and queue. Indexed by fd. */ FileEntry *file_table; @@ -479,12 +432,20 @@ int file_write(fd, ptr_to_buf, len, access_code, handle, handle_data) file_table[fd].write_q_tail = wq; } - if (file_table[fd].write_daemon == NOT_PRESENT) { - /* got to start write routine for this fd */ - comm_set_select_handler(fd, COMM_SELECT_WRITE, (PF) diskHandleWrite, - (void *) &file_table[fd]); - } + if (file_table[fd].write_daemon == PRESENT) + return DISK_OK; + /* got to start write routine for this fd */ +#if USE_ASYNC_IO + return aioFileQueueWrite(fd, + file_aio_write_complete, + &file_table[fd]); +#else + comm_set_select_handler(fd, + COMM_SELECT_WRITE, + (PF) diskHandleWrite, + (void *) &file_table[fd]); return DISK_OK; +#endif } @@ -571,12 +532,15 @@ int file_read(fd, buf, req_len, offset, handler, client_data) ctrl_dat->handler = handler; ctrl_dat->client_data = client_data; +#if USE_ASYNC_IO + return aioFileQueueRead(fd, file_aio_read_complete, ctrl_dat); +#else comm_set_select_handler(fd, COMM_SELECT_READ, (PF) diskHandleRead, (void *) ctrl_dat); - return DISK_OK; +#endif } diff --git a/src/main.cc b/src/main.cc index 5ae143e14e..181eba9eb0 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,5 +1,5 @@ /* - * $Id: main.cc,v 1.47 1996/07/09 03:41:32 wessels Exp $ + * $Id: main.cc,v 1.48 1996/07/09 04:46:52 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -388,6 +388,9 @@ static void mainInitialize() } squid_signal(SIGPIPE, SIG_IGN, SA_RESTART); squid_signal(SIGCHLD, sig_child, SA_NODEFER | SA_RESTART); +#if USE_ASYNC_IO + squid_signal(SIGIO, aioSigHandler, SA_RESTART); +#endif if (ConfigFile == NULL) ConfigFile = xstrdup(DefaultConfigFile); diff --git a/src/squid.h b/src/squid.h index 488c1c4dfb..d689715b1a 100644 --- a/src/squid.h +++ b/src/squid.h @@ -1,5 +1,5 @@ /* - * $Id: squid.h,v 1.23 1996/07/09 03:41:39 wessels Exp $ + * $Id: squid.h,v 1.24 1996/07/09 04:46:52 wessels Exp $ * * AUTHOR: Duane Wessels * @@ -124,6 +124,9 @@ #if HAVE_SYS_SELECT_H #include #endif +#if USE_ASYNC_IO && HAVE_AIO_H +#include +#endif #if defined(__STRICT_ANSI__) #include -- 2.47.2