Skip to contentSkip to conversation

Centralise documentation of CONFIG_ options (and finding unused ones)

RFC Graeme Russ 4 participants 7 messages Apr 11, 2011 – Apr 17, 2011

lore
Share & tools
lore
#0 lore raw

Hi All,

As a bit of a lark, I ran the following shell command:

grep -r -h -o -G "#define CONFIG.*" * | \
sed 's/#define[ \t]*//' | \
sed 's/^\([A-Za-z0-9_]*\).*/\1/' | \
sort -u > README.configuration.options

I then ran the result through the following script into README.configuration.options.counted

#!/bin/bash INPUT=doc/README.configuration.options

#!/bin/bash INPUT=doc/README.configuration.options

for i in cat $INPUT
do

	grep -rcs --exclude-dir=doc '\<'${i}'\>' * | \
	cut -d : -f 2 | \
	awk '{sum+=$1} END {printf("%d\t%s\n", sum, f);}' f=$i

done

The result? 5539 lines of pure configuration option goodness :)

Here's a little snippet:

6 CONFIG_100MHz
8 CONFIG_133MHZ_DRAM
7 CONFIG_300MHz
13 CONFIG_405
24 CONFIG_405CR
88 CONFIG_405EP
81 CONFIG_405EX

#1 lore raw

Hi Graeme,

Le 11/04/2011 15:11, Graeme Russ a ?crit :

Quoted 2 lines

So my RFC is twofold:
1) Should we start to systematically remove unused options

I would tend to answer 'yes'. Unused options should not clobber code or documentation.

Quoted 2 lines

2) Should we centralise all options in a single README (or two, one for
standard CONFIG options and one for CONFIG_SYS options)?

That would be nice indeed, but it requires all options to have the same semantics over all arches. While this is highly desirable, it may not be true ATM -- just thinking out loud, haven't checked. But even if some options only make sense only for some arch(es), then we could always do it this way:

doc/README.CONFIG_options
doc/README.CONFIG_SYS_options
doc/arch/README.CONFIG_options

Quoted 3 lines

Regards,

Graeme

Amicalement,

Signature · 1 line
Albert.
#2 lore raw
Quoted 19 lines · Albert ARIBAUD

Hi Graeme,

Le 11/04/2011 15:11, Graeme Russ a ?crit :

Quoted 2 lines

So my RFC is twofold:
1) Should we start to systematically remove unused options

I would tend to answer 'yes'. Unused options should not clobber code or documentation.

Quoted 2 lines

2) Should we centralise all options in a single README (or two, one for
standard CONFIG options and one for CONFIG_SYS options)?

That would be nice indeed, but it requires all options to have the same semantics over all arches. While this is highly desirable, it may not be true ATM -- just thinking out loud, haven't checked. But even if some options only make sense only for some arch(es), then we could always do it this way:

Quoted 3 lines

doc/README.CONFIG_options
doc/README.CONFIG_SYS_options
doc/arch/README.CONFIG_options

Hmm, I have a better idea after I can to the realisation that the central location for configuration options is Ctrl^F in the doc/ directory :)

doc/README.CONFIG_options.unused
doc/README.CONFIG_options.undocumented

I will tweak my scripts to produce these two files and see what the result is.

Regards,

Graeme

#3 lore raw
In reply to Graeme Russ
Quoted 7 lines
Quoted 1 line

From this it is easy to find unused options (CONFIG_ARIA is found only as a

#define in include/configs/aria.h for example)

So my RFC is twofold:
1) Should we start to systematically remove unused options
2) Should we centralise all options in a single README (or two, one for standard CONFIG options and one for CONFIG_SYS options)?

Can you post data for which options are not used. While I think automatic removal is harsh, I think something close to automatic is reasonable.

- k

#4 lore raw
Quoted 11 lines · Kumar Gala
Quoted 7 lines
Quoted 1 line

From this it is easy to find unused options (CONFIG_ARIA is found only as a

#define in include/configs/aria.h for example)

So my RFC is twofold:
1) Should we start to systematically remove unused options
2) Should we centralise all options in a single README (or two, one for standard CONFIG options and one for CONFIG_SYS options)?

Can you post data for which options are not used. While I think automatic removal is harsh, I think something close to automatic is reasonable.

- k

OK, here are some quick stats:

Total CONFIG_ options : 5559
Total CONFIG_ options not documented(*)/ : 4907 Total CONFIG_ options not used in code(+) : 1136 Total CONFIG_ options not used in any board config : 645

(*) README moved into doc/ to make the count of documented options more accurate
(+) i.e. only found in either doc/ or include/configs/

As you can see, there is scope for a LOT of code cleanup within the CONFIG_ namespace

Here is the script:

#!/bin/bash INPUT=doc/README.configuration.options.list OUTPUT1=doc/README.configuration.options.counted.code_usage OUTPUT2=doc/README.configuration.options.counted.doc OUTPUT3=doc/README.configuration.options.counted.config

echo "Catalogue Configuration Options"

grep -rhos "#define CONFIG.*" * | \
	sed 's/#define[ \t]*//' | \
	sed 's/^\([A-Za-z0-9_]*\).*/\1/' | \
	sort -u > $INPUT

echo "Counting usage of configuration options in code" rm $OUTPUT1 2> /dev/null
for i in cat $INPUT
do

	x=${i}'\s'
	grep -rcs --exclude-dir=include/configs --exclude-dir=doc '\<'${i}'\>' * | \
	cut -d : -f 2 | \
	awk '{sum+=$1} END {printf("%d\t%s\n", sum, f);}' f=$i >> $OUTPUT1

done
sort -n $OUTPUT1 > tmp
rm $OUTPUT1 2> /dev/null
mv tmp $OUTPUT1

echo "Counting documented options"
rm $OUTPUT2 2> /dev/null
for i in cat $INPUT
do

	x=${i}'\s'
	grep -rcs '\<'${i}'\>' doc/* --exclude=README.configuration.* | \
	cut -d : -f 2 | \
	awk '{sum+=$1} END {printf("%d\t%s\n", sum, f);}' f=$i >> $OUTPUT2

done
sort -n $OUTPUT2 > tmp
rm $OUTPUT2 2> /dev/null
mv tmp $OUTPUT2

echo "Counting usage of configuration options in board configuration files" rm $OUTPUT3 2> /dev/null
for i in cat $INPUT
do

	x=${i}'\s'
	grep -rcs '\<'${i}'\>' include/configs/* | \
	cut -d : -f 2 | \
	awk '{sum+=$1} END {printf("%d\t%s\n", sum, f);}' f=$i >> $OUTPUT3

done
sort -n $OUTPUT3 > tmp
rm $OUTPUT3 2> /dev/null
mv tmp $OUTPUT3

echo "Done"

Regards,

Graeme

#5 lore raw
Quoted 5 lines · Graeme Russ

#!/bin/bash INPUT=doc/README.configuration.options.list OUTPUT1=doc/README.configuration.options.counted.code_usage OUTPUT2=doc/README.configuration.options.counted.doc OUTPUT3=doc/README.configuration.options.counted.config

How about Makefiles? Sometimes a CONFIG option is used only in a Makefiles.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#6 lore raw
Quoted 10 lines · Timur Tabi
Quoted 5 lines · Graeme Russ

#!/bin/bash INPUT=doc/README.configuration.options.list OUTPUT1=doc/README.configuration.options.counted.code_usage OUTPUT2=doc/README.configuration.options.counted.doc OUTPUT3=doc/README.configuration.options.counted.config

How about Makefiles? ?Sometimes a CONFIG option is used only in a Makefiles.

code_usage includes Makefiles

Regards,

Graeme