Skip to contentSkip to conversation

POSIX personality

RFC Dave McCracken 6 participants 10 messages May 21, 2002 – Jun 5, 2002

lore
Share & tools
lore
#0 lore raw

As part of improving support for POSIX multithreading I've been putting together some patches to allow more things to be shared between tasks. Right now this is accomplished via flags to clone() with one flag per resource to be shared. This usually translates to a data structure pointed to out of task_struct, complete with reference count and lock.

In a discussion today an alternate idea was proposed by Ben LaHaise. He suggested creating a POSIX personality, or execution domain. This would take some pressure off the clone flag space as well as allowing some optimizations in the code. It could also be used in situations where POSIX-compatible behavior entails more than just sharing extra resources between tasks.

This would assume that the resources I'm sharing would only be useful for POSIX compatibility, but at this point it seems unlikely that anyone would want to share a subset of them. The resources I'm currently working on include credentials, signals, and timers, and there's a patch available for semaphore undo that could also be part of this mechanism.

Since you've made it this far my question to you all is this: assuming that we do want improved POSIX compatibility does this sound like a reasonable way to add it?

Thanks,
Dave McCracken

======================================================================
Dave McCracken IBM Linux Base Kernel Team 1-512-838-3059
[email protected] T/L 678-3059

#1 lore raw
Quoted 7 lines · Dave McCracken

In a discussion today an alternate idea was proposed by Ben LaHaise. He suggested creating a POSIX personality, or execution domain. This would take some pressure off the clone flag space as well as allowing some optimizations in the code. It could also be used in situations where POSIX-compatible behavior entails more than just sharing extra resources between tasks.

I don't see any reason to start using some fixed-mode semantics without seeing some stronger arguments on exactly why that would be a good idea. We have used up 11 of 24 bits (and more can be made available) over the last five years, and there are no obvious inefficiencies that I can see.

Also, stateful computing is usually a _bad_ idea. System calls that behave differently depending on some external state should be avoided. Yes, it's largely unavoidable if the external state is "we now emulate some other OS behaviour", but that's not an excuse to create new such state, imnsho.

Linus

#2 lore raw

--On Tuesday, May 21, 2002 01:52:37 PM -0700 Linus Torvalds

Quoted 4 lines · <[email protected]> wrote:

I don't see any reason to start using some fixed-mode semantics without seeing some stronger arguments on exactly why that would be a good idea. We have used up 11 of 24 bits (and more can be made available) over the last five years, and there are no obvious inefficiencies that I can see.

Ok, sounds reasonable. I'll add the bits as I go, then.

Dave McCracken

======================================================================
Dave McCracken IBM Linux Base Kernel Team 1-512-838-3059
[email protected] T/L 678-3059

#3 lore raw
In reply to Linus Torvalds
Quoted 4 lines · Linus Torvalds

I don't see any reason to start using some fixed-mode semantics without seeing some stronger arguments on exactly why that would be a good idea. We have used up 11 of 24 bits (and more can be made available) over the last five years, and there are no obvious inefficiencies that I can see.

I think the reason which comes to mind is avoiding future problems. By having a single POSIX mode flag not only does the program not have to know about setting the "right" other bits today, but if we find that POSIX behaviour is needed in some other area in the future, the program doesn't need to be modified and recompiled, because the POSIX behaviour "is in there" for all things.

Ideally a program could execute some make-Linux-run-POSIX in init, and have the expected behaviour everywhere without all manner of ifdefs.

I think that's a stronger argument, avoiding future problems is nice, like wearing Kevlar sox if you shoot yourself in the foot a lot.

Signature · 3 lines
bill davidsen <[email protected]>
  CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.
#4 lore raw
Quoted 7 lines · Bill Davidsen

I think the reason which comes to mind is avoiding future problems. By having a single POSIX mode flag not only does the program not have to know about setting the "right" other bits today, but if we find that POSIX behaviour is needed in some other area in the future, the program doesn't need to be modified and recompiled, because the POSIX behaviour "is in there" for all things.

