Commit 61160adf authored by Swann Perarnau's avatar Swann Perarnau
Browse files

[refactor] use request vector for dma

Use the newly introduced vector type to manage requests inside dmas.
This cleans up the API a bit, and remove dubious ops from the dma
internals.
parent 72c8508d
......@@ -574,8 +574,7 @@ struct aml_dma_request_linux_seq {
};
struct aml_dma_linux_seq_data {
size_t size;
struct aml_dma_request_linux_seq *requests;
struct aml_vector requests;
};
struct aml_dma_linux_seq_ops {
......@@ -583,10 +582,6 @@ struct aml_dma_linux_seq_ops {
struct aml_dma_request_linux_seq *req);
int (*do_move)(struct aml_dma_linux_seq_data *dma,
struct aml_dma_request_linux_seq *req);
int (*add_request)(struct aml_dma_linux_seq_data *dma,
struct aml_dma_request_linux_seq **req);
int (*remove_request)(struct aml_dma_linux_seq_data *dma,
struct aml_dma_request_linux_seq **req);
};
struct aml_dma_linux_seq {
......@@ -637,9 +632,8 @@ struct aml_dma_request_linux_par {
};
struct aml_dma_linux_par_data {
size_t nbrequests;
size_t nbthreads;
struct aml_dma_request_linux_par *requests;
struct aml_vector requests;
};
struct aml_dma_linux_par_ops {
......@@ -648,10 +642,6 @@ struct aml_dma_linux_par_ops {
struct aml_dma_request_linux_par *, int tid);
int (*do_move)(struct aml_dma_linux_par_data *,
struct aml_dma_request_linux_par *, int tid);
int (*add_request)(struct aml_dma_linux_par_data *,
struct aml_dma_request_linux_par **);
int (*remove_request)(struct aml_dma_linux_par_data *,
struct aml_dma_request_linux_par **);
};
struct aml_dma_linux_par {
......
......@@ -128,36 +128,10 @@ int aml_dma_linux_par_do_move(struct aml_dma_linux_par_data *dma,
return 0;
}
int aml_dma_linux_par_add_request(struct aml_dma_linux_par_data *data,
struct aml_dma_request_linux_par **req)
{
for(int i = 0; i < data->nbrequests; i++)
{
if(data->requests[i].type == AML_DMA_REQUEST_TYPE_INVALID)
{
*req = &data->requests[i];
return 0;
}
}
/* TODO: slow path, need to resize the array */
return 0;
}
int aml_dma_linux_par_remove_request(struct aml_dma_linux_par_data *data,
struct aml_dma_request_linux_par **req)
{
/* TODO: assert that the pointer is in the right place */
(*req)->type = AML_DMA_REQUEST_TYPE_INVALID;
return 0;
}
struct aml_dma_linux_par_ops aml_dma_linux_par_inner_ops = {
aml_dma_linux_par_do_thread,
aml_dma_linux_par_do_copy,
aml_dma_linux_par_do_move,
aml_dma_linux_par_add_request,
aml_dma_linux_par_remove_request,
};
/*******************************************************************************
......@@ -175,8 +149,7 @@ int aml_dma_linux_par_create_request(struct aml_dma_data *d,
struct aml_dma_request_linux_par *req;
/* find an available request slot */
dma->ops.add_request(&dma->data, &req);
req = aml_vector_add(&dma->data.requests);
/* init the request */
if(type == AML_DMA_REQUEST_TYPE_COPY)
......@@ -199,7 +172,8 @@ int aml_dma_linux_par_create_request(struct aml_dma_data *d,
struct aml_tiling *st = va_arg(ap, struct aml_tiling *);
void *sptr = va_arg(ap, void *);
int stid = va_arg(ap, int);
aml_dma_request_linux_par_move_init(req, darea, st, sptr, stid);
aml_dma_request_linux_par_move_init(req, darea, st, sptr,
stid);
}
for(int i = 0; i < dma->data.nbthreads; i++)
......@@ -237,7 +211,7 @@ int aml_dma_linux_par_destroy_request(struct aml_dma_data *d,
else if(req->type == AML_DMA_REQUEST_TYPE_MOVE)
aml_dma_request_linux_par_move_destroy(req);
dma->ops.remove_request(&dma->data, &req);
aml_vector_remove(&dma->data.requests, req);
return 0;
}
......@@ -258,7 +232,8 @@ int aml_dma_linux_par_wait_request(struct aml_dma_data *d,
aml_dma_request_linux_par_copy_destroy(req);
else if(req->type == AML_DMA_REQUEST_TYPE_MOVE)
aml_dma_request_linux_par_move_destroy(req);
dma->ops.remove_request(&dma->data, &req);
aml_vector_remove(&dma->data.requests, req);
return 0;
}
......@@ -299,16 +274,19 @@ int aml_dma_linux_par_vinit(struct aml_dma *d, va_list ap)
dma->ops = aml_dma_linux_par_inner_ops;
/* allocate request array */
dma->data.nbrequests = va_arg(ap, size_t);
size_t nbreqs = va_arg(ap, size_t);
dma->data.nbthreads = va_arg(ap, size_t);
dma->data.requests = calloc(dma->data.nbrequests,
sizeof(struct aml_dma_request_linux_par));
for(int i = 0; i < dma->data.nbrequests; i++)
aml_vector_init(&dma->data.requests, nbreqs,
sizeof(struct aml_dma_request_linux_par),
offsetof(struct aml_dma_request_linux_par, type),
AML_DMA_REQUEST_TYPE_INVALID);
for(int i = 0; i < nbreqs; i++)
{
dma->data.requests[i].type = AML_DMA_REQUEST_TYPE_INVALID;
dma->data.requests[i].thread_data =
calloc(dma->data.nbthreads,
sizeof(struct aml_dma_linux_par_thread_data));
struct aml_dma_request_linux_par *req =
aml_vector_get(&dma->data.requests, i);
req->thread_data = calloc(dma->data.nbthreads,
sizeof(struct aml_dma_linux_par_thread_data));
}
return 0;
}
......@@ -325,8 +303,12 @@ int aml_dma_linux_par_init(struct aml_dma *d, ...)
int aml_dma_linux_par_destroy(struct aml_dma *d)
{
struct aml_dma_linux_par *dma = (struct aml_dma_linux_par *)d->data;
for(int i = 0; i < dma->data.nbrequests; i++)
free(dma->data.requests[i].thread_data);
free(dma->data.requests);
for(int i = 0; i < aml_vector_size(&dma->data.requests); i++)
{
struct aml_dma_request_linux_par *req =
aml_vector_get(&dma->data.requests, i);
free(req->thread_data);
}
aml_vector_destroy(&dma->data.requests);
return 0;
}
......@@ -95,35 +95,9 @@ int aml_dma_linux_seq_do_move(struct aml_dma_linux_seq_data *dma,
return 0;
}
int aml_dma_linux_seq_add_request(struct aml_dma_linux_seq_data *data,
struct aml_dma_request_linux_seq **req)
{
for(int i = 0; i < data->size; i++)
{
if(data->requests[i].type == AML_DMA_REQUEST_TYPE_INVALID)
{
*req = &data->requests[i];
return 0;
}
}
/* TODO: slow path, need to resize the array */
return 0;
}
int aml_dma_linux_seq_remove_request(struct aml_dma_linux_seq_data *data,
struct aml_dma_request_linux_seq **req)
{
/* TODO: assert that the pointer is in the right place */
(*req)->type = AML_DMA_REQUEST_TYPE_INVALID;
return 0;
}
struct aml_dma_linux_seq_ops aml_dma_linux_seq_inner_ops = {
aml_dma_linux_seq_do_copy,
aml_dma_linux_seq_do_move,
aml_dma_linux_seq_add_request,
aml_dma_linux_seq_remove_request,
};
/*******************************************************************************
......@@ -141,9 +115,7 @@ int aml_dma_linux_seq_create_request(struct aml_dma_data *d,
struct aml_dma_request_linux_seq *req;
/* find an available request slot */
dma->ops.add_request(&dma->data, &req);
req = aml_vector_add(&dma->data.requests);
/* init the request */
if(type == AML_DMA_REQUEST_TYPE_COPY)
{
......@@ -165,7 +137,8 @@ int aml_dma_linux_seq_create_request(struct aml_dma_data *d,
struct aml_tiling *st = va_arg(ap, struct aml_tiling *);
void *sptr = va_arg(ap, void *);
int stid = va_arg(ap, int);
aml_dma_request_linux_seq_move_init(req, darea, st, sptr, stid);
aml_dma_request_linux_seq_move_init(req, darea, st, sptr,
stid);
}
*r = (struct aml_dma_request *)req;
return 0;
......@@ -187,7 +160,8 @@ int aml_dma_linux_seq_destroy_request(struct aml_dma_data *d,
else if(req->type == AML_DMA_REQUEST_TYPE_MOVE)
aml_dma_request_linux_seq_move_destroy(req);
dma->ops.remove_request(&dma->data, &req);
/* enough to remove from request vector */
aml_vector_remove(&dma->data.requests, req);
return 0;
}
......@@ -247,12 +221,13 @@ int aml_dma_linux_seq_vinit(struct aml_dma *d, va_list ap)
struct aml_dma_linux_seq *dma = (struct aml_dma_linux_seq *)d->data;
dma->ops = aml_dma_linux_seq_inner_ops;
/* allocate request array */
dma->data.size = va_arg(ap, size_t);
dma->data.requests = calloc(dma->data.size,
sizeof(struct aml_dma_request_linux_seq));
for(int i = 0; i < dma->data.size; i++)
dma->data.requests[i].type = AML_DMA_REQUEST_TYPE_INVALID;
/* request vector */
size_t nbreqs = va_arg(ap, size_t);
aml_vector_init(&dma->data.requests, nbreqs,
sizeof(struct aml_dma_request_linux_seq),
offsetof(struct aml_dma_request_linux_seq, type),
AML_DMA_REQUEST_TYPE_INVALID);
return 0;
}
int aml_dma_linux_seq_init(struct aml_dma *d, ...)
......@@ -268,6 +243,6 @@ int aml_dma_linux_seq_init(struct aml_dma *d, ...)
int aml_dma_linux_seq_destroy(struct aml_dma *d)
{
struct aml_dma_linux_seq *dma = (struct aml_dma_linux_seq *)d->data;
free(dma->data.requests);
aml_vector_destroy(&dma->data.requests);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment