This is a small hack that shows how to set real-time priority for a thread in Common Lisp using sbcl by calling pthread_setschedparam(3). The code should be easily adaptable for other Common Lisp implementations.
The effect of doing so can be observed by calling ps(1) and chrt(1).
The cffi based code needed is in the file setschedparam.lisp. The file main.lisp serves as a demo.
- sbcl (I am running
SBCL 2.2.9
) - quicklisp (for getting cffi)
- Allowing the user to set real-time priority
- For Arch Linux see Realtime_process_management
- Essentially, the package realtime-privileges needs to be installed.
- And then the user needs to be added to the
realtime
group (you might have to login again).
- For Arch Linux see Realtime_process_management
This demo shows the effect of calling (pthread-setschedparam :sched-rr 17)
in a new thread created with sb-thread:make-thread
.
$ { ./main.lisp & } ; sleep 1 ; ps ml $(cat sbcl.pid) ; chrt -ap $(cat sbcl.pid) [1] 81145 To load "cffi": Load 1 ASDF system: cffi ; Loading "cffi" ............ hello F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND 0 1000 81145 41968 - - 1250512 113192 - - pts/5 0:00 sbcl --script ./main.li 0 1000 - - 20 0 - - futex_ Sl - 0:00 - 1 1000 - - 20 0 - - futex_ Sl - 0:00 - 1 1000 - - -18 - - - hrtime Sl - 0:00 - pid 81145's current scheduling policy: SCHED_OTHER pid 81145's current scheduling priority: 0 pid 81147's current scheduling policy: SCHED_OTHER pid 81147's current scheduling priority: 0 pid 81150's current scheduling policy: SCHED_RR pid 81150's current scheduling priority: 17 $ bye [1]+ Done ./main.lisp $