[Libnx] Toolchain related changes

-Remove switch_pthread - It should be no longer used
-Increase SAVE_STATE_CHUNK to 4MB
-Fix overclocking on Horizon 8.0+

Note: This requires the updated Toolchain before Merge
This commit is contained in:
M4xw 2019-04-26 21:58:40 +02:00
parent fce660de29
commit ca80a3a4da
11 changed files with 206 additions and 376 deletions

View File

@ -1,131 +1,155 @@
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}",
"${workspaceRoot}/libretro-common/include"
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}",
"${workspaceRoot}/libretro-common/include"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
]
},
{
"name": "Linux",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}",
"${workspaceFolder}/libretro-common/include",
"${workspaceRoot}/libretro-common/include"
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
]
},
{
"name": "Linux",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}",
"${workspaceFolder}/libretro-common/include",
"${workspaceRoot}/libretro-common/include"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "Win32",
"includePath": [
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/um",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/ucrt",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/shared",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/winrt",
"${workspaceRoot}",
"${workspaceFolder}/libretro-common/include"
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "Win32",
"includePath": [
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/um",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/ucrt",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/shared",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/winrt",
"${workspaceRoot}",
"${workspaceFolder}/libretro-common/include"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/um",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/ucrt",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/shared",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/winrt",
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++17"
},
{
"name": "msys2-mingw32",
"includePath": [
"C:/msys64/mingw32/include",
"C:/msys64/mingw32/i686-w64-mingw32/include",
"${workspaceRoot}/libretro-common/include",
"${workspaceRoot}/include",
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"C:/msys64/mingw32/include",
"C:/msys64/mingw32/i686-w64-mingw32/include",
"${workspaceRoot}/libretro-common/include",
"${workspaceRoot}/include",
"${workspaceRoot}"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/um",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/ucrt",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/shared",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/winrt",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++17"
},
{
"name": "msys2-mingw32",
"includePath": [
"C:/msys64/mingw32/include",
"C:/msys64/mingw32/i686-w64-mingw32/include",
"${workspaceRoot}/libretro-common/include",
"${workspaceRoot}/include",
"${workspaceRoot}"
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "msys2-mingw64",
"includePath": [
"C:/msys64/mingw64/include",
"C:/msys64/mingw64/x86_64-w64-mingw32/include",
"${workspaceRoot}/libretro-common/include",
"${workspaceRoot}/include",
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"C:/msys64/mingw64/include",
"C:/msys64/mingw64/x86_64-w64-mingw32/include",
"${workspaceRoot}/libretro-common/include",
"${workspaceRoot}/include",
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"C:/msys64/mingw32/include",
"C:/msys64/mingw32/i686-w64-mingw32/include",
"${workspaceRoot}/libretro-common/include",
"${workspaceRoot}/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "msys2-mingw64",
"includePath": [
"C:/msys64/mingw64/include",
"C:/msys64/mingw64/x86_64-w64-mingw32/include",
"${workspaceRoot}/libretro-common/include",
"${workspaceRoot}/include",
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"C:/msys64/mingw64/include",
"C:/msys64/mingw64/x86_64-w64-mingw32/include",
"${workspaceRoot}/libretro-common/include",
"${workspaceRoot}/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "Switch",
"includePath": [
"/opt/devkitpro/devkitA64/aarch64-none-elf/include",
"/opt/devkitpro/devkitA64/lib/gcc/aarch64-none-elf/8.3.0/include",
"/opt/devkitpro/libnx/include",
"/opt/devkitpro/portlibs/switch/include",
"/opt/devkitpro/portlibs/switch/include/freetype2",
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"__aarch64__",
"__SWITCH__",
"HAVE_LIBNX"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "/opt/devkitpro/devkitA64/bin/aarch64-none-elf-gcc",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}

View File

@ -902,9 +902,6 @@ ifeq ($(TARGET), retroarch_switch)
ifeq ($(HAVE_OPENGL), 1)
OBJ += gfx/drivers_context/switch_ctx.o
endif
ifeq ($(HAVE_THREADS), 1)
OBJ += $(LIBRETRO_COMM_DIR)/rthreads/switch_pthread.o
endif
else
OBJ += gfx/drivers/switch_gfx.o
endif

View File

@ -19,10 +19,7 @@ GRIFFIN_BUILD = 0
OBJ :=
# For threading we need to overwrite some vars with global defines because devkitPro's includes
# make it hard for us. This works for the pthread wrapper
DEFINES_THREAD := -Dpthread_t=Thread -Dpthread_mutex_t=Mutex -Dpthread_mutexattr_t='void*' -Dpthread_attr_t=int -Dpthread_cond_t=CondVar -Dpthread_condattr_t='int' -D_SYS__PTHREADTYPES_H_
DEFINES := -D__SWITCH__=1 -U__linux__ -U__linux -DGLM_FORCE_PURE=1 -DRARCH_CONSOLE -DRARCH_INTERNAL -DGLOBAL_CONFIG_DIR='"/switch"' $(DEFINES_THREAD) -DHAVE_STB_VORBIS
DEFINES := -D__SWITCH__=1 -U__linux__ -U__linux -DGLM_FORCE_PURE=1 -DRARCH_CONSOLE -DRARCH_INTERNAL -DGLOBAL_CONFIG_DIR='"/switch"' -DHAVE_STB_VORBIS
HAVE_CC_RESAMPLER = 1
HAVE_MENU_COMMON = 1
@ -121,16 +118,12 @@ ifeq ($(strip $(HAVE_STATIC_DUMMY)),1)
CFLAGS += -DHAVE_STATIC_DUMMY=1
endif
# The following line works around an issue in newlib that produces a compilation
# error in glm. It will be removed as soon as this issue is resolved.
CFLAGS += -D_GLIBCXX_USE_C99_MATH_TR1 -D_LDBL_EQ_DBL
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs $(ARCH) -Wl,--allow-multiple-definition -Wl,-Map,$(notdir $*.map)
LIBS := -lstdc++ -lbz2 -lpng -lz -lnx -lm
LIBS := -lswresample -lavformat -lavcodec -lavutil -lswscale -lstdc++ -lbz2 -lpng -lz -lnx -lm
ifeq ($(HAVE_OPENGL), 1)
LIBS := -lEGL -lglapi -ldrm_nouveau $(LIBS)

View File

@ -75,8 +75,16 @@ extern bool nxlink_connected;
void libnx_apply_overclock() {
const size_t profiles_count = sizeof(SWITCH_CPU_PROFILES) / sizeof(SWITCH_CPU_PROFILES[1]);
if (config_get_ptr()->uints.libnx_overclock >= 0 && config_get_ptr()->uints.libnx_overclock <= profiles_count)
pcvSetClockRate(PcvModule_Cpu, SWITCH_CPU_SPEEDS_VALUES[config_get_ptr()->uints.libnx_overclock]);
if (config_get_ptr()->uints.libnx_overclock >= 0 && config_get_ptr()->uints.libnx_overclock <= profiles_count){
if(hosversionBefore(8, 0, 0)) {
pcvSetClockRate(PcvModule_CpuBus, SWITCH_CPU_SPEEDS_VALUES[config_get_ptr()->uints.libnx_overclock]);
} else {
ClkrstSession session = {0};
clkrstOpenSession(&session, PcvModuleId_CpuBus, 3);
clkrstSetClockRate(&session, SWITCH_CPU_SPEEDS_VALUES[config_get_ptr()->uints.libnx_overclock]);
clkrstCloseSession(&session);
}
}
}
static void on_applet_hook(AppletHookType hook, void *param) {
@ -97,7 +105,14 @@ static void on_applet_hook(AppletHookType hook, void *param) {
RARCH_LOG("Got AppletHook OnFocusState - new focus state is %d\n", focus_state);
platform_switch_has_focus = focus_state == AppletFocusState_Focused;
if(!platform_switch_has_focus) {
pcvSetClockRate(PcvModule_Cpu, 1020000000);
if(hosversionBefore(8, 0, 0)) {
pcvSetClockRate(PcvModule_CpuBus, 1020000000);
} else {
ClkrstSession session = {0};
clkrstOpenSession(&session, PcvModuleId_CpuBus, 3);
clkrstSetClockRate(&session, 1020000000);
clkrstCloseSession(&session);
}
} else {
libnx_apply_overclock();
}
@ -245,8 +260,18 @@ static void frontend_switch_deinit(void *data)
#ifdef HAVE_LIBNX
nifmExit();
pcvSetClockRate(PcvModule_Cpu, 1020000000); // Always 1020 MHz, unless SDEV
pcvExit();
if(hosversionBefore(8, 0, 0)) {
pcvSetClockRate(PcvModule_CpuBus, 1020000000);
pcvExit();
} else {
ClkrstSession session = {0};
clkrstOpenSession(&session, PcvModuleId_CpuBus, 3);
clkrstSetClockRate(&session, 1020000000);
clkrstCloseSession(&session);
clkrstExit();
}
#if defined(SWITCH) && defined(NXLINK)
socketExit();
#endif
@ -669,7 +694,12 @@ static void frontend_switch_init(void *data)
#ifdef HAVE_LIBNX
nifmInitialize();
pcvInitialize();
if(hosversionBefore(8, 0, 0)) {
pcvInitialize();
} else {
clkrstInitialize();
}
appletLockExit();
appletHook(&applet_hook_cookie, on_applet_hook, NULL);

View File

@ -48,8 +48,6 @@
#endif
#elif defined(GEKKO)
#include "gx_pthread.h"
#elif defined(HAVE_LIBNX)
#include "switch_pthread.h"
#elif defined(_3DS)
#include "ctr_pthread.h"
#elif defined(__CELLOS_LV2__)

View File

@ -1,60 +0,0 @@
/* Copyright (C) 2018 - M4xw <m4x@m4xw.net>, RetroArch Team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (switch_pthread.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "switch_pthread.h"
#define STACKSIZE 1000000 * 12 // 12 MB
static uint32_t threadCounter = 1;
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
{
u32 prio = 0;
Thread new_switch_thread;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
// Launch threads on Core 1
int rc = threadCreate(&new_switch_thread, (void (*)(void *))start_routine, arg, STACKSIZE, prio - 1, 1);
if (R_FAILED(rc))
{
return EAGAIN;
}
printf("[Threading]: Starting Thread(#%i)\n", threadCounter);
if (R_FAILED(threadStart(&new_switch_thread)))
{
threadClose(&new_switch_thread);
return -1;
}
*thread = new_switch_thread;
return 0;
}
void pthread_exit(void *retval)
{
(void)retval;
printf("[Threading]: Exiting Thread\n");
svcExitThread();
}

View File

@ -1,168 +0,0 @@
/* Copyright (C) 2018 - M4xw <m4x@m4xw.net>, RetroArch Team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (switch_pthread.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _SWITCH_PTHREAD_WRAP_
#define _SWITCH_PTHREAD_WRAP_
#include <time.h>
#include <stdio.h>
#include <switch.h>
#include <errno.h>
#include <retro_inline.h>
#define THREADVARS_MAGIC 0x21545624 /* !TV$ */
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg);
void pthread_exit(void *retval);
/* This structure is exactly 0x20 bytes, if more is needed modify getThreadVars() below */
typedef struct
{
/* Magic value used to check if the struct is initialized */
u32 magic;
/* Thread handle, for mutexes */
Handle handle;
/* Pointer to the current thread (if exists) */
Thread *thread_ptr;
/* Pointer to this thread's newlib state */
struct _reent *reent;
/* Pointer to this thread's thread-local segment */
void *tls_tp; /* !! Offset needs to be TLS+0x1F8 for __aarch64_read_tp !! */
} ThreadVars;
static INLINE ThreadVars *getThreadVars(void)
{
return (ThreadVars *)((u8 *)armGetTls() + 0x1E0);
}
static INLINE Thread threadGetCurrent(void)
{
ThreadVars *tv = getThreadVars();
return *tv->thread_ptr;
}
static INLINE pthread_t pthread_self(void)
{
return threadGetCurrent();
}
static INLINE int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
{
mutexInit(mutex);
return 0;
}
static INLINE int pthread_mutex_destroy(pthread_mutex_t *mutex)
{
/* Nothing */
*mutex = 0;
return 0;
}
static INLINE int pthread_mutex_lock(pthread_mutex_t *mutex)
{
mutexLock(mutex);
return 0;
}
static INLINE int pthread_mutex_unlock(pthread_mutex_t *mutex)
{
mutexUnlock(mutex);
return 0;
}
INLINE int pthread_detach(pthread_t thread)
{
(void)thread;
/* Nothing for now */
return 0;
}
static INLINE int pthread_join(pthread_t thread, void **retval)
{
printf("[Threading]: Waiting for Thread Exit\n");
threadWaitForExit(&thread);
threadClose(&thread);
return 0;
}
static INLINE int pthread_mutex_trylock(pthread_mutex_t *mutex)
{
return mutexTryLock(mutex) ? 0 : 1;
}
static INLINE int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{
condvarWait(cond, mutex);
return 0;
}
static INLINE int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)
{
condvarWaitTimeout(cond, mutex, abstime->tv_nsec);
return 0;
}
static INLINE int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
{
condvarInit(cond);
return 0;
}
static INLINE int pthread_cond_signal(pthread_cond_t *cond)
{
condvarWakeOne(cond);
return 0;
}
static INLINE int pthread_cond_broadcast(pthread_cond_t *cond)
{
condvarWakeAll(cond);
return 0;
}
INLINE int pthread_cond_destroy(pthread_cond_t *cond)
{
/* Nothing */
return 0;
}
INLINE int pthread_equal(pthread_t t1, pthread_t t2)
{
if (t1.handle == t2.handle)
return 1;
return 0;
}
#endif

View File

@ -2740,7 +2740,14 @@ static int action_ok_set_switch_cpu_profile(const char *path,
config_get_ptr()->uints.libnx_overclock = entry_idx;
unsigned profile_clock = SWITCH_CPU_SPEEDS_VALUES[entry_idx];
pcvSetClockRate(PcvModule_Cpu, (u32)profile_clock);
if(hosversionBefore(8, 0, 0)) {
pcvSetClockRate(PcvModule_CpuBus, (u32)profile_clock);
} else {
ClkrstSession session = {0};
clkrstOpenSession(&session, PcvModuleId_CpuBus, 3);
clkrstSetClockRate(&session, profile_clock);
clkrstCloseSession(&session);
}
snprintf(command, sizeof(command), "Current Clock set to %i", profile_clock);
#endif

View File

@ -4349,7 +4349,14 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
snprintf(text, sizeof(text), "Current profile : %s", current_profile);
#else
u32 currentClock = 0;
pcvGetClockRate(PcvModule_Cpu, &currentClock);
if(hosversionBefore(8, 0, 0)) {
pcvGetClockRate(PcvModule_CpuBus, &currentClock);
} else {
ClkrstSession session = {0};
clkrstOpenSession(&session, PcvModuleId_CpuBus, 3);
clkrstGetClockRate(&session, &currentClock);
clkrstCloseSession(&session);
}
snprintf(text, sizeof(text), "Current Clock : %i", currentClock);
#endif
menu_entries_append_enum(info->list,

View File

@ -108,8 +108,6 @@ bool menu_input_dialog_get_display_kb(void)
SwkbdConfig kbd;
pcvSetClockRate(PcvModule_Cpu, SWITCH_CPU_SPEEDS_VALUES[SWITCH_DEFAULT_CPU_PROFILE]);
Result rc = swkbdCreate(&kbd, 0);
if (R_SUCCEEDED(rc))

View File

@ -55,7 +55,11 @@
#include "tasks_internal.h"
#include "../managers/cheat_manager.h"
#ifdef HAVE_LIBNX
#define SAVE_STATE_CHUNK 4096 * 10
#else
#define SAVE_STATE_CHUNK 4096
#endif
static bool save_state_in_background = false;
static struct string_list *task_save_files = NULL;