Measuring - Linux Embedded systems

For each directory in the kernel build, each file is compiled into a .o file that is then linked together with the other .o files in the directory into a built-in.o file. The subdirectories’ built-in.o files are gathered together into a smaller number of built-in.o files that the kernel build process then links into the final kernel image, along with some other supporting code to get the kernel booting and the contents of the initramfs (remember, even if you never include an initramfs, the kernel still creates a small empty one that consumes a few bytes). This makes getting a measurement of what components are taking the most code space a matter of scanning the kernel directory and looking at the size of the built-in.o files. Here’s a simple one-line command that accomplishes that task on a directory that contains a kernel that has been compiled:

This produces output that looks similar to this (your system will have different numbers because it was built with a different compiler with different options; a match is unlikely):

The command looks for all the built-in.o files and then uses the size utility to print out the sizes of the different sections. You may notice that the sum of all built-in.o files is far greater than the size of the final kernel image. This is a result of the built-on.o files of parent directories containing builtin. o files of their subdirectories. To find out the size of the final kernel image, use the following command from the top of the kernel directory after building:

Because the output from the size command is a little cryptic, the following explains what each column means:

  • text: This section is the code of your program or object file. No string constants are stored in this section, despite a name that leads you to believe the contrary.
  • data: This section contains variables that are initialized to a constant value.
  • bss: This section contains global variables that are initially set to zero. BSS means Block Started by Symbol and refers to file layout from the days of yore.
  • dec / hex: These two columns have the sum of text, data, and bss, displayed in decimal and hex formats.

The following code snippet shows all these parts in context so you can get a better understanding of what goes where:

A few items in the list are the core of the operating system; they serve as the infrastructure for the rest of the kernel. The size of these elements can’t be changed much by twiddling with the kernel build parameters:

  • arch/<your arch>/<directory>/built-in.o: These directories are specific to your board and processor and contain the enabling code the rest of the kernel needs to do things like handle interrupts and manage memory. Most of this code is in assembler and is very low level, even for an operating system.
  • drivers/base/built-in.o: This file contains the infrastructure code used by the rest of the drivers handled by the kernel. Even if you have a few drivers loaded, this code is required.
  • init/built-in.o: This is the initialization code for the kernel, or the equivalent of the main() function in a C program. Much of the code here concerns itself with gathering the parameters from the user at boot time and initializing the system.
  • kernel/built-in.o: This is the core of the operating system. The scheduler, interrupt handling, process, and thread handling all happen here. You can do some things to reduce this part of the kernel, such as removing debugging and kernel-hacking features.
  • mm/built-in.o: The code in this directory handles memory management. If your system doesn’t have paged, virtual memory, removing that feature reduces the size of this component appreciably.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

Linux Embedded systems Topics