05-10-2017 05:56 AM
06-08-2017 11:18 AM
I diff'ed your code against the original dma_to_device.c
1. you are allocating size*count when you are just using "size".
rc = write(fpga_fd, buffer, size);
It would make sense if you did something like this
rc = write( fpga_fd, &buffer[size*i], size );
But as i is unbounded this would eventually blow in your code
2. Why are you doing usleep(5)?
3. you increment "i" in between taking clocks but what will happen is that you will start the clock when say i=1000 but then you will increment i - will become say 1001 and the next clock_gettime() will only execute when i=1999. This is a bug in your code.
Try this instead:
while(1) {
rc = clock_gettime(CLOCK_MONOTONIC, &ts_start);
rc = write(fpga_fd, &buffer[i*size], size);
assert(rc == size);
rc = clock_gettime(CLOCK_MONOTONIC, &ts_end);
i+=1;
if(i == 1000) {
timespec_sub(&ts_end, &ts_start);
/* display passed time, a bit less accurate but side-effects are accounted for */
printf("i=%d CLOCK_MONOTONIC %ld.%09ld seconds for 100transfer \n",i, ts_end.tv_sec, ts_end.tv_nsec);
i = 0;
}