Skip to content
Snippets Groups Projects
Select Git revision
  • main
1 result

io_uring.c

Blame
    • Florian Fischer's avatar
      ddcb2688
      add io_uring batch variant · ddcb2688
      Florian Fischer authored
      Queue-based interfaces are able to spread the syscall overhead across
      multiple requests.
      Add a new io_uring variant submitting 10 read requests with a single
      io_uring_enter call.
      
      Adapt bench.c and all other variants to support variable numbers of
      read requests issued by do_read(...).
      ddcb2688
      History
      add io_uring batch variant
      Florian Fischer authored
      Queue-based interfaces are able to spread the syscall overhead across
      multiple requests.
      Add a new io_uring variant submitting 10 read requests with a single
      io_uring_enter call.
      
      Adapt bench.c and all other variants to support variable numbers of
      read requests issued by do_read(...).
    io_uring.c 802 B
    #include <err.h>
    #include <errno.h>
    #include <liburing.h>
    #include <stdlib.h>
    
    #include "stopwatch.h"
    
    struct io_uring ring;
    
    void init(__attribute__((unused)) int fd) {
    	int res = io_uring_queue_init(1, &ring, 0);
    	if (res < 0) {
    		errno = -res;
    		err(EXIT_FAILURE, "io_uring_setup failed");
    	}
    }
    
    unsigned do_read(int fd, void *buf, size_t count) {
    	start_watch();
    
    	struct io_uring_sqe *sqe = io_uring_get_sqe(&ring);
    	io_uring_prep_read(sqe, fd, buf, count, 0);
    
    	int res = io_uring_submit_and_wait(&ring, 1);
    
    	stop_watch();
    
    	if (res < 0) err(EXIT_FAILURE, "io_uring_submit_and_wait failed");
    
    	struct io_uring_cqe *cqe;
    	res = io_uring_peek_cqe(&ring, &cqe);
    	if (res < 0) err(EXIT_FAILURE, "io_uring_peek_cqe failed");
    
    	if (cqe->res < 0) err(EXIT_FAILURE, "read request failed");
    	return 1;
    }