2 #include <mach/mach_time.h>
14 asm volatile("rdtsc" : "=a" (lo
), "=d" (hi
));
16 return (uint64_t)hi
<< 32 | lo
;
19 __attribute__((noinline
)) void
20 apply_p(void (^b
)(size_t), size_t offset
, size_t count
)
22 /* This would feed through to the existing dispatch_apply() */
26 /* a dynamically variable to eventually be added to the kernel/user 'commpage' */
27 size_t total_active_cpus
= 8;
29 __attribute__((noinline
)) void
30 apply(void (^b
)(size_t), size_t offset
, size_t count
)
32 const size_t too_long
= 100000; /* 100 us */
33 const size_t laps
= 16;
34 uint64_t delta
, tmp
, now
;
37 if (total_active_cpus
== 1) {
38 for (i
= 0; i
< count
; i
++) {
44 now
= mach_absolute_time();
46 for (i
= 0; i
< count
; i
++) {
53 tmp
= mach_absolute_time();
57 if (delta
> (too_long
* laps
) || (i
== 0 && delta
> too_long
)) {
58 apply_p(b
, offset
+ i
+ 1, count
- (i
+ 1));
67 void (^b
)(size_t) = ^(size_t index
) {
68 asm volatile(""); /* defeat compiler optimizations */
70 const size_t laps
= 10000000;
71 mach_timebase_info_data_t tbi
;
77 kr
= mach_timebase_info(&tbi
);
79 assert(tbi
.numer
== tbi
.denom
); /* This will fail on PowerPC. */
81 s
= mach_absolute_time();
82 for (i
= 0; i
< laps
; i
++) {
85 e
= mach_absolute_time();
88 printf("direct:\t%Lf ns\n", dd
);
90 s
= mach_absolute_time();
92 e
= mach_absolute_time();
95 printf("apply:\t%Lf ns\n", dd
);