From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754064AbYIPXzh (ORCPT ); Tue, 16 Sep 2008 19:55:37 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752329AbYIPXz3 (ORCPT ); Tue, 16 Sep 2008 19:55:29 -0400 Received: from mx2.suse.de ([195.135.220.15]:45667 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752319AbYIPXz2 (ORCPT ); Tue, 16 Sep 2008 19:55:28 -0400 Date: Wed, 17 Sep 2008 01:55:26 +0200 Message-ID: From: Takashi Iwai To: linux-kernel@vger.kernel.org Subject: diet-kconfig: a script to trim unneeded kconfigs User-Agent: Wanderlust/2.12.0 (Your Wildest Dreams) SEMI/1.14.6 (Maruoka) FLIM/1.14.7 (=?ISO-8859-4?Q?Sanj=F2?=) APEL/10.6 Emacs/22.2 (x86_64-suse-linux-gnu) MULE/5.0 (SAKAKI) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, a topic that just came up in kernel summit is a script to remove unneeded kernel configs automatically to reduce the compile time. Incidentally, I already wrote such a script during the last SUSE hack week a couple of weeks ago, so I'd like to share here, hopefully to give an idea for further improvements. The script checks the currently loaded modules and trims other CONFIG_XXX=m simply, and tries make oldconfig, and writes out the resultant .config in the current directory after some checks. You can specify the config file via option, as default, it reads from /proc/config.gz. The script is VERY hackish. I should have begun with perl or whatever better script language, but I chose bash and co. So, don't expect much code quality. I'm no script guy after all :) Takashi --- #!/bin/sh # this magic makes grep and co a lot faster export LANG=C kroot= subarch=$(uname -i) oldconfig=/proc/config.gz localversion= modulelist= optimize_smp= optimize_memory= outputfile= usage () { cat <> $tmpd/makefiles # find configs to create the given module find_kconfig () { module=$1 modregex=$(echo $1 | sed -e's/_/[_-]/g') grep -E '^[[:space:]]*obj-\$\([A-Za-z0-9_]*\)[[:space:]]*[+:]=.*[[:space:]]'"$modregex"'\.o' $tmpd/makefiles | \ sed -e's/^.*://g' -e's/^[[:space:]]*obj-\$(\(.*\)).*$/\1/g' } # set config no kconfig_no () { sed -i -e's/^\('$1'\)=.*/# \1 is not set/' $tmpd/kconfig } # set config yes kconfig_yes () { sed -i -e's/# '$1' .*/'$1'=y/' $tmpd/kconfig } # only previously selected modules with XXX marks kconfig_mod () { sed -i -e's/# '$1' XXX/'$1'=m/' $tmpd/kconfig } get_old_config () { case "$oldconfig" in *.gz) zcat $oldconfig ;; *) cat $oldconfig esac } list_modules () { if [ -n "$modulelist" ]; then awk '{if ($1 != "Module") {print $1}}' < $modulelist else lsmod | awk '{if ($1 != "Module") {print $1}}' fi } # copy the original kconfigs; reset all modules, but remember they were # enabled by marking XXX get_old_config | sed -e's/^\(CONFIG.*\)=m/# \1 XXX/g' > $tmpd/kconfig # optimize some stuff (if given) if [ "$optimize_smp" = "y" ]; then cpus=$(cat /proc/cpuinfo | grep -q -c 'processor[[:space:]]*:') if [ "$cpus" = 1 ]; then kconfig_no CONFIG_SMP else kconfig_yes CONFIG_SMP fi fi if [ "$subarch" = "i386" ]; then if [ "$optimize_memory" = "y" ]; then mem=$(free | grep 'Mem:' | awk '{print $2}') if [ $mem -gt 4194304 ]; then kconfig_yes CONFIG_HIGHMEM64G kconfig_no CONFIG_HIGHMEM4G kconfig_no CONFIG_NOHIGHMEM kconfig_yes CONFIG_X86_PAE elif [ $mem -gt 1048576 ]; then kconfig_no CONFIG_HIGHMEM64G kconfig_yes CONFIG_HIGHMEM4G kconfig_no CONFIG_NOHIGHMEM kconfig_no CONFIG_X86_PAE else kconfig_no CONFIG_HIGHMEM64G kconfig_no CONFIG_HIGHMEM4G kconfig_yes CONFIG_NOHIGHMEM kconfig_no CONFIG_X86_PAE fi fi fi # rewrite the local version if [ -n "$localversion" ]; then sed -i -e's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION="'$localversion'"/' $tmpd/kconfig fi # find kconfig for each module rm -f $noconfigs $okconfigs list_modules | while read m; do echo -n "Checking module $m..." cfgs=$(find_kconfig $m) if [ -z "$cfgs" ]; then echo -n "N/A" echo $m >> $tmpd/conf-no else echo -n "$m" >> $tmpd/conf-ok for c in $cfgs; do echo -n " $c" echo -n " $c" >> $tmpd/conf-ok kconfig_mod $c done echo >> $tmpd/conf-ok fi echo done # if the previously =m doesn't enable any modules, it's a virtual one, which # we should keep =m for c in $(grep '^#.*XXX$' $tmpd/kconfig | sed -e's/^#.*\(CONFIG.*\) XXX/\1/g'); do grep -q 'obj-\$('$c').*=.*\.o' $tmpd/makefiles || kconfig_mod $c done # replace XXX to standard sed -i -e's/^\(#.*\) XXX/\1 is not set/g' $tmpd/kconfig # reconfigure echo "Reconfiguring via make silentconfig" cd $curdir cp $tmpd/kconfig .config if [ -n "$kroot" ]; then make_args="-C $kroot O=$curdir" else make_args= fi make $make_args silentoldconfig ARCH=$arch if [ -n "$outputfile" ]; then echo "Copying the result to $outputfile" cp .config $outputfile fi echo echo "*** FINISHED ***" echo if [ -s $tmpd/conf-no ]; then echo "Modules not configured:" cat $tmpd/conf-no fi if [ -s $tmpd/conf-ok ]; then while read m cfgs; do found= for c in $cfgs; do if grep -q $c=m .config; then found=y break fi done if [ -z "$found" ]; then echo "Not enabled: module $m with config $cfgs" fi done < $tmpd/conf-ok fi exit 0