Kernel Programming Tips

From ChronOS Linux

Revision as of 23:00, 25 April 2011 by Aclindsa (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Kernel Programming Tips

Here are a few tools and settings you may find useful for kernel programming.

Serial Consoles

In the event of a kernel panic, the result oops and panic messages are not saved to disk, and are therefore unavailable on reboot. The easiest way to solve this is to use a serial console to a remote machine to display and save the data there. To do this, you will need to machines equipped with serial ports (or serial to USB adapters) and a mull-modem cable. Use minicom (for Linux) to listen on the remote machine. To send from the local machine, assuming your serial cable is ttyS0, add the following to your kernel line in grub

console=ttyS0,115200n8 console=tty0

Netconsole

If a serial console is not available due to lack of a serial port, netconsole is another option. It performs most of the same functions, but using UDP over ethernet rather than a serial port. The Ubuntu kernel team has an excellent tutorial here.

Note that on some Windows machines, while running netcat you may get the following message:

Invalid connection to [local address] from <UNKNOWN> [remote address]"

The solution is to remove the IP address from the command - i.e.

nc.exe -l -u -p 6666 > netconsole.txt

instead of

nc.exe -l -u -p 6666 192.168.1.100 > netconsole.txt.

Sysctl

There are several sysctl variables found in /proc/sys/kernel that are useful for kernel debugging. NOTE: You cannot sudo echo a value into them, you have to either sudo bash or sudo sh -c "echo ..." to set them.

  • sched_rt_runtime_us determines the amount of system bandwidth to devote to real-time tasks. This is enabled even if you disable group scheduler for RT tasks. Set to -1 to effectively disable the periodic bandwidth server.
  • printk determines what level of printk goes to the console. If you are using a serial console or netconsole, you most likely want it set to 8 (send everything).
  • panic determines the amount of time (in seconds) between a kernel panic and a reboot.
  • panic_on_oops is a boolean value that determines whether an oops causes a kernel panic.
  • printk_ratelimit and printk_ratelimit_burst are both used to limit the rate at which printks can be sent to the console. Set them to 0 if you want no ratelimiting.

In ChronOS /proc/sys/chronos/clear_on_sched_set< controls whether the scheduler statistics in /proc/chronos_sched are refreshed when the scheduler is reset.


Back to main page

Personal tools