Chapter 8
FreeBSD System Programming

Copyright(C) 2001,2002,2003,2004 Nathan Boeger and Mana Tominaga

8.1 FreeBSD 5.X

The FreeBSD project arrived at a significant milestone on January, 2003 with the release of the FreeBSD-5.x branch. Under development for nearly three years, the FreeBSD-5.x branch includes numerous changes to both the core kernel and the base system. For the most part these changes affect BSD administrators, not programmers, and thus will not affect any of the interfaces discussed in this book. Notable exceptions are discussed below.

8.2 Boot Layout

The first change is the organization of the boot files. The FreeBSD-5.x system has moved all modules and kernels under the /boot directory. This directory still holds all boot related configuration files, as in previous versions of FreeBSD. This seemingly minor change actually allows for more flexibility, because / and /boot (including all kernels and kernel modules) are now much easier to separate between devices.

8.3 Devfs

Our favorite new feature in FreeBSD-5.x is devfs. Prior to this branch, the /dev directory was filled with more than a thousand files. These files where device nodes and almost every supported device had an entry as a file in the /dev directory. As one can surmise, this directory became quite big and contained a lot of unnecessary files. For example, a system with IDE drives will contain device entries for scsi devices in /dev, even though the system does not have a scsi device. Such annoyances are gone with devfs. The only entries in /dev now are for devices that actually exist on the system. In fact, unlike prior releases /dev is only a mount point to a file system called devfs.

The devfs file system is similar to the proc file system. They both are mount points that contain files that don't exist on the hard disk. These files are created by the kernel and only appear as files. In fact, they are created after the system boots. Devfs allows much more flexibility because you can support multiple devfs mount points. For example if you wanted to chroot or jail a process, you don't have to create the /dev directory by hand, but instead, you can simply create a new mount point for your process and mount devfs.

Another benefit of devfs is that you can easily tell what devices a system has. All you need to do is just cd into the /dev directory and list the files. This is a very convenient way for a user to tell what devices are on a box, or more importantly, what devices have been detected.

8.4 a.out

FreeBSD-5.x series removes support for a.out binaries in the base system. You can still add support for a.out binaries, though. The reasoning behind this is that the a.out format is fairly old and the newer ELF format is more preferred. The ELF format is more flexible and more commonly used today.

8.5 gcc-3.2 tool chain

FreeBSD-5.x now uses the gcc-3.2 tool chain for the base system. This is a significant change: gcc-3.x is more ISO complaint, and its C++ ABI is much more stable. However, this might cause some growing pains for a few people. We have had issues with some code that required updating prior to compiling with gcc-3.x. If you use flex or yacc, make sure you have the latest versions, or patch your current version because they have known issues.

8.6 SMPng

FreeBSD-5.x has improved support for Shared Memory Multiprocessor (SMP) systems, under a project commonly referred to as SMPng (SMP next generation). Although previous versions of FreeBSD did have support for SMP, performance needed improvements.

8.7 Kernel Scheduler Entities (KSE)

Another new feature is the Kernel Scheduler Entities (KSE). KSE is a kernel-supported threading system conceptually similar to Scheduler Activations. On the kernel side, specifically, KSE consists of modifications to the FreeBSD scheduler; and on the user half is a POSIX threads implementation which utilizes the extra facilities provided by the kernel. However, as the changes are inextricable, you don't need special kernel configuration options to build a kernel with the KSE-related changes.

In order to use KSE in an application, you link it against libpthreads. These are not built by default, so first, build and install lipbthreads on your system. Then, in its makefiles, change the -pthread option to -lpthread and relink.

8.8 Conclusion

FreeBSD has matured over the years and now is one of the most stable operating system available. With the changes to improve SMP support and kernel threads, FreeBSD will continue the rich tradition of offering rock solid stability and high performance. Support for new platforms have been added, such as sparc64 and ia64. These new platforms will help BSD distributions to continue to offer a high quality open source alternative for many years to come.

Chapter 8
FreeBSD System Programming