From vova@express.ru  Mon Dec 10 03:32:15 2001
Return-Path: <vova@express.ru>
Received: from vbook.express.ru (asplinux.ru [195.133.213.194])
	by hub.freebsd.org (Postfix) with ESMTP id 4B1A837B419
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 10 Dec 2001 03:32:10 -0800 (PST)
Received: from vova by vbook.express.ru with local (Exim 3.31 #2)
	id 16DOfY-0000WU-00
	for FreeBSD-gnats-submit@freebsd.org; Mon, 10 Dec 2001 14:32:24 +0300
Message-Id: <E16DOfY-0000WU-00@vbook.express.ru>
Date: Mon, 10 Dec 2001 14:32:24 +0300
From: Vladimir B.Grebenschikov <vova@sw.ru>
Sender: "Vladimir B. Grebenschikov" <vova@express.ru>
Reply-To: Vladimir B.Grebenschikov <vova@sw.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: systat waste too much time reading input
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         32667
>Category:       bin
>Synopsis:       systat(1) waste too much time reading input
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Dec 10 03:40:00 PST 2001
>Closed-Date:    
>Last-Modified:  Wed May 21 21:18:21 UTC 2008
>Originator:     Vladimir B. Grebenschikov
>Release:        FreeBSD 5.0-CURRENT i386 or 4.4-RELEASE
>Organization:
SW Soft
>Environment:
System: FreeBSD vbook.express.ru 5.0-CURRENT FreeBSD 5.0-CURRENT #1: Sun Dec 2 12:07:55 MSK 2001 root@vbook.express.ru:/usr/local/src/sys/i386/compile/VBOOK i386
/usr/bin/systat from basic distribution
Have tried also on 4.4-RELEASE - same problem
>Description:
I have found that on same, not busy system top & systat runing
simulataniosly "eat" very different amount of CPU time, like:

CPU
5.37% systat
0.01% top

triing find out what happens, I have tried to run 
systat -vm 1 < /dev/null
And found that systat eats a lot of system resources during input 

  WCPU   CPU
 63.05% 16.36% systat

>How-To-Repeat:

$ systat -vm 1 < /dev/null

>Fix:

Not know
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: sheldonh 
State-Changed-When: Mon Dec 10 04:33:35 PST 2001 
State-Changed-Why:  
I'm hoping the originator will take a crack at this himself, 
now that he knows where the problem is. :-) 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32667 

From: Sheldon Hearn <sheldonh@starjuice.net>
To: "Vladimir B.Grebenschikov" <vova@sw.ru>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/32667: systat waste too much time reading input 
Date: Mon, 10 Dec 2001 14:35:16 +0200

 On Mon, 10 Dec 2001 14:32:24 +0300, "Vladimir B.Grebenschikov" wrote:
 
 > >Number:         32667
 > >Category:       bin
 > >Synopsis:       systat waste too much time reading input
 
 The problem is a very tight loop around getch() in non-delay mode, in
 the keyboard() function in keyboard.c.  This should probably be changed
 to half-delay mode.
 
 Someone who knows ncurses(3X) (or who is willing to learn) will have to
 look at this.
 
 Well-spotted.  Interested in trying to come up with a patch, based on a
 squizz at the getch(3) and ncurses(3X) manual pages?
 
 Cioa,
 Sheldon.

From: Bruce Evans <bde@zeta.org.au>
To: "Vladimir B.Grebenschikov" <vova@sw.ru>
Cc: <FreeBSD-gnats-submit@FreeBSD.ORG>
Subject: Re: bin/32667: systat waste too much time reading input
Date: Tue, 11 Dec 2001 00:28:30 +1100 (EST)

 On Mon, 10 Dec 2001, Vladimir B.Grebenschikov wrote:
 
 > Have tried also on 4.4-RELEASE - same problem
 > >Description:
 > I have found that on same, not busy system top & systat runing
 > simulataniosly "eat" very different amount of CPU time, like:
 >
 > CPU
 > 5.37% systat
 > 0.01% top
 >
 > triing find out what happens, I have tried to run
 > systat -vm 1 < /dev/null
 > And found that systat eats a lot of system resources during input
 >
 >   WCPU   CPU
 >  63.05% 16.36% systat
 
 This seems to be because the VM_METER sysctl is increadibly slow.  It
 takes 13 msec here on an Athlon1600XP system with 512MB memory, but
 "only" 3 msec on a Celeron366 system with 256MB memory.
 
 Bruce
 

