[PATCH 3/7] dma-buf: add dma_fence_chain_alloc/free self tests
Daniel Vetter
daniel at ffwll.ch
Fri Jun 11 07:58:12 UTC 2021
On Thu, Jun 10, 2021 at 11:17:56AM +0200, Christian König wrote:
> Exercise the newly added functions.
>
> Signed-off-by: Christian König <christian.koenig at amd.com>
I have honestly no idea what this checks. Spawning a few threads to
validate kmalloc/kfree feels a bit silly. Now testing whether we correctly
rcu-delay the freeing here would make some sense, but even that feels a
bit silly.
I guess if you want this explain with comments what it does and why?
-Daniel
> ---
> drivers/dma-buf/st-dma-fence-chain.c | 48 ++++++++++++++++++++++++++++
> 1 file changed, 48 insertions(+)
>
> diff --git a/drivers/dma-buf/st-dma-fence-chain.c b/drivers/dma-buf/st-dma-fence-chain.c
> index 8ce1ea59d31b..855c129c6093 100644
> --- a/drivers/dma-buf/st-dma-fence-chain.c
> +++ b/drivers/dma-buf/st-dma-fence-chain.c
> @@ -95,6 +95,53 @@ static int sanitycheck(void *arg)
> return err;
> }
>
> +static int __alloc_free(void *arg)
> +{
> + atomic_t *counter = arg;
> + int i, j;
> +
> + for (i = 0; i < 1024; ++i) {
> + struct dma_fence_chain *chains[64];
> +
> + for (j = 0; j < ARRAY_SIZE(chains); ++j)
> + chains[j] = dma_fence_chain_alloc();
> +
> + for (j = 0; j < ARRAY_SIZE(chains); ++j)
> + dma_fence_chain_free(chains[j]);
> +
> + atomic_add(ARRAY_SIZE(chains), counter);
> + }
> + return 0;
> +}
> +
> +static int alloc_free(void *arg)
> +{
> + struct task_struct *threads[8];
> + atomic_t counter = ATOMIC_INIT(0);
> + int i, err = 0;
> +
> + for (i = 0; i < ARRAY_SIZE(threads); i++) {
> + threads[i] = kthread_run(__alloc_free, &counter, "dmabuf/%d",
> + i);
> + if (IS_ERR(threads[i])) {
> + err = PTR_ERR(threads[i]);
> + break;
> + }
> + }
> +
> + while (i--) {
> + int ret;
> +
> + ret = kthread_stop(threads[i]);
> + if (ret && !err)
> + err = ret;
> + }
> +
> + pr_info("Completed %u cycles\n", atomic_read(&counter));
> +
> + return err;
> +}
> +
> struct fence_chains {
> unsigned int chain_length;
> struct dma_fence **fences;
> @@ -677,6 +724,7 @@ int dma_fence_chain(void)
> {
> static const struct subtest tests[] = {
> SUBTEST(sanitycheck),
> + SUBTEST(alloc_free),
> SUBTEST(find_seqno),
> SUBTEST(find_signaled),
> SUBTEST(find_out_of_order),
> --
> 2.25.1
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
More information about the amd-gfx
mailing list