Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Virtual Machine / May 2004

Tip: Looking for answers? Try searching our database.

JIT compilers and time resolution in psychology experiments

Thread view: 
Leo Trottier - 12 May 2004 21:27 GMT
Hi,

I write software for eye-movement psychology experiments that requires < 0.1
ms time resolution (we have to be able to draw things to the screen at
precise times, know exactly when they were drawn, etc.).  At present I have
to
write the programs in C, but my life would be made much easier if I could do
so in Java (or Python ...).  Is there any way I can get this kind of
temporal resolution from a high-level language?  Since this kind of
resolution is only necessary for brief (repeated) parts of the program's
execution, I thought perhaps the JIT compiler could provide the needed
performance.

Any ideas?

Leo
Mike Stroyan - 12 May 2004 23:15 GMT
|I write software for eye-movement psychology experiments that requires < 0.1
|ms time resolution (we have to be able to draw things to the screen at
|precise times, know exactly when they were drawn, etc.).

 Even a very good monitor can only be set to refresh at about 100 times
per second.  That means that you have at least 10.0 millisecond of
variability for when a drawn image will finish showing up on the screen.

Signature

Mike Stroyan, mike.stroyan@hp.com

Leo Trottier - 13 May 2004 00:21 GMT
True enough, however we're already using a refreshed-locked display, so at
least in C we know precisely _when_ the stimulus has been presented.  With
Java, however, we worry  about time measurement hiccups. It's not that we
really care about when to _put_ something on the screen (though, of course,
we do to a certain extent), but we _do_ want to know exactly (preferably to
the millisecond) when the thing was put there.  So it can't take more than 1
ms for us to figure out when an image was displayed.

A further issue is in the measurement of response times (both hand and
eye) - since we work on the order of ms, any constant delays screw up our
results.

Leo

