
More Linux for Less uClinuxTM on a $5.00 (US) Processor Michael Hennerich Robin Getz Analog Devices Analog Devices [email protected] [email protected] Abstract that provides a strong foundation for an ever- growing base of applications to run on. Linux is a fully functional operating system (OS) with While many in the Linux community focus on support for a variety of network and file han- enterprise and multi-processor servers, there dling protocols, a very important requirement are also many who are working and deploy- in embedded systems because of the need to ing Linux on the network edge. Due to its “connect and compute anywhere at anytime.” open nature, and the ability to swiftly develop Modular in nature, Linux is easy to slim down complex applications, Linux is rapidly becom- by removing utility programs, tools, and other ing the number one embedded operating sys- system services that are not needed in the tar- tem. However, there are many differences be- geted embedded environment. The advantages tween running Linux on a Quad processor sys- for companies using Linux in embedded mar- tem with 16Gig of Memory and 250Gig of kets are faster time to market, flexibility, and RAID storage than a on a system where the to- reliability. tal cost of hardware is less than the price of a typical meal. This paper attempts to answer several questions that all embedded developers ask: • Why use a kernel at all? 1 Introduction • What advantages does Linux provide over other operating systems? TM In the past few years, Linux has become an • What is the difference between Linux on increasingly popular operating system choice x86 and low cost processors? not only in the PC and Server market, also in the development of embedded devices— • Where can I get a kernel and how do I get particularly consumer products, telecommuni- started? cations routers and switches, Internet appli- • Is Linux capable of providing real-time ances, and industrial and automotive applica- functionality? tions. • What are the possibilities to port a existing The advantage of Embedded Linux is that it is real-time application to a system running a royalty-free, open source, compact solution also Linux? 314 • More Linux for Less 2 Why use a kernel at all 2.2 Debugged Control Structures All applications require control code as support Debugging a traditional hand-coded applica- for the algorithms that are often thought of as tion can be laborious because development the “real” program. The algorithms require data tools (compiler, assembler, and linker among to be moved to and/or from peripherals, and others) are not aware of the architecture of the many algorithms consist of more than one func- target application and the flow of control that tional block. For some systems, this control results. Debugging complex applications is code may be as simple as a “super loop” blindly much easier when instantaneous snapshots of processing data that arrives at a constant rate. the system state and statistical runtime data are However, as processors become more power- clearly presented by the tools. To help offset ful, considerably more sophisticated control or the difficulties in debugging software, embed- signal processing may be needed to realize the ded Linux kernels are tested with the same tests processor’s potential, to allow the processor to that many desktop distributions use before re- absorb the required functionality of previously leasing a Linux kernel. This ensure that the em- supported chips, and to allow a single processor bedded kernel is as bug-free as possible. to do the work of many. The following sections provide an overview of some of the benefits of using a kernel on a processor. 2.3 Code Reuse 2.1 Rapid Application Development Many programmers begin a new project by writing the infrastructure portions that transfers data to, from, and between algorithms. This The use of the Linux kernel allows rapid de- necessary control logic usually is created from velopment of applications compared to creat- scratch by each design team and infrequently ing all of the control code required by hand. reused on subsequent projects. The Linux ker- An application or algorithm can be created and nel provides much of this functionality in a debugged on an x86 PC using powerful desk- standard, portable, and reusable manner. Fur- top debugging tools, and using standard pro- thermore, the kernel and its tight integration gramming interfaces to device drivers. Moving with the GNU development and debug tools this code base to an embedded linux kernel run- are designed to promote good coding practice ning on a low-cost embedded processor is triv- and organization by partitioning large appli- ial because the device driver model is exactly cations into maintainable and comprehensible the same. Opening an audio device on the x86 blocks. By isolating the functionality of sub- Desktop is done in exactly the same was as on systems, the kernel helps to prevent the morass an embedded Linux system. This allows you to all too commonly found in systems program- concentrate on the algorithms and the desired ming. The kernel is designed specifically to control flow rather than on the implementation take advantage of commonality in user applica- details. Embedded Linux kernels and applica- tions and to encourage code reuse. Each thread tions supports the use of C, C++, and assem- of execution is created from a user-defined tem- bly language, encouraging the development of plate, either at boot time or dynamically by an- code that is highly readable and maintainable, other thread. Multiple threads can be created yet retaining the option of hand-optimizing if from the same template, but the state associ- necessary. ated with each created instance of the thread 2006 Linux Symposium, Volume One • 315 remains unique. Each thread template repre- individually coded and tested. These build- sents a complete encapsulation of an algorithm ing blocks then become reusable components that is unaware of other threads in the system in more robust and scalable systems. unless it has a direct dependency. You define the behavior of Linux applications by creating the application. Many application 2.4 Hardware Abstraction or threads of the same type can be created, but for each thread type, only one copy of the code is linked into the executable code. Each appli- In addition to a structured model for algo- cation or thread has its own private set of vari- rithms, the Linux kernel provides a hardware ables defined for the thread type, its own stack, abstraction layer. Presented programming in- and its own C run-time context. terfaces allow you to write most of the applica- tion in a platform-independent, high-level lan- When partitioning an application into threads, guage (C or C++). The Linux Application Pro- identify portions of your design in which a gramming Interface (API) is identical for all similar algorithm is applied to multiple sets of processors which support Linux, allowing code data. These are, in general, good candidates for to be easily ported to a different processor core. thread types. When data is present in the sys- When porting an application to a new plat- tem in sequential blocks, only one instance of form, programmers must only address the areas the thread type is required. If the same opera- necessarily specific to a particular processor— tion is performed on separate sets of data simul- normally device drivers. The Linux architec- taneously, multiple threads of the same type can ture identifies a crisp boundary around these coexist and be scheduled for prioritized execu- subsystems and supports the traditionally dif- tion (based on when the results are needed). ficult development with a clear programming framework and code generation. Common de- vices can use the same driver interface (for ex- 2.6 Scheduling ample a serial port driver may be specific for a certain hardware, but the application ←→ serial port driver interface should be exactly the same, The Linux kernel can be a preemptive multi- providing a well-defined hardware abstraction, tasking kernel. Each application or thread be- and making application development faster). gins execution at its entry point. Then, it ei- ther runs to completion or performs its primary 2.5 Partitioning an Application function repeatedly in an infinite loop. It is the role of the scheduler to preempt execution of a an application or thread and to resume its ex- A Linux application or thread is an encapsu- ecution when appropriate. Each application or lation of an algorithm and its associated data. thread is given a priority to assist the scheduler When beginning a new project, use this notion in determining precedence. of an application or thread to leverage the ker- nel architecture and to reduce the complexity The scheduler gives processor time to the of your system. Since many algorithms may be thread with the highest priority that is in the thought of as being composed of subalgorithm ready state. A thread is in the ready state when building blocks, an application can be parti- it is not waiting for any system resources it has tioned into smaller functional units that can be requested. 316 • More Linux for Less 2.7 Priorities 2.9 Application and Hardware Interaction Each application or thread is assigned a dy- Applications should have minimal knowledge namically modifiable priority. An application of hardware; rather, they should use device is limited to forty (40) priority levels. How- drivers for hardware control. A application can ever, the number of threads at each priority is control and interact with a device in a portable limited, in practice, only by system memory. and hardware abstracted manner through a Priority level one is the highest priority, and pri- standard set of APIs.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages22 Page
-
File Size-