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