niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » *nix » BSD » FreeBSD » mail-lists » Architecture
Why use `thread' as an argument of Syscalls?
Post new topic   Reply to topic Page 1 of 1 [11 Posts] View previous topic :: View next topic
Author Message
MingyanGuo
*nix forums beginner


Joined: 05 Jun 2006
Posts: 4

PostPosted: Mon Jun 05, 2006 7:44 am    Post subject: Why use `thread' as an argument of Syscalls? Reply with quote

Hi all,
I find that FreeBSD Syscalls always have an `thread'
argument, for example, preadv(/sys/kern/sys_generic.c)
has a `td' argument. But some Syscalls may rarely use
this argument, and thay ( and functions they invoke) can
get the `thread' who make the Syscall _easily_ via
`curthread' macro if needed. So the `thread' argument
seems not needed.
Can anybody tell me why use `thread' as an argument
of Syscalls?

Thanks.

Regards,

--
Three passions, simple but overwhelmingly strong, have governed my life:
the longing for love, the search for knowledge, and unbearable pity for
the suffering of mankind.
---------Bertrand Russell
_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
Daniel Eischen
*nix forums addict


Joined: 20 Sep 2002
Posts: 68

PostPosted: Mon Jun 05, 2006 11:50 am    Post subject: Re: Why use `thread' as an argument of Syscalls? Reply with quote

On Mon, 5 Jun 2006, MingyanGuo wrote:

Quote:
Hi all,
I find that FreeBSD Syscalls always have an `thread'
argument, for example, preadv(/sys/kern/sys_generic.c)
has a `td' argument. But some Syscalls may rarely use
this argument, and thay ( and functions they invoke) can
get the `thread' who make the Syscall _easily_ via
`curthread' macro if needed. So the `thread' argument
seems not needed.
Can anybody tell me why use `thread' as an argument
of Syscalls?

You could have asked "why use 'proc' as an argument of Syscalls"
12 years ago (or more). When the kernel became thread-aware
(almost 5 years ago), most 'struct proc' arguments were changed
to 'struct thread'.

--
DE
_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
MingyanGuo
*nix forums beginner


Joined: 05 Jun 2006
Posts: 4

PostPosted: Mon Jun 05, 2006 1:08 pm    Post subject: Re: Why use `thread' as an argument of Syscalls? Reply with quote

On 6/5/06, Daniel Eischen <deischen@freebsd.org> wrote:
Quote:

On Mon, 5 Jun 2006, MingyanGuo wrote:

Hi all,
I find that FreeBSD Syscalls always have an `thread'
argument, for example, preadv(/sys/kern/sys_generic.c)
has a `td' argument. But some Syscalls may rarely use
this argument, and thay ( and functions they invoke) can
get the `thread' who make the Syscall _easily_ via
`curthread' macro if needed. So the `thread' argument
seems not needed.
Can anybody tell me why use `thread' as an argument
of Syscalls?

You could have asked "why use 'proc' as an argument of Syscalls"
12 years ago (or more). When the kernel became thread-aware
(almost 5 years ago), most 'struct proc' arguments were changed
to 'struct thread'.

--
DE


They are the same questions, I think Wink. Now would
you please explain "why use `proc' as an argument
of Syscalls" to me Smile? I've read some source code
of the kernel, but no comments about it found.
Thanks.
Regards,

--
Three passions, simple but overwhelmingly strong, have governed my life:
the longing for love, the search for knowledge, and unbearable pity for
the suffering of mankind.
---------Bertrand Russell
_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
Daniel Eischen
*nix forums addict


Joined: 20 Sep 2002
Posts: 68

PostPosted: Mon Jun 05, 2006 3:19 pm    Post subject: Re: Why use `thread' as an argument of Syscalls? Reply with quote

On Mon, 5 Jun 2006, MingyanGuo wrote:

Quote:
On 6/5/06, Daniel Eischen <deischen@freebsd.org> wrote:

On Mon, 5 Jun 2006, MingyanGuo wrote:

Hi all,
I find that FreeBSD Syscalls always have an `thread'
argument, for example, preadv(/sys/kern/sys_generic.c)
has a `td' argument. But some Syscalls may rarely use
this argument, and thay ( and functions they invoke) can
get the `thread' who make the Syscall _easily_ via
`curthread' macro if needed. So the `thread' argument
seems not needed.
Can anybody tell me why use `thread' as an argument
of Syscalls?

You could have asked "why use 'proc' as an argument of Syscalls"
12 years ago (or more). When the kernel became thread-aware
(almost 5 years ago), most 'struct proc' arguments were changed
to 'struct thread'.

--
DE


They are the same questions, I think Wink. Now would
you please explain "why use `proc' as an argument
of Syscalls" to me Smile? I've read some source code
of the kernel, but no comments about it found.

