Re: performance....

"Richard Seaman, Jr." <[email protected]> Sun, 14 Apr 2002 16:47:00 -0500
Newsgroups gmane.linux.ngpt.user
Message-ID <[email protected]>
On Sat, Apr 13, 2002 at 01:14:55AM +0200, Julien Ducourthial wrote:
>  Hi,
> 
> I find the ngpt work very interesting (I'm pretty impressed with the 
> progress made toward posix compliance). But I've got a small concern :
> in the release notes of ngpt 1.2.1, I read "...With the exception of 
> output to stdout and semaphores, NGPT 1.2.1 out performs LinuxThreads in 
> virtually every area.". But using a dumb bench (a reversible operation 
> executed in loop), this is not exactly what I get :

[snip]

It appears to me that some NGPT syscalls could be made more efficient
than they are.  Looking at the read/write syscall wrappers, in the case
of a blocking mode read/write, it appears that the best case is this
(just listing the syscalls):

    fcntl
    select
    read or write

ie. it takes a minimum of three syscalls to effect just the single
read or write syscall.  If the syscall would block in the kernel,
it will make more syscalls still as the thread scheduler polls
the fd status from within the thread_scheduler.

(note I didn't check to see if somewhere "under the covers" the
fcntl call is just a userland call rather than a full syscall --
which would seem possible here).

It seems to me that the best case (ie. a blocking mode call
that doesn't block) could be reduced to just the read/write syscall.
This is what the FreeBSD folks accomplish with their "user threads"
pthread package.  Basically, the pthreads library manages all fd's
and when an fd is opened it is placed in non-blocking mode, and
the end users desired blocking status is kept in a user space
array.  Then, instead of making the fcntl/select calls, the read
or write call is made directly.

If the return is EWOULDBLOCK, and if the user thinks he's making
a blocking syscall, the thread gets preempted, just like in the
NGPT case.  The syscall overhead in this case is the same as
the NGPT case, except that the fcntl syscall is avoided since
the blocking status of the fd is already available in user space. 
(The first read, which returns EWOULDBLOCK has performed the same
function as the select call in the NGPT case).

But, in the case the return is something other than EWOULDBLOCK
(or EAGAIN too, I think), the code can proceed without any other
syscalls.  This saves the fcntl and select calls.  I would think
this would make blocking mode I/O syscalls quite a bit more 
efficent.  Of course, the pthreads library code gets more complex
since more syscalls need to be wrapped (eg. open, close, fcntl, etc.).
 
-- 
Richard Seaman, Jr.        email:    [email protected]
5182 N. Maple Lane         phone:    262-367-5450
Nashotah WI 53058            fax:    262-367-5852