What Is the Kernel?

“The file /bsd is OpenBSD’s kernel. Next question?”

That’s technically correct, but not exactly useful. A more general description is that “The kernel is the interface that links applications and the hardware.” That’s not a complete definition, but it’s good enough.

The kernel allows programs to write data to disk drives and to the network, and it gives instructions to the CPU and shuffles bits into memory. When you open a web page, the browser application asks the kernel to fetch the data it displays.

Some kernel responsibilities exceed this definition. For example, the kernel handles network connectivity, including forwarding packets from one interface to another if needed. The packet-filtering rules run in the kernel (although the rules are managed by applications). The kernel handles disk redundancy. And the kernel also handles all sorts of things that don’t impact applications but are integral to a functioning system.

A simplified view is to think of the kernel as the program that handles all the low-level functions, which is close enough to give you an idea of what the kernel does.

Along with kernel, you’ll also hear the term userland. Userland is everything in the system that isn’t the kernel. Your shells, libraries, and applications are all part of userland.

Kernel Messages

The kernel issues messages to userland. These include hardware attaching and detaching alerts, warnings from device drivers, and system boot messages. If you’re logged on to the system console in text mode, you might notice these messages.

To review kernel messages, you can watch the console, check the system logs (as discussed in Chapter 15), or use dmesg(8).

OpenBSD has a system message buffer, where it sends messages from the kernel. These messages are usually copied to the system logger, but they’re also accessible via dmesg.

The system message buffer is circular. As it fills up, the oldest messages are deleted to make room for new ones. Run dmesg to view it.

Startup Messages

One common question is “What hardware did your kernel find?” If the kernel handles all the device drivers and other hardware support, the list of devices found should include all the supported hardware in the system.

While the system message buffer is circular, OpenBSD copies the boot-time system messages into /var/run/dmesg.boot. Here are the boot messages from one of my test systems.

OpenBSD 5.2-current (GENERIC) #287: Tue Aug 21 18:15:00 MDT 2013
    [email protected]:/usr/src/sys/arch/i386/compile/GENERIC
cpu0: AMD Opteron(tm) Processor 4184 ("AuthenticAMD" 686-class, 512KB L2 cache) 2.80 GHz
cpu0:FPU,V86,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,
PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,NXE,MMXX,FFXSR,LONG,3DNOW2,3DNOW,SSE3,CX16,
POPCNT,LAHF,ABM,SSE4A
real mem  = 267907072 (255MB)
avail mem = 252616704 (240MB)
…

The first line lists the version of OpenBSD, the kernel name and version, the date the kernel was built, as well as the machine and directory where the kernel was built and who built it. This machine runs an official OpenBSD i386 snapshot, built by Theo de Raadt.

We then see some specifics on the processor. Those familiar with AMD will note that this is a 64-bit amd64 processor. I chose to run the 32-bit i386 version of OpenBSD, because that’s the installation disk I had handy.

This system came with 256MB of RAM, but 1MB is lost due to hardware-level weirdness. OpenBSD sees 255MB, and 240MB are available to programs other than the kernel at this moment. The kernel might use some of that memory later.

Device Attachments

The kernel then explores the hardware. When it finds hardware that matches a device driver, it attaches the device driver to the hardware.

mainbus0 at root
bios0 at mainbus0: AT/286+ BIOS, date 10/13/09, BIOS32 rev. 0 @ 0xfd780, SMBIOS rev. 2.4 @ 0xe0010 (98 entries)
bios0: vendor Phoenix Technologies LTD version "6.00" date 10/13/2009
bios0: VMware, Inc. VMware Virtual Platform
acpi0 at bios0: rev 2

OpenBSD found the main system bus, mainbus0, which is a bit odd because it’s not actually a piece of hardware. The kernel creates this logical device as a point for all other devices to attach to. It’s not the only logical device driver, but it’s present on every machine.

The bios0 device, for the hardware BIOS, isn’t terribly interesting either. You know the hardware has some kind of BIOS. We covered configuring your system BIOS back in Chapter 3, and you haven’t needed to look at it since. Similarly, the acpi0 device represents the Advanced Configuration and Power Interface (ACPI). If it needed any configuration, you took care of that after unpacking the system from the shipping box.

Connections and Numbering

Now we get into real hardware.

pci0 at mainbus0 bus 0: configuration mode 1 (bios)
pchb0 at pci0 dev 0 function 0 "Intel 82443BX AGP" rev 0x01
ppb0 at pci0 dev 1 function 0 "Intel 82443BX AGP" rev 0x01
pci1 at ppb0 bus 1
piixpcib0 at pci0 dev 7 function 0 "Intel 82371AB PIIX4 ISA" rev 0x08
pciide0 at pci0 dev 7 function 1 "Intel 82371AB IDE" rev 0x01: DMA, channel 0 configured to compatibility, channel 1 configured to compatibility

The first PCI bus, device pci0, is attached to mainbus0 in the slot bus 0. The kernel then finds a device it identifies as pchb0, and attaches it to the PCI bus as device 0. Don’t know what pchb0 is? Use man pchb to identify this as a PCI host bridge. dmesg gives you the part number.

Next is the device ppb0 (a PCI/PCI bridge, per ppb(4)), attached to PCI bus 0 as device 1. This is followed by another PCI bus, pci1, attached to the ppb device. Each instance of a device is assigned a number, starting with zero. Our tenth PCI bus would be device pci9. (There’s no technical requirement for sequential numbering, but the kernel follows this rule unless you tell it otherwise.)

If you dig through dmesg.boot, you’ll see that every device is plugged into another device somewhere. For example, here’s my keyboard.

wskbd0 at pckbd0: console keyboard, using wsdisplay0

The keyboard wskbd0 is attached to device pckbd0.

pckbc0 at isa0 port 0x60/5
pckbd0 at pckbc0 (kbd slot)

Device pckbd0 is attached to device pckbc0, which, in turn, is plugged into the isa0 device, which is the ISA bus.

isa0 at piixpcib0

The ISA bus is connected to the Intel PIIX4 ISA bridge.

piixpcib0 at pci0 dev 7 function 0 "Intel 82371AB PIIX4 ISA" rev 0x08

And this bridge is then hooked to PCI bus 0.

OpenBSD finds devices from the root outward, which means that everything is listed in the reverse order from what you’ve just seen. You get a list of which devices are attached to a device, and then the devices attached to those devices. You can backtrack starting with the end device, but that’s kind of annoying.

Using dmassage to View Installed Devices

I find the dmassage package most useful for identifying exactly what’s attached to what devices, although that’s not its only function. Install dmassage like any other package, and then run it with -t to display installed devices as a tree, like this:

root
 |-mainbus0
 |  |-bios0
 |  |-cpu0
 |  |-ioapic0
 |  |-pci0
 |  |  |-mpi0
 |  |  |  -scsibus1
 |  |  |     -sd0
 |  |  |-pchb0
 |  |  |-pciide0
 |  |  |  -atapiscsi0
 |  |  |     -scsibus0
 |  |  |        -cd0
…

While this information may not be immediately useful, dmassage illustrates how devices are interconnected on your system, which may become important later.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.103.77