netbsd and linux for embedded systems

20
NetBSD and Linux for Embedded Systems Mahendra M [email protected] http://www.infosys.com This work is licensed under a Creative Commons License http://creativecommons.org/licenses/by-sa/2.5/

Upload: mahendra-m

Post on 28-Jan-2015

112 views

Category:

Technology


0 download

DESCRIPTION

A very old talk comparing Linux and NetBSD. Talk delivered at FOSS.in/2005

TRANSCRIPT

Page 1: NetBSD and Linux for Embedded Systems

NetBSD and Linux for Embedded Systems

Mahendra [email protected]://www.infosys.com

This work is licensed under a Creative Commons Licensehttp://creativecommons.org/licenses/by-sa/2.5/

Page 2: NetBSD and Linux for Embedded Systems

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.

Page 3: NetBSD and Linux for Embedded Systems

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.

Page 4: NetBSD and Linux for Embedded Systems

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.

Page 5: NetBSD and Linux for Embedded Systems

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....

Page 6: NetBSD and Linux for Embedded Systems

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.

Page 7: NetBSD and Linux for Embedded Systems

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.

Page 8: NetBSD and Linux for Embedded Systems

Process Run-queue

Active

Expired

Task 1 Task 2 Task N

Task 1 Task 2 Task M

RunQueue

Doubly linked lists of tasks

[Priority: 1]

[Priority:140]

Migration Thread

...

...

...

...

From kernel/sched.c

Page 9: NetBSD and Linux for Embedded Systems

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.

Page 10: NetBSD and Linux for Embedded Systems

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.

Page 11: NetBSD and Linux for Embedded Systems

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

Page 12: NetBSD and Linux for Embedded Systems

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.

Page 13: NetBSD and Linux for Embedded Systems

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.

Page 14: NetBSD and Linux for Embedded Systems

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

Page 15: NetBSD and Linux for Embedded Systems

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 !!

Page 16: NetBSD and Linux for Embedded Systems

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 – build.sh

– 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...

Page 17: NetBSD and Linux for Embedded Systems

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 FOSS.in 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 :-)

Page 18: NetBSD and Linux for Embedded Systems

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.

Page 19: NetBSD and Linux for Embedded Systems

Links

http://linux-bangalore.org/blug/meetings/200401/scheduler-2.6.pdf

http://www.netbsd.org/ - One site for all NetBSD stuff

http://people.freebsd.org/~jlemon/papers/kqueue.pdf - Kqueue design

http://camars.kaist.ac.kr/courses/530/97/Readings/scheduler-act.pdf - SA design

http://josh.trancesoftware.com/linux/ - Details of Linux 2.6 scheduler

http://www.wasabisystems.com/gpl/linux.htm - A comparison

http://bulk.fefe.de/scalability/ - Started a Battle and cleanup !!

http://lkcd.sourceforge.net/

http://kgdb.sf.net/

http://oss.sgi.com/projects/kdb/

http://www.linuxjournal.com/article/3829 - Using Linux Trace Toolkit

http://www.opersys.com/LTT

http://netbsd-soc.sourceforge.net/projects/tmpfs/ - TMPFS project page

http://www.selenic.com/linux-tiny - Linux Tiny home page

Page 20: NetBSD and Linux for Embedded Systems

Finally ...

Questions ?? Thanks to

– Organizers for giving me a chance to speak at FOSS.in

– 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 :

[email protected]