* some numbers on macros
@ 2008-05-24 15:48 Mariusz Kozlowski
2008-05-24 16:33 ` Arjan van de Ven
0 siblings, 1 reply; 6+ messages in thread
From: Mariusz Kozlowski @ 2008-05-24 15:48 UTC (permalink / raw)
To: kernel-janitors; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 3258 bytes --]
Hello,
I wrote a rather dumb script to see some numbers on macros I was
interested in. The script basically parses *.c file, finds macro definitions
and counts how many times each macro was used in this source file. The script
doesn't see any context so it can produce false positives - that is one of
the reasons it doesn't look into header files - it's simply too dumb.
The macros I was interested in were these which are:
- defined and unused
- defined and used only once
- defined more than once
I dont want to start another cleanup-patches-storm so first I'd like to
know if this excersise is worth it as unused macros do not do much harm.
Would such patches be accepted?
Mariusz
example on recent linux-2.6 snapshot:
$ ./find_interesting_macros.php linux-2.6
[snip]
10189 files to parse
used defined macro
[snip]
0 1 'Tracev' /home/mariusz/linux/linux-2.6/init/initramfs.c +400
0 1 'Tracevv' /home/mariusz/linux/linux-2.6/init/initramfs.c +401
0 1 'Tracec' /home/mariusz/linux/linux-2.6/init/initramfs.c +402
0 1 'Tracecv' /home/mariusz/linux/linux-2.6/init/initramfs.c +403
1 1 'version_string' /home/mariusz/linux/linux-2.6/init/version.c +17
8 2 'DBG' /home/mariusz/linux/linux-2.6/sound/soc/at91/at91-ssc.c +39
4 2 'DBG' /home/mariusz/linux/linux-2.6/sound/soc/at91/at91-pcm.c +37
8 2 'DBG' /home/mariusz/linux/linux-2.6/sound/soc/at91/eti_b1_wm8731.c +44
25 2 'DBG' /home/mariusz/linux/linux-2.6/sound/soc/s3c24xx/s3c2412-i2s.c +49
21 2 'DBG' /home/mariusz/linux/linux-2.6/sound/soc/s3c24xx/s3c24xx-i2s.c +49
19 2 'DBG' /home/mariusz/linux/linux-2.6/sound/soc/s3c24xx/s3c24xx-pcm.c +42
0 2 'dbg' /home/mariusz/linux/linux-2.6/sound/soc/codecs/wm8750.c +41
1 1 'info' /home/mariusz/linux/linux-2.6/sound/soc/codecs/wm8750.c +48
0 1 'warn' /home/mariusz/linux/linux-2.6/sound/soc/codecs/wm8750.c +50
1 1 'wm8750_reset' /home/mariusz/linux/linux-2.6/sound/soc/codecs/wm8750.c +120
0 2 'dbg' /home/mariusz/linux/linux-2.6/sound/soc/codecs/wm8731.c +41
1 1 'info' /home/mariusz/linux/linux-2.6/sound/soc/codecs/wm8731.c +48
0 1 'warn' /home/mariusz/linux/linux-2.6/sound/soc/codecs/wm8731.c +50
1 1 'wm8731_reset' /home/mariusz/linux/linux-2.6/sound/soc/codecs/wm8731.c +120
...
BTW. How many unused macros are in *.c files?
$ ./find_interesting_macros.php linux-2.6 | grep "^0" | wc -l
1340
Well ... since it produces some false positives the real number can differ a little.
This is an example of a macro that will cause false positive:
scripts/kconfig/kconfig_load.c +7
#define P(name,type,arg) type (*name ## _p) arg
#include "lkc_proto.h"
#undef P
[-- Attachment #2: find_interesting_macros.php --]
[-- Type: application/x-php, Size: 3894 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: some numbers on macros
2008-05-24 15:48 some numbers on macros Mariusz Kozlowski
@ 2008-05-24 16:33 ` Arjan van de Ven
2008-05-24 18:52 ` Matthew Wilcox
0 siblings, 1 reply; 6+ messages in thread
From: Arjan van de Ven @ 2008-05-24 16:33 UTC (permalink / raw)
To: Mariusz Kozlowski; +Cc: kernel-janitors, linux-kernel
On Sat, 24 May 2008 17:48:19 +0200
Mariusz Kozlowski <m.kozlowski@tuxland.pl> wrote:
> Hello,
>
> I wrote a rather dumb script to see some numbers on macros I
> was interested in. The script basically parses *.c file, finds macro
> definitions and counts how many times each macro was used in this
> source file. The script doesn't see any context so it can produce
> false positives - that is one of the reasons it doesn't look into
> header files - it's simply too dumb.
>
> The macros I was interested in were these which are:
> - defined and unused
> - defined and used only once
> - defined more than once
>
> I dont want to start another cleanup-patches-storm so first I'd like
> to know if this excersise is worth it as unused macros do not do much
> harm.
>
> Would such patches be accepted?
An unused define/macro that was declared in a .c file isn't very
interesting to be honest; that tends to be helper macros for the
developer and removing those is just counter productive.
unused macros in common header files are an indication of stale APIs
otoh.. and might be of some interest. (Same for static inline in
headers)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: some numbers on macros
2008-05-24 16:33 ` Arjan van de Ven
@ 2008-05-24 18:52 ` Matthew Wilcox
2008-05-24 23:41 ` Mariusz Kozlowski
0 siblings, 1 reply; 6+ messages in thread
From: Matthew Wilcox @ 2008-05-24 18:52 UTC (permalink / raw)
To: Arjan van de Ven; +Cc: Mariusz Kozlowski, kernel-janitors, linux-kernel
On Sat, May 24, 2008 at 09:33:50AM -0700, Arjan van de Ven wrote:
> unused macros in common header files are an indication of stale APIs
> otoh.. and might be of some interest. (Same for static inline in
> headers)
Possibly. There's likely to be a lot of macros unused like these ones:
#define PCI_X_CMD_MAX_READ 0x000c /* Max Memory Read Byte Count */
/* Max # of outstanding split transactions */
#define PCI_X_CMD_SPLIT_1 0x0000 /* Max 1 */
#define PCI_X_CMD_SPLIT_2 0x0010 /* Max 2 */
#define PCI_X_CMD_SPLIT_3 0x0020 /* Max 3 */
...
where the macros embody the PCI specification in code -- possibly we
don't use them yet, but if we ever did, we'd have the macros to use.
Another category of false positive is macros that ought to be used,
but the code that ought to be using them has decided to go its own way.
That still indicates a bug, but not the one you might initially think.
In summary, this is probably an interesting exercise, but the results
would need to be interpreted with care.
--
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: some numbers on macros
2008-05-24 18:52 ` Matthew Wilcox
@ 2008-05-24 23:41 ` Mariusz Kozlowski
2008-05-24 23:46 ` Arjan van de Ven
0 siblings, 1 reply; 6+ messages in thread
From: Mariusz Kozlowski @ 2008-05-24 23:41 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: Arjan van de Ven, kernel-janitors, linux-kernel
Hello,
> On Sat, May 24, 2008 at 09:33:50AM -0700, Arjan van de Ven wrote:
> > unused macros in common header files are an indication of stale APIs
> > otoh.. and might be of some interest. (Same for static inline in
> > headers)
>
> Possibly. There's likely to be a lot of macros unused like these ones:
Maybe I wasn't precise enough. The script looks for macros which take argument(s)
i.e.
#define foobar() ...
> #define PCI_X_CMD_MAX_READ 0x000c /* Max Memory Read Byte Count */
> /* Max # of outstanding split transactions */
> #define PCI_X_CMD_SPLIT_1 0x0000 /* Max 1 */
> #define PCI_X_CMD_SPLIT_2 0x0010 /* Max 2 */
> #define PCI_X_CMD_SPLIT_3 0x0020 /* Max 3 */
> ...
>
> where the macros embody the PCI specification in code -- possibly we
> don't use them yet, but if we ever did, we'd have the macros to use.
Agreed.
> Another category of false positive is macros that ought to be used,
> but the code that ought to be using them has decided to go its own way.
> That still indicates a bug, but not the one you might initially think.
Agreed.
> In summary, this is probably an interesting exercise, but the results
> would need to be interpreted with care.
Well I'll just go through some of them. This is long term task as its number is quite
big. Maybe I can improve the script some more or apply some other measures. I guess
one can find there all sort of macros and some part of them are leftovers from something
that was there some time ago.
Interesting part would be to write a 'parser' that actually sees the context and understands
cpp directives, that could 'walk' the tree.
Mariusz
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: some numbers on macros
2008-05-24 23:41 ` Mariusz Kozlowski
@ 2008-05-24 23:46 ` Arjan van de Ven
2008-05-25 9:11 ` Mariusz Kozlowski
0 siblings, 1 reply; 6+ messages in thread
From: Arjan van de Ven @ 2008-05-24 23:46 UTC (permalink / raw)
To: Mariusz Kozlowski; +Cc: Matthew Wilcox, kernel-janitors, linux-kernel
On Sun, 25 May 2008 01:41:09 +0200
Mariusz Kozlowski <m.kozlowski@tuxland.pl> wrote:
>
> Interesting part would be to write a 'parser' that actually sees the
> context and understands cpp directives, that could 'walk' the tree.
you could approach it from the opposite angle... I mean, lxr.linux.no
already has all this data in some database.. maybe you can turn it into
a set of database queries ;)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: some numbers on macros
2008-05-24 23:46 ` Arjan van de Ven
@ 2008-05-25 9:11 ` Mariusz Kozlowski
0 siblings, 0 replies; 6+ messages in thread
From: Mariusz Kozlowski @ 2008-05-25 9:11 UTC (permalink / raw)
To: Arjan van de Ven; +Cc: Matthew Wilcox, kernel-janitors, linux-kernel
Hello,
> On Sun, 25 May 2008 01:41:09 +0200
> Mariusz Kozlowski <m.kozlowski@tuxland.pl> wrote:
> >
> > Interesting part would be to write a 'parser' that actually sees the
> > context and understands cpp directives, that could 'walk' the tree.
>
> you could approach it from the opposite angle... I mean, lxr.linux.no
> already has all this data in some database.. maybe you can turn it into
> a set of database queries ;)
Good point :) Will look into this.
Mariusz
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-05-25 9:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-24 15:48 some numbers on macros Mariusz Kozlowski
2008-05-24 16:33 ` Arjan van de Ven
2008-05-24 18:52 ` Matthew Wilcox
2008-05-24 23:41 ` Mariusz Kozlowski
2008-05-24 23:46 ` Arjan van de Ven
2008-05-25 9:11 ` Mariusz Kozlowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox