public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Powertop shows events/0 waking at high rate due to ptys
@ 2010-09-27 17:37 Jeremy Fitzhardinge
  2010-09-27 18:15 ` Alan Cox
  0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Fitzhardinge @ 2010-09-27 17:37 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Greg KH, Alan Cox, Linux Kernel Mailing List, Arjan van de Ven,
	Ian Jackson, Steven Rostedt, OGAWA Hirofumi

[-- Attachment #1: Type: text/plain, Size: 1086 bytes --]

 Hi,

I noticed on one of my systems that powertop was showing events/0 waking
at a high rate (~2000 times/sec, HZ=1000).  After a lot of tracing I
found it was due to writes pending to ptys which hadn't been read.

Specifically, in flush_to_ldisc(), these lines seem to be causing the
repeated wakeups:

			if (!tty->receive_room) {
				schedule_delayed_work(&tty->buf.work, 1);
				break;
			}

After reading the pending writes the system settles down and wakeups
drops to a normal low level.

The program provoking this was Xen's xenconsoled, which manages running
domains' consoles; the unread output was various domains console
output.  This doesn't seem to be related to Xen at all: Ian Jackson put
together a small standalone program (attached) which reproduces the
problem; he reports that this wakeup behaviour is a regression compared
to a 2.6.16 Debian kernel.

Compile ptypolling with: gcc -o ptypolling ptypolling.c -g -lutil

After running ptypolling, powertop shows events/0 waking at a high
rate.  ptypolling itself is blocked in a select() and is idle.

Thanks,
    J


[-- Attachment #2: ptypolling.c --]
[-- Type: text/x-csrc, Size: 1175 bytes --]

/* demonstrate polling wakeup */

#include <unistd.h>
#include <pty.h>
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

static int master, slave;

int main(void) {
  int r;

  r = openpty(&master,&slave,0,0,0);
  fprintf(stdout,"openpty=%d master=%d slave=%d\n", r, master, slave);
  assert(!r);
  
  r = fcntl(master, F_GETFL);  assert(r>=0);
  r = fcntl(master, F_SETFL, r | O_NONBLOCK);

  char buf[400];
  int i;
  for (i=0; i<sizeof(buf)-2; i+=2)
    sprintf(buf+i, "%02x", i);
  buf[sizeof(buf)-2]= '\r';
  buf[sizeof(buf)-1]= '\n';
  
  fd_set writefds;
  for (;;) {
    FD_ZERO(&writefds);
    FD_SET(master, &writefds);
    fprintf(stdout,"select\n");
    r= select(master+1, 0,&writefds,0, 0);
    if (r==-1) {
      fprintf(stdout,"select-fail %s\n", strerror(errno));
      continue;
    }
    assert(r==1);
    assert(FD_ISSET(master, &writefds));

    fprintf(stdout,"write\n");
    r= write(master,buf,sizeof(buf));
    if (r==-1) {
      fprintf(stdout,"write-fail %s\n", strerror(errno));
      continue;
    }
    assert(r>=0 && r<=sizeof(buf));
    fprintf(stdout,"wrote %d\n",r);
  }
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-09-30 13:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-27 17:37 Powertop shows events/0 waking at high rate due to ptys Jeremy Fitzhardinge
2010-09-27 18:15 ` Alan Cox
2010-09-28  0:27   ` Jeremy Fitzhardinge
2010-09-30  7:19     ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox