DiskCache: make Writer thread low-priority

This commit is contained in:
Pierre-Loup A. Griffais committed 2026-08-23 14:01:32 -07:00
1 parent af9b438eec
commit c3fb6ccaaa
7 files changed
+39 -17

No files matched your search

@@ -6,6 +6,8 @@
#include <FEXCore/Utils/Allocator.h>
#include <FEXCore/Utils/LongJump.h>
#include <FEXCore/Utils/Threads.h>
#include <FEXHeaderUtils/Syscalls.h>
#include <sys/resource.h>
namespace FEX::LinuxEmulation::Threads {
void* StackTracker::AllocateStackObject() {
@@ -195,10 +197,11 @@ namespace PThreads {
class PThread final : public FEXCore::Threads::Thread {
public:
PThread(StackTracker* STracker, FEXCore::Threads::ThreadFunc Func, void* Arg)
PThread(StackTracker* STracker, FEXCore::Threads::ThreadFunc Func, void* Arg, bool LowPriority)
: STracker {STracker}
, UserFunc {Func}
, UserArg {Arg} {
, UserArg {Arg}
, LowPriority {LowPriority} {
pthread_attr_t Attr {};
Stack = STracker->AllocateStackObject();
// pthreads allocates its dtv region behind our back and there is nothing we can do about it.
@@ -257,6 +260,10 @@ namespace PThreads {
return Stack;
}
bool GetLowPriority() const {
return LowPriority;
}
StackTracker* GetStackTracker() const {
return STracker;
}
@@ -287,6 +294,7 @@ namespace PThreads {
FEXCore::Threads::ThreadFunc UserFunc;
void* UserArg;
void* Stack {};
bool LowPriority {};
// Use FEXCore's UncheckedLongJump to avoid fortification checks.
// This avoids a false positive since glibc does not understand stack pivots.
@@ -305,6 +313,10 @@ namespace PThreads {
bool LongJumpExit {};
if (Thread->GetLowPriority()) {
setpriority(PRIO_PROCESS, FHU::Syscalls::gettid(), 19);
}
if (FEXCore::UncheckedLongJump::SetJump(exit_resolver) == 0) {
Thread->SetupLongJump(&exit_resolver);
// Run the user function.
@@ -354,8 +366,8 @@ namespace PThreads {
static StackTracker* STracker {};
static fextl::unique_ptr<FEXCore::Threads::Thread> CreateThread_PThread(FEXCore::Threads::ThreadFunc Func, void* Arg) {
return fextl::make_unique<PThread>(STracker, Func, Arg);
static fextl::unique_ptr<FEXCore::Threads::Thread> CreateThread_PThread(FEXCore::Threads::ThreadFunc Func, void* Arg, bool LowPriority) {
return fextl::make_unique<PThread>(STracker, Func, Arg, LowPriority);
}
static void CleanupAfterFork_PThread() {