Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easily set real-time priority #3

Closed
supercurio opened this issue Apr 5, 2018 · 6 comments
Closed

Easily set real-time priority #3

supercurio opened this issue Apr 5, 2018 · 6 comments

Comments

@supercurio
Copy link

supercurio commented Apr 5, 2018

Hi vityafx, thanks for this useful crate :)
I'm trying to set the highest real-time highest priority for low-latency audio operation.

let thread_id = thread_native_id();
set_thread_priority(thread_id,
                    ThreadPriority::Max,
                    ThreadSchedulePolicy::Realtime(RealtimeThreadSchedulePolicy::Fifo)).unwrap();

This always fails with: Err value: Pthread(22), whereas this is fine:

set_thread_priority(thread_id,
                    ThreadPriority::Min,
                    ThreadSchedulePolicy::Normal(NormalThreadSchedulePolicy::Normal)

Also this code has the result expected, but it's surprising to have a numeric value.

let policy = ThreadSchedulePolicy::Realtime(RealtimeThreadSchedulePolicy::Fifo);
let params = ScheduleParams { sched_priority: 3 };
set_thread_schedule_policy(thread_id, policy, params).unwrap();

How would you set the highest real-time priority ergonomically?

@iddm
Copy link
Owner

iddm commented Apr 5, 2018

Thank you for reporting an issue! I am going to look at it as I have time. As of now, I know that the error you have (Pthread(22)) is this:

EINVAL prio is not valid for the scheduling policy of the specified thread.

So, there is something related to priority which I pass to the function. I am going to work on it more but a bit later, just posting this info here for letting you know I got your problem.

@supercurio
Copy link
Author

Thanks :)
I also noticed that the priority in the end, as shown by top when listing threads is not as high as another audio C++ program I was looking at (when using set_thread_schedule_policy)

@iddm
Copy link
Owner

iddm commented Apr 6, 2018

I am sorry, I realized I don't have a time to work on it this week. I already have guesses why this can happen but I have not tested it yet. I'll try doing it in the end of weekend or next week.

@iddm
Copy link
Owner

iddm commented Apr 23, 2018

Sorry, still have no time. Can't give you any forecast.

@surban
Copy link
Contributor

surban commented Oct 4, 2018

This is caused by set_thread_priority not setting the scheduling policy as documented. See #5 for a fix.

@iddm
Copy link
Owner

iddm commented Jun 15, 2019

Thank you guys for participating in this. I have time now and see this has already been fixed. I am closing this, but if you have something to say or to fix in this issue, feel free to mention it.

@iddm iddm closed this as completed Jun 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants