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.
Michal
diff -u -p -r1.5 splash.c
--- splash.c 10 Jan 2007 14:16:45 -0000 1.5
+++ splash.c 17 Jan 2007 21:49:33 -0000
@@ -42,7 +42,7 @@ static int prepare_abort(struct termios
if (!ret) {
*newtrm = *oldtrm;
newtrm->c_cc[VMIN] = 0;
- newtrm->c_cc[VTIME] = 1;
+ newtrm->c_cc[VTIME] = 0;
newtrm->c_iflag = IGNBRK | IGNPAR | ICRNL | IMAXBEL;
newtrm->c_lflag = 0;
ret = tcsetattr(0, TCSANOW, newtrm);
-------------------------------------------------------------------------
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