Well it might be you're running in continuous mode. That much I do not know, but it could be difference in kernels ? I could not say.
On Tue, Sep 29, 2015 at 11:00 PM, Rathin Dholakia <[email protected]> wrote: > Hi, > > I tried running your code and I was successful and unsuccessful both!! :-) > > Success: I could compile code it compiled and when I put "time ./test" I > gave me following output > > real 0m0.011s > user 0m0.000s > sys 0m0.008s > > unsuccessful: it didn't show any readings!! > My guess is it has something to do with my kernel preemtion, isn't it? > > On Wednesday, September 30, 2015 at 11:18:20 AM UTC+5:30, William Hermans > wrote: >> >> Oh, and that is using one shot mode. I did not think to use continuous. >> BUt I really wanted to see how slow using open(), read(), and close() >> really were. Because I had done a lot of reading on the subject, but never >> actually used it( I always used mmap() ). >> >> On Tue, Sep 29, 2015 at 10:41 PM, William Hermans <[email protected]> >> wrote: >> >>> So, I got bored, and decided to do some "screwing around". But took me a >>> while because I had not used, or setup the ADC peripheral before, but . . . >>> here is some quick and dirty code, using std API stuff - Which breaks all >>> the rules I spoke of in my second post heh. But still pretty darned fast. >>> I'd be happier if I could use mmap() directly on >>> /sys/bus/iio/devices/iio:device0/in_voltage0_raw, but either I've been >>> trying to use an improper mode of operation. Or mmap() on that file >>> location is not supported. So, might be forced to use mmap() on /dev/mem . >>> ..ug! >>> >>> #include <unistd.h> >>>> #include <sys/stat.h> >>>> #include <fcntl.h> >>>> #include <stdio.h> >>>> #include <errno.h> >>>> #include <stdlib.h> >>>> >>>> void read_adc(int fd) >>>> { >>>> char adc[5] = {0}; >>>> int len = read(fd, adc, sizeof(adc - 1)); >>>> adc[len] ='\0'; >>>> printf("%s ", adc); >>>> } >>>> >>>> int main() >>>> { >>>> const char *fname = >>>> "/sys/bus/iio/devices/iio:device0/in_voltage0_raw"; >>>> int count = 0; >>>> >>>> while( count++ <= 1000){ >>>> int fd = open(fname, O_CREAT | O_RDONLY); >>>> if(fd == -1){ >>>> printf("error: %s\n", strerror(errno)); >>>> exit(1); >>>> } >>>> >>>> if(count % 15 == 0 && count != 0) >>>> printf("\n"); >>>> >>>> read_adc(fd); >>>> >>>> close(fd); >>>> } >>>> printf("\n"); >>>> >>>> return 0; >>>> } >>>> >>> >>> Output: >>> debian@beaglebone:~$ time ./test >>> 4016 4020 4007 4010 4008 4010 4005 4005 4013 4015 4015 4011 4008 4001 >>> 4010 4006 4006 4011 4007 4011 4003 4009 4006 4005 3995 3999 4005 4000 >>> 3997 >>> 4008 4016 4009 3997 4008 4011 4013 4011 4012 4009 4006 3997 4007 4007 >>> 3999 >>> 4014 4014 4007 4015 4008 4011 4012 4012 4007 4013 4016 4017 4016 4016 >>> 4013 >>> 4006 4013 4015 4006 4013 4009 4003 4011 4011 4017 4015 4008 4005 3998 >>> 4000 >>> 4002 4011 4012 4010 4013 4009 4010 4010 4010 4010 4011 4008 4007 4007 >>> 4007 >>> 4013 3998 4006 4007 4003 3999 4009 4005 4013 4018 4019 4014 4012 4003 >>> 4008 >>> 4010 4017 3999 4002 4008 4008 4008 4004 4010 4008 3996 4002 4009 4014 >>> 4011 >>> 4012 4006 4007 4004 4000 4008 4008 4010 4008 4007 4006 4003 4007 4000 >>> 4008 >>> 4003 4010 4003 4006 4006 3996 4001 4003 4000 4002 3996 4007 4003 4011 >>> 4013 >>> 4012 4017 4013 4008 4002 4010 4005 4013 4016 4014 4012 4015 4013 4013 >>> 4007 >>> 4011 4008 4010 4014 4016 4016 4015 4018 4013 4016 4005 3997 4007 3998 >>> 4007 >>> 4002 4004 4009 4007 4010 4010 4001 4005 4008 4003 4010 4012 4013 4006 >>> 3994 >>> 4014 4006 4008 4009 4014 4015 4012 4012 4013 4010 4012 4014 4015 4020 >>> 4017 >>> 4017 4013 4010 4020 4014 4012 4010 4008 3997 4002 4001 4012 4010 4006 >>> 4016 >>> 4010 4004 4004 4004 4003 4004 4004 3999 4003 4007 4008 4006 4005 4006 >>> 4007 >>> 4013 4013 4011 4010 4010 4005 3996 4002 4008 4012 4012 4007 4006 4000 >>> 3999 >>> 4009 4005 4013 4010 4008 4012 4011 4015 4016 4017 4013 4009 4008 4007 >>> 4006 >>> 4015 4012 4010 4013 4011 4016 4012 4013 4012 4009 4007 3998 3995 3998 >>> 4004 >>> 4003 4011 4009 4001 3998 4007 4008 4001 4008 4008 4012 4013 4007 3998 >>> 3999 >>> 4015 4007 3997 4005 4009 4007 4002 4009 4015 4012 4007 4009 4013 4017 >>> 4015 >>> 4010 4005 4011 4017 4015 4010 4013 4012 4004 4008 4012 4010 4014 4015 >>> 4013 >>> 4016 4016 4016 4007 4009 4011 4010 4009 4010 4010 4004 4004 4002 4002 >>> 4011 >>> 4008 4007 4004 4010 4006 4008 4007 4005 4006 4008 4002 4009 4013 4011 >>> 4006 >>> 4010 4015 4014 4016 4018 4015 4017 4015 4015 4018 4016 4013 4011 4013 >>> 4016 >>> 4017 3998 4012 4006 4008 4014 4011 4003 4012 4018 4014 4012 4005 3994 >>> 4000 >>> 4004 4003 4007 4012 4012 4005 4005 4006 4008 4001 3999 4004 4000 4004 >>> 4000 >>> 4011 4010 4005 4002 4009 4007 4002 4013 4015 4020 4012 4011 4011 4002 >>> 4011 >>> 4008 4013 4009 4012 4006 4011 4009 4015 4013 4009 4003 4008 4003 4005 >>> 4009 >>> 4017 4001 4010 4012 4009 4009 4007 4010 4007 4006 4004 4003 4008 4008 >>> 4003 >>> 4012 4009 4007 4008 4005 4006 4000 3995 4000 4007 4006 4003 4004 4009 >>> 4004 >>> 4008 4020 4010 4009 4006 4008 4015 4018 4017 4011 4014 4013 4010 4009 >>> 4012 >>> 4011 4009 4016 4017 4016 4011 4005 4007 4012 4014 4014 4005 4004 3998 >>> 4000 >>> 4009 4009 4005 3996 4006 3999 4002 4009 4014 4011 4009 4008 4008 4012 >>> 4013 >>> 4003 4007 4010 4012 4012 4010 4010 4010 4014 4017 4016 4007 4020 4013 >>> 4007 >>> 4019 4015 4014 4016 4016 4016 4009 4004 4000 4009 4012 4010 4015 4015 >>> 4015 >>> 4016 4011 4013 4008 4012 4009 4007 4006 4005 4006 4012 4004 4011 4015 >>> 4009 >>> 4010 4014 4004 3998 4008 4010 4004 4003 4008 4013 4013 4009 4007 4004 >>> 4009 >>> 4014 4013 4016 4012 4010 4011 4013 4013 4013 4008 4017 4015 4015 4011 >>> 4014 >>> 4016 4007 4013 4014 4009 3999 4008 4003 4005 4009 4014 4007 4003 3993 >>> 3999 >>> 3999 4005 4013 4003 4011 4009 4011 4010 4006 4002 4006 3998 4001 4003 >>> 4009 >>> 4011 4011 4016 4013 4018 4013 4010 4003 4000 4006 4015 4011 4017 4017 >>> 4016 >>> 4010 4017 4017 4016 4012 4016 4015 4013 4012 4013 4009 4003 4010 4006 >>> 4012 >>> 4004 4013 4001 4000 4005 3997 4004 4008 4012 4008 4005 3996 4003 3999 >>> 4006 >>> 4016 4002 4000 4002 4008 4009 4006 3995 4005 4008 4013 4012 4012 4009 >>> 4007 >>> 4013 4006 4018 4012 4005 4016 4014 4012 4011 4007 4014 4016 4015 4014 >>> 4013 >>> 4005 4007 4013 4008 4009 4002 4012 4011 4015 4013 4012 4010 4004 4007 >>> 4005 >>> 4013 4008 4013 4014 4014 4004 4012 4012 4012 4007 4009 4006 4010 4013 >>> 4014 >>> 4015 4006 4008 4009 4007 4004 4011 4005 4009 4007 4020 4015 4012 4005 >>> 4008 >>> 4021 4018 4016 4013 4003 4015 4015 4019 4014 4013 4003 4007 4009 4014 >>> 4015 >>> 3999 4016 4007 4008 4004 4008 4011 4003 4011 4012 4009 4006 4009 4008 >>> 4005 >>> 4002 4005 4011 4008 4011 4009 4016 4014 4010 4012 4016 4015 4011 4010 >>> 4009 >>> 4010 4011 4019 4018 4015 4017 4010 4000 4009 4015 4017 4017 4013 4017 >>> 4012 >>> 4011 4016 4014 3999 4008 4006 4006 4011 4010 4001 4000 4008 3998 4007 >>> 4013 >>> 4008 4007 4011 4008 4011 4007 4013 4012 4014 4009 4006 4006 4007 4000 >>> 4002 >>> 4012 4011 4008 4010 4004 4015 4013 4015 4014 4006 4019 4012 4007 4016 >>> 4016 >>> 4005 4009 4011 4010 4010 4004 4013 4014 4015 4015 4016 4011 4014 4009 >>> 4004 >>> 4015 4013 4009 4011 4009 4009 4006 4008 4005 3995 4001 4007 4007 4008 >>> 4008 >>> 4008 4008 4004 4006 4011 4010 4002 4011 4013 4009 4003 4000 4006 4011 >>> 4010 >>> 4015 4020 4016 4017 4017 4016 4016 4015 4014 4013 4010 4012 4006 4002 >>> 4000 >>> 4017 4016 4013 4010 4013 4008 4011 4010 4006 4002 4007 4009 4010 4011 >>> 4007 >>> 4011 4012 4014 4003 4003 4012 4010 4014 4013 4010 4007 3994 4000 4006 >>> 4002 >>> 3999 4006 4004 4008 4011 4005 4005 4010 4008 4012 4014 4017 4015 4015 >>> 4001 >>> 4011 4006 4015 4017 4013 4015 4014 4018 4016 4012 4011 4009 4011 4014 >>> 4015 >>> 4008 4009 4009 4006 4011 4010 4008 4010 4005 4006 4005 4005 4009 4003 >>> 4009 >>> 4008 4010 4011 4010 4012 4007 4009 4007 4000 4004 4008 4008 4013 4016 >>> 4017 >>> 4019 4016 4021 4018 4018 4012 4009 4007 4015 4015 4012 4013 >>> >>> real 0m0.328s >>> user 0m0.010s >>> sys 0m0.250s >>> >>> >>> That's actually not too bad for opening, and closing the file 1000 >>> iterations, then using printf() to display the data to stdout. So, looks >>> like 328ms for 1000 iterations on the same adc channel. >>> >>> debian@beaglebone:~$ uname -a >>> Linux beaglebone 4.1.5-ti-rt-r10 #1 SMP PREEMPT RT Fri Aug 14 00:02:42 >>> UTC 2015 armv7l GNU/Linux >>> >>> debian@beaglebone:~$ cat /etc/dogtag >>> BeagleBoard.org Debian Image 2015-03-01 >>> >>> Meaning Wheezy 7.8, and systemd disabled - if the later maters at all. >>> >>> >> -- > For more options, visit http://beagleboard.org/discuss > --- > You received this message because you are subscribed to the Google Groups > "BeagleBoard" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