I don't know. Convention? It makes sense to me.

--
DE
_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
Robert Watson
*nix forums Guru Wannabe


Joined: 22 Mar 2002
Posts: 218

PostPosted: Mon Jun 05, 2006 3:36 pm    Post subject: Re: Why use `thread' as an argument of Syscalls? Reply with quote

On Mon, 5 Jun 2006, Daniel Eischen wrote:

Quote:
They are the same questions, I think Wink. Now would you please explain "why
use `proc' as an argument of Syscalls" to me Smile? I've read some source
code of the kernel, but no comments about it found.

I don't know. Convention? It makes sense to me.

Certainly consistency. Most system calls do actually use the argument at some
point -- be it to look up a file descriptor, access control, or the like, and
the calling context has it for free and in-hand anyway.

Robert N M Watson
_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
Suleiman Souhlal
*nix forums beginner


Joined: 17 Sep 2003
Posts: 12

PostPosted: Mon Jun 05, 2006 3:42 pm    Post subject: Re: Why use `thread' as an argument of Syscalls? Reply with quote

Robert Watson wrote:
Quote:

On Mon, 5 Jun 2006, Daniel Eischen wrote:

They are the same questions, I think Wink. Now would you please
explain "why use `proc' as an argument of Syscalls" to me Smile? I've
read some source code of the kernel, but no comments about it found.


I don't know. Convention? It makes sense to me.


Certainly consistency. Most system calls do actually use the argument
at some point -- be it to look up a file descriptor, access control, or
the like, and the calling context has it for free and in-hand anyway.

But couldn't they just use curthread/curproc?

-- Suleiman
_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
Garrett Wollman
*nix forums addict


Joined: 08 May 2002
Posts: 59

PostPosted: Mon Jun 05, 2006 3:42 pm    Post subject: Re: Why use `thread' as an argument of Syscalls? Reply with quote

Robert Watson writes:

Quote:
Certainly consistency. Most system calls do actually use the argument at some
point -- be it to look up a file descriptor, access control, or the like, and
the calling context has it for free and in-hand anyway.

I believe it was the intention of the 4.4BSD developers to completely
eliminate "curproc" (as they had already successfully eliminated "u"),
on the theory that with a modern (RISC) processor architecture,
passing the current process as a parameter wouldn't cost anything
(since it would stay in a register for the life of the system call)
whereas making a context-switched "curproc" would be expensive.

-GAWollman

_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
Poul-Henning Kamp
*nix forums Guru


Joined: 21 Mar 2002
Posts: 436

PostPosted: Mon Jun 05, 2006 3:48 pm    Post subject: Re: Why use `thread' as an argument of Syscalls? Reply with quote

In message <448450FD.4030709@FreeBSD.org>, Suleiman Souhlal writes:
Quote:
Robert Watson wrote:

On Mon, 5 Jun 2006, Daniel Eischen wrote:

They are the same questions, I think Wink. Now would you please
explain "why use `proc' as an argument of Syscalls" to me Smile? I've
read some source code of the kernel, but no comments about it found.


I don't know. Convention? It makes sense to me.


Certainly consistency. Most system calls do actually use the argument
at some point -- be it to look up a file descriptor, access control, or
the like, and the calling context has it for free and in-hand anyway.

But couldn't they just use curthread/curproc?

Yes, mostly.

It's a good question how much, if anything, it helps.

--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
Robert Watson
*nix forums Guru Wannabe


Joined: 22 Mar 2002
Posts: 218

PostPosted: Mon Jun 05, 2006 3:56 pm    Post subject: Re: Why use `thread' as an argument of Syscalls? Reply with quote

On Mon, 5 Jun 2006, Suleiman Souhlal wrote:

Quote:
Robert Watson wrote:

On Mon, 5 Jun 2006, Daniel Eischen wrote:

They are the same questions, I think Wink. Now would you please explain
"why use `proc' as an argument of Syscalls" to me Smile? I've read some
source code of the kernel, but no comments about it found.

I don't know. Convention? It makes sense to me.

Certainly consistency. Most system calls do actually use the argument at
some point -- be it to look up a file descriptor, access control, or the
like, and the calling context has it for free and in-hand anyway.

But couldn't they just use curthread/curproc?

In the past, in micro-benchmarking, I've measured a small performance hit from
using per-cpu variables over variables already in the stack. However, that
was quite a while ago, and I'm not entirely convinced the test results were
valid. In the general case, it's pretty helpful to be able to pass in, for
example, explicit credential references, as it means you can do acess control
checks, auditing, accounting, etc, against arbitrary credentials rather than
always against curthread->td_ucred. In a number of places, we pass threads
down the stack where we mean to pass credentials, such as at several spots in
the network stack. There are also places where the process is passed around
so it can become a later argument to lockmgr() locking primitives, and since
those are decreasingly used, the references are increasingly unnecessary.

Robert N M Watson
_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
MingyanGuo
*nix forums beginner


Joined: 05 Jun 2006
Posts: 4

PostPosted: Mon Jun 05, 2006 4:30 pm    Post subject: Re: Why use `thread' as an argument of Syscalls? Reply with quote

On 6/5/06, Robert Watson <rwatson@freebsd.org> wrote:
Quote:


On Mon, 5 Jun 2006, Daniel Eischen wrote:

They are the same questions, I think Wink. Now would you please explain
"why
use `proc' as an argument of Syscalls" to me Smile? I've read some
source
code of the kernel, but no comments about it found.

I don't know. Convention? It makes sense to me.

Certainly consistency. Most system calls do actually use the argument at
some
point -- be it to look up a file descriptor, access control, or the like,
and
the calling context has it for free and in-hand anyway.

Robert N M Watson


Thanks for your reply. And any more reasons?
I have browsed some OpenSolaris and Linux source,
and find that they get the `proc'/`thread'/`task'
by `curproc'/`curthread'/`current' like macros
when needed, which are different from FreeBSD.
So I wanna know why FreeBSD do it in this way,
has some mysterious reasons;-)? or not.

Thanks

Regards,

MingyanGuo


--
Three passions, simple but overwhelmingly strong, have governed my life:
the longing for love, the search for knowledge, and unbearable pity for
the suffering of mankind.
---------Bertrand Russell


--
Three passions, simple but overwhelmingly strong, have governed my life:
the longing for love, the search for knowledge, and unbearable pity for
the suffering of mankind.
---------Bertrand Russell
_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
MingyanGuo
*nix forums beginner


Joined: 05 Jun 2006
Posts: 4

PostPosted: Mon Jun 05, 2006 5:13 pm    Post subject: Re: Why use `thread' as an argument of Syscalls? Reply with quote

On 6/5/06, Robert Watson <rwatson@freebsd.org> wrote:
Quote:


On Mon, 5 Jun 2006, Suleiman Souhlal wrote:

Robert Watson wrote:

On Mon, 5 Jun 2006, Daniel Eischen wrote:

They are the same questions, I think Wink. Now would you please
explain
"why use `proc' as an argument of Syscalls" to me Smile? I've read
some
source code of the kernel, but no comments about it found.

I don't know. Convention? It makes sense to me.

Certainly consistency. Most system calls do actually use the argument
at
some point -- be it to look up a file descriptor, access control, or
the
like, and the calling context has it for free and in-hand anyway.

But couldn't they just use curthread/curproc?

In the past, in micro-benchmarking, I've measured a small performance hit
from
using per-cpu variables over variables already in the stack. However,
that
was quite a while ago, and I'm not entirely convinced the test results
were
valid. In the general case, it's pretty helpful to be able to pass in,
for
example, explicit credential references, as it means you can do acess
control
checks, auditing, accounting, etc, against arbitrary credentials rather
than
always against curthread->td_ucred. In a number of places, we pass
threads
down the stack where we mean to pass credentials, such as at several spots
in
the network stack. There are also places where the process is passed
around
so it can become a later argument to lockmgr() locking primitives, and
since
those are decreasingly used, the references are increasingly unnecessary.

Robert N M Watson


Thanks.

MingyanGuo

--
Three passions, simple but overwhelmingly strong, have governed my life:
the longing for love, the search for knowledge, and unbearable pity for
the suffering of mankind.
---------Bertrand Russell
_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [11 Posts] View previous topic :: View next topic
The time now is Fri Nov 21, 2008 1:03 am | All times are GMT
navigation Forum index » *nix » BSD » FreeBSD » mail-lists » Architecture
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Can thread start other threads? John Henry python 2 Tue Jul 18, 2006 9:58 pm
No new posts Function Prototype - different argument names cybernerdsx2 C 3 Tue Jul 18, 2006 4:50 am
No new posts Which allocator to use? For fixed-size, single-thread, po... collection60@hotmail.com C++ 5 Mon Jul 17, 2006 1:40 pm
No new posts urllib (in thread) never returns Kingsley python 1 Mon Jul 17, 2006 12:53 am
No new posts Can just reading a global be thread unsafe? greg wellman C++ 6 Fri Jul 14, 2006 6:35 am

Credit Card Consolidation | Problem Mortgage | Loans | Loan | Adverse Credit Remortgage
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 1.9294s ][ Queries: 16 (1.7938s) ][ GZIP on - Debug on ]