Table Of Contents:

Description

This page describes the "DO_PRINTK" feature. This is a small tweak on the already-supported printk configuration option in the kernel, which allows a developer to configure whether the kernel will be compiled with or without printk messages.

This feature allows you to turn off printk messages, while preserving the printk function itself. Then, you can turn on the printk messages from an individual file, or set of files. This allows you greater granularity of control over the printk messages that are compiled into the kernel.

Rationale

Control over the printk messages in the kernel is important because the kernel messages comprise a substantial portion of the overall kernel size (ranging from 5 to 10% of overall kernel image size.)

The kernel (as of this writing, version 2.6.17) already supports an option to turn off all printk messages. However, sometimes this is too much. Sometimes, an embedded developer may want to see a few printk messages from specific files or routines, while still not enabling every single printk message in the kernel. The DO_PRINTK feature provides this fine-grained control.

Downloads

Patch

How To Use

To use DO_PRINTK, perform the following steps:

Ways to force printks to be preserved

There are actually several ways to get DO_PRINTK defined for a particular file:



Sample Results

Examples of use with measurement of the effects.

Case Study 1

On an x86 machine, using kernel.org 2.6.17.4 kernel, I got the results below, using the DO_PRINTK feature in combination with the PRINTK configuration option.

Here is the key for the following tables:

kernel

CONFIG_PRINTK_FUNC

CONFIG_PRINTK

DO_PRINTK used with files...

Notes

func.yes-printk.yes-do.na/vmlinux

yes

yes

not applicable

This is a pretty regularly-configured kernel (used for baseline in first set of comparisons)

func.yes-printk.no-do.none/vmlinux

yes

no

none

Turn off all messages, but leave printk function in place

func.no-printk.na-do.na/vmlinux

no

not applicable

not applicable

Turn off all messages and remove printk function

func.yes-printk.no-do.init.star/vmlinux

yes

no

init/*.c

Turn off most messages, preserve messages from files in 'init' source directory

func.yes-printk.no-do.init.main.c/vmlinux

yes

no

init/main.c

Turn off most messages, preserve messages from init/main.c

Summary of image size results

Kernel sizes (sorted by decreasing size):

text

data

bss

dec

hex

filename

2621433

564958

137072

3323463

32b647

func.yes-printk.yes-do.na/vmlinux (a.k.a. baseline)

2376317

564958

137072

3078347

2ef8cb

func.yes-printk.no-do.init.star/vmlinux

2375508

564958

137072

3077538

2ef5a2

func.yes-printk.no-do.init.main.c/vmlinux

2374733

564958

137072

3076763

2ef29b

func.yes-printk.no-do.none/vmlinux (a.k.a. printk-off baseline)

2371463

564514

120688

3056665

2ea419

func.no-printk.na-do.na/vmlinux

Image size results compared to baseline

The following tables show the image sizes of various kernels compared with a baseline kernel. The baseline kernel has a fairly normally i386 configuration, with CONFIG_PRINTK_FUNC=y and CONFIG_PRINTK=y.

Size delta results:

section

baseline/vmlinux

func.no-printk.na-do.na/vmlinux

change

percent

text

2621433

2371463

-249970

-9%

data

564958

564514

-444

0%

bss

137072

120688

-16384

-11%

total

3323463

3056665

-266798

-8% *

* Full size reduction using printk elimination is 266K or 8% of vmlinux


Size delta results:

section

baseline/vmlinux

func.yes-printk.no-do.init.main.c/vmlinux

change

percent

text

2621433

2375508

-245925

-9%

data

564958

564958

0

0%

bss

137072

137072

0

0%

total

3323463

3077538

-245925

-7%


Size delta results:

section

baseline/vmlinux

func.yes-printk.no-do.init.star/vmlinux

change

percent

text

2621433

2376317

-245116

-9%

data

564958

564958

0

0%

bss

137072

137072

0

0%

total

3323463

3078347

-245116

-7%


Size delta results:

section

baseline/vmlinux

func.yes-printk.no-do.none/vmlinux

change

percent

text

2621433

2374733

-246700

-9%

data

564958

564958

0

0%

bss

137072

137072

0

0%

total

3323463

3076763

-246700

-7%


Image size results compared to 'printk-off' baseline

The following tables show the image sizes of various kernels compared with a baseline kernel. The baseline kernel has 'printk-off' configuration, with CONFIG_PRINTK_FUNC=y and CONFIG_PRINTK=n.

Size delta results:

section

func.yes-printk.no-do.none/vmlinux

func.no-printk.na-do.na/vmlinux

change

percent

text

2374733

2371463

-3270 *

0%

data

564958

564514

-444 *

0%

bss

137072

120688

-16384 *

-11%

total

3076763

3056665

-20098 *

0%

* Size of printk function alone is about 3.6k in image and 20k in static memory


Size delta results:

section

func.yes-printk.no-do.none/vmlinux

func.yes-printk.no-do.init.main.c/vmlinux

change

percent

text

2374733

2375508

775 *

0%

data

564958

564958

0

0%

bss

137072

137072

0

0%

total

3076763

3077538

775

0%

* Size of printk messages from a single C file (init/main.c in this case) was 775 bytes. Obviously, this is heavily dependent on the number of printk calls and the size of the messages in that file.


Size delta results:

section

func.yes-printk.no-do.none/vmlinux

func.yes-printk.no-do.init.star/vmlinux

change

percent

text

2374733

2376317

1584

0%

data

564958

564958

0

0%

bss

137072

137072

0

0%

total

3076763

3078347

1584

0%


Size delta results:

section

func.yes-printk.no-do.none/vmlinux

func.yes-printk.yes-do.na/vmlinux

change

percent

text

2374733

2621433

246700

10%

data

564958

564958

0

0%

bss

137072

137072

0

0%

total

3076763

3323463

246700

8%


Case Study 2

[need to post PPC and MIPS results here also]

Status

Future Work/Action Items

Here is a list of things that could be worked on for this feature:

DoPrintk (last edited 2008-05-07 18:21:58 by localhost)