Hi,

On Wednesday, 17 January 2007 23:03, Michal Schmidt wrote:
> Pavel Machek wrote:
> > Hi!
> > 
> >> writing the image to disk wastes 10 seconds by waiting for 0.1s a 
> >> hundred times.
> > 
> > Are you sure?
> 
> In practice the real slowdown is less than 10s, because the disk is 
> usually writing while key_pressed() is waiting. If you had a very fast 
> disk, the slowdown would become more noticeable. I actually tried 
> commenting out the call to swap_write_page from the loop in save_image 
> and the loop still took 10s to run. With my patch it executes almost 
> instantly.
> 
> >> The problem is the key_pressed function. It always attempts to read a 
> >> char from the terminal with a timeout of 1 decisecond. It's better to 
> >> poll the terminal without unnecessary waiting.
> >>
> >> On my laptop the improvement is very noticeable if I enable compression. 
> >> With compression disabled, the effect is not so obvious, because disk 
> >> throughput is the bottleneck.
> > 
> >> @@ -54,6 +52,14 @@
> >>  static int key_pressed(const char key)
> >>  {
> >>    char c;
> >> +  fd_set fds;
> >> +  struct timeval tv = {0, 0};
> >> +
> >> +  FD_ZERO(&fds);
> >> +  FD_SET(0, &fds);
> >> +  if (select(1, &fds, NULL, NULL, &tv) <= 0)
> >> +          return 0;
> >> +
> >>    if (read(0, &c, 1) > 0 && c == key) 
> >>            return 1;
> > 
> > 
> > That seems unneccessarily complex, just set stdin to nonblocking mode
> > and read should return immediately, right?
> >                                                                     Pavel
> 
> Right. Here's a much simpler patch with the same effect.

I think this one is simple enough so that we can apply it. :-)  Pavel?


-- 
If you don't have the time to read,
you don't have the time or the tools to write.
                - Stephen King

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Suspend-devel mailing list
Suspend-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/suspend-devel

Reply via email to