// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2016 Red Hat, Inc. * Author: Michael S. Tsirkin <mst@redhat.com> * * Command line processing and common functions for ring benchmarking.
*/ #define _GNU_SOURCE #include <getopt.h> #include <pthread.h> #include <assert.h> #include <sched.h> #include"main.h" #include <sys/eventfd.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <limits.h>
int runcycles = 10000000; int max_outstanding = INT_MAX; int batch = 1; int param = 0;
ret = pthread_setaffinity_np(self, sizeof(cpu_set_t), &cpuset);
assert(!ret);
}
void poll_used(void)
{ while (used_empty())
busy_wait();
}
staticvoid __attribute__((__flatten__)) run_guest(void)
{ int completed_before; int completed = 0; int started = 0; int bufs = runcycles; int spurious = 0; int r; unsigned len; void *buf; int tokick = batch;
for (;;) { if (do_sleep)
disable_call();
completed_before = completed; do { if (started < bufs &&
started - completed < max_outstanding) {
r = add_inbuf(0, "Buffer\n", "Hello, world!"); if (__builtin_expect(r == 0, true)) {
++started; if (!--tokick) {
tokick = batch; if (do_sleep)
kick_available();
}
}
} else
r = -1;
/* Flush out completed bufs if any */ if (get_buf(&len, &buf)) {
++completed; if (__builtin_expect(completed == bufs, false)) return;
r = 0;
}
} while (r == 0); if (completed == completed_before)
++spurious;
assert(completed <= bufs);
assert(started <= bufs); if (do_sleep) { if (used_empty() && enable_call())
wait_for_call();
} else {
poll_used();
}
}
}
void poll_avail(void)
{ while (avail_empty())
busy_wait();
}
staticvoid __attribute__((__flatten__)) run_host(void)
{ int completed_before; int completed = 0; int spurious = 0; int bufs = runcycles; unsigned len; void *buf;
for (;;) { if (do_sleep) { if (avail_empty() && enable_kick())
wait_for_kick();
} else {
poll_avail();
} if (do_sleep)
disable_kick();
completed_before = completed; while (__builtin_expect(use_buf(&len, &buf), true)) { if (do_sleep)
call_used();
++completed; if (__builtin_expect(completed == bufs, false)) return;
} if (completed == completed_before)
++spurious;
assert(completed <= bufs); if (completed == bufs) break;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.