NetBSD and Linux for Embedded Systems


Published on

A very old talk comparing Linux and NetBSD. Talk delivered at

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

NetBSD and Linux for Embedded Systems

  1. 1. NetBSD and Linux for Embedded SystemsMahendra MMahendra_M@infosys.comhttp://www.infosys.comThis work is licensed under a Creative Commons License
  2. 2. About the talk This talk is NOT about to compare NetBSD and Linux and find out which is better. – We shall compare – but not criticize !! We shall try to understand both systems in their own merit It is about sharing our experiences with both the systems – more from a embedded & telecom OS perspective. We hope to help you choose.
  3. 3. Agenda A short introduction to NetBSD and Linux based systems Suitability for embedded systems Introduction to the features available in NB and Linux – Specifically for Embedded Systems Feature wise comparison of the two kernels – Core architecture, Threading model, Real time capabilities, modularity, performance, ease of deployment, portability Linux capabilities. NetBSD Capabilities – Kqueue : Event notification framework Availability of Code for future needs Feasibility and time to market along with License issues.
  4. 4. About the Systems Linux – Refers only to the kernel – Distributions are built around it. ( distros available for embedded systems ) – Has a history of around 15 years – Is under the GPL license ( v2.0 ) and supports binary modules. NetBSD – A BSD “ distribution” targeted at portability. – Includes a kernel, libraries, config tools, scripts and build systems. – Targeted at portability – The BSD systems have had a history of around 25 years. – Is under a BSD license.
  5. 5. Common stuff ... Highly portable – ports exist for a large number of architectures and reference boards. Both are POSIX compliant Good VM, Networking, Threading subsystems Both have been time tested in the market Active development happening – Directly on Linux kernel – on multiple trees maintained by different people. – NetBSD tend to let features stabilize on FreeBSD/OpenBSD and then pick it up :-) Let us get on with the differences....
  6. 6. Memory foot print Linux is slowly getting bloated. – There are projects that are working on reducing the size of Linux kernel – “ Linux Tiny” project provides a set of patches that can be applied to the Linux kernel to reduce the kernel size (built image and run time memory requirements) NetBSD projects boast of reduced kernel size. – TINY configuration file is distributed along with the source. Both kernels can be easily reduced to a size of less than 1MB ( uncompressed : ~900k, compressed : ~400k ) With sufficient hacking around, it can be reduced even further.
  7. 7. Process Scheduling Both OS follow a similar model in running user space processes. – Time slice based – and O(1) in nature. – They have priority based levels and processes are placed on these levels based on their priority – Both support dynamic priority modification based on interactiveness of a process  Not needed for embedded systems – and can be turned off at compile time. – Both support the same user space priorities (40) Linux has two run-queues : An active and an expired run- queue. Linux also has a run-queue per CPU – for SMP boxes.
  8. 8. Process Run-queueRunQueue Doubly linked lists of tasks Active Task 1 Task 2 ... Task N [Priority: 1] ... Task 1 Task 2 Task M [Priority:140] Expired ... ... Migration Thread From kernel/sched.c
  9. 9. Other stuff ... Kernel pre-emption. – Linux kernel supports kernel pre-emption, but only at pre- emptible points inside in the kernel. – There are still areas within the kernel which cannot be pre- empted. – NetBSD does not support kernel pre-emption.  Hence real-time support is pretty poor on NetBSD systems SMP Support ( not really critical in embedded systems ) – Very good in Linux. – Worked upon in NetBSD.
  10. 10. Real-time performance Hard real-time performance – Not available in both kernels by default. – FSM labs provides patches to the Linux kernel ( under GPL ) and commercial patches to NetBSD.  Works by running Linux/NetBSD kernel as low priority tasks under a real time kernel. Soft real-time performance. – Linux is pretty good in providing soft real time facilities. – In addition to the 40 user land priorities, Linux provides an additional 100 real-time priorities – Linux supports two soft real time scheduling options  SCHED_FIFO – First in first out  SCHED_RR – Round robin – Real time tasks cannot be pre-empted.
  11. 11. Threading models Both kernels are thread aware and are POSIX compliant They support different threading models – This is where the difference starts and things get interesting.. Linux – Supports 1:1 model of threading ( NPTL ) – The kernel does not distinguish between threads and processes  A process is a group of thread ids – thats it. – All threads in a process are visible as tasks to the kernel and active threads are allocated time-slices for scheduling.  All active threads will get their time-slices – Can set real time priorities to tasks. – APIs are available for real time threads handling
  12. 12. Threading models ( contd .. ) NetBSD – Treats threads (lwp) and processes differently – Supports Scheduler Activations.  m:n model of threading – Not all threads are visible to the kernel scheduler. User space code takes part in telling the kernel which thread to schedule. – The threads in a process have co-operative scheduling.  A thread can keep running for most of the time – careful programing required. Both groups had debated the models before taking up their approaches. Both methods are “ claimed” to be better than the other. Today, Linux seems to have better thread/process creation, spawning and context switching times.
  13. 13. Debugging support NetBSD has much better debugging support. – DDB – an in-kernel debugger – Supports kernel crash dumps – Supports KGDB (source level debug) – remote debugging. Linux – Patches available for crash dumps and KDB & KGDB (not available for all architectures) – Linux Trace Toolkit, UML etc. are also available methods. – Has “ Kernel Hacking” Option in kernel configuration  Allows debugging using “ Magic SysRQs” , Debugging of actions like memory allocations, file systems, highmem, stack overflows, page allocations etc.  Also allows stats collection for some modules. – Also, early printk() support is pretty recent.
  14. 14. Flash Devices and File Systems Support is poor in NetBSD Linux supports – Advanced MTD support ( device concatenation, FTL, NFTL ) – JFFS2 ( JFFS3 is being worked on ) – RAM file systems and ramdisk support – Supports initrd In NetBSD – OpenSource implementations of the above are not available. ( Commercial products are available ) – Results in considerable lead time in development. – Supports MFS ( not memory efficient ) : tmpfs is being worked upon – For boot time, it allows embedding a file-system into the kernel
  15. 15. KQueue : Event notification mechanism NetBSD supports a generic event notification framework – kqueues. Excellent replacement for select() / poll() APIs. – No need to pass entire descriptor set to each call. – On return, applications need not check all file descriptors for updates. – Reduces data copying ( fd list from kernel to user space and vice-versa ) Can handle multiple types of events. – Signals, Vnode/Process monitoring, Timer events etc. Can club multiple occurrences of an event into a single event New event types can be easily added. All with just two system calls !!
  16. 16. Build systems and configuration NetBSD is better – The entire system : kernel, compilers and tools, libraries and applications can be compiled ( native or cross platform ) using a single script – – The same script can build distributions, tarballs, archives and can also update existing systems and install fresh systems. – Adding new components to the build framework is extremely easy. Linux – Such systems exist but it is not as flexible as BSD Both NetBSD and Linux provide different configuration mechanisms. – NetBSD builds a device tree format. – Linux provides a GUI interface for configuring the kernel...
  17. 17. Other differences. Linux kernel code throws out lot of warnings during compilation. NetBSD is very clean in this aspect. Linux supports MMU Less operations. Loadable kernel modules – Better supported in Linux. Better device support in Linux With 2.6 kernel, the device driver model has vastly improved ( attend other talks at for more details ) Portability has been a design goal for NetBSD. Development models are vastly different :-) – NetBSD is more “ cathedral” like !! In Linux, you get answers easily :-)
  18. 18. Business related License (violation) is a serious cause of concern – BSD License is very liberal – One of the main reasons why telecom companies go for BSD – eg: Juniper ( JUNOS ) Protocol stacks and third party code – Are available usually for most BSDs and Linux. – To be more portable, they tend to ignore benefits of one OS New device support – Vendors of new devices like Network Processors, etc. release code only/mainly for Linux ( kernel modules etc. ). – Extra effort is required in such cases to port things to NetBSD. In case of Linux, extra time is required in selecting and integrating components of the system.
  19. 19. Links - One site for all NetBSD stuff - Kqueue design - SA design - Details of Linux 2.6 scheduler - A comparison - Started a Battle and cleanup !! - Using Linux Trace Toolkit - TMPFS project page - Linux Tiny home page
  20. 20. Finally ... Questions ?? Thanks to – Organizers for giving me a chance to speak at – NetBSD and Linux developers who helped me during my work – Linux kernel team for doing a wonderful job !! Special thanks to YOU for listening... You can contact me at :