Skip to content

Commit 1a9e141

Browse files
committed
Refactor priority options. Fix incorrect priority setting.
1 parent e012972 commit 1a9e141

File tree

6 files changed

+43
-44
lines changed

6 files changed

+43
-44
lines changed

SerialPrograms/Source/CommonFramework/Environment/Environment_Windows.tpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ bool set_thread_priority(Logger& logger, ThreadPriority priority){
6767
default:
6868
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Invalid Priority: " + std::to_string((int)priority));
6969
}
70-
if (SetPriorityClass(GetCurrentProcess(), native_priority)){
70+
if (SetPriorityClass(GetCurrentThread(), native_priority)){
7171
// cout << "Thread priority set to: " + PRIORITY_DATABASE().find(priority)->display << endl;
7272
logger.log("Thread priority set to: " + PRIORITY_DATABASE().find(priority)->display, COLOR_BLUE);
7373
return true;

SerialPrograms/Source/CommonFramework/Options/Environment/PerformanceOptions.h

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,76 +24,73 @@ class PerformanceOptions : public GroupOption{
2424
LockMode::LOCK_WHILE_RUNNING,
2525
GroupOption::EnableMode::ALWAYS_ENABLED, true
2626
)
27-
, PRECISE_WAKE_MARGIN(
28-
"<b>Precise Wake Time Margin:</b><br>"
29-
"Some operations require a thread to wake up at a very precise time - "
30-
"more precise than what the operating system's scheduler can provide. "
31-
"This option will force such operations to wake up this many "
32-
"microseconds earlier, then busy wait until the time is reached. "
33-
"The sys-botbase controller is an example of something that requires "
34-
"extremely precise wake times.",
35-
LockMode::UNLOCK_WHILE_RUNNING,
36-
"2000 us"
37-
)
3827
, REALTIME_THREAD_PRIORITY(
3928
"<b>Realtime Thread Priority:</b><br>"
4029
"Thread priority of real-time threads. (UI thread, audio threads)<br>"
4130
"Restart the program for this to fully take effect.",
4231
DEFAULT_PRIORITY_REALTIME
4332
)
44-
, REALTIME_INFERENCE_PRIORITY(
45-
"<b>Inference Priority:</b><br>"
46-
"Thread priority of realtime inference threads that must run fast "
47-
"enough to keep a program working properly.",
33+
, INFERENCE_PIVOT_PRIORITY(
34+
"<b>Inference Pivot Priority:</b><br>"
35+
"Thread priority of inference dispatcher threads.",
4836
DEFAULT_PRIORITY_REALTIME_INFERENCE
4937
)
50-
, NORMAL_INFERENCE_PRIORITY(
51-
"<b>Normal Inference Priority:</b><br>"
52-
"Thread priority of non-realtime inference threads that can be slow "
53-
"without negatively affecting a program.",
54-
DEFAULT_PRIORITY_NORMAL_INFERENCE
55-
)
5638
, COMPUTE_PRIORITY(
5739
"<b>Compute Priority:</b><br>"
5840
"Thread priority of computation threads.",
5941
DEFAULT_PRIORITY_COMPUTE
6042
)
61-
, THREAD_POOL_REALTIME_INFERENCE(
62-
"Thread Pool: Real-time Inference",
43+
, REALTIME_THREAD_POOL(
44+
"Real-time Thread Pool",
45+
"Thread pool for tasks that must run fast enough to keep a "
46+
"program running properly.<br>"
47+
"Restart program for changes to take full effect.",
6348
DEFAULT_PRIORITY_REALTIME_INFERENCE,
6449
0.5
6550
)
66-
, THREAD_POOL_NORMAL_INFERENCE(
67-
"Thread Pool: Normal Inference",
51+
, NORMAL_THREAD_POOL(
52+
"Normal Thread Pool",
53+
"Thread pool for tasks that can be slow without negatively "
54+
"affecting a program.<br>"
55+
"Restart program for changes to take full effect.",
6856
DEFAULT_PRIORITY_NORMAL_INFERENCE,
6957
1.0
7058
)
59+
, PRECISE_WAKE_MARGIN(
60+
"<b>Precise Wake Time Margin:</b><br>"
61+
"Some operations require a thread to wake up at a very precise time - "
62+
"more precise than what the operating system's scheduler can provide. "
63+
"This option will force such operations to wake up this many "
64+
"microseconds earlier, then busy wait until the time is reached. "
65+
"The sys-botbase controller is an example of something that requires "
66+
"extremely precise wake times.",
67+
LockMode::UNLOCK_WHILE_RUNNING,
68+
"2000 us"
69+
)
7170
{
72-
PA_ADD_OPTION(PRECISE_WAKE_MARGIN);
71+
PA_ADD_OPTION(PROCESSOR_LEVEL);
7372

7473
PA_ADD_OPTION(REALTIME_THREAD_PRIORITY);
75-
PA_ADD_OPTION(REALTIME_INFERENCE_PRIORITY);
76-
PA_ADD_OPTION(NORMAL_INFERENCE_PRIORITY);
74+
PA_ADD_OPTION(INFERENCE_PIVOT_PRIORITY);
7775
PA_ADD_OPTION(COMPUTE_PRIORITY);
7876

79-
PA_ADD_OPTION(THREAD_POOL_REALTIME_INFERENCE);
80-
PA_ADD_OPTION(THREAD_POOL_NORMAL_INFERENCE);
77+
PA_ADD_OPTION(REALTIME_THREAD_POOL);
78+
PA_ADD_OPTION(NORMAL_THREAD_POOL);
8179

82-
PA_ADD_OPTION(PROCESSOR_LEVEL);
80+
PA_ADD_OPTION(PRECISE_WAKE_MARGIN);
8381
}
8482

8583
public:
86-
MicrosecondsOption PRECISE_WAKE_MARGIN;
84+
ProcessorLevelOption PROCESSOR_LEVEL;
8785

8886
ThreadPriorityOption REALTIME_THREAD_PRIORITY;
89-
ThreadPriorityOption REALTIME_INFERENCE_PRIORITY;
90-
ThreadPriorityOption NORMAL_INFERENCE_PRIORITY;
87+
ThreadPriorityOption INFERENCE_PIVOT_PRIORITY;
9188
ThreadPriorityOption COMPUTE_PRIORITY;
9289

93-
ThreadPoolOption THREAD_POOL_REALTIME_INFERENCE;
94-
ThreadPoolOption THREAD_POOL_NORMAL_INFERENCE;
90+
ThreadPoolOption REALTIME_THREAD_POOL;
91+
ThreadPoolOption NORMAL_THREAD_POOL;
9592

96-
ProcessorLevelOption PROCESSOR_LEVEL;
93+
MicrosecondsOption PRECISE_WAKE_MARGIN;
9794
};
9895

9996

SerialPrograms/Source/CommonFramework/Options/ThreadPoolOption.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace PokemonAutomation{
1212

1313
ThreadPoolOption::ThreadPoolOption(
1414
std::string label,
15+
std::string description,
1516
ThreadPriority default_priority,
1617
double default_max_thread_ratio
1718
)
@@ -32,7 +33,7 @@ ThreadPoolOption::ThreadPoolOption(
3233
LockMode::UNLOCK_WHILE_RUNNING,
3334
std::thread::hardware_concurrency()
3435
)
35-
, m_description("Restart program for changes to take full effect.")
36+
, m_description(std::move(description))
3637
, PRIORITY("<b>Thread Priority:</b>", default_priority)
3738
, MAX_THREADS(
3839
"<b>Maximum Threads:</b>",

SerialPrograms/Source/CommonFramework/Options/ThreadPoolOption.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ThreadPoolOption : public GroupOption{
1919
public:
2020
ThreadPoolOption(
2121
std::string label,
22+
std::string description,
2223
ThreadPriority default_priority,
2324
double default_max_thread_ratio = 1.0
2425
);

SerialPrograms/Source/CommonFramework/Tools/GlobalThreadPools.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ namespace GlobalThreadPools{
1717
ComputationThreadPool& realtime_inference(){
1818
static ComputationThreadPool runner(
1919
[](){
20-
GlobalSettings::instance().PERFORMANCE->THREAD_POOL_REALTIME_INFERENCE.PRIORITY.set_on_this_thread(global_logger_tagged());
20+
GlobalSettings::instance().PERFORMANCE->REALTIME_THREAD_POOL.PRIORITY.set_on_this_thread(global_logger_tagged());
2121
},
22-
0, GlobalSettings::instance().PERFORMANCE->THREAD_POOL_REALTIME_INFERENCE.MAX_THREADS
22+
0, GlobalSettings::instance().PERFORMANCE->REALTIME_THREAD_POOL.MAX_THREADS
2323
);
2424
return runner;
2525
}
2626
ComputationThreadPool& normal_inference(){
2727
static ComputationThreadPool runner(
2828
[](){
29-
GlobalSettings::instance().PERFORMANCE->THREAD_POOL_NORMAL_INFERENCE.PRIORITY.set_on_this_thread(global_logger_tagged());
29+
GlobalSettings::instance().PERFORMANCE->NORMAL_THREAD_POOL.PRIORITY.set_on_this_thread(global_logger_tagged());
3030
},
31-
0, GlobalSettings::instance().PERFORMANCE->THREAD_POOL_NORMAL_INFERENCE.MAX_THREADS
31+
0, GlobalSettings::instance().PERFORMANCE->NORMAL_THREAD_POOL.MAX_THREADS
3232
);
3333
return runner;
3434
}

SerialPrograms/Source/CommonFramework/Tools/ProgramEnvironment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct ProgramEnvironmentData{
3535
)
3636
, m_realtime_inference_dispatcher(
3737
[](){
38-
GlobalSettings::instance().PERFORMANCE->REALTIME_INFERENCE_PRIORITY.set_on_this_thread(global_logger_tagged());
38+
GlobalSettings::instance().PERFORMANCE->INFERENCE_PIVOT_PRIORITY.set_on_this_thread(global_logger_tagged());
3939
},
4040
0
4141
)

0 commit comments

Comments
 (0)