That's a nice argument in theory, but if you change the behaviour of existing flags, you might fix some program for the real semantics, but you might equally well _break_ some program that unwittingly depended on the old semantics.

So I think your argument is fundamentally flawed. The binary has been tested with the old behaviour, and assuming that you can "fix" existing binaries by changing kernel behaviour is a seriously flawed argument.

Yes, it might work for some programs, but basically you're on very thin ice.

Does Linux break stuff when absolutely required? Sure. But designing an interface that _plans_ on changing semantics is just incredibly stupid, and should absolutely not be done. Ever.

Linus

#5 lore raw
In reply to Bill Davidsen
Quoted 20 lines · Linus Torvalds
Quoted 7 lines · Bill Davidsen

I think the reason which comes to mind is avoiding future problems. By having a single POSIX mode flag not only does the program not have to know about setting the "right" other bits today, but if we find that POSIX behaviour is needed in some other area in the future, the program doesn't need to be modified and recompiled, because the POSIX behaviour "is in there" for all things.

That's a nice argument in theory, but if you change the behaviour of existing flags, you might fix some program for the real semantics, but you might equally well _break_ some program that unwittingly depended on the old semantics.

So I think your argument is fundamentally flawed. The binary has been tested with the old behaviour, and assuming that you can "fix" existing binaries by changing kernel behaviour is a seriously flawed argument.

Quoted 8 lines

Yes, it might work for some programs, but basically you're on very thin ice.

Does Linux break stuff when absolutely required? Sure. But designing an interface that _plans_ on changing semantics is just incredibly stupid, and should absolutely not be done. Ever.

Linus

It seems to me that the biggest issue here is maintaining POSIX behavior without having to modify application source every time the flag set changes.

Perhaps a POSIX bitmask could be defined.

For a degree of binary compatibility a few unused flags could be reserved and the POSIX bitmask include them whether they had meaning yet or not.

Signature · 5 lines
________________________________________________________________
	J.W. Schultz            Pegasystems Technologies
	email address:		[email protected]

		Remember Cernan and Schmitt
#6 lore raw
Quoted 3 lines

It seems to me that the biggest issue here is maintaining POSIX behavior without having to modify application source every time the flag set changes.

I don't think that is a big problem. Think about how it evolves over time

App calls pthread_foo libpthreads/ngpt does all the work by emulation

Add CLONE_somefoo

App calls pthread_foo libpthreads/ngpt does all the work by emulation
and doesnt set the flag

New libpthreads

App calls pthread_foo libpthreads/ngpt uses the kernel assists

The behaviour is good - it means that the new kernel/old library setup won't break the emulation gunge by suddenely providing precise semantics itself

#7 lore raw
In reply to jw schultz
Quoted 34 lines · jw schultz
Quoted 20 lines · Linus Torvalds
Quoted 7 lines · Bill Davidsen

I think the reason which comes to mind is avoiding future problems. By having a single POSIX mode flag not only does the program not have to know about setting the "right" other bits today, but if we find that POSIX behaviour is needed in some other area in the future, the program doesn't need to be modified and recompiled, because the POSIX behaviour "is in there" for all things.

That's a nice argument in theory, but if you change the behaviour of existing flags, you might fix some program for the real semantics, but you might equally well _break_ some program that unwittingly depended on the old semantics.

So I think your argument is fundamentally flawed. The binary has been tested with the old behaviour, and assuming that you can "fix" existing binaries by changing kernel behaviour is a seriously flawed argument.

Quoted 8 lines

Yes, it might work for some programs, but basically you're on very thin ice.

Does Linux break stuff when absolutely required? Sure. But designing an interface that _plans_ on changing semantics is just incredibly stupid, and should absolutely not be done. Ever.

Linus

It seems to me that the biggest issue here is maintaining POSIX behavior without having to modify application source every time the flag set changes.

Quoted 5 lines

Perhaps a POSIX bitmask could be defined.

