Re: scrolling eats too much cpu (2)

Alexander V. Lukyanov (lav@yars.free.net)
Fri, 11 Dec 1998 18:55:51 +0300


On Fri, Dec 11, 1998 at 03:59:51PM +0000, Alan Cox wrote:
> > So, when a program writes large blocks to graphical console (e.g.
> > telnet or cat), scheduling does not occur quite a long time.
> >
> > I tried the following hack, and it helped in -opost case. But I know
> > it's not correct solution. Any ideas?
>
> There is a flag the scheduler keeps on the current task you can test
> to see if it thinks you should by now have given up the CPU. So providing
> you put it somewhere that sleeping is ok (eg by the copy from user)
> then
>
> if(current->need_resched)
> schedule();
>
> should do the trick

Thanks a lot! I was suspecting something like this, but was not sure.
Below is what I have now, and it solves my problems.

Question remains: can setting current->state in do_con_write affect something?
It is needed to avoid sleep on write_wait in write_chan.

BTW, this patch adds check for signals in opost case, this speeds up
interrupting a process writing to console. Umm, maybe such check should
be also added to do_con_write?

--- console.c.1 Fri Dec 11 18:43:24 1998
+++ console.c Fri Dec 11 18:46:13 1998
@@ -1912,6 +1912,15 @@
}
FLUSH
do_con_trol(tty, currcons, c);
+
+ if(current->need_resched)
+ {
+ /* To avoid stalls in chan_write (-opost case) */
+ current->state=TASK_RUNNING;
+ /* Can't call schedule here, return to caller.
+ Caller must schedule if it can. */
+ break;
+ }
}
FLUSH
enable_bh(CONSOLE_BH);
--- n_tty.c.1 Thu Dec 10 13:13:51 1998
+++ n_tty.c Fri Dec 11 18:36:36 1998
@@ -1081,7 +1081,17 @@
nr -= num;
if (nr == 0)
break;
+ if (signal_pending(current)) {
+ retval = -ERESTARTSYS;
+ goto break_out;
+ }
get_user(c, b);
+ if (current->need_resched)
+ {
+ current->state = TASK_RUNNING;
+ schedule();
+ current->state = TASK_INTERRUPTIBLE;
+ }
if (opost(c, tty) < 0)
break;
b++; nr--;

Alexander.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/