Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor cleanups to make it more cross platform #54

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

LIBSOURCES = fft_fftw.c libcsdr_wrapper.c
#SOURCES = csdr.c $(LIBSOURCES)
cpufeature = $(if $(findstring $(1),$(shell cat /proc/cpuinfo)),$(2))
cpufeature = $(if $(findstring $(1),$(shell list_cpu_features)),$(2))
PARAMS_SSE = $(call cpufeature,sse,-msse) $(call cpufeature,sse2,-msse2) $(call cpufeature,sse3,-msse3) $(call cpufeature,sse4a,-msse4a) $(call cpufeature,sse4_1,-msse4.1) $(call cpufeature,sse4_2,-msse4.2 -msse4) -mfpmath=sse
PARAMS_NEON = -mfloat-abi=hard -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mvectorize-with-neon-quad -funsafe-math-optimizations -Wformat=0 -DNEON_OPTS
#tnx Jan Szumiec for the Raspberry Pi support
Expand Down
44 changes: 44 additions & 0 deletions csdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ char usage[]=

int env_csdr_fixed_bufsize = 1024;
int env_csdr_fixed_big_bufsize = 1024*16;
#if !__linux__
int env_csdr_dynamic_bufsize_on = 1;
#else
int env_csdr_dynamic_bufsize_on = 0;
#endif
int env_csdr_print_bufsizes = 0;
int bigbufs = 0;

Expand Down Expand Up @@ -366,19 +370,25 @@ int initialize_buffers()
buffer_u8 = (unsigned char*)malloc(the_bufsize*sizeof(unsigned char));
buffer_i16 = (short*) malloc(the_bufsize*sizeof(short));
temp_f = (float*) malloc(the_bufsize*sizeof(float) * 4);

if(the_bufsize<=4096) //this is hacky, should be done correctly
{
#if __linux__
fcntl(STDIN_FILENO, F_SETPIPE_SZ, 4096);
fcntl(STDOUT_FILENO, F_SETPIPE_SZ, 4096);
#endif
}

return the_bufsize;
}

int sendbufsize(int size)
{
if(size<=4096)
{
#if __linux__
fcntl(STDOUT_FILENO, F_SETPIPE_SZ, 4096);
#endif
}
//The first word is a preamble, "csdr".
//If the next csdr process detects it, sets the buffer size according to the second word
Expand Down Expand Up @@ -424,8 +434,10 @@ int main(int argc, char *argv[])
if(argc<=1) return badsyntax(0);
if(!strcmp(argv[1],"--help")) return badsyntax(0);

#if __linux__
fcntl(STDIN_FILENO, F_SETPIPE_SZ, 65536*32);
fcntl(STDOUT_FILENO, F_SETPIPE_SZ, 65536*32);
#endif
//fprintf(stderr, "csdr: F_SETPIPE_SZ\n");

if(!strcmp(argv[1],"setbuf"))
Expand Down Expand Up @@ -1793,15 +1805,31 @@ int main(int argc, char *argv[])
//initialize FFT library, and measure time
errhead(); fprintf(stderr,"initializing... ");
struct timespec start_time, end_time;
#if __FreeBSD__
clock_gettime(CLOCK_MONOTONIC_FAST, &start_time);
#else
clock_gettime(CLOCK_MONOTONIC_RAW, &start_time);
#endif
FFT_PLAN_T* plan=make_fft_c2c(fft_size,input,output,1,benchmark);
#if __FreeBSD__
clock_gettime(CLOCK_MONOTONIC_FAST, &end_time);
#else
clock_gettime(CLOCK_MONOTONIC_RAW, &end_time);
#endif
fprintf(stderr,"done in %g seconds.\n",TIME_TAKEN(start_time,end_time));

//do the actual measurement about the FFT
#if __FreeBSD__
clock_gettime(CLOCK_MONOTONIC_FAST, &start_time);
#else
clock_gettime(CLOCK_MONOTONIC_RAW, &start_time);
#endif
for(int i=0;i<fft_cycles;i++) fft_execute(plan);
#if __FreeBSD__
clock_gettime(CLOCK_MONOTONIC_FAST, &end_time);
#else
clock_gettime(CLOCK_MONOTONIC_RAW, &end_time);
#endif
float time_taken_fft = TIME_TAKEN(start_time,end_time);
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);
return 0;
Expand Down Expand Up @@ -2004,11 +2032,19 @@ int main(int argc, char *argv[])
if(flowcontrol_is_buffering)
{
fprintf(stderr, "flowcontrol: buffering, flowcontrol_bufindex = %d\n", flowcontrol_bufindex);
#if __FreeBSD__
if(flowcontrol_bufindex==flowcontrol_bufsize) { flowcontrol_is_buffering = 0; clock_gettime(CLOCK_MONOTONIC_FAST, &start_time); }
#else
if(flowcontrol_bufindex==flowcontrol_bufsize) { flowcontrol_is_buffering = 0; clock_gettime(CLOCK_MONOTONIC_RAW, &start_time); }
#endif
else if(read_return<=0) continue;
}
else {
#if __FreeBSD__
clock_gettime(CLOCK_MONOTONIC_FAST, &end_time);
#else
clock_gettime(CLOCK_MONOTONIC_RAW, &end_time);
#endif
int thrust_added=0;
while( (all_bytes_written+thrust*flowcontrol_readsize) / TIME_TAKEN(start_time,end_time) < data_rate )
{
Expand Down Expand Up @@ -2063,11 +2099,19 @@ int main(int argc, char *argv[])
if(!time_now_sec)
{
time_now_sec=1;
#if __FreeBSD__
clock_gettime(CLOCK_MONOTONIC_FAST, &start_time);
#else
clock_gettime(CLOCK_MONOTONIC_RAW, &start_time);
#endif
}
else
{
#if __FreeBSD__
clock_gettime(CLOCK_MONOTONIC_FAST, &end_time);
#else
clock_gettime(CLOCK_MONOTONIC_RAW, &end_time);
#endif
float timetaken;
if(time_now_sec<(timetaken=TIME_TAKEN(start_time,end_time)))
{
Expand Down
2 changes: 1 addition & 1 deletion parsevect
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/env python2
print "" # python2.7 is required to run parsevect instead of python3
"""
This software is part of libcsdr, a set of simple DSP routines for
Expand Down