mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-02 23:18:44 +00:00
Benchmark signal delivery
This commit is contained in:
parent
449fb2fb59
commit
db8217b37b
2 changed files with 61 additions and 5 deletions
|
@ -23,7 +23,7 @@
|
|||
|
||||
typedef uint64_t xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
|
||||
|
||||
static dontinline antiquity int memcmp_sse(const char *p, const char *q,
|
||||
static dontinline antiquity int bcmp_sse(const char *p, const char *q,
|
||||
size_t n) {
|
||||
xmm_t a;
|
||||
while (n > 32) {
|
||||
|
@ -38,8 +38,8 @@ static dontinline antiquity int memcmp_sse(const char *p, const char *q,
|
|||
return !!(a[0] | a[1]);
|
||||
}
|
||||
|
||||
microarchitecture("avx") static int memcmp_avx(const char *p, const char *q,
|
||||
size_t n) {
|
||||
microarchitecture("avx") static int bcmp_avx(const char *p, const char *q,
|
||||
size_t n) {
|
||||
xmm_t a, b, c, d;
|
||||
if (n > 32) {
|
||||
if (n >= 16 + 64) {
|
||||
|
@ -123,9 +123,9 @@ int bcmp(const void *a, const void *b, size_t n) {
|
|||
return !!(i ^ j);
|
||||
}
|
||||
} else if (LIKELY(X86_HAVE(AVX))) {
|
||||
return memcmp_avx(p, q, n);
|
||||
return bcmp_avx(p, q, n);
|
||||
} else {
|
||||
return memcmp_sse(p, q, n);
|
||||
return bcmp_sse(p, q, n);
|
||||
}
|
||||
}
|
||||
while (n--) {
|
||||
|
|
|
@ -21,7 +21,9 @@
|
|||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
testonly void OnUsr1(int sig) {
|
||||
|
@ -38,3 +40,57 @@ TEST(signal, test) {
|
|||
ASSERT_NE(-1, raise(SIGUSR1));
|
||||
__die();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// signal round-trip delivery takes about 1µs
|
||||
|
||||
void OnSigTrap(int sig, struct siginfo *si, struct ucontext *ctx) {
|
||||
}
|
||||
|
||||
void TrapBench(int n) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
asm("int3");
|
||||
}
|
||||
}
|
||||
|
||||
BENCH(signal, trapBench) {
|
||||
struct sigaction old;
|
||||
struct sigaction sabus = {.sa_sigaction = OnSigTrap};
|
||||
ASSERT_SYS(0, 0, sigaction(SIGTRAP, &sabus, &old));
|
||||
EZBENCH_N("signal trap", 16, TrapBench(16));
|
||||
EZBENCH_N("signal trap", 256, TrapBench(256));
|
||||
EZBENCH_N("signal trap", 1024, TrapBench(1024));
|
||||
sigaction(SIGTRAP, &old, 0);
|
||||
}
|
||||
|
||||
BENCH(signal, trapBenchSiginfo) {
|
||||
struct sigaction old;
|
||||
struct sigaction sabus = {.sa_sigaction = OnSigTrap, .sa_flags = SA_SIGINFO};
|
||||
ASSERT_SYS(0, 0, sigaction(SIGTRAP, &sabus, &old));
|
||||
EZBENCH_N("siginfo trap", 16, TrapBench(16));
|
||||
EZBENCH_N("siginfo trap", 256, TrapBench(256));
|
||||
EZBENCH_N("siginfo trap", 1024, TrapBench(1024));
|
||||
sigaction(SIGTRAP, &old, 0);
|
||||
}
|
||||
|
||||
void OnSigHlt(int sig, struct siginfo *si, struct ucontext *ctx) {
|
||||
ctx->uc_mcontext.rip += 1;
|
||||
}
|
||||
|
||||
void HltBench(int n) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
asm("hlt");
|
||||
}
|
||||
}
|
||||
|
||||
BENCH(signal, hltBenchSiginfo) {
|
||||
struct sigaction old[2];
|
||||
struct sigaction sabus = {.sa_sigaction = OnSigHlt, .sa_flags = SA_SIGINFO};
|
||||
ASSERT_SYS(0, 0, sigaction(SIGSEGV, &sabus, old + 0));
|
||||
ASSERT_SYS(0, 0, sigaction(SIGBUS, &sabus, old + 1));
|
||||
EZBENCH_N("siginfo hlt", 16, HltBench(16));
|
||||
EZBENCH_N("siginfo hlt", 256, HltBench(256));
|
||||
EZBENCH_N("siginfo hlt", 1024, HltBench(1024));
|
||||
sigaction(SIGSEGV, old + 0, 0);
|
||||
sigaction(SIGBUS, old + 1, 0);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue