xref: /xnu-12377.81.4/tests/mpsc.c (revision 043036a2b3718f7f0be807e2870f8f47d3fa0796)
1*043036a2SApple OSS Distributions /*
2*043036a2SApple OSS Distributions  * mpsc: test the MPSC interface
3*043036a2SApple OSS Distributions  */
4*043036a2SApple OSS Distributions 
5*043036a2SApple OSS Distributions #ifdef T_NAMESPACE
6*043036a2SApple OSS Distributions #undef T_NAMESPACE
7*043036a2SApple OSS Distributions #endif
8*043036a2SApple OSS Distributions 
9*043036a2SApple OSS Distributions #include <darwintest.h>
10*043036a2SApple OSS Distributions #include <sys/sysctl.h>
11*043036a2SApple OSS Distributions 
12*043036a2SApple OSS Distributions T_GLOBAL_META(T_META_NAMESPACE("xnu.mpsc"),
13*043036a2SApple OSS Distributions     T_META_RUN_CONCURRENTLY(true));
14*043036a2SApple OSS Distributions 
15*043036a2SApple OSS Distributions T_DECL(pingpong, "mpsc_pingpong", T_META_ASROOT(true))
16*043036a2SApple OSS Distributions {
17*043036a2SApple OSS Distributions 	uint64_t count = 100 * 1000, nsecs = 0;
18*043036a2SApple OSS Distributions 	size_t nlen = sizeof(nsecs);
19*043036a2SApple OSS Distributions 	int error;
20*043036a2SApple OSS Distributions 
21*043036a2SApple OSS Distributions 	error = sysctlbyname("kern.mpsc_test_pingpong", &nsecs, &nlen,
22*043036a2SApple OSS Distributions 	    &count, sizeof(count));
23*043036a2SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(error, "sysctlbyname");
24*043036a2SApple OSS Distributions 	T_LOG("%lld asyncs in %lld ns (%g us/async)", count, nsecs,
25*043036a2SApple OSS Distributions 	    (nsecs / 1e3) / count);
26*043036a2SApple OSS Distributions }
27