Thanks dude, you probably helped me more with this than you'd ever expectedColonel Kernel wrote:I also think it would be silly for the OS API to vary wildly depending on the underlying policies.
As I've already mentioned before my plan was to divide the OS into three part:
[*] kernel + drivers: mechanism to access/multiplex the hardware, protected by hierarchical capabilities
[*] user-level managers: system-wide minimum policy to provide fairness
[*] libraries: abstraction for the app programmer, policy as far as the user-level managers would allow
What you've pointed me to is that I never really wasted a thought about how the user-level managers should actually accomplish their task in detail. I just had the rather faint idea that they would have to decide upon a policy (that's why I wanted to support multiple managers..) and then provide a somewhat specialized interface to the apps. I always had a bad feeling about this as it means taking away some of the policy from the apps which in my opinion made it necessary to support multiple managers with all the problem this would cause (different APIs, resource balancing between managers, etc).
What I've for some reason not noticed is that it's not the policy that ensures fairness in a kernel, but built in limits that are either statically set by the programmer or can be specified by the user. One example would be a priority round robin scheduler that seems to ensure fairness although it itself doesn't at all force that apps won't schedule themselves forever by setting their priority to a very high value. In fact it's a built-in limitation that makes sure that this doesn't happen by either restricting access to high priority classes to certain privileged apps (eg: drivers only) or by using some kind of time limitation (priority shrinks for each time-slice used completly).
Consequently it should also be possible to ensure system-wide fairness without involving any policy but only by enforcing user set limitations/quotas for the resources provided by the kernel. This can be done by allowing the user to specify these restrictions in advance using some ini-file and then using a user-space manager that enforces these limits.
In order to show you how this can work in real life, I'll present a small example that will deal with scheduling as this is in my opinion the most complex kernel resource (CPU, Memory+I/O, IRQ) to manage. Let's assume that the user is using a system that runs mostly desktop tasks, but sometimes would also like to execute apps that have to meet real-time constraints.
Here's a small sketch of the ini-file to be used:
[pre]
[scheduler - version: 1.0]
class realtime
{
level: 0
cpu: 100%
capability: GID 0x0012, GID 0x0013
quantum_min: 1 TS
quantum_max: 10 TS
}
class round-robin
{
level: 1
cpu: 50%
capability: 0
quantum_min: 1 TS
quantum_max: 4 TS
}
class priority-class
{
level: 1
cpu: 50%
capability: 0
quantum_min: 3 TS
quantum_max: 6 TS
}
[/pre]
As the scheduler's job in my approach is mainly to decide who gets how many resources, all it has to do when when a new task shall be started, is to keep to what the user has specified. In this case this would mean that there are 3 scheduler classes (real-time, round-robin, priority-class) on two levels. Tasks that are scheduled according to the real-time class can together consume all of the cpu time but it requires a special group ID to be allowed to use it. The other two classes share whatever of the CPU time remains in equal parts (50%, 50%). They don't require any authorisation and are thus open for all. Infact these two classes only differ in the allowed quantum lenght and I only didn't combine them for demonstration purposes
Any opinions about this idea ?
cheers
gaf