]> git.alsa-project.org Git - alsa-utils.git/commitdiff
axfer: test: use memfd_create() for container-test
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Thu, 11 Mar 2021 05:21:40 +0000 (14:21 +0900)
committerJaroslav Kysela <perex@perex.cz>
Thu, 11 Mar 2021 08:30:02 +0000 (09:30 +0100)
The container test program writes audio data frame to file, and read
them from the file, then validate them. For the operations, usage of
any in-memory file is good to shorten time of overall operations.

This commit uses shm via memfd_create(). As a result, overall time to
run is shorten one half of before, depending on machine environment.

I note that we can achieve the same result by using O_TMPFILE flag in
open(2) system call, however the implementation of O_TMPFILE is to add
i-node without name on underling file system, thus it has overhead
depending on implementation in each file system. On the other hand,
memfd_create() is directly relevant to shm and expected to be less
overhead.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
axfer/test/container-test.c

index 501e2af04cb8f1f6367d56b8c3b86dd4298b8ac6..0b231d0546740846f702c4da4a689d1d81b03400 100644 (file)
@@ -6,11 +6,20 @@
 //
 // Licensed under the terms of the GNU General Public License, version 2.
 
+#include <aconfig.h>
+#ifdef HAVE_MEMFD_CREATE
+#define _GNU_SOURCE
+#endif
+
 #include "../container.h"
 #include "../misc.h"
 
 #include "generator.h"
 
+#ifdef HAVE_MEMFD_CREATE
+#include <sys/mman.h>
+#endif
+
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdbool.h>
@@ -142,16 +151,17 @@ static int callback(struct test_generator *gen, snd_pcm_access_t access,
        if (buf == NULL)
                return -ENOMEM;
 
-       // Remove a result of a previous trial.
-       unlink(name);
-
        for (i = 0; i < ARRAY_SIZE(entries); ++i) {
                int fd;
                off64_t pos;
 
                frames_per_second = entries[i];
 
+#ifdef HAVE_MEMFD_CREATE
+               fd = memfd_create(name, 0);
+#else
                fd = open(name, O_RDWR | O_CREAT | O_TRUNC, 0644);
+#endif
                if (fd < 0) {
                        err = -errno;
                        break;
@@ -176,7 +186,6 @@ static int callback(struct test_generator *gen, snd_pcm_access_t access,
                assert(err == 0);
 
                close(fd);
-               unlink(name);
        }
 
        free(buf);