@@ -472,19 +472,37 @@ pub fn tune_current_control_thread() {
472472}
473473
474474pub fn tune_current_data_thread ( core_id : Option < core_affinity:: CoreId > ) {
475- use rustix:: thread:: { current_timer_slack, set_current_timer_slack} ;
476-
477- if let Some ( core) = core_id {
478- if core_affinity:: set_for_current ( core) {
479- tracing:: info!( ?core, "Data thread pinned to CPU core" ) ;
480- } else {
481- tracing:: warn!( ?core, "Failed to pin Data thread to CPU core" ) ;
482- }
483- }
484-
485475 #[ cfg( target_os = "linux" ) ]
486476 {
477+ use rustix:: thread:: { current_timer_slack, set_current_timer_slack} ;
487478 use std:: num:: NonZero ;
479+ use thread_priority:: {
480+ RealtimeThreadSchedulePolicy , ScheduleParams , ThreadPriority , ThreadSchedulePolicy ,
481+ thread_native_id,
482+ } ;
483+
484+ if let Some ( core) = core_id {
485+ if core_affinity:: set_for_current ( core) {
486+ tracing:: info!( ?core, "Data thread pinned to CPU core" ) ;
487+ } else {
488+ tracing:: warn!( ?core, "Failed to pin Data thread to CPU core" ) ;
489+ }
490+ }
491+
492+ let current_thread_id = thread_native_id ( ) ;
493+ let policy = ThreadSchedulePolicy :: Realtime ( RealtimeThreadSchedulePolicy :: Fifo ) ;
494+
495+ let priority = ThreadPriority :: from_posix ( ScheduleParams { sched_priority : 50 } ) ;
496+ if let Err ( e) =
497+ thread_priority:: set_thread_priority_and_policy ( current_thread_id, priority, policy)
498+ {
499+ tracing:: warn!(
500+ "Failed to set Data Thread to SCHED_FIFO at priority 50 (requires CAP_SYS_NICE): {:?}" ,
501+ e
502+ ) ;
503+ } else {
504+ tracing:: info!( "Data thread successfully elevated to SCHED_FIFO (Priority 50)" ) ;
505+ }
488506
489507 // attempt to get closer to SCHED_FIFO without CAP_SYS_ADMIN
490508 let slack_value = NonZero :: new ( 1 ) ;
0 commit comments