Changeset 2921 in kBuild
- Timestamp:
- Sep 15, 2016 3:24:55 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kWorker/kWorker.c
r2920 r2921 8743 8743 } 8744 8744 8745 #if 18746 8745 8747 8746 int main(int argc, char **argv) … … 9006 9005 9007 9006 CloseHandle(hPipe); 9008 # 9007 #ifdef WITH_LOG_FILE 9009 9008 if (g_hLogFile != INVALID_HANDLE_VALUE && g_hLogFile != NULL) 9010 9009 CloseHandle(g_hLogFile); 9011 # 9010 #endif 9012 9011 return rc > 0 ? 0 : 1; 9013 9012 } 9014 9013 } 9015 9014 9016 #else 9017 9018 static int kwExecCmdLine(const char *pszExe, const char *pszCmdLine) 9019 { 9020 int rc; 9021 PKWTOOL pTool = kwToolLookup(pszExe); 9022 if (pTool) 9023 { 9024 int rcExitCode; 9025 switch (pTool->enmType) 9026 { 9027 case KWTOOLTYPE_SANDBOXED: 9028 KW_LOG(("Sandboxing tool %s\n", pTool->pszPath)); 9029 rc = kwSandboxExec(&g_Sandbox, pTool, pszCmdLine, &rcExitCode); 9030 break; 9031 default: 9032 kHlpAssertFailed(); 9033 KW_LOG(("TODO: Direct exec tool %s\n", pTool->pszPath)); 9034 rc = rcExitCode = 2; 9035 break; 9036 } 9037 KW_LOG(("rcExitCode=%d (rc=%d)\n", rcExitCode, rc)); 9038 } 9039 else 9040 rc = 1; 9041 return rc; 9042 } 9043 9044 int main(int argc, char **argv) 9045 { 9046 int rc = 0; 9047 int i; 9048 argv[2] = "\"E:/vbox/svn/trunk/tools/win.x86/vcc/v10sp1/bin/amd64/cl.exe\" -c -c -TP -nologo -Zi -Zi -Zl -GR- -EHsc -GF -Zc:wchar_t- -Oy- -MT -W4 -Wall -wd4065 -wd4996 -wd4127 -wd4706 -wd4201 -wd4214 -wd4510 -wd4512 -wd4610 -wd4514 -wd4820 -wd4365 -wd4987 -wd4710 -wd4061 -wd4986 -wd4191 -wd4574 -wd4917 -wd4711 -wd4611 -wd4571 -wd4324 -wd4505 -wd4263 -wd4264 -wd4738 -wd4242 -wd4244 -WX -RTCsu -IE:/vbox/svn/trunk/tools/win.x86/vcc/v10sp1/include -IE:/vbox/svn/trunk/tools/win.x86/vcc/v10sp1/atlmfc/include -IE:/vbox/svn/trunk/tools/win.x86/sdk/v7.1/Include -IE:/vbox/svn/trunk/include -IE:/vbox/svn/trunk/out/win.amd64/debug -IE:/vbox/svn/trunk/tools/win.x86/vcc/v10sp1/include -IE:/vbox/svn/trunk/tools/win.x86/vcc/v10sp1/atlmfc/include -DVBOX -DVBOX_WITH_64_BITS_GUESTS -DVBOX_WITH_REM -DVBOX_WITH_RAW_MODE -DDEBUG -DDEBUG_bird -DDEBUG_USERNAME=bird -DRT_OS_WINDOWS -D__WIN__ -DRT_ARCH_AMD64 -D__AMD64__ -D__WIN64__ -DVBOX_WITH_DEBUGGER -DRT_LOCK_STRICT -DRT_LOCK_STRICT_ORDER -DIN_RING3 -DLOG_DISABLED -DIN_BLD_PROG -D_CRT_SECURE_NO_DEPRECATE -FdE:/vbox/svn/trunk/out/win.amd64/debug/obj/VBoxBs2Linker/VBoxBs2Linker-obj.pdb -FD -FoE:/vbox/svn/trunk/out/win.amd64/debug/obj/VBoxBs2Linker/VBoxBs2Linker.obj E:\\vbox\\svn\\trunk\\src\\VBox\\ValidationKit\\bootsectors\\VBoxBs2Linker.cpp"; 9049 # if 0 9050 rc = kwExecCmdLine(argv[1], argv[2]); 9051 rc = kwExecCmdLine(argv[1], argv[2]); 9052 K_NOREF(i); 9053 # else 9054 // Skylake (W10/amd64, only stdandard MS defender): 9055 // cmd 1: 48 /1024 = 0x0 (0.046875) [for /l %i in (1,1,1024) do ...] 9056 // kmk 1: 44 /1024 = 0x0 (0.04296875) [all: ; 1024 x cl.exe] 9057 // run 1: 37 /1024 = 0x0 (0.0361328125) [just process creation gain] 9058 // run 2: 34 /1024 = 0x0 (0.033203125) [get file attribs] 9059 // run 3: 32.77 /1024 = 0x0 (0.032001953125) [read caching of headers] 9060 // run 4: 32.67 /1024 = 0x0 (0.031904296875) [loader tweaking] 9061 // run 5: 29.144/1024 = 0x0 (0.0284609375) [with temp files in memory] 9062 // r2881 building src/VBox/Runtime: 9063 // without: 2m01.016388s = 120.016388 s 9064 // with: 1m15.165069s = 75.165069 s => 120.016388s - 75.165069s = 44.851319s => 44.85/120.02 = 37% speed up. 9065 // r2884 building vbox/debug (r110512): 9066 // without: 11m14.446609s = 674.446609 s 9067 // with: 9m01.017344s = 541.017344 s => 674.446609s - 541.017344s = 133.429265 => 133.43/674.45 = 19% speed up 9068 // r2896 building vbox/debug (r110577): 9069 // with: 8m31.182384s = 511.182384 s => 674.446609s - 511.182384s = 163.264225 = 163.26/674.45 = 24% speed up 9070 // 9071 // Dell (W7/amd64, infected by mcafee): 9072 // kmk 1: 285.278/1024 = 0x0 (0.278591796875) 9073 // run 1: 134.503/1024 = 0x0 (0.1313505859375) [w/o temp files in memory] 9074 // run 2: 78.161/1024 = 0x0 (0.0763291015625) [with temp files in memory] 9075 g_cVerbose = 0; 9076 for (i = 0; i < 1024 && rc == 0; i++) 9077 rc = kwExecCmdLine(argv[1], argv[2]); 9078 # endif 9079 return rc; 9080 } 9081 9082 #endif 9083 9015 9016 /** @page pg_kWorker kSubmit / kWorker 9017 * 9018 * @section sec_kWorker_Motivation Motivation / Inspiration 9019 * 9020 * The kSubmit / kWorker combo was conceived as a way to speed up VirtualBox 9021 * builds on machines "infested" by Anti Virus protection and disk encryption 9022 * software. Build times jumping from 35-40 min to 77-82 min after the machine 9023 * got "infected". 9024 * 9025 * There was also a desire to speed up the rebuilding of the Boot Sector Kit 9026 * \#3, do does a lot of very small assembler and compiler jobs. As some of us 9027 * OS/2 users recalled, the Watcom make program can run its own toolchain from 9028 * within the same process, saving a lot of overhead. 9029 * 9030 * 9031 * @section sec_kWorker_kSubmit About kSubmit 9032 * 9033 * When wanting to execute a job in a kWorker instance, it must be submitted 9034 * using the kmk_builtin_kSubmit command in kmk. As the name suggest, this is 9035 * built into kmk and does not exist as an external program. The reason for 9036 * this is that it keep track of the kWorker instances. 9037 * 9038 * The kSubmit command has the --32-bit and --64-bit options for selecting 9039 * between 32-bit and 64-bit worker instance. We generally assume the user of 9040 * the command knows which bit count the executable has, so kSubmit is spared 9041 * the extra work of finding out. 9042 * 9043 * The kSubmit command shares a environment and current directory manipulation 9044 * with the kRedirect command, but not the file redirection. So long no file 9045 * operation is involed, kSubmit is a drop in kRedirect replacement. This is 9046 * hand for tools like OpenWatcom, NASM and YASM which all require enviornment 9047 * and/or current directory changes to work. 9048 * 9049 * Unlike the kRedirect command, the kSubmit command can also specify an 9050 * internall post command to be executed after the main command succeeds. 9051 * Currently only kmk_builtin_kDepObj is supported. kDepObj gathers dependency 9052 * information from Microsoft COFF object files and Watcom OMF object files and 9053 * is scheduled to replace kDepIDB. 9054 * 9055 * 9056 * @section sec_kWorker_Interaction kSubmit / kWorker interaction 9057 * 9058 * The kmk_builtin_kSubmit communicates with the kWorker instances over pipes. 9059 * A job request is written by kSubmit and kWorker read, unpacks it and executes 9060 * it. When the job is completed, kWorker writes a short reply with the exit 9061 * code and an internal status indicating whether it is going to restart. 9062 * 9063 * The kWorker intance will reply to kSubmit before completing all the internal 9064 * cleanup work, so as not to delay the next job execution unnecessarily. This 9065 * includes checking its own memory consumption and checking whether it needs 9066 * restarting. So, a decision to restart unfortunately have to wait till after 9067 * the next job has completed. This is a little bit unfortunate if the next job 9068 * requires a lot of memory and kWorker has already leaked/used a lot. 9069 * 9070 * 9071 * @section sec_kWorker_How_Works How kWorker Works 9072 * 9073 * kWorker will load the executable specified by kSubmit into memory and call 9074 * it's entrypoint in a lightly sandbox'ed environment. 9075 * 9076 * 9077 * @subsection sec_kWorker_How_Works_Loading Image loading 9078 * 9079 * kWorker will manually load all the executable images into memory, fix them 9080 * up, and make a copy of the virgin image so it can be restored using memcpy 9081 * the next time it is used. 9082 * 9083 * Imported functions are monitored and replacements used for a few of them. 9084 * These replacements are serve the following purposes: 9085 * - Provide a different command line. 9086 * - Provide a different environment. 9087 * - Intercept process termination. 9088 * - Intercept thread creation (only linker is allowed to create threads). 9089 * - Intercept file reading for caching (header files, ++) as file system 9090 * access is made even slower by anti-virus software. 9091 * - Intercept temporary files (%TEMP%/_CL_XXXXXXyy) to keep the entirely 9092 * in memory as writing files grows expensive with encryption and 9093 * anti-virus software active. 9094 * - Intercept some file system queries to use the kFsCache instead of 9095 * going to the kernel and slowly worm thru the AV filter driver. 9096 * - Intercept standard output/error and console writes to aggressivly 9097 * buffer the output. The MS CRT does not buffer either when it goes to 9098 * the console, resulting in terrible performance and mixing up output 9099 * with other compile jobs. 9100 * This also allows us to filter out the annoying source file announcements 9101 * by cl.exe. 9102 * - Intercept VirtualAlloc and VirtualFree to prevent 9103 * CL.EXE/C1.DLL/C1XX.DLL from leaking some 72MB internal allocat area. 9104 * - Intercept FlsAlloc/FlsFree to make sure the allocations are freed and 9105 * the callbacks run after each job. 9106 * - Intercept HeapCreate/HeapFree to reduce leaks from statically linked 9107 * executables and tools using custom heaps (like the microsoft linker). 9108 * [exectuable images only] 9109 * - Intercept atexit and _onexit registration to be able run them after 9110 * each job instead of crashing as kWorker exits. This also helps avoid 9111 * some leaks. [executable image only] 9112 * 9113 * DLLs falls into two categories, system DLLs which we always load using the 9114 * native loader, and tool DLLs which can be handled like the executable or 9115 * optionally using the native loader. We maintain a hardcoded white listing of 9116 * tool DLLs we trust to load using the native loader. 9117 * 9118 * Imports of natively loaded DLLs are processed too, but we only replace a 9119 * subset of the functions compared to natively loaded excutable and DLL images. 9120 * 9121 * DLLs are never unloaded and we cache LoadLibrary requests (hash the input). 9122 * This is to speed up job execution. 9123 * 9124 * It was thought that we needed to restore (memcpy) natively loaded tool DLLs 9125 * for each job run, but so far this hasn't been necessary. 9126 * 9127 * 9128 * 9129 * 9130 * @section sec_kWorker_Numbers Some measurements. 9131 * 9132 * - r2881 building src/VBox/Runtime: 9133 * - without: 2m01.016388s = 120.016388 s 9134 * - with: 1m15.165069s = 75.165069 s => 120.016388s - 75.165069s = 44.851319s => 44.85/120.02 = 37% speed up. 9135 * - r2884 building vbox/debug (r110512): 9136 * - without: 11m14.446609s = 674.446609 s 9137 * - with: 9m01.017344s = 541.017344 s => 674.446609s - 541.017344s = 133.429265 => 133.43/674.45 = 19% speed up 9138 * - r2896 building vbox/debug (r110577): 9139 * - with: 8m31.182384s = 511.182384 s => 674.446609s - 511.182384s = 163.264225 = 163.26/674.45 = 24% speed up 9140 * 9141 * @subsection subsec_kWorker_Early_Numbers Early Experiments 9142 * 9143 * These are some early experiments doing 1024 compilations of 9144 * VBoxBS2Linker.cpp using a hard coded command line and looping in kWorker's 9145 * main function: 9146 * 9147 * Skylake (W10/amd64, only stdandard MS defender): 9148 * - cmd 1: 48 /1024 = 0x0 (0.046875) [for /l %i in (1,1,1024) do ...] 9149 * - kmk 1: 44 /1024 = 0x0 (0.04296875) [all: ; 1024 x cl.exe] 9150 * - run 1: 37 /1024 = 0x0 (0.0361328125) [just process creation gain] 9151 * - run 2: 34 /1024 = 0x0 (0.033203125) [get file attribs] 9152 * - run 3: 32.77 /1024 = 0x0 (0.032001953125) [read caching of headers] 9153 * - run 4: 32.67 /1024 = 0x0 (0.031904296875) [loader tweaking] 9154 * - run 5: 29.144/1024 = 0x0 (0.0284609375) [with temp files in memory] 9155 * 9156 * Dell (W7/amd64, infected by mcafee): 9157 * - kmk 1: 285.278/1024 = 0x0 (0.278591796875) 9158 * - run 1: 134.503/1024 = 0x0 (0.1313505859375) [w/o temp files in memory] 9159 * - run 2: 78.161/1024 = 0x0 (0.0763291015625) [with temp files in memory] 9160 * 9161 * The command line: 9162 * @code{.cpp} 9163 "\"E:/vbox/svn/trunk/tools/win.x86/vcc/v10sp1/bin/amd64/cl.exe\" -c -c -TP -nologo -Zi -Zi -Zl -GR- -EHsc -GF -Zc:wchar_t- -Oy- -MT -W4 -Wall -wd4065 -wd4996 -wd4127 -wd4706 -wd4201 -wd4214 -wd4510 -wd4512 -wd4610 -wd4514 -wd4820 -wd4365 -wd4987 -wd4710 -wd4061 -wd4986 -wd4191 -wd4574 -wd4917 -wd4711 -wd4611 -wd4571 -wd4324 -wd4505 -wd4263 -wd4264 -wd4738 -wd4242 -wd4244 -WX -RTCsu -IE:/vbox/svn/trunk/tools/win.x86/vcc/v10sp1/include -IE:/vbox/svn/trunk/tools/win.x86/vcc/v10sp1/atlmfc/include -IE:/vbox/svn/trunk/tools/win.x86/sdk/v7.1/Include -IE:/vbox/svn/trunk/include -IE:/vbox/svn/trunk/out/win.amd64/debug -IE:/vbox/svn/trunk/tools/win.x86/vcc/v10sp1/include -IE:/vbox/svn/trunk/tools/win.x86/vcc/v10sp1/atlmfc/include -DVBOX -DVBOX_WITH_64_BITS_GUESTS -DVBOX_WITH_REM -DVBOX_WITH_RAW_MODE -DDEBUG -DDEBUG_bird -DDEBUG_USERNAME=bird -DRT_OS_WINDOWS -D__WIN__ -DRT_ARCH_AMD64 -D__AMD64__ -D__WIN64__ -DVBOX_WITH_DEBUGGER -DRT_LOCK_STRICT -DRT_LOCK_STRICT_ORDER -DIN_RING3 -DLOG_DISABLED -DIN_BLD_PROG -D_CRT_SECURE_NO_DEPRECATE -FdE:/vbox/svn/trunk/out/win.amd64/debug/obj/VBoxBs2Linker/VBoxBs2Linker-obj.pdb -FD -FoE:/vbox/svn/trunk/out/win.amd64/debug/obj/VBoxBs2Linker/VBoxBs2Linker.obj E:\\vbox\\svn\\trunk\\src\\VBox\\ValidationKit\\bootsectors\\VBoxBs2Linker.cpp" 9164 * @endcode 9165 */ 9166
Note:
See TracChangeset
for help on using the changeset viewer.