From: eLinux.org

Optimize RC Scripts

Contents

RC Scripts Speed-Up

This material was excerpted from a document with the following copyright
statement:

  • Copyright 2002, 2003, 2004 Sony Corporation
  • Copyright 2002, 2003, 2004 Matsushita Electric Industrial Co., Ltd.
  • Copyright 2002-2004 by MontaVista Software.

It was submitted as input to the forum by Sony Corporation, on April 8,
2004.

Introduction

The init scripts of the existing Embedded Linux distribution are the
shell scripts to be executed with ’bash’. To reduce system boot time,
some modifications to be applied to the scripts and faster shell
interpreter to be used. The document describes the BusyBox
optimizations; the init scripts modifications; how to reduce the system
boot time using the optimized BusyBox, and to optimize shell scripts for
BusyBox. Also, the benchmark procedure and optimization results are
described.

Purpose of Feature

The init scripts execution time, i.e. the time interval between the
start of the init process and the start of user applications, must be
reduced.

Feature requirements

  • The modified init scripts must be run with “bash” as well as the
    BusyBox “ash” shell.
  • The execution time of the init scripts and the total system boot
    time must be reduced.
  • The guide to speed-optimization of the init scripts must be
    provided.

Acceptance Criteria

  • The modified init scripts are able to successfully run with “bash”
    as well as the BusyBox “ash” shell.
  • The execution time of the init scripts with BusyBox is reduced in
    the comparison with the original init scripts with “bash”; the total
    system boot time is not greater then 5 sec.
  • The guide to speed-optimization of the init scripts is available.

BusyBox Optimization

Since ’bash’ and GNU utilities are very heavy applications, BusyBox is
useful to reduce system boot time. BusyBox combines tiny versions of
many common UNIX utilities (shellutils, fileutils, etc.) into a single
small executable. The commands and utilities included in BusyBox are
divided into the classes: built-ins and applets. The built-ins are
simply invoked as functions, and applets are invoked by means of the
’fork/exec’ system calls. Also, BusyBox scripts can use external
commands and utilities.

