initial

parents
hugepage_uring_0copy_perf
programs = hugepage_uring_0copy_perf
sources = main.c
CC = gcc
LDFLAGS = -luring
all: $(programs)
$(programs): $(sources)
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
check: $(programs)
./hugepage_uring_0copy_perf 1
.PHONY: check
/*
* simple demo to show long execution times of mmap of 1GB huge pages and
* io_uring configuration for zero copy
*
* March 2022, Nils Goroll <slink@uplex.de>
*/
#include <assert.h>
#include <errno.h>
#include <liburing.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/mman.h>
#include <linux/mman.h>
/* BEGIN from varnish-cache */
#define AZ(foo) do { assert((foo) == 0); } while (0)
#define AN(foo) do { assert((foo) != 0); } while (0)
static double
VTIM_mono(void)
{
struct timespec ts;
AZ(clock_gettime(CLOCK_MONOTONIC, &ts));
return (ts.tv_sec + 1e-9 * ts.tv_nsec);
}
/* END from varnish-cache */
#define ptime(t, d, x) printf(x "\t%.6fs\n", t[d] - t[d - 1])
static void
usage(const char *name)
{
printf("Usage: %s <gb>\n\t<gr> is gigabytes to mmap()\n", name);
exit(1);
}
static int
register_buffers(struct io_uring *ring, void *base, unsigned long gb)
{
unsigned u, n = gb + 1;
struct iovec iov[n];
const size_t sz = (size_t)1<<30;
uintptr_t p;
memset(iov, 0, sizeof iov);
p = (uintptr_t)base;
for (u = 0; u < gb ; u++) {
iov[u].iov_base = (void *)p;
iov[u].iov_len = sz;
p += sz;
}
return (io_uring_register_buffers(ring, iov, gb));
}
int
main(int argc, char **argv)
{
double t[5];
unsigned long gb;
char *p;
void *base;
struct io_uring_probe *probe;
struct io_uring ring[1];
if (argc != 2)
usage(argv[0]);
gb = strtoul(argv[1], &p, 10);
if (p == argv[1] || *p != '\0')
usage(argv[0]);
probe = io_uring_get_probe();
AN(probe);
assert(io_uring_opcode_supported(probe, IORING_OP_READ_FIXED));
free(probe);
AZ(io_uring_queue_init(1024, ring, 0));
t[0] = VTIM_mono();
base = mmap(NULL, (size_t)gb << 30, PROT_READ|PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE | MAP_LOCKED |
MAP_HUGETLB | MAP_HUGE_1GB, -1, 0);
t[1] = VTIM_mono();
if (base == MAP_FAILED) {
fprintf(stderr, "mmap() failed with %s (%d)\n"
"Hint: /sys/kernel/mm/hugepages/"
"hugepages-1048576kB/nr_hugepages\n"
"and ulimit -l must be configured\n",
strerror(errno), errno);
exit(1);
}
assert(base != MAP_FAILED);
ptime(t, 1, "mmap()");
AZ(register_buffers(ring, base, gb));
t[2] = VTIM_mono();
ptime(t, 2, "io_uring_register_buffers()");
printf("total\t%.6fs\n", t[2] - t[0]);
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