From fa476a9200202c9df5b657d4fe93890594e9c3e8 Mon Sep 17 00:00:00 2001 From: leitner Date: Wed, 7 Jan 2004 15:58:44 +0000 Subject: [PATCH] add experimental prefetching support --- io/iob_prefetch.c | 29 +++++++++++++++++++++++++++++ io/iob_send.c | 3 ++- iob.h | 1 + test/dnsip.c | 2 +- 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 io/iob_prefetch.c diff --git a/io/iob_prefetch.c b/io/iob_prefetch.c new file mode 100644 index 0000000..1f40b83 --- /dev/null +++ b/io/iob_prefetch.c @@ -0,0 +1,29 @@ +#include "iob_internal.h" +#include +#include + +void iob_prefetch(io_batch* b,uint64 bytes) { + iob_entry* e,* last; + if (b->bytesleft==0) return; + last=(iob_entry*)(((char*)array_start(&b->b))+array_bytes(&b->b)); + e=(iob_entry*)array_start(&b->b); + if (!e) return; + for (; etype==FROMFILE) { + char* c,* d; + if (e->n>=1000000) { + d=c=mmap(0,bytes,PROT_READ,MAP_SHARED,e->fd,(e->offset|4095)+1); + if (c!=MAP_FAILED) { + while (bytes>4096) { + volatile char x=*d; + bytes-=4096; + d+=4096; + (void)x; + } + } + munmap(c,bytes); + } + return; + } + } +} diff --git a/io/iob_send.c b/io/iob_send.c index ed3afc1..e09f39c 100644 --- a/io/iob_send.c +++ b/io/iob_send.c @@ -20,7 +20,7 @@ int64 iob_send(int64 s,io_batch* b) { #endif if (b->bytesleft==0) return 0; - last=((char*)array_start(&b->b))+array_bytes(&b->b); + last=(iob_entry*)(((char*)array_start(&b->b))+array_bytes(&b->b)); v=alloca(b->bufs*sizeof(struct iovec)); total=0; for (;;) { @@ -114,6 +114,7 @@ eagain: if (!rest) break; } else { e[i].offset+=rest; + e[i].n-=rest; goto abort; } } diff --git a/iob.h b/iob.h index 8bfb30a..0a46fa6 100644 --- a/iob.h +++ b/iob.h @@ -29,5 +29,6 @@ int iob_adds_free(io_batch* b,const char* s); int iob_addfile(io_batch* b,int64 fd,uint64 off,uint64 n); int64 iob_send(int64 s,io_batch* b); void iob_reset(io_batch* b); +void iob_prefetch(io_batch* b,uint64 bytes); #endif diff --git a/test/dnsip.c b/test/dnsip.c index 0f7d6e0..6f01900 100644 --- a/test/dnsip.c +++ b/test/dnsip.c @@ -22,7 +22,7 @@ int main(int argc,char* argv[]) { buffer_puts(buffer_2,"unable to find IP address for "); buffer_puts(buffer_2,*argv); buffer_puts(buffer_2,": "); - buffer_puts(buffer_2,strerror(errno)); + buffer_puterror(buffer_2); buffer_putnlflush(buffer_2); return 111; }