mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 10:56:58 +02:00
kernel: block short sleep requests instead of busy waiting
This commit is contained in:
+1
-30
@@ -512,15 +512,6 @@ static void SchedulerBackoffOnce() {
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool SleepMicroSchedulerBackoff(uint64_t microseconds) {
|
||||
if (microseconds > 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SchedulerBackoffOnce();
|
||||
return true;
|
||||
}
|
||||
|
||||
static void SleepMicroWithSignalPoll(uint64_t microseconds) {
|
||||
if (microseconds == 0) {
|
||||
KernelDispatchPendingSignalForCurrentThread();
|
||||
@@ -529,9 +520,7 @@ static void SleepMicroWithSignalPoll(uint64_t microseconds) {
|
||||
|
||||
while (microseconds > 0) {
|
||||
const auto step = std::min<uint64_t>(microseconds, SIGNAL_APC_POLL_MICROS);
|
||||
if (!SleepMicroSchedulerBackoff(step)) {
|
||||
Common::Thread::SleepMicro(step);
|
||||
}
|
||||
Common::Thread::SleepMicro(step);
|
||||
microseconds -= step;
|
||||
KernelDispatchPendingSignalForCurrentThread();
|
||||
}
|
||||
@@ -3842,28 +3831,16 @@ void KYTY_SYSV_ABI KernelSetThreadDtors(thread_dtors_func_t dtors) {
|
||||
}
|
||||
|
||||
int KYTY_SYSV_ABI KernelUsleep(KernelUseconds microseconds) {
|
||||
Common::Timer t;
|
||||
t.Start();
|
||||
SleepMicroWithSignalPoll(microseconds);
|
||||
// double ts = t.GetTimeS();
|
||||
// LOGF("\tactual: %g microseconds\n", ts * 1000000.0);
|
||||
return OK;
|
||||
}
|
||||
|
||||
unsigned int KYTY_SYSV_ABI KernelSleep(unsigned int seconds) {
|
||||
PRINT_NAME();
|
||||
LOGF("\tsleep: %u\n", seconds);
|
||||
Common::Timer t;
|
||||
t.Start();
|
||||
SleepMicroWithSignalPoll(static_cast<uint64_t>(seconds) * 1000000ull);
|
||||
double ts = t.GetTimeS();
|
||||
LOGF("\tactual: %g seconds\n", ts);
|
||||
return OK;
|
||||
}
|
||||
|
||||
int KYTY_SYSV_ABI KernelNanosleep(const KernelTimespec* rqtp, KernelTimespec* rmtp) {
|
||||
PRINT_NAME();
|
||||
|
||||
if (rqtp == nullptr) {
|
||||
return KERNEL_ERROR_EFAULT;
|
||||
}
|
||||
@@ -3880,13 +3857,7 @@ int KYTY_SYSV_ABI KernelNanosleep(const KernelTimespec* rqtp, KernelTimespec* rm
|
||||
uint64_t nanos =
|
||||
static_cast<uint64_t>(rqtp->tv_sec) * 1000000000ull + static_cast<uint64_t>(rqtp->tv_nsec);
|
||||
|
||||
LOGF("\tnanosleep: %" PRIu64 "\n", nanos);
|
||||
|
||||
Common::Timer t;
|
||||
t.Start();
|
||||
SleepNanoWithSignalPoll(nanos);
|
||||
double ts = t.GetTimeS();
|
||||
LOGF("\tactual: %g nanoseconds\n", ts * 1000000000.0);
|
||||
|
||||
if (rmtp != nullptr) {
|
||||
rmtp->tv_sec = 0;
|
||||
|
||||
Reference in New Issue
Block a user