tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

top(1) WCPU value output for threaded application on SMP systems



Hi,

While working on some threaded application; i noticed that, on SMP
systems, the WCPU percent value displayed by top(1) can now overflows
the provided 5 columns :

CPU0 states: 95.0% user,  0.0% nice,  5.0% system,  0.0% interrupt,  0.0% idle
CPU1 states: 94.1% user,  0.0% nice,  0.0% system,  0.0% interrupt,  5.9% idle
Memory: 1111M Act, 555M Inact, 7364K Wired, 30M Exec, 1589M File, 28M Free
Swap: 10G Total, 10G Free

  PID USERNAME PRI NICE   SIZE   RES STATE      TIME   WCPU    CPU COMMAND
15891 njoly     25    0    57M   23M RUN/0      0:13 146.63% 48.39% thread_test
    0 root     124    0     0K   15M CPU/0      1:32  0.00%  0.00% [system]

The attached patch ensure that it won't escape anymore, by discarding
the decimal part when the value reaches 100.0% :

  PID USERNAME PRI NICE   SIZE   RES STATE      TIME   WCPU    CPU COMMAND
15891 njoly     25    0    57M   23M RUN/0      0:13   146% 48.39% thread_test
    0 root     124    0     0K   15M CPU/0      1:32  0.00%  0.00% [system]

Comments ?

-- 
Nicolas Joly

Biological Software and Databanks.
Institut Pasteur, Paris.
Index: external/bsd/top/dist/machine/m_netbsd.c
===================================================================
RCS file: /cvsroot/src/external/bsd/top/dist/machine/m_netbsd.c,v
retrieving revision 1.7
diff -u -p -r1.7 m_netbsd.c
--- external/bsd/top/dist/machine/m_netbsd.c    29 Mar 2009 01:02:49 -0000      
1.7
+++ external/bsd/top/dist/machine/m_netbsd.c    24 Apr 2009 18:02:01 -0000
@@ -106,7 +106,7 @@ static char Proc_header[] =
 /* 0123456   -- field to fill in starts at header+6 */
 #define PROC_UNAME_START 6
 #define Proc_format \
-       "%5d %-8.8s %3d %4d%7s %5s %-8.8s%7s %5.2f%% %5.2f%% %.12s"
+       "%5d %-8.8s %3d %4d%7s %5s %-8.8s%7s %5.*f%% %5.2f%% %.12s"
 
 static char Thread_header[] =
   "  PID   LID X        PRI STATE      TIME   WCPU    CPU COMMAND      NAME";
@@ -771,7 +771,7 @@ format_next_proc(caddr_t handle, char *(
 {
        struct kinfo_proc2 *pp;
        long cputime;
-       double pct;
+       double pct, wcpu;
        struct handle *hp;
        const char *statep;
 #ifdef KI_NOCPU
@@ -839,6 +839,8 @@ format_next_proc(caddr_t handle, char *(
                }
        }
 #endif
+       wcpu = 100.0 * weighted_cpu(p_, pct, pp);
+
        /* format this entry */
        sprintf(fmt,
            Proc_format,
@@ -850,7 +852,7 @@ format_next_proc(caddr_t handle, char *(
            format_k(pagetok(pp->p_vm_rssize)),
            statep,
            format_time(cputime),
-           100.0 * weighted_cpu(p_, pct, pp),
+           (wcpu >= 100.0) ? 0 : 2, wcpu,
            100.0 * pct,
            printable(pp->p_comm));
 


Home | Main Index | Thread Index | Old Index