add experimental prefetching support

master
leitner 21 years ago
parent f52aa87441
commit fa476a9200

@ -0,0 +1,29 @@
#include "iob_internal.h"
#include <stdio.h>
#include <sys/mman.h>
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 (; e<last; ++e) {
if (e->type==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;
}
}
}

@ -20,7 +20,7 @@ int64 iob_send(int64 s,io_batch* b) {
#endif #endif
if (b->bytesleft==0) return 0; 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)); v=alloca(b->bufs*sizeof(struct iovec));
total=0; total=0;
for (;;) { for (;;) {
@ -114,6 +114,7 @@ eagain:
if (!rest) break; if (!rest) break;
} else { } else {
e[i].offset+=rest; e[i].offset+=rest;
e[i].n-=rest;
goto abort; goto abort;
} }
} }

@ -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); int iob_addfile(io_batch* b,int64 fd,uint64 off,uint64 n);
int64 iob_send(int64 s,io_batch* b); int64 iob_send(int64 s,io_batch* b);
void iob_reset(io_batch* b); void iob_reset(io_batch* b);
void iob_prefetch(io_batch* b,uint64 bytes);
#endif #endif

@ -22,7 +22,7 @@ int main(int argc,char* argv[]) {
buffer_puts(buffer_2,"unable to find IP address for "); buffer_puts(buffer_2,"unable to find IP address for ");
buffer_puts(buffer_2,*argv); buffer_puts(buffer_2,*argv);
buffer_puts(buffer_2,": "); buffer_puts(buffer_2,": ");
buffer_puts(buffer_2,strerror(errno)); buffer_puterror(buffer_2);
buffer_putnlflush(buffer_2); buffer_putnlflush(buffer_2);
return 111; return 111;
} }

Loading…
Cancel
Save