Commit cb98d0b9 authored by Swann Perarnau's avatar Swann Perarnau

[refactor] convert scratch to new errors, create

Implement #31 for scratch.
Improve error management.
Checkpatch scratch.
parent 1a4d44d0
Pipeline #6801 passed with stages
in 4 minutes and 28 seconds
......@@ -16,6 +16,8 @@ include/aml.h
include/aml/area/linux.h
include/aml/dma/linux-seq.h
include/aml/dma/linux-par.h
include/aml/scratch/seq.h
include/aml/scratch/par.h
include/aml/utils/bitmap.h
include/aml/utils/error.h
src/aml.c
......@@ -24,4 +26,7 @@ src/area/linux.c
src/dma/dma.c
src/dma/dma_linux_seq.c
src/dma/dma_linux_par.c
src/scratch/scratch.c
src/scratch/scratch_seq.c
src/scratch/scratch_par.c
src/utils/error.c
......@@ -182,8 +182,8 @@ int main(int argc, char* argv[])
/* print the flops in GFLOPS */
printf("dgemm-prefetch: %llu %lld %lld %f\n", N, memsize, time,
flops/1e9);
aml_scratch_par_destroy(&sa);
aml_scratch_par_destroy(&sb);
aml_scratch_par_fini(&sa);
aml_scratch_par_fini(&sb);
aml_dma_linux_seq_fini(&dma);
aml_area_munmap(slow, a, memsize);
aml_area_munmap(slow, b, memsize);
......
......@@ -118,8 +118,8 @@ int main(int argc, char *argv[])
assert(c[i] == esize);
}
aml_scratch_seq_destroy(&sa);
aml_scratch_seq_destroy(&sb);
aml_scratch_seq_fini(&sa);
aml_scratch_seq_fini(&sb);
aml_dma_linux_par_fini(&dma);
aml_area_munmap(slow, a, memsize);
aml_area_munmap(slow, b, memsize);
......
......@@ -131,8 +131,8 @@ int main(int argc, char *argv[])
assert(c[i] == esize);
}
aml_scratch_par_destroy(&sa);
aml_scratch_par_destroy(&sb);
aml_scratch_par_fini(&sa);
aml_scratch_par_fini(&sb);
aml_dma_linux_seq_fini(&dma);
aml_area_munmap(slow, a, memsize);
aml_area_munmap(slow, b, memsize);
......
......@@ -142,8 +142,8 @@ int main(int argc, char *argv[])
assert(c[i] == esize);
}
aml_scratch_par_destroy(&sa);
aml_scratch_par_destroy(&sb);
aml_scratch_par_fini(&sa);
aml_scratch_par_fini(&sb);
aml_dma_linux_seq_fini(&dma);
aml_area_munmap(slow, a, memsize);
aml_area_munmap(slow, b, memsize);
......
......@@ -31,16 +31,16 @@ struct aml_scratch_request_par {
struct aml_scratch_par_data {
struct aml_area *src_area, *sch_area;
struct aml_tiling *tiling;
size_t scratch_size;
size_t scratch_size;
struct aml_dma *dma;
void * sch_ptr;
void *sch_ptr;
struct aml_vector tilemap;
struct aml_vector requests;
pthread_mutex_t lock;
};
struct aml_scratch_par_ops {
void *(*do_thread)(void *);
void *(*do_thread)(void *par_request);
};
struct aml_scratch_par {
......@@ -59,49 +59,53 @@ struct aml_scratch_par {
(sizeof(struct aml_scratch_par) + \
sizeof(struct aml_scratch))
/*
/**
* Allocates and initializes a new parallel scratchpad.
* "scratch": an address where the pointer to the newly allocated scratchpad
* structure will be stored.
* Variadic arguments:
* - "scratch_area": an argument of type struct aml_area*; the memory area
* where the scratchpad will be allocated from.
* - "source_area": an argument of type struct aml_area*; the memory area
* containing the user data structure.
* - "dma": an argument of type struct aml_dma*; the DMA that will be used for
* migrating data to and from the scratchpad.
* - "tiling": an argument of type struct aml_tiling*; the tiling to use on the
* user data structure and the scratchpad.
* - "nbtiles": an argument of type size_t; number of tiles to divide the
* scratchpad into.
* - "nbreqs": an argument of type size_t; the initial number of slots for
* asynchronous request that are in-flight (will be increased
* automatically if necessary).
* Returns 0 if successful; an error code otherwise.
*/
int aml_scratch_par_create(struct aml_scratch **scratch, ...);
/*
* Initializes a new parallel scratchpad. This is a varargs-variant of the
* aml_scratch_par_vinit() routine.
* "scratch": an allocated scratchpad structure.
* Variadic arguments: see aml_scratch_par_create().
* Returns 0 if successful; an error code otherwise.
*/
int aml_scratch_par_init(struct aml_scratch *scratch, ...);
/*
* Initializes a new parallel scratchpad.
* "scratch": an allocated scratchpad structure.
* "args": see the variadic arguments of see aml_scratch_par_create().
* Returns 0 if successful; an error code otherwise.
*/
int aml_scratch_par_vinit(struct aml_scratch *scratch, va_list args);
/*
* Tears down an initialized parallel scratchpad.
* "scratch": an initialized scratchpad structure.
* Returns 0 if successful; an error code otherwise.
*/
int aml_scratch_par_destroy(struct aml_scratch *scratch);
*
* @param scratch an address where the pointer to the newly allocated scratchpad
* structure will be stored.
*
* @param scratch_area the memory area where the scratchpad will be allocated.
* @param source_area the memory area containing the user data structure.
* @param dma the DMA that will be used for migrating data to and from
* the scratchpad.
* @param tiling the tiling to use on the user data structure and the scratch.
* @param nbtiles number of tiles to divide the scratchpad into.
* @param nbreqs the initial number of slots for asynchronous request that
* are in-flight (will be increased automatically if necessary).
* @return 0 if successful; an error code otherwise.
**/
int aml_scratch_par_create(struct aml_scratch **scratch,
struct aml_area *scratch_area,
struct aml_area *src_area,
struct aml_dma *dma, struct aml_tiling *tiling,
size_t nbtiles, size_t nbreqs);
/**
* Initializes a new parallel scratchpad. Similar to the create.
*
* @param scratch a pointer to a scratch declared with AML_SCRATCH_PAR_DECL.
*
* @return 0 if successful; an error code otherwise.
**/
int aml_scratch_par_init(struct aml_scratch *scratch,
struct aml_area *scratch_area,
struct aml_area *src_area,
struct aml_dma *dma, struct aml_tiling *tiling,
size_t nbtiles, size_t nbreqs);
/**
* Finalize a scratchpad.
*
* @param scratch a pointer to a scratch initialized by aml_scratch_par_init
**/
void aml_scratch_par_fini(struct aml_scratch *scratch);
/**
* Tears down an initialized parallel scratchpad.
*
* @param scratch an initialized scratchpad structure. NULL on return.
*/
void aml_scratch_par_destroy(struct aml_scratch **scratch);
#endif // AML_SCRATCH_PAR_H
......@@ -20,7 +20,7 @@ extern struct aml_scratch_ops aml_scratch_seq_ops;
struct aml_scratch_request_seq {
int type;
struct aml_tiling *tiling;
struct aml_tiling *tiling;
void *srcptr;
int srcid;
void *dstptr;
......@@ -33,7 +33,7 @@ struct aml_scratch_seq_data {
struct aml_tiling *tiling;
size_t scratch_size;
struct aml_dma *dma;
void * sch_ptr;
void *sch_ptr;
struct aml_vector tilemap;
struct aml_vector requests;
pthread_mutex_t lock;
......@@ -60,47 +60,53 @@ struct aml_scratch_seq {
(sizeof(struct aml_scratch_seq) + \
sizeof(struct aml_scratch))
/*
/**
* Allocates and initializes a new sequential scratchpad.
* "scratch": an address where the pointer to the newly allocated scratchpad
* structure will be stored.
* Variadic arguments:
* - "scratch_area": an argument of type struct aml_area*; the memory area
* where the scratchpad will be allocated from.
* - "source_area": an argument of type struct aml_area*; the memory area
* containing the user data structure.
* - "dma": an argument of type struct aml_dma*; the DMA that will be used for
* migrating data to and from the scratchpad.
* - "tiling": an argument of type struct aml_tiling*; the tiling to use on the
* user data structure and the scratchpad.
* - "nbtiles": an argument of type size_t; number of tiles to divide the
* scratchpad into.
* - "nbreqs": an argument of type size_t; the initial number of slots for
* asynchronous request that are in-flight (will be increased
* automatically if necessary).
* Returns 0 if successful; an error code otherwise.
*/
int aml_scratch_seq_create(struct aml_scratch **scratch, ...);
/*
* Initializes a new sequential scratchpad. This is a varargs-variant of the
* aml_scratch_seq_vinit() routine.
* "scratch": an allocated scratchpad structure.
* Variadic arguments: see aml_scratch_seq_create().
* Returns 0 if successful; an error code otherwise.
*/
int aml_scratch_seq_init(struct aml_scratch *scratch, ...);
/*
* Initializes a new sequential scratchpad.
* "scratch": an allocated scratchpad structure.
* "args": see the variadic arguments of see aml_scratch_seq_create().
* Returns 0 if successful; an error code otherwise.
*/
int aml_scratch_seq_vinit(struct aml_scratch *scratch, va_list args);
/*
*
* @param scratch an address where the pointer to the newly allocated scratchpad
* structure will be stored.
*
* @param scratch_area the memory area where the scratchpad will be allocated.
* @param source_area the memory area containing the user data structure.
* @param dma the DMA that will be used for migrating data to and from
* the scratchpad.
* @param tiling the tiling to use on the user data structure and the scratch.
* @param nbtiles number of tiles to divide the scratchpad into.
* @param nbreqs the initial number of slots for asynchronous request that
* are in-flight (will be increased automatically if necessary).
* @return 0 if successful; an error code otherwise.
**/
int aml_scratch_seq_create(struct aml_scratch **scratch,
struct aml_area *scratch_area,
struct aml_area *src_area,
struct aml_dma *dma, struct aml_tiling *tiling,
size_t nbtiles, size_t nbreqs);
/**
* Initializes a new sequential scratchpad. Similar to the create.
*
* @param scratch a pointer to a scratch declared with AML_SCRATCH_SEQ_DECL.
*
* @return 0 if successful; an error code otherwise.
**/
int aml_scratch_seq_init(struct aml_scratch *scratch,
struct aml_area *scratch_area,
struct aml_area *src_area,
struct aml_dma *dma, struct aml_tiling *tiling,
size_t nbtiles, size_t nbreqs);
/**
* Finalize a scratchpad.
*
* @param scratch a pointer to a scratch initialized by aml_scratch_seq_init
**/
void aml_scratch_seq_fini(struct aml_scratch *scratch);
/**
* Tears down an initialized sequential scratchpad.
* "scratch": an initialized scratchpad structure.
* Returns 0 if successful; an error code otherwise.
*
* @param scratch an initialized scratchpad structure. NULL on return.
*/
int aml_scratch_seq_destroy(struct aml_scratch *scratch);
void aml_scratch_seq_destroy(struct aml_scratch **scratch);
#endif // AML_SCRATCH_SEQ_H
......@@ -26,6 +26,7 @@ int aml_scratch_pull(struct aml_scratch *scratch, ...)
va_list ap;
int ret;
struct aml_scratch_request *req;
va_start(ap, scratch);
ret = scratch->ops->create_request(scratch->data, &req,
AML_SCRATCH_REQUEST_TYPE_PULL, ap);
......@@ -41,6 +42,7 @@ int aml_scratch_async_pull(struct aml_scratch *scratch,
assert(req != NULL);
va_list ap;
int ret;
va_start(ap, req);
ret = scratch->ops->create_request(scratch->data, req,
AML_SCRATCH_REQUEST_TYPE_PULL, ap);
......@@ -54,6 +56,7 @@ int aml_scratch_push(struct aml_scratch *scratch, ...)
struct aml_scratch_request *req;
va_list ap;
int ret;
va_start(ap, scratch);
ret = scratch->ops->create_request(scratch->data, &req,
AML_SCRATCH_REQUEST_TYPE_PUSH, ap);
......@@ -63,12 +66,14 @@ int aml_scratch_push(struct aml_scratch *scratch, ...)
}
int aml_scratch_async_push(struct aml_scratch *scratch, struct aml_scratch_request **req, ...)
int aml_scratch_async_push(struct aml_scratch *scratch,
struct aml_scratch_request **req, ...)
{
assert(scratch != NULL);
assert(req != NULL);
va_list ap;
int ret;
va_start(ap, req);
ret = scratch->ops->create_request(scratch->data, req,
AML_SCRATCH_REQUEST_TYPE_PUSH, ap);
......@@ -76,14 +81,16 @@ int aml_scratch_async_push(struct aml_scratch *scratch, struct aml_scratch_reque
return ret;
}
int aml_scratch_cancel(struct aml_scratch *scratch, struct aml_scratch_request *req)
int aml_scratch_cancel(struct aml_scratch *scratch,
struct aml_scratch_request *req)
{
assert(scratch != NULL);
assert(req != NULL);
return scratch->ops->destroy_request(scratch->data, req);
}
int aml_scratch_wait(struct aml_scratch *scratch, struct aml_scratch_request *req)
int aml_scratch_wait(struct aml_scratch *scratch,
struct aml_scratch_request *req)
{
assert(scratch != NULL);
assert(req != NULL);
......
......@@ -27,7 +27,8 @@
int aml_scratch_request_par_init(struct aml_scratch_request_par *req, int type,
struct aml_scratch_par *scratch,
void *dstptr, int dstid, void *srcptr, int srcid)
void *dstptr, int dstid, void *srcptr,
int srcid)
{
assert(req != NULL);
......@@ -83,8 +84,7 @@ int aml_scratch_par_create_request(struct aml_scratch_data *d,
pthread_mutex_lock(&scratch->data.lock);
req = aml_vector_add(&scratch->data.requests);
/* init the request */
if(type == AML_SCRATCH_REQUEST_TYPE_PUSH)
{
if (type == AML_SCRATCH_REQUEST_TYPE_PUSH) {
int scratchid;
int *srcid;
void *srcptr;
......@@ -97,19 +97,19 @@ int aml_scratch_par_create_request(struct aml_scratch_data *d,
/* find destination tile */
int *slot = aml_vector_get(&scratch->data.tilemap, scratchid);
assert(slot != NULL);
*srcid = *slot;
/* init request */
aml_scratch_request_par_init(req, type, scratch, srcptr, *srcid,
scratchptr, scratchid);
}
else if(type == AML_SCRATCH_REQUEST_TYPE_PULL)
{
} else if (type == AML_SCRATCH_REQUEST_TYPE_PULL) {
int *scratchid;
int srcid;
void *srcptr;
void *scratchptr;
int slot, *tile;
scratchptr = va_arg(ap, void *);
scratchid = va_arg(ap, int *);
......@@ -119,15 +119,13 @@ int aml_scratch_par_create_request(struct aml_scratch_data *d,
/* find destination tile
* We don't use add here because adding a tile means allocating
* new tiles on the sch_area too. */
int slot = aml_vector_find(&scratch->data.tilemap, srcid);
if(slot == -1)
{
slot = aml_vector_find(&scratch->data.tilemap, srcid);
if (slot == -1) {
slot = aml_vector_find(&scratch->data.tilemap, -1);
assert(slot != -1);
int *tile = aml_vector_get(&scratch->data.tilemap, slot);
tile = aml_vector_get(&scratch->data.tilemap, slot);
*tile = srcid;
}
else
} else
type = AML_SCRATCH_REQUEST_TYPE_NOOP;
/* save the key */
......@@ -140,7 +138,7 @@ int aml_scratch_par_create_request(struct aml_scratch_data *d,
}
pthread_mutex_unlock(&scratch->data.lock);
/* thread creation */
if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
if (req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
pthread_create(&req->thread, NULL, scratch->ops.do_thread, req);
*r = (struct aml_scratch_request *)req;
return 0;
......@@ -158,8 +156,7 @@ int aml_scratch_par_destroy_request(struct aml_scratch_data *d,
(struct aml_scratch_request_par *)r;
int *tile;
if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
{
if (req->type != AML_SCRATCH_REQUEST_TYPE_NOOP) {
pthread_cancel(req->thread);
pthread_join(req->thread, NULL);
}
......@@ -168,10 +165,10 @@ int aml_scratch_par_destroy_request(struct aml_scratch_data *d,
/* destroy removes the tile from the scratch */
pthread_mutex_lock(&scratch->data.lock);
if(req->type == AML_SCRATCH_REQUEST_TYPE_PUSH)
tile = aml_vector_get(&scratch->data.tilemap,req->srcid);
else if(req->type == AML_SCRATCH_REQUEST_TYPE_PULL)
tile = aml_vector_get(&scratch->data.tilemap,req->dstid);
if (req->type == AML_SCRATCH_REQUEST_TYPE_PUSH)
tile = aml_vector_get(&scratch->data.tilemap, req->srcid);
else if (req->type == AML_SCRATCH_REQUEST_TYPE_PULL)
tile = aml_vector_get(&scratch->data.tilemap, req->dstid);
aml_vector_remove(&scratch->data.tilemap, tile);
aml_vector_remove(&scratch->data.requests, req);
pthread_mutex_unlock(&scratch->data.lock);
......@@ -189,15 +186,14 @@ int aml_scratch_par_wait_request(struct aml_scratch_data *d,
int *tile;
/* wait for completion of the request */
if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
if (req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
pthread_join(req->thread, NULL);
/* cleanup a completed request. In case of push, free up the tile */
aml_scratch_request_par_destroy(req);
pthread_mutex_lock(&scratch->data.lock);
if(req->type == AML_SCRATCH_REQUEST_TYPE_PUSH)
{
tile = aml_vector_get(&scratch->data.tilemap,req->srcid);
if (req->type == AML_SCRATCH_REQUEST_TYPE_PUSH) {
tile = aml_vector_get(&scratch->data.tilemap, req->srcid);
aml_vector_remove(&scratch->data.tilemap, tile);
}
aml_vector_remove(&scratch->data.requests, req);
......@@ -208,7 +204,9 @@ int aml_scratch_par_wait_request(struct aml_scratch_data *d,
void *aml_scratch_par_baseptr(const struct aml_scratch_data *d)
{
assert(d != NULL);
const struct aml_scratch_par *scratch = (const struct aml_scratch_par *)d;
const struct aml_scratch_par *scratch =
(const struct aml_scratch_par *)d;
return scratch->data.sch_ptr;
}
......@@ -220,7 +218,7 @@ int aml_scratch_par_release(struct aml_scratch_data *d, int scratchid)
pthread_mutex_lock(&scratch->data.lock);
tile = aml_vector_get(&scratch->data.tilemap, scratchid);
if(tile != NULL)
if (tile != NULL)
aml_vector_remove(&scratch->data.tilemap, tile);
pthread_mutex_unlock(&scratch->data.lock);
return 0;
......@@ -238,39 +236,63 @@ struct aml_scratch_ops aml_scratch_par_ops = {
* Init functions:
******************************************************************************/
int aml_scratch_par_create(struct aml_scratch **d, ...)
int aml_scratch_par_create(struct aml_scratch **d,
struct aml_area *scratch_area,
struct aml_area *src_area,
struct aml_dma *dma, struct aml_tiling *tiling,
size_t nbtiles, size_t nbreqs)
{
va_list ap;
struct aml_scratch *ret = NULL;
intptr_t baseptr, dataptr;
va_start(ap, d);
int err;
if (d == NULL)
return -AML_EINVAL;
/* alloc */
baseptr = (intptr_t) calloc(1, AML_SCRATCH_PAR_ALLOCSIZE);
if (baseptr == 0) {
*d = NULL;
return -AML_ENOMEM;
}
dataptr = baseptr + sizeof(struct aml_scratch);
ret = (struct aml_scratch *)baseptr;
ret->data = (struct aml_scratch_data *)dataptr;
ret->ops = &aml_scratch_par_ops;
err = aml_scratch_par_init(ret, scratch_area, src_area, dma,
tiling, nbtiles, nbreqs);
if (err) {
*d = NULL;
free(ret);
return err;
}
aml_scratch_par_vinit(ret, ap);
va_end(ap);
*d = ret;
return 0;
}
int aml_scratch_par_vinit(struct aml_scratch *d, va_list ap)
int aml_scratch_par_init(struct aml_scratch *d,
struct aml_area *scratch_area,
struct aml_area *src_area,
struct aml_dma *dma, struct aml_tiling *tiling,
size_t nbtiles, size_t nbreqs)
{
d->ops = &aml_scratch_par_ops;
struct aml_scratch_par *scratch = (struct aml_scratch_par *)d->data;
struct aml_scratch_par *scratch;
if (d == NULL || d->data == NULL
|| scratch_area == NULL || src_area == NULL
|| dma == NULL || tiling == NULL)
return -AML_EINVAL;
scratch = (struct aml_scratch_par *)d->data;
scratch->ops = aml_scratch_par_inner_ops;
scratch->data.sch_area = va_arg(ap, struct aml_area *);
scratch->data.src_area = va_arg(ap, struct aml_area *);
scratch->data.dma = va_arg(ap, struct aml_dma *);
scratch->data.tiling = va_arg(ap, struct aml_tiling *);
size_t nbtiles = va_arg(ap, size_t);
size_t nbreqs = va_arg(ap, size_t);
scratch->data.sch_area = scratch_area;
scratch->data.src_area = src_area;
scratch->data.dma = dma;
scratch->data.tiling = tiling;
/* allocate request array */
aml_vector_init(&scratch->data.requests, nbreqs,
......@@ -281,31 +303,35 @@ int aml_scratch_par_vinit(struct aml_scratch *d, va_list ap)
/* scratch init */
aml_vector_init(&scratch->data.tilemap, nbtiles, sizeof(int), 0, -1);
size_t tilesize = aml_tiling_tilesize(scratch->data.tiling, 0);
scratch->data.scratch_size = nbtiles * tilesize;
scratch->data.scratch_size = nbtiles * tilesize;
scratch->data.sch_ptr = aml_area_mmap(scratch->data.sch_area,
NULL,
scratch->data.scratch_size);
pthread_mutex_init(&scratch->data.lock, NULL);
return 0;
}
int aml_scratch_par_init(struct aml_scratch *d, ...)
{
int err;
va_list ap;
va_start(ap, d);
err = aml_scratch_par_vinit(d, ap);
va_end(ap);
return err;
}
int aml_scratch_par_destroy(struct aml_scratch *d)
void aml_scratch_par_fini(struct aml_scratch *d)
{
struct aml_scratch_par *scratch = (struct aml_scratch_par *)d->data;
struct aml_scratch_par *scratch;
if (d == NULL)
return;
scratch = (struct aml_scratch_par *)d->data;
aml_vector_destroy(&scratch->data.requests);
aml_vector_destroy(&scratch->data.tilemap);
aml_area_munmap(scratch->data.sch_area,
scratch->data.sch_ptr,
scratch->data.scratch_size);
pthread_mutex_destroy(&scratch->data.lock);
return 0;
}
void aml_scratch_par_destroy(struct aml_scratch **d)
{
if (d == NULL)
return;
aml_scratch_par_fini(*d);
free(*d);
*d = NULL;
}
......@@ -83,8 +83,7 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d,
pthread_mutex_lock(&scratch->data.lock);
req = aml_vector_add(&scratch->data.requests);
/* init the request */
if(type == AML_SCRATCH_REQUEST_TYPE_PUSH)
{
if (type == AML_SCRATCH_REQUEST_TYPE_PUSH) {
int scratchid;
int *srcid;
void *srcptr;
......@@ -97,6 +96,7 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d,
/* find destination tile */
int *slot = aml_vector_get(&scratch->data.tilemap, scratchid);
assert(slot != NULL);
*srcid = *slot;
......@@ -105,13 +105,12 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d,
scratch->data.tiling,
srcptr, *srcid,
scratchptr, scratchid);
}
else if(type == AML_SCRATCH_REQUEST_TYPE_PULL)
{
} else if (type == AML_SCRATCH_REQUEST_TYPE_PULL) {
int *scratchid;
int srcid;
void *srcptr;
void *scratchptr;
int slot, *tile;
scratchptr = va_arg(ap, void *);
scratchid = va_arg(ap, int *);
......@@ -124,15 +123,13 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d,
/* TODO: this is kind of a bug: we reuse a tile, instead of
* creating a no-op request
*/
int slot = aml_vector_find(&scratch->data.tilemap, srcid);
if(slot == -1)
{
slot = aml_vector_find(&scratch->data.tilemap, srcid);
if (slot == -1) {
slot = aml_vector_find(&scratch->data.tilemap, -1);
assert(slot != -1);
int *tile = aml_vector_get(&scratch->data.tilemap, slot);
tile = aml_vector_get(&scratch->data.tilemap, slot);
*tile = srcid;
}
else
} else
type = AML_SCRATCH_REQUEST_TYPE_NOOP;
/* save the key */
......@@ -144,7 +141,7 @@ int aml_scratch_seq_create_request(struct aml_scratch_data *d,
srcptr, srcid);
}
pthread_mutex_unlock(&scratch->data.lock);
if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
if (req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
scratch->ops.doit(&scratch->data, req);
*r = (struct aml_scratch_request *)req;
......@@ -163,16 +160,16 @@ int aml_scratch_seq_destroy_request(struct aml_scratch_data *d,
(struct aml_scratch_request_seq *)r;
int *tile;
if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
if (req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
aml_dma_cancel(scratch->data.dma, req->dma_req);
aml_scratch_request_seq_destroy(req);
/* destroy removes the tile from the scratch */
pthread_mutex_lock(&scratch->data.lock);
if(req->type == AML_SCRATCH_REQUEST_TYPE_PUSH)
tile = aml_vector_get(&scratch->data.tilemap,req->srcid);
else if(req->type == AML_SCRATCH_REQUEST_TYPE_PULL)
tile = aml_vector_get(&scratch->data.tilemap,req->dstid);
if (req->type == AML_SCRATCH_REQUEST_TYPE_PUSH)
tile = aml_vector_get(&scratch->data.tilemap, req->srcid);
else if (req->type == AML_SCRATCH_REQUEST_TYPE_PULL)
tile = aml_vector_get(&scratch->data.tilemap, req->dstid);
aml_vector_remove(&scratch->data.tilemap, tile);
aml_vector_remove(&scratch->data.requests, req);
pthread_mutex_unlock(&scratch->data.lock);
......@@ -190,15 +187,14 @@ int aml_scratch_seq_wait_request(struct aml_scratch_data *d,
int *tile;
/* wait for completion of the request */
if(req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
if (req->type != AML_SCRATCH_REQUEST_TYPE_NOOP)
aml_dma_wait(scratch->data.dma, req->dma_req);
/* cleanup a completed request. In case of push, free up the tile */
aml_scratch_request_seq_destroy(req);
pthread_mutex_lock(&scratch->data.lock);
if(req->type == AML_SCRATCH_REQUEST_TYPE_PUSH)
{
tile = aml_vector_get(&scratch->data.tilemap,req->srcid);
if (req->type == AML_SCRATCH_REQUEST_TYPE_PUSH) {
tile = aml_vector_get(&scratch->data.tilemap, req->srcid);
aml_vector_remove(&scratch->data.tilemap, tile);
}
aml_vector_remove(&scratch->data.requests, req);
......@@ -209,7 +205,9 @@ int aml_scratch_seq_wait_request(struct aml_scratch_data *d,
void *aml_scratch_seq_baseptr(const struct aml_scratch_data *d)
{
assert(d != NULL);
const struct aml_scratch_seq *scratch = (const struct aml_scratch_seq *)d;
const struct aml_scratch_seq *scratch =
(const struct aml_scratch_seq *)d;
return scratch->data.sch_ptr;
}
......@@ -221,7 +219,7 @@ int aml_scratch_seq_release(struct aml_scratch_data *d, int scratchid)