Commit 0978dafc authored by Florian Fischer's avatar Florian Fischer
Browse files

Merge branch 'work-work-work' into 'main'

Work work work

See merge request i4/manycore/fgbs-syscall-eval!3
parents f28d8a46 0cf52e2f
Pipeline #66509 passed with stage
in 56 seconds
BENCH_MAIN := bench.c
SYSCALLS := blocking io-uring io-uring-sqpoll io-uring-no-syscall epoll aio-sig aio-thrd
SYSCALLS := blocking io-uring io-uring-sqpoll io-uring-no-syscall epoll paio-sig paio-thrd
OBJ := $(addprefix bench-,$(SYSCALLS))
LDFLAGS := -luring -pthread -lrt
CFLAGS := -Werror -Wall -g -O3
CFLAGS := -Werror -Wall -g -O3 -D_GNU_SOURCE
# CFLAGS := -Werror -Wall -g -O0
.PHONY: all clean eval docker-eval check
......
#include <err.h>
#include <fcntl.h>
#include <sched.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/eventfd.h>
#include <unistd.h>
#include "stopwatch.h"
void init(int fd);
void do_write(int fd, const void *buf, size_t count);
const size_t warmup = 10000;
const size_t iterations = 1000000;
size_t warmup = 10000;
size_t iterations = 1000000;
#define BUFSIZE 64
......@@ -23,18 +25,33 @@ static int create_eventfd() {
return fd;
}
static void set_cpu_affinity(int cpu) {
cpu_set_t set;
// NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling)
CPU_ZERO(&set);
CPU_SET(cpu, &set);
if (sched_setaffinity(getpid(), sizeof(set), &set) == -1)
err(EXIT_FAILURE, "sched_setaffinity failed");
}
int main() {
uint64_t cycles_sum = 0;
uint64_t nanos_sum = 0;
uint64_t write_buf = 1;
set_cpu_affinity(0);
int fd = create_eventfd();
init(fd);
const size_t exp_warmup = warmup;
const size_t exp_iterations = iterations;
if (exp_iterations == 0) errx(EXIT_FAILURE, "experiment must do at least one iteration");
for (size_t i = 0; i < warmup; ++i) do_write(fd, &write_buf, sizeof(write_buf));
for (size_t i = 0; i < exp_warmup; ++i) do_write(fd, &write_buf, sizeof(write_buf));
for (int64_t i = 1; i <= iterations; ++i) {
for (int64_t i = 1; i <= exp_iterations; ++i) {
do_write(fd, &write_buf, sizeof(write_buf));
if (__builtin_add_overflow(nanos_sum, clock_diff_nanos(), &nanos_sum))
errx(EXIT_FAILURE, "nanos overflowed at %ld", i);
......@@ -45,8 +62,8 @@ int main() {
// Since uint64_t <-> double conversion are not well defined
// and we use really small units (cycles and nanoseconds) I am willing
// to accept that we throw away anything after the decimal point.
uint64_t avg_nanos = nanos_sum / iterations;
uint64_t avg_cycles = cycles_sum / iterations;
uint64_t avg_nanos = nanos_sum / exp_iterations;
uint64_t avg_cycles = cycles_sum / exp_iterations;
printf("%lu ns, %lu cycles\n", avg_nanos, avg_cycles);
return 0;
......
#pragma once
#define unlikely(x) __builtin_expect(!!(x), 0)
extern size_t warmup, iterations;
......@@ -5,6 +5,7 @@
#include <stdint.h>
#include <stdlib.h>
#include "common.h"
#include "stopwatch.h"
atomic_int done;
......@@ -19,6 +20,9 @@ void callback(union sigval sigval) {
}
void init(int fd) {
// decrease the experiment size because this takes much longer than anything else
warmup = 10;
iterations = 100;
aiocb.aio_fildes = fd;
aiocb.aio_sigevent.sigev_notify = SIGEV_THREAD;
aiocb.aio_sigevent.sigev_notify_function = callback;
......
Supports Markdown
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