in reply to Re: Any ideas for using perl as a simple pulse generator?
in thread Any ideas for using perl as a simple pulse generator?

Excellent description. Just out of curiosity, I tried your second example on my idle system (linux, newer AMD quad). It used <2% cpu and showed 2-3 *microsecond* precision:

1279058169.099145 1279058169.599145 1279058170.099145 1279058170.599144 1279058171.099144 1279058171.599144 1279058172.099146 1279058172.599144 1279058173.099145 1279058173.599144 1279058174.099145 1279058174.599146 1279058175.099144 1279058175.599145 1279058176.099146 1279058176.599145 1279058177.099145 1279058177.599144

Then I started two fsck processes and 4 prime number searching threads which overtax all CPUs and FPUs. I got this:

1279057824.4011 1279057824.9012 1279057825.4012 1279057825.9011 1279057826.4012 1279057826.9012 1279057827.4012 1279057827.9012 1279057828.4011 1279057828.9011 1279057829.4012 1279057829.9011 1279057830.4012 1279057830.9012 1279057831.4030 1279057831.9012

Which still looks like 1-2 millisecond precision. This is of course much better than I need. I don't know how valid those tests are, though, so I'll have to read up on the linux kernel schedulers.

Any tips for code to do the actual writing? I'll probably use the autoflush=1 example posted in the thread.

Replies are listed 'Best First'.
Re^3: Any ideas for using perl as a simple pulse generator?
by BrowserUk (Patriarch) on Jul 13, 2010 at 23:08 UTC
    Any tips for code to do the actual writing?

    I don't really understand how writing to a file creates pulses to a pump.

    Is this a real file that you're writing to? Or some kind of memory mapped IO?

    if the latter, I'd probably drop into Inline::C for this. On windows, I'd write the whole timing and writing loop in C and run it in a system thread. But I don't know enough about Linux to know if this makes sense there.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Any ideas for using perl as a simple pulse generator?
by JavaFan (Canon) on Jul 14, 2010 at 07:40 UTC
    Any tips for code to do the actual writing?
    syswrite, and if you aren't checking whether your write actually succeeded, open the file in O_ASYNC mode (use sysopen for that).

    But since you don't mind a variation of a couple of hundred msecs (on a delay of five hundred msecs) running it with autoflush and without O_ASYNC should be ok. Just as an unconditional sleep - writing a byte shouldn't take hundreds of msecs anyway (I presume the file you're writing to isn't on some NFS drive while the OS doesn't have any memory for file buffers). And as you said, the write takes a few tens of msecs.