Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 3 Apr 2003 17:32:07 +0400 (MSD)
From:      Igor Sysoev <is@rambler-co.ru>
To:        Terry Lambert <tlambert2@mindspring.com>
Cc:        freebsd-arch@freebsd.org
Subject:   Re: libthr and 1:1 threading.
Message-ID:  <Pine.BSF.4.21.0304031659020.32175-100000@is>
In-Reply-To: <3E8C18CC.AF2C6B7F@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 3 Apr 2003, Terry Lambert wrote:

> Igor Sysoev wrote:
> > If a process caused a page fault or memory mapping fault at user level
> > where do you suppose to return in user space after a fault was just queued ?
> > To the same instruction that caused this fault ?
> 
> Yes.  And then return as if the fault had failed.
> 
> Only it's not fatal, because you only return out of the code if
> the fd was marked async; otherwise you go to sleep on the buffer
> getting filled in by an I/O initiated by the fault.  If you do
> return, you don't crash the process, you return with EAGAIN.

I did not say about read() operation. I said about some user land CPU
instruction that accessed a page that is not in a memory. This instruction
causes page fault.

> > BTW what do you mean by 'async fd' in Solaris ?
> > O_ASYNC ? I do not see it in Solaris 8.
> > O_NONBLOCK ? It does not matter for disk files.
> 
> O_NONBLOCK.
> 
> Examining the Solaris 8 sources, it seems to have been removed from
> the disk I/O modules, and applies only to socktpi.c, ptm.c, audio_mc.c,
> ecpp.c, and envctrl.c.  Apparently, it's also missing from the tty
> code, which goes against what Matt claimed, actually.

If Solaris 8's stdin handled by tty code then tty supports O_NONBLOCK:

-----
>uname -imprsv
SunOS 5.8 Generic_108529-17 i86pc i386 i86pc
>cat t1.c

#include <unistd.h>
#include <errno.h>
#include <fcntl.h>

main()
{
   int  rc;
   char buf[1024];

   if ((rc = fcntl(0, F_GETFL)) == -1) {
       printf("fcntl(F_GETFL) failed: %d: %s\n", errno, strerror(errno));
       exit(1);
   }

   if ((rc = fcntl(0, F_SETFL, rc | O_NONBLOCK)) == -1) {
       printf("fcntl(F_SETFL) failed: %d: %s\n", errno, strerror(errno));
       exit(1);
   }

   if ((rc = read(0, buf, 1024)) == -1) {
       printf("read() failed: %d: %s\n", errno, strerror(errno));
   }
}
>gcc -o t1 t1.c 
>./t1 
read() failed: 11: Resource temporarily unavailable
-----

> This is unfortunate, in that it leaves me without an easily
> accessible example, unless you have a USL UNIX source license?
>
> Is there any chance you have legal access to the Solaris 2.2 or
> even the 2.4 source code, which is immediately following the project
> for integration between USL and SunSoft?

This Solaris 2.4's readv() man
http://www.doc.ic.ac.uk/~mac/manuals/solaris-manual-pages/solaris/usr/man/man2/read.2.html 
states that O_NONBLOCKed regular disk file can return EAGAIN only
if there is a mandatory file/record lock. Solaris 8's man states the same.

> Or the USL SVR4.0.2 or SVR4.2 source code?

No, I have not an access to this source code.
But if you have an access to these systems it's easy to check whethear
these systems supports O_NONBLOCK on disk files or not.

> > >> Certainly, you can argue that the application should be structured
> > >> to make all I/O explicit and asynchronous, but for various reasons,
> > >> that's not the case :-).
> > > 
> > >The mmap'ed file case is obviously not something that can be
> > >handled without an explicit contract between user and kernel
> > >for notification of the pagein temporary failure (I would use
> > >a signal for that, probably, as a gross first approximation,
> > >but per-process signal handling is currently not happy...).
> > 
> > And what do you suppose to do in a signal handler ?
> > Using some non-reenterant library functions ?
> 
> No.  Call the user thread scheduler as a result of a fault that
> is normally not trappable because it resulted from a memory access
> to an mmap()'ed region of the address space, rather than resulting
> from an explicit system call.  There is no system call context when
> a trap like that occurs, there is only a trap context.

This is the same thing that KSE M:N model does with page faults.
It upcalls UTS when a thread blocked on a pagein operation.


Igor Sysoev
http://sysoev.ru/en/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0304031659020.32175-100000>