For a degree of binary compatibility a few unused flags could be reserved and the POSIX bitmask include them whether they had meaning yet or not.

Obviously two ways of looking at things. Linus wants it to work the same all the time, I want it to work the same on all POSIX systems, and if we add (or find) a kernel change which isn't POSIX, and doing things in the POSIX manner breaks the binary, the error is in the program. I have no problem with bits to make little parts of Linux behave in a POSIX manner, but I would like one POSIX bit which sets the most compliant behaviour available.

I shouldn't have to recompile every time another instance of POSIX behaviour is added, and I fail to see that bits are so precious that there couldn't be one POSIX bit in addition to the bits allowing a monmgrel hybred of POSIX and non-POSIX behaviour.

if (environ & OPTION_POSIX_FOO) { standard... } else { non-standard }
is no faster than
if (environ & (OPTION_POSIX | OPTION_POSIX_FOO)) ...
and I fail to see why Linus is fighting the idea so hard. If correct
behaviour breaks my portable program it wasn't portable and the program is in error. I set the bit, I have no complaint.

Signature · 3 lines
bill davidsen <[email protected]>
  CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.
#8 lore raw
In reply to Dave McCracken
Quoted 20 lines · Dave McCracken

As part of improving support for POSIX multithreading I've been putting together some patches to allow more things to be shared between tasks. Right now this is accomplished via flags to clone() with one flag per resource to be shared. This usually translates to a data structure pointed to out of task_struct, complete with reference count and lock.

In a discussion today an alternate idea was proposed by Ben LaHaise. He suggested creating a POSIX personality, or execution domain. This would take some pressure off the clone flag space as well as allowing some optimizations in the code. It could also be used in situations where POSIX-compatible behavior entails more than just sharing extra resources between tasks.

This would assume that the resources I'm sharing would only be useful for POSIX compatibility, but at this point it seems unlikely that anyone would want to share a subset of them. The resources I'm currently working on include credentials, signals, and timers, and there's a patch available for semaphore undo that could also be part of this mechanism.

Quoted 4 lines

Since you've made it this far my question to you all is this: assuming that we do want improved POSIX compatibility does this sound like a reasonable way to add it?

What you are proposing seem a bit vague. I think that CLONE_THREAD should group all the thread related stuff under the one flag. IMHO POSIX compatibility should not be off in the corner as a step child, but rather should be the norm. The CLONE_THREAD flag would indicate to fork that it should create a POSIX thread and set up the needed shared stuff. I rather image this to be a structure that each task_struct points to, possibly with a usage count (but that is a detail). Each thread_struct would point to such a structure, but processes that are not threaded would not be sharing this area with other threads.

Is this close to what you had in mind?

-g

Quoted 10 lines

======================================================================
Dave McCracken IBM Linux Base Kernel Team 1-512-838-3059
[email protected] T/L 678-3059

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 6 lines
George Anzinger   [email protected]
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Real time sched:  http://sourceforge.net/projects/rtsched/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml
#9 lore raw

--On Tuesday, May 21, 2002 02:13:01 PM -0700 george anzinger

Quoted 11 lines · <[email protected]> wrote:

What you are proposing seem a bit vague. I think that CLONE_THREAD should group all the thread related stuff under the one flag. IMHO POSIX compatibility should not be off in the corner as a step child, but rather should be the norm. The CLONE_THREAD flag would indicate to fork that it should create a POSIX thread and set up the needed shared stuff. I rather image this to be a structure that each task_struct points to, possibly with a usage count (but that is a detail). Each thread_struct would point to such a structure, but processes that are not threaded would not be sharing this area with other threads.

That's a possibility I've considered, but I gather most of the kernel community would prefer to see each resource have its own flag to clone() so applications can pick and choose which ones to share. I'm guessing that in most cases multithreaded apps will choose all flags.

Dave McCracken

======================================================================
Dave McCracken IBM Linux Base Kernel Team 1-512-838-3059
[email protected] T/L 678-3059