> |I write software for eye-movement psychology experiments that requires < 0.1
> |ms time resolution (we have to be able to draw things to the screen at
[quoted text clipped - 3 lines]
> per second.  That means that you have at least 10.0 millisecond of
> variability for when a drawn image will finish showing up on the screen.
Mark Bottomley - 13 May 2004 02:01 GMT
Leo:

Unless you are using some display technology that is not common (LCD or
CRT). The time between writing to the display memory and the appearance of
the text/image on the screen is tied to the display refresh rate which is
usually in the range of 60-100Hz (16.6 - 10 milliseconds). The data, if not
completely written before that portion of the display memory is read out to
the display will result in partial screen updates separated by a refresh
cycle time. (Try dragging a window rapidly around the screen and you can see
the update artifacts). On older (antique?) CGA displays, one would get
"snow" if updating the screen during redraw. What you want to access is the
vertical retrace display signal to get the start time for a screen redraw. I
don't know how you could access that signal from Java. If you think you can
resolve something on the display to the resolution of a millisecond, then it
will matter where vertically you write it as the display is updated linearly
top to bottom over most of the redraw cycle after time for the front porch
of the video signal, and various blanking times. I don't believe that the
high resolution Java timers bear any relationship to the video retrace
timings.

A further complication on a CRT may occur if the display is interlaced
(draws interleaved lines on each display update) like a standard NTSC TV.
These are not common in computer monitors, but do occur.

If you are interested in what a CRT signal looks like, find the EIA/RS-170A
spec. for monochrome video signals (I forget the variant for colour -
RS-343?). VGA signals are not much different except they separate the
colours and I believe that the sync is overlaid on the green signal.

Mark...

> True enough, however we're already using a refreshed-locked display, so at
> least in C we know precisely _when_ the stimulus has been presented.  With
[quoted text clipped - 18 lines]
> > per second.  That means that you have at least 10.0 millisecond of
> > variability for when a drawn image will finish showing up on the screen.
Leo Trottier - 13 May 2004 16:53 GMT
As I mentioned, I don't think it's too difficult to get refresh-locked
displays.  But there are other high-time resolution concerns, such as very
accurately _reporting_ when something was drawn, and doing so consistently.
I don't want the garbage collector to start looking around between when I've
called for the image to be displayed and when I print the time that records
such an event.  A JNI could probably take care of this particular problem
... but the issue is with using Java as a whole, because there are other
timing-related things that must be done precisely.

I'm looking into IBM's high resolution time stamp facility, which uses JNIs
to get around such issues, and supposedly has microsecond time resolution.

Any other input, though, is welcome.

Leo

> Leo:
>
[quoted text clipped - 53 lines]
> > > per second.  That means that you have at least 10.0 millisecond of
> > > variability for when a drawn image will finish showing up on the screen.
Roedy Green - 13 May 2004 19:54 GMT
>I'm looking into IBM's high resolution time stamp facility, which uses JNIs
>to get around such issues, and supposedly has microsecond time resolution.

Let's say gc spoils an experiment every once in a while.  You can
detect that and discard the test.  Use explicit System.gc() at
convenient times.

There is the RDTSC instruction for high res timing.

This is the sort of thing that would have been ever so much easier
back in the DOS days where you could poke at the hardware yourself any
time you wanted and there was documentation around on how to do it.

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Mark Bottomley - 13 May 2004 23:26 GMT
Leo:

   As Roedy said, you can use System.gc() to try to encourage a garbage
collection in Java (The method is a hint, not a command IIRC). The safer
solution is do the usual real-time stuff like pre-allocating the objects you
will need to avoid GC's. Also unless you are doing many allocations and
abandoning them, the GC most likely will not be doing anything.

   As far as reporting when it was written to the display memory, that can
be done, but what probably matters is when it is streamed to display. The
only signal possibly visible to the PC is the vertical retrace of the video
and then the time of display is relative to that as the display raster is
written. e.g. a 640x480 screen non-interlaced at 60Hz draws a line of 640
pixels every ~34usec or a pixel every ~50nsec. It would take ~32x34usec = 1
msec to draw a 32 row high icon and the offset from the vertical retrace is
approximately 1 msec for every 32 rows down the screen. These numbers can be
adjusted for other resolutions/refresh rates. What you need to do is access
the refresh signal and either write immediately for display lower down the
screen, or delay from the refresh until you know the display position has
been scanned out to the monitor and then write the data for display on the
next pass. No hardware I know will tell you when it is rendered to the
display, but refresh signals are not uncommon.

   I think it would be useful for you to describe what you are trying to
achieve, beacuse if you are trying to display something for n exact
duration, then you have the same problem with turning off the image and the
time quantum will be 1 screen redraw.

   FYI, I believe that the fastest refresh rates for low res. (640x480) are
approaching 160-180Hz on a top end video card/monitor combo and 100-120Hz
for higher resolutions.

Mark...

> As I mentioned, I don't think it's too difficult to get refresh-locked
> displays.  But there are other high-time resolution concerns, such as very
[quoted text clipped - 87 lines]
> > > > variability for when a drawn image will finish showing up on the
> screen.
George Neuner - 21 May 2004 08:10 GMT
>Hi,
>
[quoted text clipped - 12 lines]
>
>Leo

I haven't worked with any of these for a long time, but some of the
high performance graphics cards that offered hardware sprites used to
have a horizontal refresh interrupt that could be triggered on an
arbitrary set of scan lines ( you used the refresh time to update the
sprites or whatever before the line was drawn ).  

It would mean writing interrupt handlers, but if you can get an
interrupt on the image's first raster line, you could work out from
the scan frequency and the image's horizontal position exactly when it
will be drawn.

George
=============================================
Send real email to GNEUNER2 at COMCAST o NET
Roedy Green - 21 May 2004 17:22 GMT
>It would mean writing interrupt handlers, but if you can get an
>interrupt on the image's first raster line, you could work out from
>the scan frequency and the image's horizontal position exactly when it
>will be drawn.

Thinking about solving this another way. What if you turned a dot on
and off again very quickly, and asked the user to tell you when it was
visible. You home in by some sort of binary search.

Perhaps you could calibrate the horizontal frequency against the high
res cycle counter RDTSC clock.

I don't know how long it would stay calibrated.

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.