OpenWrt Forum Archive

Topic: How to optimize build for speed?

The content of this topic has been archived on 7 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

I don't use many components, and current image size is only 4mb (out of 8mb my wndr3700 has). also RAM is used only 30mb out of 64.
since I have plenty of resources, and I understand that by default OpenWRT optimizes for size, I want to optimize for speed.
I tried to change -Os to -O2 in several places
1) include/target.mk
2) kernel configuration
3) .config

but I still can see some components are compiled with both -O2 and -Os which doesn't make much sense.
what is proper way to turn on global speed optimization, and should I use -O2 or -O3?

thanks!
Andrey

anyone?

For enabling O2:

make menuconfig
Change OS to O2 in this box dialog:

Location:
  -> Advanced configuration options (for developers) (DEVEL [=y])
    -> Target Options (TARGET_OPTIONS [=y])
??????????????????????????????????? Target Options ?????????????????????????????
? ???????????????????????????????????????????????????????????????????????????? ?
? ? --- Target Options                                                       ? ?
? ? (-O2 -pipe -mips32 -mtune=mips32 -fno-caller-saves) Target Optimizations ? ? 
? ? [*]   Use software floating point by default                             ? ?
? ???????????????????????????????????????????????????????????????????????????? ?
????????????????????????????????????????????????????????????????????????????????   
?                          <Select>    < Exit >    < Help >                    ?   
????????????????????????????????????????????????????????????????????????????????

make kernel_menuconfig
Uncheck "optimize for size" in this box dialog:

Location:
    -> General setup
?????????????????????????????????? General setup ?????????????????????????????
? ?????^(-)????????????????????????????????????????????????????????????????? ?
? ?    [ ] Control Group support  --->                                     ? ?   
? ?    [ ] Namespaces support  --->                                        ? ?
? ?    [ ] enable deprecated sysfs features to support old userspace tools ? ?
? ?    [*] Kernel->user space relay support (formerly relayfs)             ? ?
? ?    [*] Crash logging                                                   ? ?
? ?    [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support  ? ?
? ?    ()    Initramfs source file(s)                                      ? ?
? ?    [ ]   Support initial ramdisks compressed using gzip                ? ?
? ?    [ ]   Support initial ramdisks compressed using bzip2               ? ?
? ?    [*]   Support initial ramdisks compressed using LZMA                ? ?
? ?    [ ] Optimize for size                                               ? ?
? ?    [*] Configure standard kernel features (for small systems)  --->    ? ?
? ?        Kernel Performance Events And Counters  --->                    ? ?
? ?    [*] Enable VM event counters for /proc/vmstat                       ? ?
? ?????v(+)????????????????????????????????????????????????????????????????? ?
??????????????????????????????????????????????????????????????????????????????
?                        <Select>    < Exit >    < Help >                    ?
??????????????????????????????????????????????????????????????????????????????

Now make the world to produce your images

make V=99

The difference between O2 and Os seems to be minor:
Os does not align the variables at word boundaries, but otherwise applies practically all the other O2 optimizations.

http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

-Os enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.
-Os disables the following optimization flags:

          -falign-functions  -falign-jumps  -falign-loops
          -falign-labels  -freorder-blocks  -freorder-blocks-and-partition
          -fprefetch-loop-arrays  -ftree-vect-loop-version

And looking closely to those align-options, it looks to me that the user should probably specify the word size in the compiler options, or possibly the alignment happens at n=1 byte, meaning no alignment in practise. I am not sure if the machine-specific default is set to anything meaningful somewhere in the makefiles.

-O3 or even -Ofast might be correct ones to really get some effect.

Has any of the developers played around the optimization options recently?
I found the only real references to decisions related optimization options:
- from Nbd in 2009 as a comment to changeset 15821 ( https://dev.openwrt.org/changeset/15821 ) " turn off -Os by default for the kernel and stick to -O2. Repeated tests have shown the -O2 kernel to react much better to high cpu/network load situations", and
- the current kernel patches ( https://dev.openwrt.org/browser/trunk/t … tion.patch ). It is either "-Os -fno-caller-saves" for size or "-O2 -fno-reorder-blocks -fno-tree-ch -fno-caller-saves " for speed.

On the other hand, the ar71xx specific config files again sets the "CONFIG_CC_OPTIMIZE_FOR_SIZE=y" by default meaning -Os is applied to at least some of the code.

The discussion might have continued from here.