Hey fellow AIXer's,
I am an AIX sysadmin consultant, and I am very interested in internal Unix system design. Below is, based on my research, how the AIX cpu scheduler works in the life of a thread. Could someone with AIX scheduler knowledge confirm?
Thanks,
--Justin Richard Bleistein
AIX/TSM/Oracle Administrator
Note: Forget about virtualization for this document, we are only dealing with the internals working of AIX here.
1.) A user runs a program - (i.e. --> They run a shell script like: ./script.ksh). SNOME
2.) That program becomes a process on the system, which allocates the required system resources to run. SIDLE
3.) That process dispatches a thread, in this example it is a single threaded program, (although programs can be multi-threaded as well.)
4.) That thread goes into the system global run queue known as RUN-RUN.
5.) That thread is then put on a CPU's run queue where it's priority is governed by a nice value for new processes, and re-nice for already running processes.
6.) That thread is then selected with other competing threads for CPU time, to run on that CPU.
7.) The thread runs on a CPU for 10ms at a time.
8.) At the end of that 10ms timeslice, or quantum of time, which is called a clock tick the kernel will interrupt that user thread running on the cpu, and perform some internal system
housekeeping routines, as well as update the CPU usage for that running thread. Note: That thread will be charged even for the kernel interrupt. This kernel interrupt
is known as an external interrupt. Also during that 10ms interrupt the kernel will check to see if a new, or existing thread has entered that CPU's run queue with a higher priority or equal priority of the one running.
If there is one then that thread takes the place of the currently running thread on that CPU, and the currently running thread gets put back into that CPU's run queue.
If no new thread has come in with a higher priority, then the currently running thread on that CPU, will run for another 10 ms.
9.) After 1 second, a clock click, (once every second), this is assuming nothing has preempted the currently running thread, and this thread is taking more then 1 second to run, all of the threads in that CPU's run queue's priorities are re-calculated, and that running thread gets thrown back into that CPU's run-queue to attempt and keep processor affinity for re-dispatchement of it later. You see a thread can only run for 1 second total which is known as a clock click, if it's not interrupted before it gets to that 1 second. After 1 second all threads in that CPU's run queue including that one are re-calculated, and another re-calculated thread could now run on the CPU. This is to give everyone a chance to run on the CPU.
There are internal interrupts as well. This is when the user thread makes a system call, for the kernel to do something on it's behalf. If the system feels that this is like an i/o operation
which will require some time to complete, it still wants to give other threads in the run queue who maybe ready to run now, a chance to run. That being the case, the user thread interrupts
itself by making a system call for the kernel to run in system mode. The user thread will then go back into the queue as a sleeping process, S, waiting for that I/O to complete, while that I/O is running another thread can make use of that CPU. When that i/o is done then that thread will gain control of a cpu, and run once again continuing it's run.
Internal interrupt is also known as giving up the CPU voluntarily.
External interrupt is also known as giving up the CPU involuntarily.
While a thread is running on a CPU, it will be interrupted always by the kernel, if the kernel has to service a h/w request. After a h/w interrupt the kernel will check the run-queue of that CPU, to see if any thread which is runnable has a better priority then then one which was just interrupted by the h/w interrupt. The only thing which can interrupt a 10 ms timeslice during that 10 ms is a h/w interrupt, higher or equal priority threads which are new can only possible preempt that thread on that CPU at the end of that current 10ms timeslice.
Only one CPU can make a system call to a kernel/access the kernel at one time.
The one second click click where all threads priorities are adjusted is refered to as a major clock cycle.
I am an AIX sysadmin consultant, and I am very interested in internal Unix system design. Below is, based on my research, how the AIX cpu scheduler works in the life of a thread. Could someone with AIX scheduler knowledge confirm?
Thanks,
--Justin Richard Bleistein
AIX/TSM/Oracle Administrator
Note: Forget about virtualization for this document, we are only dealing with the internals working of AIX here.
1.) A user runs a program - (i.e. --> They run a shell script like: ./script.ksh). SNOME
2.) That program becomes a process on the system, which allocates the required system resources to run. SIDLE
3.) That process dispatches a thread, in this example it is a single threaded program, (although programs can be multi-threaded as well.)
4.) That thread goes into the system global run queue known as RUN-RUN.
5.) That thread is then put on a CPU's run queue where it's priority is governed by a nice value for new processes, and re-nice for already running processes.
6.) That thread is then selected with other competing threads for CPU time, to run on that CPU.
7.) The thread runs on a CPU for 10ms at a time.
8.) At the end of that 10ms timeslice, or quantum of time, which is called a clock tick the kernel will interrupt that user thread running on the cpu, and perform some internal system
housekeeping routines, as well as update the CPU usage for that running thread. Note: That thread will be charged even for the kernel interrupt. This kernel interrupt
is known as an external interrupt. Also during that 10ms interrupt the kernel will check to see if a new, or existing thread has entered that CPU's run queue with a higher priority or equal priority of the one running.
If there is one then that thread takes the place of the currently running thread on that CPU, and the currently running thread gets put back into that CPU's run queue.
If no new thread has come in with a higher priority, then the currently running thread on that CPU, will run for another 10 ms.
9.) After 1 second, a clock click, (once every second), this is assuming nothing has preempted the currently running thread, and this thread is taking more then 1 second to run, all of the threads in that CPU's run queue's priorities are re-calculated, and that running thread gets thrown back into that CPU's run-queue to attempt and keep processor affinity for re-dispatchement of it later. You see a thread can only run for 1 second total which is known as a clock click, if it's not interrupted before it gets to that 1 second. After 1 second all threads in that CPU's run queue including that one are re-calculated, and another re-calculated thread could now run on the CPU. This is to give everyone a chance to run on the CPU.
There are internal interrupts as well. This is when the user thread makes a system call, for the kernel to do something on it's behalf. If the system feels that this is like an i/o operation
which will require some time to complete, it still wants to give other threads in the run queue who maybe ready to run now, a chance to run. That being the case, the user thread interrupts
itself by making a system call for the kernel to run in system mode. The user thread will then go back into the queue as a sleeping process, S, waiting for that I/O to complete, while that I/O is running another thread can make use of that CPU. When that i/o is done then that thread will gain control of a cpu, and run once again continuing it's run.
Internal interrupt is also known as giving up the CPU voluntarily.
External interrupt is also known as giving up the CPU involuntarily.
While a thread is running on a CPU, it will be interrupted always by the kernel, if the kernel has to service a h/w request. After a h/w interrupt the kernel will check the run-queue of that CPU, to see if any thread which is runnable has a better priority then then one which was just interrupted by the h/w interrupt. The only thing which can interrupt a 10 ms timeslice during that 10 ms is a h/w interrupt, higher or equal priority threads which are new can only possible preempt that thread on that CPU at the end of that current 10ms timeslice.
Only one CPU can make a system call to a kernel/access the kernel at one time.
The one second click click where all threads priorities are adjusted is refered to as a major clock cycle.