This is the mail archive of the cygwin-developers@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Daemon reviewer



===
----- Original Message -----
From: "egor duda" <deo@logos-m.ru>


> Hi!
>
> Sunday, 27 January, 2002 Robert Collins robert.collins@itdomain.com.au
wrote:
>
> RC> Gary, will you have to time make some sort of comment on the
code/design
> RC> quality in the next (say) fortnight?
>
> i'm in process of looking into it. the first thing i've stumbled
> over is that cygserver.exe depends on cygwin1.dll. I believe it's
> just wrong and may be a source of difficult to find errors. Is there
> any particular reason for linking daemon with cygwin1.dll? original
> named-pipes-as-transport thingie was made with self-sufficiency
> requirement.

I dont' recall offhand exactly what I used from cygwin itself, but I do
recall needing some functions and not wanting to have to extract them
all by hand. I don't think it will produce any strange results though -
because the daemon's cygwin1.dll instance will be running daemonless.
Ah! I recall. Unix sockets for win95 - that was the key thing I wanted.
Rather than duplicate the cygwin code, allowing for version skew issues,
I used cygwin to manage unix sockets. The only trouble I had was with
cygserver recieving signals - and that was only AFTER I installeda
signal handler.

> second, you wrote that it's mulithreaded, but it's not very clear what
> does that mean.

Ok, I can do a threading model primer if needed, but this daemon uses a
producer-consumer model. There are:
a set of work queues.
for each queue a fixed set of worker threads.
a queue control thread.

Each operation gets a dedicated thread for the life of the operation,
and then the thread resumes waiting.


> Do i understand right that every client connection
> creates a separate thread to handle requests from that client?

No. Every client connection uses an existing worker  thread for each
request. Also a single client can have multiple concurrent requests
(i.e. one from each thread in the client). This is as close to the
optimal performance threaded model, (which is asynchronous non-blocking
IO with 1 thread per processor) as we can get reliably on win95, and
it's very high performance anyway for NT. The reason we have a fixed
number of worker threads is to prevent thrashing during high work load
periods (I've never hit the default limit). Any requests recieved while
ALL threads are busy will get queued and the queue head is dequeued by
the next thread that finishes a task - without context switching. The
threads are not ordered, so ideally NT/9x's kernel will let long-term
idle threads swap out, and preferentially signal threads that have
handled more requests. If we ever get all the threads active at once,
then the dequeuing code becomesactive and the threads will work at full
efficiency. (see threaded_queue.cc::worker_function).

The worker threads are somewhat specialised, but for a given
queue_request  hierarchy, can handle any requests via overridden
process() methods. (This is only particular relevant when looking at the
process cache - SHM related stuff - because all the cygwin<->daemon
calls will get handled by one queue and set of worker threads.)

We can opt for a runtime, or even load tunable number of threads, but
that shouldn't be needed (IMO).

> If it's
> so, i'm afraid i don't understand what all those Interlocked* calls
> and synchronization-related FIXME:'s are for. For instance, in
> cygserver_transport_pipes.cc (transport_layer_pipes::init_security)
> there's a FIXME: comment about the need of something like
> pthread_once. i don't see why it's needed. Standard security
> descriptors should be initialized once at the program startup, before
> any new threads are being spawned.

Right. Well the security descriptors are inited when the first transport
object is created.... so there is an opportunity for someone to create
two threads, and have both create a transport object at the same time.
We don't do that in cygsserver, and it's model won't ever do that, but
if someone takes the code elsewhere, they should add syncronisation at
that point.

Anyway, I hope the earlier description explains why the syncronisation
calls are needed.

Rob


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]