Empirical Performance Comparison of Hardware and Software Task Context Switching
Total Page:16
File Type:pdf, Size:1020Kb
View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by Calhoun, Institutional Archive of the Naval Postgraduate School Calhoun: The NPS Institutional Archive Theses and Dissertations Thesis Collection 2009-06 Empirical Performance Comparison of Hardware and Software Task Context Switching Schultz, Eric A. Monterey, California. Naval Postgraduate School http://hdl.handle.net/10945/46226 NAVAL POSTGRADUATE SCHOOL MONTEREY, CALIFORNIA THESIS EMPIRICAL PERFORMANCE COMPARISON OF HARDWARE AND SOFTWARE TASK CONTEXT SWITCHING by Eric A. Schultz June 2009 Thesis Advisor: Cynthia E. Irvine Second Reader: David J. Shifflett Approved for public release; distribution is unlimited THIS PAGE INTENTIONALLY LEFT BLANK ii Form Approved REPORT DOCUMENTATION PAGE OMB No. 0704–0188 The public reporting burden for this collection of information is estimated to average 1 hour per response, including the time for reviewing instructions, searching existing data sources, gathering and maintaining the data needed, and completing and reviewing the collection of information. Send comments regarding this burden estimate or any other aspect of this collection of information, including suggestions for reducing this burden to Department of Defense, Washington Headquarters Services, Directorate for Information Operations and Reports (0704–0188), 1215 Jefferson Davis Highway, Suite 1204, Arlington, VA 22202–4302. Respondents should be aware that notwithstanding any other provision of law, no person shall be subject to any penalty for failing to comply with a collection of information if it does not display a currently valid OMB control number. PLEASE DO NOT RETURN YOUR FORM TO THE ABOVE ADDRESS. 1. REPORT DATE (DD–MM–YYYY) 2. REPORT TYPE 3. DATES COVERED (From — To) 15–6–2009 Master’s Thesis 01-01-2009–06-19-2009 4. TITLE AND SUBTITLE 5a. CONTRACT NUMBER 5b. GRANT NUMBER Empirical Performance Comparison of Hardware and Software Task Context Switching 5c. PROGRAM ELEMENT NUMBER 6. AUTHOR(S) 5d. PROJECT NUMBER 5e. TASK NUMBER Eric A. Schultz 5f. WORK UNIT NUMBER 7. PERFORMING ORGANIZATION NAME(S) AND ADDRESS(ES) 8. PERFORMING ORGANIZATION REPORT NUMBER Naval Postgraduate School Monterey, CA 93943 9. SPONSORING / MONITORING AGENCY NAME(S) AND ADDRESS(ES) 10. SPONSOR/MONITOR’S ACRONYM(S) Department of the Navy 11. SPONSOR/MONITOR’S REPORT NUMBER(S) 12. DISTRIBUTION / AVAILABILITY STATEMENT Approved for public release; distribution is unlimited 13. SUPPLEMENTARY NOTES 14. ABSTRACT There are many divergent opinions regarding possible differences between the performance of hardware and software context switching implementations. However, there are no concrete empirical measures of their true differences. Using an empirical testing methodology, this research performed seven experiments, collecting quantitative performance results on hardware and software-based context switch implementations with two and four hardware privilege level support. The implementations measured are the hardware-based Intel IA-32 context switch, the software-based MINIX 3 context switch, a software-based simulation of a MINIX 3 context switch with four hardware privileged level support, and a software-based simulation of an Intel IA-32 hardware context switch. Experiments were executed using the Trusted Computing Exemplar Least Privilege Separation Kernel and the Linux 2.6 Kernel. The results include the number of cycles and time required to complete processing of each implementation. This study concludes that the hardware-based context switching mechanism is significantly slower than software implementation, even those that simulate the elaborate checks of the hardware implementation. A possible reason for this is posited. 15. SUBJECT TERMS Performance, Context Switch, Task Switch, TCX, LPSK, Intel, IA-32, MINIX 3 16. SECURITY CLASSIFICATION OF: 17. LIMITATION OF 18. NUMBER19a. NAME OF RESPONSIBLE PERSON a. REPORT b. ABSTRACTc.THIS PAGE ABSTRACT OF PAGES 19b. TELEPHONE NUMBER (include area code) Unclassified Unclassified Unclassified UU 176 Standard Form 298 (Rev. 8–98) i Prescribed by ANSI Std. Z39.18 THIS PAGE INTENTIONALLY LEFT BLANK ii Approved for public release; distribution is unlimited EMPIRICAL PERFORMANCE COMPARISON OF HARDWARE AND SOFTWARE TASK CONTEXT SWITCHING Eric A. Schultz Civilian, Naval Postgraduate School B.S., Rocky Mountain College, 2007 Submitted in partial fulfillment of the requirements for the degree of MASTER OF SCIENCE IN COMPUTER SCIENCE from the NAVAL POSTGRADUATE SCHOOL June 2009 Author: Eric A. Schultz Approved by: Cynthia E. Irvine Thesis Advisor David J. Shifflett Second Reader Peter J. Denning Chair, Department of Computer Science iii THIS PAGE INTENTIONALLY LEFT BLANK iv ABSTRACT There are many divergent opinions regarding possible differences between the performance of hardware and software context switching implementations. However, there are no concrete empirical measures of their true differences. Using an empirical testing methodology, this re- search performed seven experiments, collecting quantitative performance results on hardware and software-based context switch implementations with two and four hardware privilege level support. The implementations measured are the hardware-based Intel IA-32 context switch, the software-based MINIX 3 context switch, a software-based simulation of a MINIX 3 con- text switch with four hardware privileged level support, and a software-based simulation of an Intel IA-32 hardware context switch. Experiments were executed using the Trusted Comput- ing Exemplar Least Privilege Separation Kernel and the Linux 2.6 Kernel. The results include the number of cycles and time required to complete processing of each implementation. This study concludes that the hardware-based context switching mechanism is significantly slower than software implementation, even those that simulate the elaborate checks of the hardware implementation. A possible reason for this is posited. v THIS PAGE INTENTIONALLY LEFT BLANK vi Contents 1 Introduction1 1.1 Motivation.............................1 1.2 Purpose of Study..........................2 1.3 Organization of Thesis........................3 2 Background5 2.1 Multitasking Operating Systems Overview................5 2.2 Context Switches.......................... 12 2.3 Summary............................. 14 3 Methodologies and Testing Techniques 15 3.1 Operating Systems Selection...................... 16 3.2 Hardware Selection......................... 20 3.3 Context Switching Constructs..................... 21 3.4 Testing Strategies.......................... 31 3.5 Summary............................. 50 4 Results and Analysis 53 4.1 Measurements of RDTSC, CPUID and Cache Warming........... 53 4.2 Minimal Software Context Switch Results................ 54 4.3 MINIX 3 Software Context Switch Results................ 54 4.4 Intel IA-32 Hardware Context Switch Results............... 55 4.5 Modified Four Hardware Privilege Level Supported MINIX 3 Software Context Switch Results................ 55 4.6 Linux Software Simulation of Intel IA-32 Hardware Context Switch Results... 56 4.7 TCX LPSK Software Simulation of Intel IA-32 Hardware Context Switch Results 56 4.8 Single Execution of Intel IA-32 Hardware Context Switch Results....... 57 4.9 Final Analysis and Conclusions.................... 58 4.10 Summary............................. 62 5 Discussion and Conclusions 63 5.1 Future Work............................ 63 5.2 Related Work............................ 64 5.3 Summary and Conclusions...................... 66 vii Contents Contents List of References 69 Appendix A MINIX 3 Software Context Switch Source 73 A.1 Save Procedure........................... 73 A.2 Restart Procedure.......................... 74 Appendix B Experiments Source Code 75 B.1 RDTSC Measurement Source..................... 75 B.2 CPUID Measurement Source..................... 77 B.3 TCX LPSK Assembler Functions task switch asm and task switch dummy ......................... 78 B.4 Experiment One Source–Minimal Context Switch Cost........... 80 B.5 Experiment Two Source–MINIX 3 Software Context Switch......... 86 B.6 Experiment Three Source–Intel IA-32 Hardware Context Switch....... 95 B.7 Experiment Four Source–Modified MINIX 3 Four Hardware Privilege Level Sup- ported Software Context Switch.................... 103 B.8 Experiment Five Source–Linux Software Simulation of Intel IA-32 Hardware Con- text Switch............................. 112 B.9 Experiment Six Source–TCX LPSK Software Simulation of Intel IA-32 Hardware Context Switch........................... 122 B.10 Experiment Seven Source–Single Intel IA-32 Hardware Context Switch.... 131 Appendix C Experiment Data 139 C.1 RDTSC Instruction CPI Results.................... 139 C.2 CPUID Instruction CPI Results..................... 141 C.3 Experiment One Results–Minimal Context Switch Cost........... 142 C.4 Experiment Two Results–MINIX 3 Software Context Switch......... 143 C.5 Experiment Three Results–Intel IA-32 Hardware Context Switch....... 144 C.6 Experiment Four Results–Modified MINIX 3 Four Hardware Privilege Level Sup- ported Software Context Switch.................... 147 C.7 Experiment Five Results–Linux Software Simulation of Intel IA-32 Hardware Con- text Switch............................. 148 C.8 Experiment Six Results–TCX LPSK Software Simulation of Intel IA-32 Hardware Context Switch........................... 149 C.9 Experiment Seven Results–Single Intel IA-32 Hardware Context Switch.... 150 Referenced Authors 153 viii Contents