4 * All-threads getuid timing test.
13 #include <machine/atomic.h>
17 extern int getuid_test(void);
22 struct timespec ts
, ts2
;
32 done
= mmap(NULL
, 4096, PROT_READ
|PROT_WRITE
,
33 MAP_SHARED
|MAP_ANON
, -1, 0);
36 * How many cpu threads are there?
39 ncpu_size
= sizeof(ncpu
);
40 if (sysctlbyname("hw.ncpu", &ncpu
, &ncpu_size
, NULL
, 0) < 0) {
41 perror("sysctl hw.ncpu");
44 printf("timing standard getuid() syscall, %d threads\n", ncpu
);
45 printf("if using powerd, run several times\n");
49 * Approximate timing run length
52 while (stop_timing(0, NULL
) == 0) {
53 for (j
= 0; j
< 100; ++j
)
60 * Run same length on all threads.
62 for (cpuno
= 0; cpuno
< ncpu
; ++cpuno
) {
65 * Give scheduler time to move threads around
68 while (stop_timing(0, NULL
) == 0) {
69 for (j
= 0; j
< 100; ++j
)
74 * Actual timing test is here.
77 for (count
= 0; count
< max
; count
+= 100) {
78 for (j
= 0; j
< 100; ++j
)
81 stop_timing(count
, "getuid() sysmsg");
84 * Don't unbusy the cpu until the other threads are
87 atomic_add_int(done
, 1);
88 while (*done
< ncpu
) /* wait for other threads */
93 while (wait3(NULL
, 0, NULL
) > 0 || errno
== EINTR
)