mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[hal] Set HAL Notifier thread as RT by default (#3482)
This PR gives the Notifier HAL thread RT priority 40 in RobotBase after HAL initialization and before the user code is run. This drastically improves scheduling jitter for TimedRobot's AddPeriodic() functions (in 3512's experience). It's too risky to set user code as RT because badly behaved code will lock up the Rio (potentially requiring safe mode to recover). This needs the user program to be setuid admin to succeed.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import java.util.logging.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
/** Tests to see if the thread and process priority functions work. */
|
||||
public class PriorityTest extends AbstractComsSetup {
|
||||
private static final Logger logger = Logger.getLogger(PriorityTest.class.getName());
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCurrentThreadPriority() {
|
||||
// Non-RT thread has priority of zero
|
||||
assertEquals(0, Threads.getCurrentThreadPriority());
|
||||
assertFalse(Threads.getCurrentThreadIsRealTime());
|
||||
|
||||
// Set thread priority to 15
|
||||
assertTrue(Threads.setCurrentThreadPriority(true, 15));
|
||||
|
||||
// Verify thread was given priority 15
|
||||
assertEquals(15, Threads.getCurrentThreadPriority());
|
||||
assertTrue(Threads.getCurrentThreadIsRealTime());
|
||||
|
||||
// Set thread back to non-RT
|
||||
assertTrue(Threads.setCurrentThreadPriority(false, 0));
|
||||
|
||||
// Verify thread is now non-RT
|
||||
assertEquals(0, Threads.getCurrentThreadPriority());
|
||||
assertFalse(Threads.getCurrentThreadIsRealTime());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user