Comment by wheels

Comment by wheels 10 months ago

4 replies

There's some difference between user space and kernel. I don't have much experience in the kernel, but I feel like it's more about making sure tasks are preemptable.

In user space it's often about complexity and guarantees: for example, you really try not to do mallocs in a real-time thread in user space, because it's a system call that will only return in an unpredictable amount of time. Better to preallocate buffers or use the stack. Same for opening files, or stuff like that -- you want to avoid variable time syscalls and do them at thread / application setup.

Choice of algorithms needs to be such that for whatever n you're working with, that it can be processed inside of one sample generation interal. I'm mostly familiar with audio -- e.g. if you're generating audio at 44100 Hz, you need your algorithms to be able to process chunks in less than 22 microseconds.

saagarjha 10 months ago

Real-time performance is not really possible in userspace unless your kernel is kept in the loop, because preemption can happen at any time.

  • kaba0 10 months ago

    I guess we really have to add whether it is soft or hard realtime we are talking about. The former can be done in userspace (e.g. video games), the latter probably need a custom OS (I don’t think rt-linux is good for actual hard realtime stuff)

dgan 10 months ago

How do you handle runtime - defined sizes then? Just preallocate maximum possible number of bytes?

  • wheels 10 months ago

    Well, usually in a realtime system you're required to produce something in a fixed amount of time. Designing the algorithms to not need variable amounts of memory is one of the challenges. Commonly you can have a buffer that's the largest you could reasonably work on in that time slice.