Optimize Embedded Linux Boot Time Performance
Total Page:16
File Type:pdf, Size:1020Kb
Optimize Embedded Linux Boot Time Performance WHITE PAPER TABLE OF CONTENTS Abstract ............................................................................................. 3 What is “Embedded Linux”? ............................................................. 4 What does Embedded Linux offer? .................................................. 4 What is Boot Time? ........................................................................... 5 Boot Sequence .................................................................................. 6 Optimizing Boot Time in an Embedded Linux System ...................... 6 Reducing Kernel Boot Time Thereby Increasing Speed ................... 7 Increasing System Startup Time and Application Speed .................. 8 Reducing the Disk Footprint and RAM Size of the Linux Kernel ....... 9 Reducing Application Size and RAM Usage..................................... 10 Reducing Power Consumption ........................................................ 10 Conclusion ....................................................................................... 11 Reference ........................................................................................ 12 Author Info .................................................................................... 112 ©2014, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author. All rights reserved. Abstract Almost everyone has heard of Linux. It is open source, and has been much in discussion in the software development and system administration communities. Linux was originally targeted specifically for desktop PCs running an Intel 80x86 or compatible microprocessor. Linus Torvalds, the inventor of Linux, had said, “Linux will never run on anything but a PC with an IDE hard disk since that is all that I have”. At present, Linux is ported to different microprocessors and runs on multiple platforms that don’t have a hard disk. Most of these devices are not general purpose computer systems and include devices such as network routers and data collection units for tracking tornadoes. It is these types of systems that have collectively been labeled as “Embedded Linux”. Linux has won the race in the embedded device segment. By offering enormous advantages, Linux has crossed every hurdle to enter embedded systems across a wide variety of processor architectures. This has led developers to raise questions about how they could get more performance out of their embedded Linux design, which made “reducing boot time” one of the hot topics of discussion in the embedded Linux community. It is not necessary to invent an engineering resource to save boot time. It is possible to substantially reduce boot time by applying certain system configurations. This whitepaper presents an insight into embedded Linux and a typical boot sequence. It also covers various techniques that can be used to optimize boot time. ©2014, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author. All rights reserved. 3 What is “Embedded Linux”? Linux is itself referred to as a kernel but in daily usage it rarely means so. Embedded Linux generally refers to a complete Linux distribution aimed at embedded devices. In reference to embedded development, there is a Linux kernel and other software or an embedded Linux distribution which contains a package of applications and development tools meant for embedded systems. Linux was originally designed to be a general-purpose operating system (OS). Many approaches have commenced to convert the Linux OS into an embedded OS. There are two ways to switch to embedded Linux: 1. Solutions provided and supported by vendors like MontaVista, Wind River or TimeSys contain their own development tools and environments, and use a few open- source components and proprietary tools. 2. Using community solutions that are open and supported by the community. With Linux, the dimension of computing applications increases, and this includes IBM's tiny Linux wrist watch, hand-held devices (PDAs and cell phones), Internet appliances, robotics, telephony infrastructure equipment, and much more. What does Embedded Linux offer? Though most Linux systems run on PC platforms, it can be a reliable OS for embedded systems. Linux is easier and more flexible to install and administer. Its “back-to-basics” approach is an added advantage. Though a fully featured Linux kernel requires about 1 MB of memory, the Linux micro-kernel actually consumes very little of ©2014, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author. All rights reserved. 4 this memory - around 100K on a Pentium CPU, which also includes a virtual memory and all core operating system functions. It is considered a lightweight operating system. The core Linux OS has a simple micro-kernel architecture. It provides a modular block to build a custom embedded system. The File system is on the top of the micro-kernel. Drivers can be either compiled or added to the kernel at run-time. Linux supports multiprocessor systems and is best-suited for embedded Internet devices. It offers scalability that opens an option of running a real-time application on a dual processor system. In various market segments like consumer electronics, products are such that the device needs to be available for immediate use after power on. An OS for desktops offers boot times in the range of 20 seconds to a few minutes. This is highly unacceptable for various market segments. For a device to qualify for an embedded market, it must be available for use as soon as it is turned on. What is Boot Time? Boot time is the time taken by the system to make it available from the time the power button is pressed. Boot time is one of the major factors in defining the usability of the system. The definition of system availability is different for different devices: For display devices like cellphones – the appearance of home For display of shell prompt on development systems with consoles There is no set criterion to measure boot time. In fact, boot time must be measured in the context of the device and its usage. ©2014, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author. All rights reserved. 5 Boot Sequence Power Applied Pwr/CLK/Reset Load and execute BootLoader Load and execute Kernel Kernel Init Locate/Load/Mount RootFS Init User Space Application start Optimizing Boot Time in an Embedded Linux System Many factors are responsible for boot time performance. This calls for a set of techniques to be applied to optimize the boot time of a Linux system. We are using the term 'optimizing' - instead of 'reducing'. as ‘reducing’ means achieving less boot time by taking custom shortcuts, which are difficult to maintain across component versions. Optimization methods are generic in nature and are easy to maintain across different versions. ©2014, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author. All rights reserved. 6 Areas of optimization Optimization methods fall under the following categories: 1. Size Reducing the size of binaries for each component loaded Removing features that are not required 2. Speed Optimizing the target processor Reducing the number of steps for booting Removing features that are not required To begin with optimizing the boot time of a device: Identify the current boot-time Set the target environment (processor) Define boundary conditions that are specific to the end-product Optimization is an iterative process. To measure the boot time, a reliable source is required. We have listed a set of techniques that can be applied in order to achieve an optimized boot-time for an embedded Linux system. Reducing Kernel Boot Time and thereby Increasing Speed 1. Disable IP auto-config – Instead of initializing the IP address on the kernel command line, use the /etc/init.d/rcS script. 2. The output of kernel bootup messages to the console consumes time. This is normally not needed in the production environment. Disable unwanted console output messages using the “quiet” argument in the Linux kernel bootloader settings. ©2014, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author. All rights reserved. 7 Example: root=/dev/ram0 rw init=/startup.sh quiet 3. Directly boot from the bootstrap code to directly load and execute the Linux kernel image instead of the Uboot. 4. Reduce the kernel size by removing things like features, debugging facilities, etc., which are not from the dedicated system. A smaller kernel loads fast and also executes fast. This reduces the time spent on initializing drivers. 5. Spare memory at boot time by skipping the memory allocation part and manage it yourself. Example: there is 32 MB of RAM Boot your kernel with mem=30 The remaining 2 MB can be claimed by the driver code buf = ioremap ( 0x1e00000, /* Start: 30 MB */ 0x200000 /* Size: 2 MB */ ); This saves a critical amount of time allocating memory. Increasing System Startup Time and Application Speed 1. SysV vs Init – SysV starts the services sequentially. It waits for the current startup script to be completed before starting the next one. In case of Init, if the pre-requisites are fulfilled, it starts the services in parallel. System utilization is also better in the case of Init. 2. Compiler speed optimizations – Most tools are compiled using compiler optimizations. “O2” is the most