1. An example of the case that disabling interrupts will not cause any harm:
int i;//Linux OS
_asm_ ("cli;");//We disable interrupts (Intel/AMD).
i=i/0;// Causes the divide by zero fault, faults can't be disabled.
The fault happens after some nanoseconds after disabling interrupts. Divide by zero causes fault.
OS handles the fault and crashes the current task and starts an other with interrupts enabled.
No harm done, because during some ns we have not lost anything important- hopefully.
If we comment the line i=i/0 in the above code, the processor hangs until the next boot.
2. SMP (many processors):
A "cli"-instruction most probably hangs only one processor running the "bad" task (can depend on the system and error handling of OS).
What if we run (Linux) the code:
sleep(5);//We sleep 5 seconds to wait tasks are divided to run queues of procssors, otherwise first running task with cli stops our experiment.
Here we start 100 tasks. Hopefully (and probable) tasks are divided between all CPUs (for example 2- 4).
If every processor is poisoned with a "bad" task, every processor is useless.
Simulate the above case (Linux) with:
#define work_as_parlament() while(1)
for (j=0;j<100;j++)//100 could be replaced with the number of your CPUs, but then it is pssible that
if(fork()) work_as_parlament(); //more than one of the forked tasks is scheduled to one CPU - leaving one free
Look at the system monitor. Is the load of all processors about at the same level (100%)?
This proves the scheduling
of "bad" tasks to all CPUs.
(Monitor works still fine (Linux has the round robin multilevel queue scheduling.)
3. How, we can experiment are the answers correct.
Many ways, one example:
- Use Linux
- Install KML- patch// Kernel Mode Linux (for "kernel capable tasks" to some extent)
- Compile the kernel
- Put the experiment program to the directory /trusted
- Compile/run the program
Still we are far from complete.