klabhub / neurostim

Design and run visual neuroscience experiments using Matlab and the Psychophysics Toolbox.
MIT License
4 stars 3 forks source link

Linux gamemode priority fix #212

Closed cnuahs closed 1 year ago

cnuahs commented 1 year ago

We've encountered a problem running neurostim on Ubuntu Linux, described here: https://psychtoolbox.discourse.group/t/linux-failed-to-start-gamemode/4047. In short, after many trials PTB reports “PTB-WARNING: Failed to start gamemode optimizations:”.

The changes here (in cic's run() method) call Priority(MaxPriority(c.mainWindow)); at the start of an experiment (before entering the block loop) and then calls Priority(0); at the end of the experiment (to downgrade priority), rather than the present arrangement that calls Priority() before and after each trial.

This follows the advice from Mario Kleiner at the link above and seems to resolve, i.e., eliminate, the gamemode warnings.

There is one other change here related to issue #134 (from 2019). This isn't strictly related to gamemode, but in testing gamemode priority changes I convinced myself that the busy waiting in the ITI introduced re: #134 was actually detrimental to performance on our rig (Ubuntu 22.04 with low-latency kernel). Can anyone comment on this? Is this busy waiting [still] necessary?

adammorrissirrommada commented 1 year ago

The conditions required to observe the timing issue I reported (and addressed with the ITI hack) were pretty specific. Only manifest when creating huge arrays immediately after ITI. I have no way to know if that issue remains (it was on the Monash psych rig). I am not opposed to removing the "fix".

adammorrissirrommada commented 1 year ago

I don't access to a proper rig, but the way to test is to log a GetSecs tic() and toc() around a call to rand() with a very large size (can't remember how big, but BIG!) on frame 1. Run some trials, then look at histogram of results.

Repeat with and without the ITI load business.

adammorrissirrommada commented 1 year ago

On a Windows 10 machine....

bartkrekelberg commented 1 year ago

I see that Kleiner recommends changing priority only once. This makes sense, but given that the current code runs fine on Windows (and leaving some time between trials for windows to do its thing) I am a bit hesitant to make these changes. For this particular issue, I also think that a test on Ubuntu has little bearing on running in Windows.

You could define a new property (c.screen.gameModePerTrial?) that makes these changes optional and the changes backward compatible? With some code comments that could help a future developer in finding a way to speed up their code.

cnuahs commented 1 year ago

Agreed. I'll look at making it conditional/configurable.