mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #801 from Raghav314/feat/kernel-get-available-cpumask
feat(libkernel): implement sceKernelGetAvailableCpumask
This commit is contained in:
@@ -264,6 +264,16 @@ if(BUILD_TESTING)
|
||||
set_tests_properties(guest_sync_on_address PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
|
||||
endif()
|
||||
add_test_executable(guest_available_cpumask_tests ${LIBS_INCLUDE_DIR}/tests/GuestAvailableCpumask.cpp)
|
||||
target_include_directories(guest_available_cpumask_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_available_cpumask_tests PRIVATE libkernel libc)
|
||||
configure_windows_unwind(guest_available_cpumask_tests)
|
||||
add_test(NAME guest_available_cpumask COMMAND guest_available_cpumask_tests)
|
||||
set_tests_properties(guest_available_cpumask PROPERTIES TIMEOUT 20)
|
||||
if(WIN32)
|
||||
set_tests_properties(guest_available_cpumask PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
|
||||
endif()
|
||||
add_test_executable(guest_kernel_error_tests ${LIBS_INCLUDE_DIR}/tests/GuestKernelErrors.cpp)
|
||||
target_include_directories(guest_kernel_error_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_kernel_error_tests PRIVATE libkernel libc)
|
||||
|
||||
@@ -379,6 +379,10 @@ int APS5_VABI scePthreadEqual(Pthread thread1, Pthread thread2) {
|
||||
return thread1 == thread2 ? 1 : 0;
|
||||
}
|
||||
|
||||
KernelCpumask APS5_VABI sceKernelGetAvailableCpumask(void) {
|
||||
return DEFAULT_THREAD_AFFINITY;
|
||||
}
|
||||
|
||||
int APS5_VABI scePthreadGetaffinity(Pthread thread, KernelCpumask* mask) {
|
||||
if (!thread || !mask) return SCE_KERNEL_ERROR_EINVAL;
|
||||
*mask = thread->affinity.load(std::memory_order_relaxed);
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#include "SceTypes.hpp"
|
||||
#include <cstdlib>
|
||||
#include <future>
|
||||
|
||||
extern "C" {
|
||||
KernelCpumask APS5_VABI sceKernelGetAvailableCpumask(void);
|
||||
int APS5_VABI scePthreadCreate(Pthread* thread, const PthreadAttr* attr, PthreadEntry entry, void* arg, const char* name);
|
||||
int APS5_VABI scePthreadJoin(Pthread thread, void** retval);
|
||||
int APS5_VABI scePthreadGetaffinity(Pthread thread, KernelCpumask* mask);
|
||||
int APS5_VABI scePthreadSetaffinity(Pthread thread, KernelCpumask mask);
|
||||
int APS5_VABI scePthreadAttrInit(PthreadAttr* attr);
|
||||
int APS5_VABI scePthreadAttrDestroy(PthreadAttr* attr);
|
||||
int APS5_VABI scePthreadAttrGetaffinity(const PthreadAttr* attr, KernelCpumask* mask);
|
||||
}
|
||||
|
||||
static constexpr int SCE_OK = 0;
|
||||
static constexpr int PS5_LOGICAL_CPUS = 16;
|
||||
|
||||
static void Require(bool value) { if (!value) std::abort(); }
|
||||
|
||||
static void* APS5_VABI Worker(void* arg) {
|
||||
static_cast<std::future<void>*>(arg)->get();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void* APS5_VABI ReportMask(void* arg) {
|
||||
*static_cast<KernelCpumask*>(arg) = sceKernelGetAvailableCpumask();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main() {
|
||||
const KernelCpumask available = sceKernelGetAvailableCpumask();
|
||||
Require(available != 0);
|
||||
Require((available >> PS5_LOGICAL_CPUS) == 0);
|
||||
Require(sceKernelGetAvailableCpumask() == available);
|
||||
|
||||
PthreadAttr attr = nullptr;
|
||||
Require(scePthreadAttrInit(&attr) == SCE_OK);
|
||||
KernelCpumask defaultAffinity = 0;
|
||||
Require(scePthreadAttrGetaffinity(&attr, &defaultAffinity) == SCE_OK);
|
||||
Require(defaultAffinity == available);
|
||||
|
||||
std::promise<void> release;
|
||||
auto released = release.get_future();
|
||||
Pthread thread = nullptr;
|
||||
Require(scePthreadCreate(&thread, &attr, Worker, &released, nullptr) == SCE_OK);
|
||||
KernelCpumask threadAffinity = 0;
|
||||
Require(scePthreadGetaffinity(thread, &threadAffinity) == SCE_OK);
|
||||
Require(threadAffinity == available);
|
||||
|
||||
for (KernelCpumask cpu = 1; cpu != 0; cpu <<= 1) {
|
||||
if ((available & cpu) == 0) continue;
|
||||
Require(scePthreadSetaffinity(thread, cpu) == SCE_OK);
|
||||
Require(scePthreadGetaffinity(thread, &threadAffinity) == SCE_OK);
|
||||
Require(threadAffinity == cpu);
|
||||
}
|
||||
release.set_value();
|
||||
Require(scePthreadJoin(thread, nullptr) == SCE_OK);
|
||||
|
||||
KernelCpumask fromThread = 0;
|
||||
Require(scePthreadCreate(&thread, &attr, ReportMask, &fromThread, nullptr) == SCE_OK);
|
||||
Require(scePthreadJoin(thread, nullptr) == SCE_OK);
|
||||
Require(fromThread == available);
|
||||
Require(scePthreadAttrDestroy(&attr) == SCE_OK);
|
||||
}
|
||||
@@ -65,6 +65,7 @@ Throughout the project, every function at every stage either **does exactly what
|
||||
- [sceKernelInternalMemoryGetModuleSegmentInfo](../../core/libs/prx/libkernel/Module/src/Module.cpp) (libkernel) - unknown signature
|
||||
- [sceKernelSyncOnAddressWait](../../core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp) (libkernel) - the only known caller passes a null timeout and a name string as the fourth argument; the timeout is assumed to point to microseconds like the other kernel waits, and the name is ignored
|
||||
- [sceKernelSyncOnAddressWait8 / sceKernelSyncOnAddressWait16 / sceKernelSyncOnAddressWait32 / sceKernelSyncOnAddressWait64](../../core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp) (libkernel) - libc's `__std_atomic_wait_direct_8/16/32/64` pass a microsecond timeout or null and ignore the result; the by-value comparand, return values and the 2- and 8-byte alignment of Wait16 and Wait64 are assumed
|
||||
- [sceKernelGetAvailableCpumask](../../core/libs/prx/libkernel/Pthread/src/Thread.cpp) (libkernel) - returns the default thread affinity, 0x1FFF (CPUs 0 to 12), as KytyPS5 does. Titles pin threads within it (PPSA02664 passes 0x1FFB, Hades II PPSA36082 0x3 and 0x3F); whether CPU 13 is available to a title is not confirmed
|
||||
- [sceKernelMapNamedFlexibleMemoryInternal](../../core/libs/prx/libkernel/DirectMemory/Export.cpp) (libkernel) - flag 0x8000 unknown; only the sceKernelMapNamedFlexibleMemory flags are accepted
|
||||
- [Guest arena](../../core/libs/prx/libc/src/GuestArena.cpp) (libc) - the application map area is assumed to end at 0xFC_0000_0000, as `SCE_KERNEL_APP_MAP_AREA_END_ADDR` does on the PS4. On Windows, host allocations made in the arena before libc loads stay, and a fixed guest mapping over one throws
|
||||
- [sceLibcInternalBacktraceForGame](../../core/libs/prx/libc/src/HeapDiagnostics.cpp) (libSceLibcInternal, implemented in libc) - unknown signature
|
||||
|
||||
Reference in New Issue
Block a user