Re: Important patch to fix select!

Rogier Wolff (R.E.Wolff@BitWizard.nl)
Thu, 8 Jul 1999 22:37:45 +0200 (MEST)


Jamie Lokier wrote:
> My credentials: I have written or modified several interactive games
> inside and outside X, on several Unix variants.
>
> And one thing that showed up as a pain was the scheduling behaviour of
> select().
>
> For 3d games, precise frame timing doesn't seem to matter. You just
> don't notice. For 2d, if there's only a few things moving you really
> notice the difference between "smooth" and "not smooth". Ie. visual
> jitter. I'm going to describe what I had to do to get "smooth" under
> SunOS 4.
>
> Basically, to smoothly move an image across the screen at say 25Hz you
> have to do this:
>
> time = gettimeofday();
> while (1) {
> move_sprite_to_new_position();
> flush_X_commands();
> time = time + 1/frame_rate;
> select(0,0,0,0, new_time - gettimeofday() - SCHEDULER_TICK);
> while (gettimeofday() < new_time) {
> /* Busy wait for av. 0.5 ticks, and _don't_ yield. */
> }
> }

What happens if you just forget the "SCHEDULER_TICK" and the "while
loop"?

I'd expect the program to get scheduled about 10ms too late. Every
time, not cumulative.

Now it could be that if you try to go for 30Hz, the one-in-three times
that you'd have 4 timer ticks instead of 3 looks really lowsy. But if
you evenly divide into an integer number of timer ticks it should work
about as good as your implementation. Of course, 70Hz is pushing the
limit... You'd want a 14ms wakup call, but in reality get 0, 10 or
twenty. That probably doesn't look too good.

Decoupling the kernel-HZ and the userland HZ will certainly help. I've
posted about that in a different message. If done right, we should be
able to increase kernel-HZ to any value the hardware can support....

I find it odd that 3d games have less of a problem with this. Maybe
the 3D graphics accellerator smoothens things out, because it is
always running at max throughput....

Roger.

-- 
** R.E.Wolff@BitWizard.nl ** http://www.BitWizard.nl/ ** +31-15-2137555 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
------ Microsoft SELLS you Windows, Linux GIVES you the whole house ------

- 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/