Need a method to check for the warning that Priority can't be set

Curious if anyone has any thoughts on this. I did pay for priority support and I’m happy to send along the key if that’s needed for this, but maybe it’s a very quick/easy question.

I set the Priority at the top of my Psychtoolbox script. If PsychLinuxConfiguration hasn’t run, that command gives a warning and tells the user to run it. I’d like to have my code stop on that warning (so that it can’t run if the priority can’t be set). I tried using “lastwarn” but it doesn’t catch it, and I assume that’s because it’s just a statement printed by the special Screen(‘GetMouseHelper’, -5) call and not an actual Matlab warning. Does anyone have thoughts on code that could “trap” that warning in my code? Or another way to easily test if Priority is able to be set and return if it isn’t?

Thanks!

Please do, so we can account for it. And thanks for being one of the few people who do the right thing so far.

What does oldpriority = Priority() return after a Priority(n) call, ie. if you call it again after the Priority(n) call?

oldpriority = Priority(newpriority); currentpriority = Priority(); If currentpriority is still == oldpriority that should signal failure to change priority.

-mario

oldPriority = Priority() returns 0, with that warning. You’re right, that’s an easy idea, I can see if the new priority I’m setting changes from 0 (which it does on my machines that have had PsychLinuxConfig run). I’m sure that will work - should have thought of it. Thanks!

The number reflects the actual realtime scheduling policy and priority (0 = standard non-RT mode, > 0 = realtime scheduling with given priority). Our config file installed in /etc/security/limits.d/99-psychtoolboxlimits.conf will allow priorities up to 50, although changing that files settings would allow to go up to the maximum of 99 iirc. Rarely is more than the MaxPriority() recommendation of 1 needed.

On macOS or Windows that is all that Priority will do, but Linux users enjoy some more optimizations but improved real-time behaviour.

Priority(>0) will also lock all of Octaves/Matlab memory into physical system RAM to prevent paging, the limit for the amount of lockable RAM is set to “unlimited” in our config file, although the system itself may impose some maximum like 50% of the installed system RAM. If that locking would fail, you’d get a warning not reflected in the priority value, as this is a more minor failure on systems with sufficient amounts of RAM installed. Similar, on modern distributions like Ubuntu 20.04 LTS, the command will request “gamemode” optimizations and a failure of getting those would only print a warning, as they are a bonus, not critically needed. Gamemode will change various system parameters to tune for maximum performance even if this means higher power consumption, or battery drain on a laptop, like prioritized disc i/o, cpu’s and some gpu models tuned for performance etc.

-mario