[PATCH] make top.c even smaller #2

Rob Landley rob at landley.net
Thu Feb 16 01:16:04 UTC 2006


On Wednesday 15 February 2006 4:30 am, Denis Vlasenko wrote:
> On Tuesday 14 February 2006 15:01, Rob Landley wrote:
> > On Tuesday 14 February 2006 10:15 am, Denis Vlasenko wrote:
> > > Patch gets rid of jiffie-per-sec estimation code,
> > > uses raw jiffies count from /proc/stat
> > > for CPU% calculation.
> >
> > A nice cleanup, but it collided with Vladimir's patch.  (Apparently,
> > keeping it inline results in smaller code on gcc 4.0.2.)  Could you
> > respin?
>
> No problem, especially considering that CPU% calculations
> were not precise enough (sum can get over 100%, not nice).
>
> Attached top.patch has following changes:
> * CPU% = process[i].ticks/sum(process[i].ticks) *
> busy_cpu_ticks/total_cpu_ticks * got rid of empty line under "Load average"
> line
>   and used last line - +2 visible processes
> * do not do float conversion of loadavg, just read it as string from /proc
> * fix display on small screens (see example below)
> * dropped unused .stime, .utime fields
> * a few variables were renamed

I built with just top and did "make sizes" on both the old version and the new 
version.  Here's the end of a diff between them.

 00000048 T main
 0000004a T bb_vperror_msg
 0000004a T __libc_csu_fini
+00000050 b jif
+00000050 b prev_jif
 00000051 T __libc_csu_init
 00000056 T bb_getug
 0000005b T bb_show_usage
-0000005b t file_to_buf
 00000071 T run_applet_by_name
 000000ca T busybox_main
-00000180 t do_stats
+00000186 T __udivdi3
+000001f2 t do_stats
 00000297 T procps_scan
 00000375 T bb_getopt_ulflags
-0000078d T top_main
+000004aa T top_main

If you could eliminate the _udivdi3 in there, it would be a clear win.  I 
believe this is something that gcc is sucking in from libgcc in order to do a 
"long long" divide.

I'm checking it in because in a larger app that piece of nastiness is shared 
with anything else that uses it, but if you could find a way to eliminate 
that, it'd be seriously cool.

> top2.patch contains a style cleanup for inconsistent
> use of parens, apply on top of top.patch.

Unfortunately, the style of the existing code (inherited from erik) is 
inconsistent, but consistently so.

if (blah);
while (blah);
do (blah);
function(blah);

I don't know why, but I'm not currently trying to change it.  A cleanup patch 
to remove the space between if and the ( after if matches my personal style, 
but not the style of the project.

I care more about the style consistent than being right, so...

Patch #1 applied, patch #2 not.


Rob
-- 
Never bet against the cheap plastic solution.



More information about the busybox mailing list