l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
October 7: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2006 Apr 04 14:26

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Must a 300 microsecond delay keep the CPU busy?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] Must a 300 microsecond delay keep the CPU busy?



On Tue, Apr 04, 2006 at 11:52:52AM -0700, Chris Jenks wrote:
>   I'm writing a C program on my Debian system to read from an interface 
> board through the parallel port. I need to wait at least 300 microseconds 
> before reading from the next channel, to give the A/D converter on the 
> board time to stabilize, but I don't want to wait much longer (e.g., 10 

Assuming you've got a somewhat standard kernel then... try this to enhance
your scheduling priority... this will increase the resolution of your
sleeps, maybe enough to do what you need.  Oh, and pay attention to what
you're doing.  When you have a high priority process running, if you did
anything wrong at all, you'll essentially lock the system up. A simple
"while(1);" becomes "ooops, must hit reset button".  Note, one call tells
the scheduler how important you are (and there are more options on the man
page, and the other call locks your program's memory so that your process
(or part of it) cannot be swapped out to disk.

Another trick is to read the CPU cycle counter, but I believe that is only
available on Pentium class CPUs.  http://faydoc.tripod.com/cpu/rdtsc.htm
seems to confirm that.

On last thought would be to do your normal sleep for 90% of the time you
need, and then do a more expensive time test for the last 10% in order to
increase your timing resolution only when it's most critical.


#include <stdio.h>
#include <time.h>
#include <sched.h>
#include <sys/mman.h>

/* TD July 24, 1999 or before */

int main()
{   
    struct sched_param sp;

    sp.sched_priority=90;
    if (sched_setscheduler(0,SCHED_FIFO, &sp)) {perror("setcheduler");exit(1);}
    if (mlockall(MCL_FUTURE)) { perror("mlockall"); exit(1); }

    printf("HIGH PRIORITY shell being launched\n");

    system("/bin/bash");

    exit(0);
}


-- 
Ted Deppner
http://www.deppner.us/
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.