mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-26 20:15:03 +00:00
SCHED_ULE and SCHED_4BSD
This commit is contained in:
parent
49132b3564
commit
d1a5e8c990
@ -57,29 +57,51 @@ void pthreadInitSelfMainThread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI scePthreadAttrInit(ScePthreadAttr* attr) {
|
int PS4_SYSV_ABI scePthreadAttrInit(ScePthreadAttr* attr) {
|
||||||
|
if (attr == nullptr) {
|
||||||
|
return SCE_KERNEL_ERROR_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
*attr = new PthreadAttrInternal{};
|
*attr = new PthreadAttrInternal{};
|
||||||
|
|
||||||
int result = pthread_attr_init(&(*attr)->pth_attr);
|
int result = pthread_attr_init(&(*attr)->pth_attr);
|
||||||
|
|
||||||
|
if (result != 0) {
|
||||||
|
delete *attr;
|
||||||
|
*attr = nullptr;
|
||||||
|
return SCE_KERNEL_ERROR_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
(*attr)->affinity = 0x7f;
|
(*attr)->affinity = 0x7f;
|
||||||
(*attr)->guard_size = 0x1000;
|
(*attr)->guard_size = 0x1000;
|
||||||
|
|
||||||
|
result = scePthreadAttrSetinheritsched(attr, PTHREAD_EXPLICIT_SCHED);
|
||||||
|
|
||||||
|
if (result != SCE_OK) {
|
||||||
|
delete *attr;
|
||||||
|
*attr = nullptr;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
SceKernelSchedParam param{};
|
SceKernelSchedParam param{};
|
||||||
param.sched_priority = 700;
|
param.sched_priority = 700;
|
||||||
|
|
||||||
result = (result == 0 ? scePthreadAttrSetinheritsched(attr, 4) : result);
|
result = scePthreadAttrSetschedparam(attr, ¶m);
|
||||||
result = (result == 0 ? scePthreadAttrSetschedparam(attr, ¶m) : result);
|
|
||||||
result = (result == 0 ? scePthreadAttrSetschedpolicy(attr, SCHED_OTHER) : result);
|
|
||||||
result = (result == 0 ? scePthreadAttrSetdetachstate(attr, PTHREAD_CREATE_JOINABLE) : result);
|
|
||||||
|
|
||||||
switch (result) {
|
if (result != SCE_OK) {
|
||||||
case 0:
|
delete *attr;
|
||||||
return SCE_OK;
|
*attr = nullptr;
|
||||||
case ENOMEM:
|
return result;
|
||||||
return SCE_KERNEL_ERROR_ENOMEM;
|
|
||||||
default:
|
|
||||||
return SCE_KERNEL_ERROR_EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = scePthreadAttrSetdetachstate(attr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
|
||||||
|
if (result != SCE_OK) {
|
||||||
|
delete *attr;
|
||||||
|
*attr = nullptr;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SCE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI scePthreadAttrDestroy(ScePthreadAttr* attr) {
|
int PS4_SYSV_ABI scePthreadAttrDestroy(ScePthreadAttr* attr) {
|
||||||
@ -231,19 +253,26 @@ int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr,
|
|||||||
return SCE_KERNEL_ERROR_EINVAL;
|
return SCE_KERNEL_ERROR_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SceKernelSchedParam pparam{};
|
struct sched_param sched_param;
|
||||||
if (param->sched_priority <= 478) {
|
sched_param.sched_priority = param->sched_priority;
|
||||||
pparam.sched_priority = +2;
|
|
||||||
} else if (param->sched_priority >= 733) {
|
int result;
|
||||||
pparam.sched_priority = -2;
|
switch ((*attr)->policy) {
|
||||||
} else {
|
case SCHED_OTHER:
|
||||||
pparam.sched_priority = 0;
|
sched_param.sched_priority = 700;
|
||||||
|
break;
|
||||||
|
case SCHED_FIFO:
|
||||||
|
case SCHED_RR:
|
||||||
|
case SCHED_ULE:
|
||||||
|
case SCHED_4BSD:
|
||||||
|
result = pthread_attr_setschedparam(&(*attr)->pth_attr, &sched_param);
|
||||||
|
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||||
|
default:
|
||||||
|
LOG_ERROR(Kernel_Pthread, "policy={} not supported by winpthreads", (*attr)->policy);
|
||||||
|
return SCE_KERNEL_ERROR_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We always use SCHED_OTHER for now, so don't call this for now.
|
return SCE_OK;
|
||||||
// int result = pthread_attr_setschedparam(&(*attr)->pth_attr, &pparam);
|
|
||||||
int result = 0;
|
|
||||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI scePthreadAttrGetschedpolicy(const ScePthreadAttr* attr, int* policy) {
|
int PS4_SYSV_ABI scePthreadAttrGetschedpolicy(const ScePthreadAttr* attr, int* policy) {
|
||||||
@ -255,19 +284,16 @@ int PS4_SYSV_ABI scePthreadAttrGetschedpolicy(const ScePthreadAttr* attr, int* p
|
|||||||
|
|
||||||
switch (*policy) {
|
switch (*policy) {
|
||||||
case SCHED_OTHER:
|
case SCHED_OTHER:
|
||||||
*policy = (*attr)->policy;
|
|
||||||
break;
|
|
||||||
case SCHED_FIFO:
|
case SCHED_FIFO:
|
||||||
*policy = 1;
|
|
||||||
break;
|
|
||||||
case SCHED_RR:
|
case SCHED_RR:
|
||||||
*policy = 3;
|
case SCHED_ULE:
|
||||||
break;
|
case SCHED_4BSD:
|
||||||
|
return SCE_OK;
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
LOG_ERROR(Kernel_Pthread, "Unknown policy={} returned by pthread_attr_getschedpolicy",
|
||||||
|
*policy);
|
||||||
|
return SCE_KERNEL_ERROR_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) {
|
int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) {
|
||||||
@ -280,6 +306,8 @@ int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy)
|
|||||||
case SCHED_OTHER:
|
case SCHED_OTHER:
|
||||||
case SCHED_FIFO:
|
case SCHED_FIFO:
|
||||||
case SCHED_RR:
|
case SCHED_RR:
|
||||||
|
case SCHED_ULE:
|
||||||
|
case SCHED_4BSD:
|
||||||
ppolicy = policy;
|
ppolicy = policy;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user