From 1896ca0e90fed53d900143d333a090b7272e29d8 Mon Sep 17 00:00:00 2001 From: Boris Gjenero Date: Tue, 6 Dec 2022 10:51:43 -0500 Subject: [PATCH] Only apply Asyncify to functions that really need it This creates asyncify.txt from emterpretify.txt, with functions in the different format needed by ASYNCIFY_ONLY. It leads to a bunch of these warnings, because some functions get inlined: warning: Asyncify onlylist contained a non-matching pattern: That is okay and apparently unavoidable. The important thing is that no such warnings occur when the final link is done using -O0. ASYNCIFY_ADVISE has shown that a lot more would be processed by Asyncify without this. The performance penalty isn't too bad, and is much better than the Emterpreter. Maybe more extensive use of Asyncify could make more things work, but taking advantage of that would require code changes. --- src/Makefile.am | 3 ++- src/asyncify.txt | 48 +++++++++++++++++++++++++++++++++++++++++++++ src/gui/sdlmain.cpp | 9 +++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/asyncify.txt diff --git a/src/Makefile.am b/src/Makefile.am index 6f1dcd5c3..673b8ed50 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,7 +28,8 @@ else # It is only required when using emterpreter. dosbox_LDFLAGS+=--memory-init-file 0 if ASYNCIFY -dosbox_LDFLAGS+=-s ASYNCIFY=1 -s FETCH=1 +dosbox_LDFLAGS+=-s ASYNCIFY=1 -s FETCH=1 -s ASYNCIFY_ONLY=@asyncify.txt +EXTRA_dosbox_DEPENDENCIES=asyncify.txt endif endif if WEBASSEMBLY diff --git a/src/asyncify.txt b/src/asyncify.txt new file mode 100644 index 000000000..7b797edcd --- /dev/null +++ b/src/asyncify.txt @@ -0,0 +1,48 @@ +[ +"main", +"SHELL_Init()", +"DOS_ReadFile(unsigned short, unsigned char*, unsigned short*, bool)", +"DOSBOX_RunMachine()", +"CALLBACK_RunRealInt(unsigned char)", +"CALLBACK_RunRealFar(unsigned short, unsigned short)", +"CALLBACK_Idle()", +"Normal_Loop()", +"DOS_21Handler()", +"PROGRAMS_Handler()", +"device_CON::Read(unsigned char*, unsigned short*)", +"device_CON::device_CON()", +"DOS_Device::Read(unsigned char*, unsigned short*)", +"MEM::Run()", +"INTRO::Run()", +"BOOT::Run()", +"Config::StartUp()", +"Config::Init()", +"Section::ExecuteInit(bool)", +"GUI_StartUp(Section*)", +"DOS_Shell::InputCommand(char*)", +"DOS_Shell::Run()", +"DOS_Shell::Execute(char*, char*)", +"DOS_Shell::DoCommand(char*)", +"DOS_Shell::ParseLine(char*)", +"DOS_Shell::CMD_HELP(char*)", +"DOS_Shell::CMD_PAUSE(char*)", +"DOS_Shell::CMD_CHOICE(char*)", +"DOS_Shell::CMD_DIR(char*)", +"DOS_Shell::CMD_TIME(char*)", +"DOS_Shell::CMD_CLS(char*)", +"DOS_Shell::CMD_DATE(char*)", +"DOS_Shell::CMD_COPY(char*)", +"Reboot_Handler()", +"DOS_LoadKeyboardLayout(char const*, int, char const*)", +"DOS_KeyboardLayout_Init(Section*)", +"DOS_SwitchKeyboardLayout(char const*, int&)", +"keyboard_layout::read_codepage_file(char const*, int)", +"keyboard_layout::switch_keyboard_layout(char const*, keyboard_layout*&, int&)", +"DOS_KeyboardLayout::DOS_KeyboardLayout(Section*)", +"KEYB::Run()", +"PIC_RunQueue()", +"MAPPER_RunEvent(unsigned int)", +"MAPPER_RunInternal()", +"Pause_Loop()", +"WGET::Run()" +] diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index 9bfa968bb..939d28542 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -2915,6 +2915,15 @@ int main(int argc, char* argv[]) { LOG_MSG("---"); /* Init SDL */ +#if SDL_VERSION_ATLEAST(2,0,0) && defined(EM_ASYNCIFY) + /* SDL calling emscripten_sleep() would be unnecessary, and would also + * require many more functions to be processed via asyncify. + * This was added in SDL 2.0.14, so it can cause compile errors with old + * SDL. Compile errors are better than SDL calling emscripten_sleep() + * and causing mysterious exceptions. + */ + SDL_SetHint(SDL_HINT_EMSCRIPTEN_ASYNCIFY, "0"); +#endif #if SDL_VERSION_ATLEAST(1, 2, 14) /* Or debian/ubuntu with older libsdl version as they have done this themselves, but then differently. * with this variable they will work correctly. I've only tested the 1.2.14 behaviour against the windows version