From: Sheldon Hearn <sheldonh@starjuice.net>
To: Bruce Evans <bde@zeta.org.au>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/32667: systat waste too much time reading input 
Date: Mon, 10 Dec 2001 15:42:35 +0200

 On Mon, 10 Dec 2001 05:30:02 PST, Bruce Evans wrote:
 
 >  This seems to be because the VM_METER sysctl is increadibly slow.  It
 >  takes 13 msec here on an Athlon1600XP system with 512MB memory, but
 >  "only" 3 msec on a Celeron366 system with 256MB memory.
 
 Are you sure?
 
 The originator reports that the following patch (which he sent me in
 private) makes the symptoms go away.  Is it just because it reduces the
 number of queries to no more than 1 per second?
 
 Ciao,
 Sheldon.
 
 Index: keyboard.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/systat/keyboard.c,v
 retrieving revision 1.1.1.1
 diff -u -d -r1.1.1.1 keyboard.c
 --- keyboard.c	27 May 1994 12:32:44 -0000	1.1.1.1
 +++ keyboard.c	10 Dec 2001 13:37:07 -0000
 @@ -54,8 +54,10 @@
                  do {
                          refresh();
                          ch = getch() & 0177;
 -                        if (ch == 0177 && ferror(stdin)) {
 -                                clearerr(stdin);
 +                        if (ch == 0177) {
 +				sleep(1);
 +				if (ferror(stdin))
 +                                	clearerr(stdin);
                                  continue;
                          }
                          if (ch >= 'A' && ch <= 'Z')
 Index: main.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/systat/main.c,v
 retrieving revision 1.15
 diff -u -d -r1.15 main.c
 --- main.c	25 May 2001 23:10:27 -0000	1.15
 +++ main.c	10 Dec 2001 13:25:56 -0000
 @@ -174,7 +174,7 @@
  	signal(SIGALRM, display);
  	display(0);
  	noecho();
 -	crmode();
 +	halfdelay(10);
  	keyboard();
  	/*NOTREACHED*/
  
 

From: Bruce Evans <bde@zeta.org.au>
To: Sheldon Hearn <sheldonh@starjuice.net>
Cc: <freebsd-gnats-submit@FreeBSD.org>
Subject: Re: bin/32667: systat waste too much time reading input 
Date: Tue, 11 Dec 2001 02:33:56 +1100 (EST)

 On Mon, 10 Dec 2001, Sheldon Hearn wrote:
 
 > On Mon, 10 Dec 2001 05:30:02 PST, Bruce Evans wrote:
 >
 > >  This seems to be because the VM_METER sysctl is increadibly slow.  It
 > >  takes 13 msec here on an Athlon1600XP system with 512MB memory, but
 > >  "only" 3 msec on a Celeron366 system with 256MB memory.
 >
 > Are you sure?
 >
 > The originator reports that the following patch (which he sent me in
 > private) makes the symptoms go away.  Is it just because it reduces the
 > number of queries to no more than 1 per second?
 
 I didn't notice the redirection of stdin in the PR and found a completely
 different problem: "systat -v 1" shows itself taking 1.5% overhead on one
 system.  This is mostly from one syscall that takes 13+ msec being called
 every second.  I guess it could take even longer on a machine with more
 mmory and/or more processes.
 
 Bruce
 
State-Changed-From-To: feedback->open 
State-Changed-By: sheldonh 
State-Changed-When: Mon Dec 10 08:18:37 PST 2001 
State-Changed-Why:  
We've had feedback from both bde and the originator.  One problem 
is easy to fix, the other harder. :-) 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32667 
>Unformatted:
