[GRASS5] 5.7: XDRIVER modification - CPU load

Hi 5.7 users,

update to XDRIVER:
The XDRIVER should consume less CPU now when querying maps or
zooming into. I have added a nanosleep of 500 milliseconds.
We have to experiment with this value to find a good one
with respect to CPU power, operating system and sleepyness
of d.what.vect/d.zoom.

Let me know. The modified file is indicated below.

Markus

On Thu, Mar 18, 2004 at 04:22:10PM +0100, grass@intevation.de wrote:

Author: markus

Update of /grassrepository/grass51/display/drivers/lib
In directory doto:/tmp/cvs-serv29397

Modified Files:
  command.c
Log Message:
nanosleep() added to reduce CPU load when querying/zooming into maps

On Thu, Mar 18, 2004 at 04:28:01PM +0100, Markus Neteler wrote:

Hi 5.7 users,

update to XDRIVER:
The XDRIVER should consume less CPU now when querying maps or
zooming into. I have added a nanosleep of 500 milliseconds.
We have to experiment with this value to find a good one
with respect to CPU power, operating system and sleepyness
of d.what.vect/d.zoom.

Let me know. The modified file is indicated below.

Mhh. I just realized that the change is nice for d.what.vect,
but makes d.zoom extremely slow. Suggestions welcome.

Markus

Markus Neteler wrote:

> The XDRIVER should consume less CPU now when querying maps or
> zooming into. I have added a nanosleep of 500 milliseconds.
> We have to experiment with this value to find a good one
> with respect to CPU power, operating system and sleepyness
> of d.what.vect/d.zoom.
>
> Let me know. The modified file is indicated below.

Mhh. I just realized that the change is nice for d.what.vect,
but makes d.zoom extremely slow. Suggestions welcome.

FWIW (and I accept that's probably next to nothing) I would suggest
either:

1. Reverting the Get_location_with_* functions to the 5.3 versions,
and just accepting their limitations.

2. Getting rid of the Get_location_with_* functions altogether, making
the "display" API into a *display* API. Use a GUI toolkit if you want
interaction. [If you got rid of the resize handling at the same time,
the driver architecture (not just XDRIVER) would become vastly
simpler, as you wouldn't need to handle X events *at all*.]

In any case, a busy-wait (repeated non-blocking calls in a loop)
definitely isn't the solution. The only sensible approach is to use
select() on both the X descriptor and the driver socket. Get_Xevent()
already does this; I suggest using it; like 5.0/5.3 do.

--
Glynn Clements <glynn.clements@virgin.net>

On Thu, Mar 18, 2004 at 06:08:54PM +0000, Glynn Clements wrote:

Markus Neteler wrote:

> > The XDRIVER should consume less CPU now when querying maps or
> > zooming into. I have added a nanosleep of 500 milliseconds.
> > We have to experiment with this value to find a good one
> > with respect to CPU power, operating system and sleepyness
> > of d.what.vect/d.zoom.
> >
> > Let me know. The modified file is indicated below.
>
> Mhh. I just realized that the change is nice for d.what.vect,
> but makes d.zoom extremely slow. Suggestions welcome.

For now I have reverted the change.

FWIW (and I accept that's probably next to nothing) I would suggest
either:

1. Reverting the Get_location_with_* functions to the 5.3 versions,
and just accepting their limitations.

2. Getting rid of the Get_location_with_* functions altogether, making
the "display" API into a *display* API. Use a GUI toolkit if you want
interaction. [If you got rid of the resize handling at the same time,
the driver architecture (not just XDRIVER) would become vastly
simpler, as you wouldn't need to handle X events *at all*.]

In any case, a busy-wait (repeated non-blocking calls in a loop)
definitely isn't the solution. The only sensible approach is to use
select() on both the X descriptor and the driver socket. Get_Xevent()
already does this; I suggest using it; like 5.0/5.3 do.

Using select() and friends seems to be the (temporal) solution unless
someone writes a new display driver. Unfortunatelty I don't know
how to change that. The reasons why select() etc are not used
I cannot remember (if it was ever posted).

Markus

--
Markus Neteler <neteler itc it> http://mpa.itc.it
ITC-irst - Centro per la Ricerca Scientifica e Tecnologica
MPBA - Predictive Models for Biol. & Environ. Data Analysis
Via Sommarive, 18 - 38050 Povo (Trento), Italy

Markus Neteler wrote:

> In any case, a busy-wait (repeated non-blocking calls in a loop)
> definitely isn't the solution. The only sensible approach is to use
> select() on both the X descriptor and the driver socket. Get_Xevent()
> already does this; I suggest using it; like 5.0/5.3 do.

Using select() and friends seems to be the (temporal) solution unless
someone writes a new display driver. Unfortunatelty I don't know
how to change that. The reasons why select() etc are not used
I cannot remember (if it was ever posted).

FWIW:

Even if someone does write a new display driver, select() (or poll(),
which serves essentially the same purpose) will still be the solution.

If you don't use select/poll, you're reduced to either:

a) blocking on the X connection,
b) blocking on the client connection,
c) manual polling, i.e. making both descriptors non-blocking and
checking them continuously, or
d) as for c), but sleeping in between checks.

The problems with the above are:

In case a), if the client terminates, the driver will still be waiting
for the user to press a mouse button; other clients won't be able to
connect until that happens. [This is what XDRIVER used to do.]

Case b) isn't an option for the Get_location_with_* functions; normal
operation involves X button events occurring before the client
terminates.

Case c) will result in the driver consuming all available CPU cycles.

Case d) avoids the CPU-hogging at the expense of introducing a delay
between the event occurring and the driver handling it.

The only approach which doesn't have any of these drawbacks is to
block until either an X event is received via the X connection or the
client terminates (resulting in EOF on the client connection). IOW,
select() or poll().

--
Glynn Clements <glynn.clements@virgin.net>