mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
Fix some newline ugliness that BK wouldn't correct.
Signed-off-by: akw27@cl.cam.ac.uk
This commit is contained in:
1 parent
fe39b61fe4
commit
2d984d10eb
4 files changed
+749
-749
No files matched your search
+159
-159
@@ -1,49 +1,49 @@
|
||||
/* block-async.c
|
||||
*
|
||||
* Asynchronous block wrappers for parallax.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include "block-async.h"
|
||||
#include "blockstore.h"
|
||||
#include "vdi.h"
|
||||
|
||||
|
||||
#if 0
|
||||
#define DPRINTF(_f, _a...) printf ( _f , ## _a )
|
||||
#else
|
||||
#define DPRINTF(_f, _a...) ((void)0)
|
||||
#endif
|
||||
|
||||
/* We have a queue of outstanding I/O requests implemented as a
|
||||
* circular producer-consumer ring with free-running buffers.
|
||||
* to allow reordering, this ring indirects to indexes in an
|
||||
* ring of io_structs.
|
||||
*
|
||||
* the block_* calls may either add an entry to this ring and return,
|
||||
* or satisfy the request immediately and call the callback directly.
|
||||
* None of the io calls in parallax should be nested enough to worry
|
||||
* about stack problems with this approach.
|
||||
*/
|
||||
|
||||
struct read_args {
|
||||
/* block-async.c
|
||||
*
|
||||
* Asynchronous block wrappers for parallax.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include "block-async.h"
|
||||
#include "blockstore.h"
|
||||
#include "vdi.h"
|
||||
|
||||
|
||||
#if 0
|
||||
#define DPRINTF(_f, _a...) printf ( _f , ## _a )
|
||||
#else
|
||||
#define DPRINTF(_f, _a...) ((void)0)
|
||||
#endif
|
||||
|
||||
/* We have a queue of outstanding I/O requests implemented as a
|
||||
* circular producer-consumer ring with free-running buffers.
|
||||
* to allow reordering, this ring indirects to indexes in an
|
||||
* ring of io_structs.
|
||||
*
|
||||
* the block_* calls may either add an entry to this ring and return,
|
||||
* or satisfy the request immediately and call the callback directly.
|
||||
* None of the io calls in parallax should be nested enough to worry
|
||||
* about stack problems with this approach.
|
||||
*/
|
||||
|
||||
struct read_args {
|
||||
u64 addr;
|
||||
};
|
||||
|
||||
struct write_args {
|
||||
};
|
||||
|
||||
struct write_args {
|
||||
u64 addr;
|
||||
char *block;
|
||||
};
|
||||
|
||||
struct alloc_args {
|
||||
};
|
||||
|
||||
struct alloc_args {
|
||||
char *block;
|
||||
};
|
||||
|
||||
struct pending_io_req {
|
||||
};
|
||||
|
||||
struct pending_io_req {
|
||||
enum {IO_READ, IO_WRITE, IO_ALLOC, IO_RWAKE, IO_WWAKE} op;
|
||||
union {
|
||||
struct read_args r;
|
||||
@@ -52,10 +52,10 @@ struct pending_io_req {
|
||||
} u;
|
||||
io_cb_t cb;
|
||||
void *param;
|
||||
};
|
||||
|
||||
void radix_lock_init(struct radix_lock *r)
|
||||
{
|
||||
};
|
||||
|
||||
void radix_lock_init(struct radix_lock *r)
|
||||
{
|
||||
int i;
|
||||
|
||||
pthread_mutex_init(&r->lock, NULL);
|
||||
@@ -64,38 +64,38 @@ void radix_lock_init(struct radix_lock *r)
|
||||
r->waiters[i] = NULL;
|
||||
r->state[i] = ANY;
|
||||
}
|
||||
}
|
||||
|
||||
/* maximum outstanding I/O requests issued asynchronously */
|
||||
/* must be a power of 2.*/
|
||||
}
|
||||
|
||||
/* maximum outstanding I/O requests issued asynchronously */
|
||||
/* must be a power of 2.*/
|
||||
#define MAX_PENDING_IO 1024
|
||||
|
||||
/* how many threads to concurrently issue I/O to the disk. */
|
||||
|
||||
/* how many threads to concurrently issue I/O to the disk. */
|
||||
#define IO_POOL_SIZE 10
|
||||
|
||||
static struct pending_io_req pending_io_reqs[MAX_PENDING_IO];
|
||||
static int pending_io_list[MAX_PENDING_IO];
|
||||
static unsigned long io_prod = 0, io_cons = 0, io_free = 0;
|
||||
#define PENDING_IO_MASK(_x) ((_x) & (MAX_PENDING_IO - 1))
|
||||
#define PENDING_IO_IDX(_x) ((_x) - pending_io_reqs)
|
||||
#define PENDING_IO_ENT(_x) \
|
||||
(&pending_io_reqs[pending_io_list[PENDING_IO_MASK(_x)]])
|
||||
#define CAN_PRODUCE_PENDING_IO ((io_free + MAX_PENDING_IO) != io_prod)
|
||||
#define CAN_CONSUME_PENDING_IO (io_cons != io_prod)
|
||||
static pthread_mutex_t pending_io_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_cond_t pending_io_cond = PTHREAD_COND_INITIALIZER;
|
||||
|
||||
static void init_pending_io(void)
|
||||
{
|
||||
|
||||
static struct pending_io_req pending_io_reqs[MAX_PENDING_IO];
|
||||
static int pending_io_list[MAX_PENDING_IO];
|
||||
static unsigned long io_prod = 0, io_cons = 0, io_free = 0;
|
||||
#define PENDING_IO_MASK(_x) ((_x) & (MAX_PENDING_IO - 1))
|
||||
#define PENDING_IO_IDX(_x) ((_x) - pending_io_reqs)
|
||||
#define PENDING_IO_ENT(_x) \
|
||||
(&pending_io_reqs[pending_io_list[PENDING_IO_MASK(_x)]])
|
||||
#define CAN_PRODUCE_PENDING_IO ((io_free + MAX_PENDING_IO) != io_prod)
|
||||
#define CAN_CONSUME_PENDING_IO (io_cons != io_prod)
|
||||
static pthread_mutex_t pending_io_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_cond_t pending_io_cond = PTHREAD_COND_INITIALIZER;
|
||||
|
||||
static void init_pending_io(void)
|
||||
{
|
||||
int 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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void block_read(u64 addr, io_cb_t cb, void *param)
|
||||
{
|
||||
struct pending_io_req *req;
|
||||
|
||||
pthread_mutex_lock(&pending_io_lock);
|
||||
@@ -108,13 +108,13 @@ void block_read(u64 addr, io_cb_t cb, void *param)
|
||||
req->cb = cb;
|
||||
req->param = param;
|
||||
|
||||
pthread_cond_signal(&pending_io_cond);
|
||||
pthread_cond_signal(&pending_io_cond);
|
||||
pthread_mutex_unlock(&pending_io_lock);
|
||||
}
|
||||
|
||||
|
||||
void block_write(u64 addr, char *block, io_cb_t cb, void *param)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void block_write(u64 addr, char *block, io_cb_t cb, void *param)
|
||||
{
|
||||
struct pending_io_req *req;
|
||||
|
||||
pthread_mutex_lock(&pending_io_lock);
|
||||
@@ -128,15 +128,15 @@ void block_write(u64 addr, char *block, io_cb_t cb, void *param)
|
||||
req->cb = cb;
|
||||
req->param = param;
|
||||
|
||||
pthread_cond_signal(&pending_io_cond);
|
||||
pthread_cond_signal(&pending_io_cond);
|
||||
pthread_mutex_unlock(&pending_io_lock);
|
||||
}
|
||||
|
||||
|
||||
void block_alloc(char *block, io_cb_t cb, void *param)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
@@ -146,12 +146,12 @@ void block_alloc(char *block, io_cb_t cb, void *param)
|
||||
req->cb = cb;
|
||||
req->param = param;
|
||||
|
||||
pthread_cond_signal(&pending_io_cond);
|
||||
pthread_cond_signal(&pending_io_cond);
|
||||
pthread_mutex_unlock(&pending_io_lock);
|
||||
}
|
||||
|
||||
void block_rlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
|
||||
{
|
||||
}
|
||||
|
||||
void block_rlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
|
||||
{
|
||||
struct io_ret ret;
|
||||
pthread_mutex_lock(&r->lock);
|
||||
|
||||
@@ -179,11 +179,11 @@ void block_rlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
|
||||
pthread_mutex_unlock(&r->lock);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void block_wlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void block_wlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
|
||||
{
|
||||
struct io_ret ret;
|
||||
pthread_mutex_lock(&r->lock);
|
||||
|
||||
@@ -212,12 +212,12 @@ void block_wlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
|
||||
pthread_mutex_unlock(&r->lock);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* called with radix_lock locked and lock count of zero. */
|
||||
static void wake_waiters(struct radix_lock *r, int row)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* called with radix_lock locked and lock count of zero. */
|
||||
static void wake_waiters(struct radix_lock *r, int row)
|
||||
{
|
||||
struct pending_io_req *req;
|
||||
struct radix_wait *rw;
|
||||
|
||||
@@ -263,14 +263,14 @@ static void wake_waiters(struct radix_lock *r, int row)
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&pending_io_lock);
|
||||
pthread_cond_signal(&pending_io_cond);
|
||||
pthread_cond_signal(&pending_io_cond);
|
||||
pthread_mutex_unlock(&pending_io_lock);
|
||||
}
|
||||
|
||||
void block_runlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
|
||||
{
|
||||
}
|
||||
|
||||
void block_runlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
|
||||
{
|
||||
struct io_ret ret;
|
||||
|
||||
|
||||
pthread_mutex_lock(&r->lock);
|
||||
assert(r->lines[row] > 0); /* try to catch misuse. */
|
||||
r->lines[row]--;
|
||||
@@ -280,10 +280,10 @@ void block_runlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
|
||||
}
|
||||
pthread_mutex_unlock(&r->lock);
|
||||
cb(ret, param);
|
||||
}
|
||||
|
||||
void block_wunlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
|
||||
{
|
||||
}
|
||||
|
||||
void block_wunlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
|
||||
{
|
||||
struct io_ret ret;
|
||||
|
||||
pthread_mutex_lock(&r->lock);
|
||||
@@ -293,11 +293,11 @@ void block_wunlock(struct radix_lock *r, int row, io_cb_t cb, void *param)
|
||||
wake_waiters(r, row);
|
||||
pthread_mutex_unlock(&r->lock);
|
||||
cb(ret, param);
|
||||
}
|
||||
|
||||
/* consumer calls */
|
||||
static void do_next_io_req(struct pending_io_req *req)
|
||||
{
|
||||
}
|
||||
|
||||
/* consumer calls */
|
||||
static void do_next_io_req(struct pending_io_req *req)
|
||||
{
|
||||
struct io_ret ret;
|
||||
void *param;
|
||||
|
||||
@@ -334,60 +334,60 @@ static void do_next_io_req(struct pending_io_req *req)
|
||||
pthread_mutex_lock(&pending_io_lock);
|
||||
pending_io_list[PENDING_IO_MASK(io_free++)] = PENDING_IO_IDX(req);
|
||||
pthread_mutex_unlock(&pending_io_lock);
|
||||
|
||||
|
||||
assert(req->cb != NULL);
|
||||
req->cb(ret, param);
|
||||
|
||||
}
|
||||
|
||||
void *io_thread(void *param)
|
||||
{
|
||||
}
|
||||
|
||||
void *io_thread(void *param)
|
||||
{
|
||||
int tid;
|
||||
struct pending_io_req *req;
|
||||
|
||||
/* Set this thread's tid. */
|
||||
tid = *(int *)param;
|
||||
free(param);
|
||||
|
||||
start:
|
||||
pthread_mutex_lock(&pending_io_lock);
|
||||
while (io_prod == io_cons) {
|
||||
pthread_cond_wait(&pending_io_cond, &pending_io_lock);
|
||||
}
|
||||
|
||||
if (io_prod == io_cons) {
|
||||
/* unnecessary wakeup. */
|
||||
pthread_mutex_unlock(&pending_io_lock);
|
||||
goto start;
|
||||
}
|
||||
|
||||
tid = *(int *)param;
|
||||
free(param);
|
||||
|
||||
start:
|
||||
pthread_mutex_lock(&pending_io_lock);
|
||||
while (io_prod == io_cons) {
|
||||
pthread_cond_wait(&pending_io_cond, &pending_io_lock);
|
||||
}
|
||||
|
||||
if (io_prod == io_cons) {
|
||||
/* unnecessary wakeup. */
|
||||
pthread_mutex_unlock(&pending_io_lock);
|
||||
goto start;
|
||||
}
|
||||
|
||||
req = PENDING_IO_ENT(io_cons++);
|
||||
pthread_mutex_unlock(&pending_io_lock);
|
||||
|
||||
do_next_io_req(req);
|
||||
|
||||
|
||||
do_next_io_req(req);
|
||||
|
||||
goto start;
|
||||
|
||||
}
|
||||
|
||||
static pthread_t io_pool[IO_POOL_SIZE];
|
||||
void start_io_threads(void)
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static pthread_t io_pool[IO_POOL_SIZE];
|
||||
void start_io_threads(void)
|
||||
|
||||
{
|
||||
int i, tid=0;
|
||||
|
||||
for (i=0; i < IO_POOL_SIZE; i++) {
|
||||
int ret, *t;
|
||||
t = (int *)malloc(sizeof(int));
|
||||
*t = tid++;
|
||||
ret = pthread_create(&io_pool[i], NULL, io_thread, t);
|
||||
if (ret != 0) printf("Error starting thread %d\n", i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void init_block_async(void)
|
||||
{
|
||||
int ret, *t;
|
||||
t = (int *)malloc(sizeof(int));
|
||||
*t = tid++;
|
||||
ret = pthread_create(&io_pool[i], NULL, io_thread, t);
|
||||
if (ret != 0) printf("Error starting thread %d\n", i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void init_block_async(void)
|
||||
{
|
||||
init_pending_io();
|
||||
start_io_threads();
|
||||
}
|
||||
}
|
||||
+49
-49
@@ -1,69 +1,69 @@
|
||||
/* block-async.h
|
||||
*
|
||||
* Asynchronous block wrappers for parallax.
|
||||
*/
|
||||
|
||||
#ifndef _BLOCKASYNC_H_
|
||||
#define _BLOCKASYNC_H_
|
||||
|
||||
#include <assert.h>
|
||||
#include <xc.h>
|
||||
#include "vdi.h"
|
||||
|
||||
struct io_ret
|
||||
{
|
||||
/* block-async.h
|
||||
*
|
||||
* Asynchronous block wrappers for parallax.
|
||||
*/
|
||||
|
||||
#ifndef _BLOCKASYNC_H_
|
||||
#define _BLOCKASYNC_H_
|
||||
|
||||
#include <assert.h>
|
||||
#include <xc.h>
|
||||
#include "vdi.h"
|
||||
|
||||
struct io_ret
|
||||
{
|
||||
enum {IO_ADDR_T, IO_BLOCK_T, IO_INT_T} type;
|
||||
union {
|
||||
u64 a;
|
||||
char *b;
|
||||
int i;
|
||||
} u;
|
||||
};
|
||||
|
||||
typedef void (*io_cb_t)(struct io_ret r, void *param);
|
||||
|
||||
/* per-vdi lock structures to make sure requests run in a safe order. */
|
||||
struct radix_wait {
|
||||
};
|
||||
|
||||
typedef void (*io_cb_t)(struct io_ret r, void *param);
|
||||
|
||||
/* per-vdi lock structures to make sure requests run in a safe order. */
|
||||
struct radix_wait {
|
||||
enum {RLOCK, WLOCK} type;
|
||||
io_cb_t cb;
|
||||
void *param;
|
||||
struct radix_wait *next;
|
||||
};
|
||||
|
||||
struct radix_lock {
|
||||
};
|
||||
|
||||
struct radix_lock {
|
||||
pthread_mutex_t lock;
|
||||
int lines[1024];
|
||||
struct radix_wait *waiters[1024];
|
||||
enum {ANY, READ, STOP} state[1024];
|
||||
};
|
||||
void radix_lock_init(struct radix_lock *r);
|
||||
|
||||
void block_read(u64 addr, io_cb_t cb, void *param);
|
||||
void block_write(u64 addr, char *block, io_cb_t cb, void *param);
|
||||
void block_alloc(char *block, io_cb_t cb, void *param);
|
||||
void block_rlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
|
||||
void block_wlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
|
||||
void block_runlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
|
||||
void block_wunlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
|
||||
void init_block_async(void);
|
||||
|
||||
static inline u64 IO_ADDR(struct io_ret r)
|
||||
{
|
||||
};
|
||||
void radix_lock_init(struct radix_lock *r);
|
||||
|
||||
void block_read(u64 addr, io_cb_t cb, void *param);
|
||||
void block_write(u64 addr, char *block, io_cb_t cb, void *param);
|
||||
void block_alloc(char *block, io_cb_t cb, void *param);
|
||||
void block_rlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
|
||||
void block_wlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
|
||||
void block_runlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
|
||||
void block_wunlock(struct radix_lock *r, int row, io_cb_t cb, void *param);
|
||||
void init_block_async(void);
|
||||
|
||||
static inline u64 IO_ADDR(struct io_ret r)
|
||||
{
|
||||
assert(r.type == IO_ADDR_T);
|
||||
return r.u.a;
|
||||
}
|
||||
|
||||
static inline char *IO_BLOCK(struct io_ret r)
|
||||
{
|
||||
}
|
||||
|
||||
static inline char *IO_BLOCK(struct io_ret r)
|
||||
{
|
||||
assert(r.type == IO_BLOCK_T);
|
||||
return r.u.b;
|
||||
}
|
||||
|
||||
static inline int IO_INT(struct io_ret r)
|
||||
{
|
||||
}
|
||||
|
||||
static inline int IO_INT(struct io_ret r)
|
||||
{
|
||||
assert(r.type == IO_INT_T);
|
||||
return r.u.i;
|
||||
}
|
||||
|
||||
|
||||
#endif //_BLOCKASYNC_H_
|
||||
}
|
||||
|
||||
|
||||
#endif //_BLOCKASYNC_H_
|
||||
+524
-524
File diff suppressed because it is too large.
Load diff
@@ -1,24 +1,24 @@
|
||||
#ifndef _REQUESTSASYNC_H_
|
||||
#define _REQUESTSASYNC_H_
|
||||
|
||||
#include "block-async.h"
|
||||
#include "blockstore.h" /* for newblock etc. */
|
||||
|
||||
/*
|
||||
#define BLOCK_SIZE 4096
|
||||
#define ZERO 0ULL
|
||||
#define getid(x) (((x)>>1)&0x7fffffffffffffffLLU)
|
||||
#define iswritable(x) (((x) & 1LLU) != 0)
|
||||
#define writable(x) (((x) << 1) | 1LLU)
|
||||
#define readonly(x) ((u64)((x) << 1))
|
||||
*/
|
||||
|
||||
#ifndef _REQUESTSASYNC_H_
|
||||
#define _REQUESTSASYNC_H_
|
||||
|
||||
#include "block-async.h"
|
||||
#include "blockstore.h" /* for newblock etc. */
|
||||
|
||||
/*
|
||||
#define BLOCK_SIZE 4096
|
||||
#define ZERO 0ULL
|
||||
#define getid(x) (((x)>>1)&0x7fffffffffffffffLLU)
|
||||
#define iswritable(x) (((x) & 1LLU) != 0)
|
||||
#define writable(x) (((x) << 1) | 1LLU)
|
||||
#define readonly(x) ((u64)((x) << 1))
|
||||
*/
|
||||
|
||||
#define VADDR_MASK 0x0000000003ffffffLLU /* 26-bits = 256Gig */
|
||||
#define VALID_VADDR(x) (((x) & VADDR_MASK) == (x))
|
||||
|
||||
int vdi_read (vdi_t *vdi, u64 vaddr, io_cb_t cb, void *param);
|
||||
int vdi_write(vdi_t *vdi, u64 vaddr, char *block, io_cb_t cb, void *param);
|
||||
|
||||
|
||||
/* synchronous versions: */
|
||||
char *vdi_read_s (vdi_t *vdi, u64 vaddr);
|
||||
int vdi_write_s(vdi_t *vdi, u64 vaddr, char *block);
|
||||
@@ -26,4 +26,4 @@ int vdi_write_s(vdi_t *vdi, u64 vaddr, char *block);
|
||||
#define ERR_BAD_VADDR -1
|
||||
#define ERR_NOMEM -2
|
||||
|
||||
#endif //_REQUESTSASYNC_H_
|
||||
#endif //_REQUESTSASYNC_H_
|
||||