Usage of the BusyBox built-ins is rather than the applets and external
commands by performance reasons, because the ’fork/exec’ system calls
are very heavy and they make the main contribution to shell
inefficiency. Because the original BusyBox is only size-optimized, the
following features must be considered from the performance standpoint:

  • Each command including built-ins within pipes are forked.
  • Each back-quoted command is forked.
  • The ’echo’, ’test’, and ’[’ commands and other most frequent
    commands in the scripts are implemented as applets.

To avoid such drawbacks, we optimized BusyBox 1.00-pre3 in order to
speed up script execution. The BusyBox optimizations for the ’ash’ shell
are listed below:

  • The set of shell commands and utilities is implemented as built-ins.
  • The invoked ’cat’ command at the beginning of pipes is eliminated
    and file descriptors are passed only into the next command of the
    pipe.

The following shell commands and utilities are implemented as built-ins
in the optimized BusyBox ’ash’ shell: ’,’, ’:’,’[’, ’alias’, ’break’,
’cd’, ’chdir’, ’continue’, ’echo’, ’eval’, ’exec’, ’exit’, ’export’,
’false’, ’kill’, ’let’, ’local’, ’pidof’, ’pwd’, ’read’, ’readonly’,
’return’, ’set’, ’shift’, ’test’, ’times’, ’trap’, ’true’, ’type’,
’ulimit’, ’umask’, ’unalias’, ’unset’, ’wait’.

NOTES:

  • This need seems to be addressed for all applets at least in Busybox
    1.1.1 (and perhaps in earlier versions). The “Shells -> Standalone
    shell” configuration setting is supposed to address this need. See
    the menuconfig help for details.
  • In newer BusyBox releases (1.13.0 and maybe even earlier releases)
    the most frequently used applets, ‘test’, ‘echo’ can be configured
    as being ‘built-in’. The newer BusyBox releases are also smaller in
    size and can save some extra milliseconds in execution of startup
    scripts.

Known Problems

The following BusyBox commands work in the different manner from the
’bash’ commands and GNU utilities: ’nice’, ’find’, ’mount’, ’umount’,
’init’, ’halt’, ’shutdown’, ’syslogd’, ’klogd’, ’hwclock’, ’cron’,
’anacron’, ’crontab’, ‘pidof’.

If the different behaviour is unwanted or these BusyBox applets do not
provide the necessary utility, use the external commands instead of
them, or simply do not configure them as applets.

How to Optimize Init Scripts for BusyBox

Follow the rules listed below to reduce execution time for the init
scripts:

  • Do not use unnecessary codes in the scripts.
  • Replace external commands and utilities with the BusyBox built-ins
    as far as possible.
  • Do not use the piped commands as far as possible.
  • Reduce the number of commands within a pipe.
  • Do not use the back-quoted commands as far as possible.

The main goal of such optimization is to reduce the number of the
“fork/exec” calls during a script execution.

Examples of Init Scripts Optimization

The following examples demonstrate how the recommendations of shell
scripts optimization can be applied to the init scripts.

Unnecessary codes elimination

This example demonstrates the elimination of duplicate codes from the
“mountswap.sh” and “checkrootfs.sh” scripts: the command “swapon” runs
one time in the modified scripts.

  • Before optimization:

checkrootfs.sh:

  1. if [ "$FSCKSWAP" !== no ]
  2. then
  3. if [ -x /sbin/swapon ]
  4. then
  5. mount -n /proc
  6. if ! grep -qs resync /proc/mdstat
  7. then
  8. [ "$VERBOSE" !== no ] && echo "Activating swap..."
  9. swapon -a 2> /dev/null
  10. fi
  11. umount -n /proc
  12. fi
  13. fi

mountswap.sh:

  1. grep -qs resync /proc/mdstat || swapon -a 2> /dev/null
  • After optimization:

checkrootfs.sh:

mountswap.sh:

  1. if [ "$FSCKSWAP" !== "no" ]; then
  2. if [ ! grep -qs resync /proc/mdstat ]
  3. then
  4. log_status_msg "Starting $DESC: " -n
  5. log_status_msg "$BASENAME1" -n
  6. $DAEMON1 $ARGS1
  7. RET==$?
  8. if [ $RET -eq 0 ]; then
  9. log_success_msg ". " -n
  10. else
  11. log_failure_msg " failed ($RET: $ERROR)."
  12. return 1
  13. fi
  14. fi
  15. fi

Built-in usage

This example demonstrates usage of the “echo” built-in instead of the
external command “printf” in the “nfs-common” script.

  • Before optimization:

nfs-common:

  1. printf "Starting $DESC:"
  2. printf " statd"
  • After optimization: init-functions:
  1. log_status_msg() {
  2. if [ "$1" !== "" ] && [ "$1" !== "-n" ]
  3. then
  4. if [ "$2" == "-n" ]
  5. then echo -n "$1"
  6. else echo "$1"
  7. fi
  8. fi
  9. return 0
  10. }

nfs-common.sh:

  1. log_status_msg "Starting $DESC: " -n
  2. log_status_msg "$BASENAME1" ?n

Piped command usage

This example demonstrates the elimination of the piped commands (the
example is hypothetic, because the init scripts do not contain such
inefficiencies).

  • Before optimization:
  1. cat /proc/mounts | grep ext3 | cut -d -f2,3
  • After optimization:
  1. sed -n s/^[^ ]* \([^ ]*\) \(ext3\) .*$/\1 \2/p /proc/mounts

This example demonstrates the reduction of the commands in the pipe (the
example is also hypothetic). Note, the optimized version does not invoke
the “fork” call, because the “cat” optimization is used.

  • Before optimization:
  1. cat /etc/passwd | grep user | wc -l | tr -d ’’ | sed s/ *//’
  • After optimization:
  1. cat /etc/passwd | grep -c user

Back-quoted command usage

This example demonstrates the back-quoted command elimination (the
example is hypothetic, because the init scripts do not contain such
inefficiencies).

  • Before optimization:
  1. if [ "‘grep rpcuser /etc/passwd‘" !== "" ]
  2. then
  3. echo "rpcuser"
  4. else
  5. echo "no rpcuser"
  6. fi
  • After optimization:
  1. if grep rpcuser /etc/passwd >/dev/null
  2. then
  3. echo "rpcuser"
  4. else
  5. echo "no rpcuser"
  6. fi

Init Scripts Optimization

The existing init scripts were modified to reduce their execution time
following the recommendations, which are described above.

Benchmark Environment and Procedure

To estimate the results of the init script optimization and the BusyBox
usage, the TI OMAP 1510 Innovator platform is used. To measure the
duration of the kernel loading, the KFI support is used (to measure the
init script execution time, the KFI support is disabled). The
measurements are performed on the systems with/without XIP support To
take measurements without the XIP support, the following kernel
configuration is used:

  1. CONFIG_ARM==y
  2. CONFIG_UID16==y
  3. CONFIG_RWSEM_GENERIC_SPINLOCK==y
  4. CONFIG_EXPERIMENTAL==y
  5. CONFIG_ADVANCED_OPTIONS==y
  6. CONFIG_MODULES==y
  7. CONFIG_KMOD==y
  8. CONFIG_ARCH_OMAP==y
  9. CONFIG_OMAP_INNOVATOR==y
  10. CONFIG_INNOVATOR_MISSED_IRQS==y
  11. CONFIG_ARCH_OMAP1510==y
  12. CONFIG_CLOCK_COUNTS_DOWN==y
  13. CONFIG_CPU_32==y
  14. CONFIG_CPU_ARM925T==y
  15. CONFIG_CPU_ARM925_CPU_IDLE==y
  16. CONFIG_CPU_ARM925_I_CACHE_ON==y
  17. CONFIG_CPU_ARM925_NON_STREAMING_ON==y
  18. CONFIG_CPU_ARM925_D_CACHE_ON==y
  19. CONFIG_CPU_32v4==y
  20. CONFIG_KERNEL_START==0xc0000000
  21. CONFIG_ZBOOT_ROM_TEXT==0
  22. CONFIG_ZBOOT_ROM_BSS==0
  23. CONFIG_NET==y
  24. CONFIG_SYSVIPC==y
  25. CONFIG_SYSCTL==y
  26. CONFIG_MAX_USER_RT_PRIO==100
  27. CONFIG_MAX_RT_PRIO==0
  28. CONFIG_FPE_NWFPE==m
  29. CONFIG_KCORE_ELF==y
  30. CONFIG_BINFMT_AOUT==m
  31. CONFIG_BINFMT_ELF==y
  32. CONFIG_OMAP1510_PM==y
  33. CONFIG_DPM==y
  34. CONFIG_BOOT_FREQ==y
  35. CONFIG_OMAP_ARM_168MHZ==y
  36. CONFIG_OMAP1510_DPM==y
  37. CONFIG_INNOVATOR_DPM==y
  38. CONFIG_CMDLINE=="mem==32M console==ttyS0,115200n8 noinitrd root==/dev/null rootflags==physaddr==0x0260000"
  39. CONFIG_ALIGNMENT_TRAP==y
  40. CONFIG_PREEMPT==y
  41. CONFIG_LOCK_BREAK==y
  42. CONFIG_MTD==y
  43. CONFIG_MTD_PARTITIONS==y
  44. CONFIG_MTD_CONCAT==y
  45. CONFIG_MTD_CHAR==y
  46. CONFIG_MTD_BLOCK==y
  47. CONFIG_MTD_CFI==y
  48. CONFIG_MTD_GEN_PROBE==y
  49. CONFIG_MTD_CFI_ADV_OPTIONS==y
  50. CONFIG_MTD_CFI_NOSWAP==y
  51. CONFIG_MTD_CFI_GEOMETRY==y
  52. CONFIG_MTD_CFI_B2==y
  53. CONFIG_MTD_CFI_I1==y
  54. CONFIG_MTD_CFI_INTELEXT==y
  55. CONFIG_MTD_CFI_AMDSTD==y
  56. CONFIG_MTD_OMAP==y
  57. CONFIG_MTD_OMAP_0==y
  58. CONFIG_MTD_OMAP_1==y
  59. CONFIG_BLK_DEV_LOOP==m
  60. CONFIG_BLK_DEV_RAM==y
  61. CONFIG_BLK_DEV_RAM_SIZE==4096
  62. CONFIG_BLK_DEV_INITRD==y
  63. CONFIG_PACKET==m
  64. CONFIG_NETFILTER==y
  65. CONFIG_UNIX==y
  66. CONFIG_INET==y
  67. CONFIG_IP_MULTICAST==y
  68. CONFIG_IP_PNP==y
  69. CONFIG_NETDEVICES==y
  70. CONFIG_NET_ETHERNET==y
  71. CONFIG_NET_VENDOR_SMC==y
  72. CONFIG_SMC9194==y
  73. CONFIG_PPP==m
  74. CONFIG_PPP_MULTILINK==y
  75. CONFIG_PPP_ASYNC==m
  76. CONFIG_PPP_DEFLATE==m
  77. CONFIG_PPPOE==m
  78. CONFIG_IRDA==m
  79. CONFIG_IRLAN==m
  80. CONFIG_IRNET==m
  81. CONFIG_IRCOMM==m
  82. CONFIG_OMAP_SIR==m
  83. CONFIG_INPUT==m
  84. CONFIG_INPUT_KEYBDEV==m
  85. CONFIG_INPUT_MOUSEDEV==m
  86. CONFIG_INPUT_MOUSEDEV_SCREEN_X==240
  87. CONFIG_INPUT_MOUSEDEV_SCREEN_Y==320
  88. CONFIG_INPUT_EVDEV==m
  89. CONFIG_VT==y
  90. CONFIG_VT_CONSOLE==y
  91. CONFIG_SERIAL==y
  92. CONFIG_SERIAL_CONSOLE==y
  93. CONFIG_UNIX98_PTYS==y
  94. CONFIG_UNIX98_PTY_COUNT==256
  95. CONFIG_I2C==m
  96. CONFIG_I2C_ALGOBIT==m
  97. CONFIG_I2C_OMAP1510==m
  98. CONFIG_I2C_CHARDEV==m
  99. CONFIG_I2C_PROC==m
  100. CONFIG_SENSORS==y
  101. CONFIG_SENSORS_OTHER==y
  102. CONFIG_SENSORS_EEPROM==m
  103. CONFIG_WATCHDOG==y
  104. CONFIG_OMAP_WATCHDOG==m
  105. CONFIG_OMAP_RTC==m
  106. CONFIG_RV5C387_RTC==m
  107. CONFIG_RV5C387_RTC==m
  108. CONFIG_VIDEO_DEV==m
  109. CONFIG_VIDEO_PROC_FS==y
  110. CONFIG_AUTOFS4_FS==m
  111. CONFIG_EXT3_FS==m
  112. CONFIG_JBD==m
  113. CONFIG_FAT_FS==m
  114. CONFIG_MSDOS_FS==m
  115. CONFIG_VFAT_FS==m
  116. CONFIG_JFFS_FS==m
  117. CONFIG_JFFS_FS_VERBOSE==0
  118. CONFIG_JFFS2_FS==y
  119. CONFIG_JFFS2_FS_DEBUG==0
  120. CONFIG_CRAMFS==y
  121. CONFIG_CRAMFS_LINEAR==y
  122. CONFIG_CRAMFS_LINEAR_XIP==y
  123. CONFIG_ROOT_CRAMFS_LINEAR==y
  124. CONFIG_TMPFS==y
  125. CONFIG_RAMFS==y
  126. CONFIG_PROC_FS==y
  127. CONFIG_DEVPTS_FS==y
  128. CONFIG_EXT2_FS==m
  129. CONFIG_NFS_FS==y
  130. CONFIG_NFS_V3==y
  131. CONFIG_NFSD==m
  132. CONFIG_NFSD_V3==y
  133. CONFIG_SUNRPC==y
  134. CONFIG_LOCKD==y
  135. CONFIG_LOCKD_V4==y
  136. CONFIG_SMB_FS==m
  137. CONFIG_MSDOS_PARTITION==y
  138. CONFIG_SMB_NLS==y
  139. CONFIG_NLS==y
  140. CONFIG_NLS_DEFAULT=="iso8859-1"
  141. CONFIG_NLS_CODEPAGE_437==m
  142. CONFIG_PC_KEYMAP==y
  143. CONFIG_FB==y
  144. CONFIG_DUMMY_CONSOLE==y
  145. CONFIG_FB_OMAP==y
  146. CONFIG_FBCON_ADVANCED==y
  147. CONFIG_FBCON_CFB16==y
  148. CONFIG_FBCON_FONTWIDTH8_ONLY==y
  149. CONFIG_FBCON_FONTS==y
  150. CONFIG_FONT_8x8==y
  151. CONFIG_FONT_ACORN_8x8==y
  152. CONFIG_SOUND==m
  153. CONFIG_SOUND_OMAP==m
  154. CONFIG_SOUND_OMAP_AIC23==m
  155. CONFIG_INNOVATOR_TS==y
  156. CONFIG_MMC==m
  157. CONFIG_OMAP_MMC==m
  158. CONFIG_INSTANT_ON==y
  159. CONFIG_DEFAULT_LPJ==414720
  160. CONFIG_INSTANT_ON_LPJ==414720
  161. CONFIG_FRAME_POINTER==y
  162. CONFIG_DEBUG_INFO==y
  163. CONFIG_DEBUG_KERNEL==y
  164. CONFIG_MAGIC_SYSRQ==y
  165. CONFIG_DEBUG_BUGVERBOSE==y
  166. CONFIG_DEBUG_ERRORS==y
  167. CONFIG_ZLIB_INFLATE==y
  168. CONFIG_ZLIB_DEFLATE==y

To take measurements with the XIP support, the following kernel
configuration is used:

  1. CONFIG_ARM==y
  2. CONFIG_UID16==y
  3. CONFIG_RWSEM_GENERIC_SPINLOCK==y
  4. CONFIG_EXPERIMENTAL==y
  5. CONFIG_ADVANCED_OPTIONS==y
  6. CONFIG_MODULES==y
  7. CONFIG_KMOD==y
  8. CONFIG_ARCH_OMAP==y
  9. CONFIG_OMAP_INNOVATOR==y
  10. CONFIG_INNOVATOR_MISSED_IRQS==y
  11. CONFIG_ARCH_OMAP1510==y
  12. CONFIG_CLOCK_COUNTS_DOWN==y
  13. CONFIG_CPU_32==y
  14. CONFIG_CPU_ARM925T==y
  15. CONFIG_CPU_ARM925_CPU_IDLE==y
  16. CONFIG_CPU_ARM925_I_CACHE_ON==y
  17. CONFIG_CPU_ARM925_NON_STREAMING_ON==y
  18. CONFIG_CPU_ARM925_D_CACHE_ON==y
  19. CONFIG_CPU_32v4==y
  20. CONFIG_KERNEL_START==0xc0000000
  21. CONFIG_ZBOOT_ROM_TEXT==0
  22. CONFIG_ZBOOT_ROM_BSS==0
  23. CONFIG_NET==y
  24. CONFIG_SYSVIPC==y
  25. CONFIG_SYSCTL==y
  26. CONFIG_MAX_USER_RT_PRIO==100
  27. CONFIG_MAX_RT_PRIO==0
  28. CONFIG_XIP_ROM==y
  29. CONFIG_XIP_PHYS_ADDR==60400
  30. CONFIG_FPE_NWFPE==m
  31. CONFIG_KCORE_ELF==y
  32. CONFIG_BINFMT_AOUT==m
  33. CONFIG_BINFMT_ELF==y
  34. CONFIG_OMAP1510_PM==y
  35. CONFIG_DPM==y
  36. CONFIG_BOOT_FREQ==y
  37. CONFIG_OMAP_ARM_168MHZ==y
  38. CONFIG_OMAP1510_DPM==y
  39. CONFIG_INNOVATOR_DPM==y
  40. CONFIG_CMDLINE=="mem==32M console==ttyS0,115200n8 noinitrd root==/dev/null rootflags==physaddr==0x0260000"
  41. CONFIG_ALIGNMENT_TRAP==y
  42. CONFIG_PREEMPT==y
  43. CONFIG_LOCK_BREAK==y
  44. CONFIG_MTD==y
  45. CONFIG_MTD_DEBUG==y
  46. CONFIG_MTD_DEBUG_VERBOSE==0
  47. CONFIG_MTD_PARTITIONS==y
  48. CONFIG_MTD_CONCAT==y
  49. CONFIG_MTD_CHAR==y
  50. CONFIG_MTD_BLOCK==y
  51. CONFIG_MTD_CFI==y
  52. CONFIG_MTD_GEN_PROBE==y
  53. CONFIG_MTD_CFI_ADV_OPTIONS==y
  54. CONFIG_MTD_CFI_NOSWAP==y
  55. CONFIG_MTD_CFI_GEOMETRY==y
  56. CONFIG_MTD_CFI_B2==y
  57. CONFIG_MTD_CFI_I1==y
  58. CONFIG_MTD_CFI_INTELEXT==y
  59. CONFIG_MTD_CFI_AMDSTD==y
  60. CONFIG_MTD_OMAP==y
  61. CONFIG_MTD_OMAP_1==y
  62. CONFIG_BLK_DEV_LOOP==m
  63. CONFIG_BLK_DEV_RAM==y
  64. CONFIG_BLK_DEV_RAM_SIZE==4096
  65. CONFIG_BLK_DEV_INITRD==y
  66. CONFIG_PACKET==m
  67. CONFIG_NETFILTER==y
  68. CONFIG_UNIX==y
  69. CONFIG_INET==y
  70. CONFIG_IP_MULTICAST==y
  71. CONFIG_IP_PNP==y
  72. CONFIG_NETDEVICES==y
  73. CONFIG_NET_ETHERNET==y
  74. CONFIG_NET_VENDOR_SMC==y
  75. CONFIG_SMC9194==y
  76. CONFIG_PPP==m
  77. CONFIG_PPP_MULTILINK==y
  78. CONFIG_PPP_ASYNC==m
  79. CONFIG_PPP_DEFLATE==m
  80. CONFIG_PPPOE==m
  81. CONFIG_IRDA==m
  82. CONFIG_IRLAN==m
  83. CONFIG_IRNET==m
  84. CONFIG_IRCOMM==m
  85. CONFIG_OMAP_SIR==m
  86. CONFIG_INPUT==m
  87. CONFIG_INPUT_KEYBDEV==m
  88. CONFIG_INPUT_MOUSEDEV==m
  89. CONFIG_INPUT_MOUSEDEV_SCREEN_X==240
  90. CONFIG_INPUT_MOUSEDEV_SCREEN_Y==320
  91. CONFIG_INPUT_EVDEV==m
  92. CONFIG_VT==y
  93. CONFIG_VT_CONSOLE==y
  94. CONFIG_SERIAL==y
  95. CONFIG_SERIAL_CONSOLE==y
  96. CONFIG_UNIX98_PTYS==y
  97. CONFIG_UNIX98_PTY_COUNT==256
  98. CONFIG_I2C==m
  99. CONFIG_I2C_ALGOBIT==m
  100. CONFIG_I2C_OMAP1510==m
  101. CONFIG_I2C_CHARDEV==m
  102. CONFIG_I2C_PROC==m
  103. CONFIG_SENSORS==y
  104. CONFIG_SENSORS_OTHER==y
  105. CONFIG_SENSORS_EEPROM==m
  106. CONFIG_WATCHDOG==y
  107. CONFIG_OMAP_WATCHDOG==m
  108. CONFIG_OMAP_RTC==m
  109. CONFIG_RV5C387_RTC==m
  110. CONFIG_RV5C387_RTC==m
  111. CONFIG_VIDEO_DEV==m
  112. CONFIG_VIDEO_PROC_FS==y
  113. CONFIG_AUTOFS4_FS==m
  114. CONFIG_EXT3_FS==m
  115. CONFIG_JBD==m
  116. CONFIG_FAT_FS==m
  117. CONFIG_MSDOS_FS==m
  118. CONFIG_VFAT_FS==m
  119. CONFIG_JFFS_FS==m
  120. CONFIG_JFFS_FS_VERBOSE==0
  121. CONFIG_JFFS2_FS==y
  122. CONFIG_JFFS2_FS_DEBUG==0
  123. CONFIG_CRAMFS==y
  124. CONFIG_CRAMFS_LINEAR==y
  125. CONFIG_CRAMFS_LINEAR_XIP==y
  126. CONFIG_ROOT_CRAMFS_LINEAR==y
  127. CONFIG_TMPFS==y
  128. CONFIG_RAMFS==y
  129. CONFIG_PROC_FS==y
  130. CONFIG_DEVPTS_FS==y
  131. CONFIG_EXT2_FS==m
  132. CONFIG_NFS_FS==y
  133. CONFIG_NFS_V3==y
  134. CONFIG_NFSD==m
  135. CONFIG_NFSD_V3==y
  136. CONFIG_SUNRPC==y
  137. CONFIG_LOCKD==y
  138. CONFIG_LOCKD_V4==y
  139. CONFIG_SMB_FS==m
  140. CONFIG_MSDOS_PARTITION==y
  141. CONFIG_SMB_NLS==y
  142. CONFIG_NLS==y
  143. CONFIG_NLS_DEFAULT=="iso8859-1"
  144. CONFIG_NLS_CODEPAGE_437==m
  145. CONFIG_PC_KEYMAP==y
  146. CONFIG_FB==y
  147. CONFIG_DUMMY_CONSOLE==y
  148. CONFIG_FB_OMAP==y
  149. CONFIG_FBCON_ADVANCED==y
  150. CONFIG_FBCON_CFB16==y
  151. CONFIG_FBCON_FONTWIDTH8_ONLY==y
  152. CONFIG_FBCON_FONTS==y
  153. CONFIG_FONT_8x8==y
  154. CONFIG_FONT_ACORN_8x8==y
  155. CONFIG_SOUND==m
  156. CONFIG_SOUND_OMAP==m
  157. CONFIG_SOUND_OMAP_AIC23==m
  158. CONFIG_INNOVATOR_TS==y
  159. CONFIG_MMC==m
  160. CONFIG_OMAP_MMC==m
  161. CONFIG_TRACE==y
  162. CONFIG_TRACE_BOOT==y
  163. CONFIG_INSTANT_ON==y
  164. CONFIG_DEFAULT_LPJ==414720
  165. CONFIG_INSTANT_ON_LPJ==414720
  166. CONFIG_FRAME_POINTER==y
  167. CONFIG_DEBUG_INFO==y
  168. CONFIG_DEBUG_KERNEL==y
  169. CONFIG_MAGIC_SYSRQ==y
  170. CONFIG_DEBUG_BUGVERBOSE==y
  171. CONFIG_DEBUG_ERRORS==y
  172. CONFIG_ZLIB_INFLATE==y
  173. CONFIG_ZLIB_DEFLATE==y

The set of the init scripts of the consumer packages is divided into the
minimal and optional subsets. The following scripts belong to the
minimal subset: ’bootmisc.sh’, ’checkfs.sh’, ’checkroot.sh’,
’hwclock.sh’, ’modutils.sh’, ’mountall.sh’, ’networking.sh’,
’urandom.sh’.

The following scripts belong to the optional subset: ’anacron.sh’,
’cron.sh’, ’devfsd.sh’, ’devshm.sh’, ’ifupdown.sh’, ’rmnologin.sh’,
’syslog.sh’.

Thus,

  • the minimal packages are: “initscripts”, “util-linux”, “modutils”,
    and “netbase”;
  • the optional packages are: “initscripts”, “anacron”, “cron”,
    “devfsd”, “ifupdown”, “sysklogd”, “util-linux”, “modutils”, and
    “netbase”.

The init scripts are used with the “bash”, BusyBox, 0.60.3 and the
optimized BusyBox 1.00-pre3. The sizes of the shell executables are:

Since profiling tools slow up program execution, the Linux Trace Toolkit
(LTT) is not used to measure the execution time of the init scripts.


























ShellSize
bash562 Kb
BusyBox 0.60.3872 Kb
BusyBox 1.00-pre3210 Kb
The optimized BusyBox 1.00-pre3259 Kb

To obtain the start time of the init scripts, the modified “init”
utility is used. The following patch for the “init” utility is applied:

  1. diff -Naur sysvinit-2.78.orig/src/init.c sysvinit-2.78/src/init.c
  2. --- sysvinit-2.78.orig/src/init.c 2000-02-11 14:17:02.000000000 +0300
  3. +++ sysvinit-2.78/src/init.c 2003-12-08 20:20:15.000000000 +0300
  4. @@ -684,7 +684,7 @@
  5. (void) tcgetattr(fd, &tty);
  6. tty.c_cflag &== CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
  7. - tty.c_cflag |== HUPCL|CLOCAL;
  8. + tty.c_cflag |== CREAD|HUPCL|CLOCAL;
  9. tty.c_cc[VINTR] == 3; /* ctrl(’c’) */
  10. tty.c_cc[VQUIT] == 28; /* ctrl(’\\’) */
  11. @@ -2443,6 +2443,13 @@
  12. FILE *fp;
  13. char *p;
  14. int f, fd;
  15. +
  16. +#ifdef TIME_MEASURE
  17. + struct timeval current;
  18. + if (!gettimeofday (&current, 0))
  19. + printf ("INIT: started at %ld\n", (current.tv_sec * 1000) + (current.tv_usec / 1000));
  20. +#endif
  21. /* Get my own name */
  22. if ((p == strrchr(argv[0], ’/’)) !== NULL)

To obtain the time of the end of the init script execution, the
following program is used in the inittab:

  1. #include <sys/time.h>
  2. #include <stdio.h>
  3. int main (int argc, char **argv)
  4. {
  5. struct timeval current;
  6. if (!gettimeofday (&current, 0))
  7. printf ("printtime: current time %ld ms\n", (current.tv_sec * 1000) + (current.tv_usec / 1000));
  8. return 0;
  9. }

Thus, we consider the sum of the init script execution time and the
kernel loading time, which are measured in ways described above, is the
total system boot time.

Optimization Results

















































Measurement results with the XIP support Kernel loading time: 0.6 sec. Init script execution time:
Script setShellTime%
minimalbash3.6 sec.35%
minimalBusyBox 0.60.35.3 sec.52%
minimaloptimized BusyBox 1.00-pre32.6 sec.25%
minimal + optionalbash7.6 sec.74%
minimal + optionalBusyBox 0.60.310.1 sec.100%
minimal + optionaloptimized BusyBox 1.00-pre34.9 sec.48%
















































Total system boot time (kernel loading time + init script execution time):
Script setShellTime%
minimalbash4.3 sec.39%
minimalBusyBox 0.60.36.0 sec.55%
minimaloptimized BusyBox 1.00-pre33.2 sec.29%
minimal + optionalbash8.2 sec.76%
minimal + optionalBusyBox 0.60.310.7 sec.100%
minimal + optionaloptimized BusyBox 1.00-pre35.5 sec.51%
















































Measurement results without the XIP support Kernel loading time: 0.4 sec. Init script execution time:
Script setShellTime%
minimalbash4.4 sec.52%
minimalBusyBox 0.60.35.0 sec.59%
minimaloptimized BusyBox 1.00-pre32.9 sec.34%
minimal + optionalbash6.8 sec.82%
minimal + optionalBusyBox 0.60.38.3 sec.100%
minimal + optionaloptimized BusyBox 1.00-pre34.6 sec.55%
















































*Total system boot time (kernel loading time + init script execution time):
Script setShellTime%
minimalbash4.8 sec.55%
minimalBusyBox 0.60.35.4 sec.61%
minimaloptimized BusyBox 1.00-pre33.3 sec.38%
minimal + optionalbash7.3 sec.83%
minimal + optionalBusyBox 0.60.38.7 sec.100%
minimal + optionaloptimized BusyBox 1.00-pre35.0 sec.57%

Downloads

Categories: