Tuesday, January 06, 2009

Grokking Linux Modules


A lot of the functionality of Linux is contained in the kernel modules. These small pieces of software link the Linux kernel to your hardware, but it's not all that easy to get information about them if you are having trouble with a particular module.


The command lsmod will list all currently loaded modules.

The command modinfo will list general information about a particular module.

The command get_module will list specific information about a particular module as loaded in your kernel.

My system was generating an error message about the shpchp module. To see what other modules might be associated with it:

# lsmod | grep shpchp
shpchp 33556 0
pci_hotplug 29476 1 shpchp

To get the general information about the module:

# modinfo shpchp
filename: /lib/modules/2.6.27.5-desktop-2mnb/kernel/drivers/pci/hotplug/shpchp.ko.gz
license: GPL
description: Standard Hot Plug PCI Controller Driver
author: Dan Zink , Greg Kroah-Hartman , Dely Sy
alias: pci:v*d*sv*sd*bc06sc04i00*
depends: pci_hotplug
vermagic: 2.6.27.5-desktop-2mnb SMP mod_unload 686
parm: shpchp_debug:Debugging mode enabled or not (bool)
parm: shpchp_poll_mode:Using polling mechanism for hot-plug events or not (bool)
parm: shpchp_poll_time:Polling mechanism frequency, in seconds (int)

Here, the author of this module has provided a human-understandable description of the module (not all do), tells us what the license is, where the module can be found on our system internal alias of the device will be, and provides an email address or two if we need to report a bug with the module. The items marked param: are the configurable parameters of the module, but what are the values used on this system?

# get_module shpchp
initstate : live
refcnt : 0
Parameters:
shpchp_debug : Y
shpchp_poll_mode : N
shpchp_poll_time : 0
Sections:
.altinstr_replacement : 0xf8f66ab1
.altinstructions : 0xf8f68308

__bug_table : 0xf8f68397
__param : 0xf8f682cc

You can see that the descriptions under Parameters: match up with those shown by the modinfo command. So debugging is enabled; we are NOT using the poling mechanism for hot-plugging events; and we are not polling. But what does all that mean? If we believe all the Linux propaganda, we should be able to look at the source code and get a clue and get help from the maintainer. Well, no quite . . .

Lo and behold, if we search the several files that comprise the source code for the shpchp module, there is a reference to
/*
* Mask Global Interrupt Mask - see implementation
* note on p. 139 of SHPC spec rev 1.0
*/

After a little searching on Google, the Standard Hotplug Controller (SHPC) specification is hosted at PCI-SIG, the Peripheral Component Interconnect Standards Industry Group, at their website along with lots of documentation about the PCI bus. However, membership in the organization is required to download the document.

Fortunately for us, it doesn't seem relevant anyway since the error message is:

shpchp: shpc_init: cannot reserve MMIO region

and since MMIO is Memory Mapped Input Output, it seems that the driver cannot reserve the memory space it wanted. That means a bug report needs to be filed with the author (since a Google search of the error message turns up nothing useful). I'll post back here if I hear anything.

UPDATE

This message apparently is no big deal and is one of those "errors" that are really more informational warnings than "errors", but it was interesting learning about some of the workings of the OS.


No comments: