@@ -53,10 +53,26 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53
53
#include "fastddc.h"
54
54
#include <assert.h>
55
55
56
- #ifdef __APPLE__
57
- #define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
56
+ #ifdef __MACH__
57
+ #include <mach/clock.h>
58
+ #include <mach/mach.h>
58
59
#endif
59
60
61
+ // Use clock_gettime in linux, clock_get_time in OS X.
62
+ void get_monotonic_time (struct timespec * ts ){
63
+ #ifdef __MACH__
64
+ clock_serv_t cclock ;
65
+ mach_timespec_t mts ;
66
+ host_get_clock_service (mach_host_self (), SYSTEM_CLOCK , & cclock );
67
+ clock_get_time (cclock , & mts );
68
+ mach_port_deallocate (mach_task_self (), cclock );
69
+ ts -> tv_sec = mts .tv_sec ;
70
+ ts -> tv_nsec = mts .tv_nsec ;
71
+ #else
72
+ clock_gettime (CLOCK_MONOTONIC_RAW , ts );
73
+ #endif
74
+ }
75
+
60
76
char usage []=
61
77
"csdr - a simple commandline tool for Software Defined Radio receiver DSP.\n\n"
62
78
"usage: \n\n"
@@ -1803,15 +1819,15 @@ int main(int argc, char *argv[])
1803
1819
//initialize FFT library, and measure time
1804
1820
errhead (); fprintf (stderr ,"initializing... " );
1805
1821
struct timespec start_time , end_time ;
1806
- clock_gettime ( CLOCK_MONOTONIC_RAW , & start_time );
1822
+ get_monotonic_time ( & start_time );
1807
1823
FFT_PLAN_T * plan = make_fft_c2c (fft_size ,input ,output ,1 ,benchmark );
1808
- clock_gettime ( CLOCK_MONOTONIC_RAW , & end_time );
1824
+ get_monotonic_time ( & end_time );
1809
1825
fprintf (stderr ,"done in %g seconds.\n" ,TIME_TAKEN (start_time ,end_time ));
1810
1826
1811
1827
//do the actual measurement about the FFT
1812
- clock_gettime ( CLOCK_MONOTONIC_RAW , & start_time );
1828
+ get_monotonic_time ( & start_time );
1813
1829
for (int i = 0 ;i < fft_cycles ;i ++ ) fft_execute (plan );
1814
- clock_gettime ( CLOCK_MONOTONIC_RAW , & end_time );
1830
+ get_monotonic_time ( & end_time );
1815
1831
float time_taken_fft = TIME_TAKEN (start_time ,end_time );
1816
1832
errhead (); fprintf (stderr ,"%d transforms of %d processed in %g seconds, %g seconds each.\n" ,fft_cycles ,fft_size ,time_taken_fft ,time_taken_fft /fft_cycles );
1817
1833
return 0 ;
@@ -2014,11 +2030,11 @@ int main(int argc, char *argv[])
2014
2030
if (flowcontrol_is_buffering )
2015
2031
{
2016
2032
fprintf (stderr , "flowcontrol: buffering, flowcontrol_bufindex = %d\n" , flowcontrol_bufindex );
2017
- if (flowcontrol_bufindex == flowcontrol_bufsize ) { flowcontrol_is_buffering = 0 ; clock_gettime ( CLOCK_MONOTONIC_RAW , & start_time ); }
2033
+ if (flowcontrol_bufindex == flowcontrol_bufsize ) { flowcontrol_is_buffering = 0 ; get_monotonic_time ( & start_time ); }
2018
2034
else if (read_return <=0 ) continue ;
2019
2035
}
2020
2036
else {
2021
- clock_gettime ( CLOCK_MONOTONIC_RAW , & end_time );
2037
+ get_monotonic_time ( & end_time );
2022
2038
int thrust_added = 0 ;
2023
2039
while ( (all_bytes_written + thrust * flowcontrol_readsize ) / TIME_TAKEN (start_time ,end_time ) < data_rate )
2024
2040
{
@@ -2027,7 +2043,7 @@ int main(int argc, char *argv[])
2027
2043
//if(!(test++%10)) fprintf(stderr, "abw=%g\n", all_bytes_written / TIME_TAKEN(start_time,end_time));
2028
2044
/*if(!thrust_added && TIME_TAKEN(start_time,end_time)>50)
2029
2045
{
2030
- clock_gettime(CLOCK_MONOTONIC_RAW, &start_time);
2046
+ get_monotonic_time( &start_time);
2031
2047
all_bytes_written=0;
2032
2048
}*/
2033
2049
while (all_bytes_written > data_rate && TIME_TAKEN (start_time ,end_time )> 1 )
@@ -2073,11 +2089,11 @@ int main(int argc, char *argv[])
2073
2089
if (!time_now_sec )
2074
2090
{
2075
2091
time_now_sec = 1 ;
2076
- clock_gettime ( CLOCK_MONOTONIC_RAW , & start_time );
2092
+ get_monotonic_time ( & start_time );
2077
2093
}
2078
2094
else
2079
2095
{
2080
- clock_gettime ( CLOCK_MONOTONIC_RAW , & end_time );
2096
+ get_monotonic_time ( & end_time );
2081
2097
float timetaken ;
2082
2098
if (time_now_sec < (timetaken = TIME_TAKEN (start_time ,end_time )))
2083
2099
{
0 commit comments