[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] Parallax code cleanups.
ChangeSet 1.1686.1.1, 2005/06/07 16:26:07+01:00, akw27@xxxxxxxxxxxxxxxxxxxxxx Parallax code cleanups. Signed-off-by: andrew.warfield@xxxxxxxxxxxx block-async.c | 481 ++++++++++++++++++++++++++----------------------------- block-async.h | 40 ++-- parallax.c | 107 ++++++------ requests-async.c | 139 +++++++-------- 4 files changed, 375 insertions(+), 392 deletions(-) diff -Nru a/tools/blktap/block-async.c b/tools/blktap/block-async.c --- a/tools/blktap/block-async.c 2005-06-09 10:02:05 -04:00 +++ b/tools/blktap/block-async.c 2005-06-09 10:02:05 -04:00 @@ -31,47 +31,47 @@ */ struct read_args { - u64 addr; + u64 addr; }; struct write_args { - u64 addr; - char *block; + u64 addr; + char *block; }; struct alloc_args { - char *block; + char *block; }; struct pending_io_req { - enum {IO_READ, IO_WRITE, IO_ALLOC, IO_RWAKE, IO_WWAKE} op; - union { - struct read_args r; - struct write_args w; - struct alloc_args a; - } u; - io_cb_t cb; - void *param; + enum {IO_READ, IO_WRITE, IO_ALLOC, IO_RWAKE, IO_WWAKE} op; + union { + struct read_args r; + struct write_args w; + struct alloc_args a; + } u; + io_cb_t cb; + void *param; }; void radix_lock_init(struct radix_lock *r) { - int i; - - pthread_mutex_init(&r->lock, NULL); - for (i=0; i < 1024; i++) { - r->lines[i] = 0; - r->waiters[i] = NULL; - r->state[i] = ANY; - } + int i; + + pthread_mutex_init(&r->lock, NULL); + for (i=0; i < 1024; i++) { + r->lines[i] = 0; + r->waiters[i] = NULL; + r->state[i] = ANY; + } } /* maximum outstanding I/O requests issued asynchronously */ /* must be a power of 2.*/ -#define MAX_PENDING_IO 1024 //1024 +#define MAX_PENDING_IO 1024 /* how many threads to concurrently issue I/O to the disk. */ -#define IO_POOL_SIZE 10 //10 +#define IO_POOL_SIZE 10 static struct pending_io_req pending_io_reqs[MAX_PENDING_IO]; static int pending_io_list[MAX_PENDING_IO]; @@ -87,276 +87,268 @@ static void init_pending_io(void) { - int i; + int i; - for (i=0; i<MAX_PENDING_IO; i++) - pending_io_list[i] = i; + for (i=0; i<MAX_PENDING_IO; i++) + pending_io_list[i] = i; } void block_read(u64 addr, io_cb_t cb, void *param) { - struct pending_io_req *req; - - pthread_mutex_lock(&pending_io_lock); - assert(CAN_PRODUCE_PENDING_IO); - - req = PENDING_IO_ENT(io_prod++); - DPRINTF("Produce (R) %lu (%p)\n", io_prod - 1, req); - req->op = IO_READ; - req->u.r.addr = addr; - req->cb = cb; - req->param = param; - + struct pending_io_req *req; + + pthread_mutex_lock(&pending_io_lock); + assert(CAN_PRODUCE_PENDING_IO); + + req = PENDING_IO_ENT(io_prod++); + DPRINTF("Produce (R) %lu (%p)\n", io_prod - 1, req); + req->op = IO_READ; + req->u.r.addr = addr; + req->cb = cb; + req->param = param; + pthread_cond_signal(&pending_io_cond); - pthread_mutex_unlock(&pending_io_lock); + pthread_mutex_unlock(&pending_io_lock); } void block_write(u64 addr, char *block, io_cb_t cb, void *param) { - struct pending_io_req *req; - - pthread_mutex_lock(&pending_io_lock); - assert(CAN_PRODUCE_PENDING_IO); - - req = PENDING_IO_ENT(io_prod++); - DPRINTF("Produce (W) %lu (%p)\n", io_prod - 1, req); - req->op = IO_WRITE; - req->u.w.addr = addr; - req->u.w.block = block; - req->cb = cb; - req->param = param; - + struct pending_io_req *req; + + pthread_mutex_lock(&pending_io_lock); + assert(CAN_PRODUCE_PENDING_IO); + + req = PENDING_IO_ENT(io_prod++); + DPRINTF("Produce (W) %lu (%p)\n", io_prod - 1, req); + req->op = IO_WRITE; + req->u.w.addr = addr; + req->u.w.block = block; + req->cb = cb; + req->param = param; + pthread_cond_signal(&pending_io_cond); - pthread_mutex_unlock(&pending_io_lock); + pthread_mutex_unlock(&pending_io_lock); } void block_alloc(char *block, io_cb_t cb, void *param) { - struct pending_io_req *req; - - pthread_mutex_lock(&pending_io_lock); - assert(CAN_PRODUCE_PENDING_IO); - - req = PENDING_IO_ENT(io_prod++); - req->op = IO_ALLOC; - req->u.a.block = block; - req->cb = cb; - req->param = param; + struct pending_io_req *req; + pthread_mutex_lock(&pending_io_lock); + assert(CAN_PRODUCE_PENDING_IO); + + req = PENDING_IO_ENT(io_prod++); + req->op = IO_ALLOC; + req->u.a.block = block; + req->cb = cb; + req->param = param; + pthread_cond_signal(&pending_io_cond); - pthread_mutex_unlock(&pending_io_lock); + pthread_mutex_unlock(&pending_io_lock); } void block_rlock(struct radix_lock *r, int row, io_cb_t cb, void *param) { - struct io_ret ret; - pthread_mutex_lock(&r->lock); - - if (( r->lines[row] >= 0 ) && (r->state[row] != STOP)) { - r->lines[row]++; - r->state[row] = READ; - DPRINTF("RLOCK : %3d (row: %d)\n", r->lines[row], row); - pthread_mutex_unlock(&r->lock); - ret.type = IO_INT_T; - ret.u.i = 0; - cb(ret, param); - } else { - struct radix_wait **rwc; - struct radix_wait *rw = - (struct radix_wait *) malloc (sizeof(struct radix_wait)); - DPRINTF("RLOCK : %3d (row: %d) -- DEFERRED!\n", r->lines[row], row); - rw->type = RLOCK; - rw->param = param; - rw->cb = cb; - rw->next = NULL; - /* append to waiters list. */ - rwc = &r->waiters[row]; - while (*rwc != NULL) rwc = &(*rwc)->next; - *rwc = rw; - pthread_mutex_unlock(&r->lock); - return; - } + struct io_ret ret; + pthread_mutex_lock(&r->lock); + + if (( r->lines[row] >= 0 ) && (r->state[row] != STOP)) { + r->lines[row]++; + r->state[row] = READ; + DPRINTF("RLOCK : %3d (row: %d)\n", r->lines[row], row); + pthread_mutex_unlock(&r->lock); + ret.type = IO_INT_T; + ret.u.i = 0; + cb(ret, param); + } else { + struct radix_wait **rwc; + struct radix_wait *rw = + (struct radix_wait *) malloc (sizeof(struct radix_wait)); + DPRINTF("RLOCK : %3d (row: %d) -- DEFERRED!\n", r->lines[row], row); + rw->type = RLOCK; + rw->param = param; + rw->cb = cb; + rw->next = NULL; + /* append to waiters list. */ + rwc = &r->waiters[row]; + while (*rwc != NULL) rwc = &(*rwc)->next; + *rwc = rw; + pthread_mutex_unlock(&r->lock); + return; + } } void block_wlock(struct radix_lock *r, int row, io_cb_t cb, void *param) { - struct io_ret ret; - pthread_mutex_lock(&r->lock); - - /* the second check here is redundant -- just here for debugging now. */ - if ((r->state[row] == ANY) && ( r->lines[row] == 0 )) { - r->state[row] = STOP; - r->lines[row] = -1; - DPRINTF("WLOCK : %3d (row: %d)\n", r->lines[row], row); _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |