Commit 7260868d authored by Swann Perarnau's avatar Swann Perarnau

[feature] add function to release a scratch tile

When a user doesn't need a tile to be pushed back into the scratchpad,
it is better to just `release` that tile instead. This is particularly
useful for read-only data for applications that are bandwidth limited.
parent d07894c9
......@@ -1395,6 +1395,7 @@ struct aml_scratch_ops {
int (*wait_request)(struct aml_scratch_data *scratch,
struct aml_scratch_request *req);
void *(*baseptr)(const struct aml_scratch_data *scratch);
int (*release)(struct aml_scratch_data *scratch, int scratchid);
};
struct aml_scratch {
......@@ -1461,6 +1462,7 @@ int aml_scratch_async_push(struct aml_scratch *scratch,
*/
int aml_scratch_wait(struct aml_scratch *scratch,
struct aml_scratch_request *req);
/*
* Tears down an asynchronous scratch request before it completes.
* "scratch": an initialized scratch structure.
......@@ -1476,6 +1478,14 @@ int aml_scratch_cancel(struct aml_scratch *scratch,
*/
void* aml_scratch_baseptr(const struct aml_scratch *scratch);
/*
* Release a scratch tile for immediate reuse.
* "scratch": an initialized scratchpad structure.
* "scratchid": an argument of type int; the scratchpad tile identifier.
* Returns 0 if successuf; an error code otherwise.
*/
int aml_scratch_release(struct aml_scratch *scratch, int scratchid);
/*******************************************************************************
* Sequential scratchpad API:
* Scratchpad uses calling thread to trigger asynchronous dma movements.
......
......@@ -85,3 +85,9 @@ void *aml_scratch_baseptr(const struct aml_scratch *scratch)
assert(scratch != NULL);
return scratch->ops->baseptr(scratch->data);
}
int aml_scratch_release(struct aml_scratch *scratch, int scratchid)
{
assert(scratch != NULL);
return scratch->ops->release(scratch->data, scratchid);
}
......@@ -191,11 +191,26 @@ void *aml_scratch_par_baseptr(const struct aml_scratch_data *d)
return scratch->data.sch_ptr;
}
int aml_scratch_par_release(struct aml_scratch_data *d, int scratchid)
{
assert(d != NULL);
struct aml_scratch_par *scratch = (struct aml_scratch_par *)d;
int *tile;
pthread_mutex_lock(&scratch->data.lock);
tile = aml_vector_get(&scratch->data.tilemap, scratchid);
if(tile != NULL)
aml_vector_remove(&scratch->data.tilemap, tile);
pthread_mutex_unlock(&scratch->data.lock);
return 0;
}
struct aml_scratch_ops aml_scratch_par_ops = {
aml_scratch_par_create_request,
aml_scratch_par_destroy_request,
aml_scratch_par_wait_request,
aml_scratch_par_baseptr,
aml_scratch_par_release,
};
/*******************************************************************************
......
......@@ -193,11 +193,26 @@ void *aml_scratch_seq_baseptr(const struct aml_scratch_data *d)
return scratch->data.sch_ptr;
}
int aml_scratch_seq_release(struct aml_scratch_data *d, int scratchid)
{
assert(d != NULL);
struct aml_scratch_seq *scratch = (struct aml_scratch_seq *)d;
int *tile;
pthread_mutex_lock(&scratch->data.lock);
tile = aml_vector_get(&scratch->data.tilemap, scratchid);
if(tile != NULL)
aml_vector_remove(&scratch->data.tilemap, tile);
pthread_mutex_unlock(&scratch->data.lock);
return 0;
}
struct aml_scratch_ops aml_scratch_seq_ops = {
aml_scratch_seq_create_request,
aml_scratch_seq_destroy_request,
aml_scratch_seq_wait_request,
aml_scratch_seq_baseptr,
aml_scratch_seq_release,
};
/*******************************************************************************
......
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