title: Inter Processor Interrupt usage
body: <p><strong>An</strong> educational principle is: There is not such a thing as a stupid question. The basic idea behind this is that people learn by asking. 
  I was asked to: "Can you show and explain at a programming level what bad will happen if every task could execute all instructions."</p>
  
  <p>I did give the code</p>
  
  <pre><code>    main(){
        _asm_("cli;");
        while(1);
      }
  </code></pre>
  
  <p>and explained it (the system frozen for good- UP)</p>
  
  <p>Then I was asked: "Is it possible give an example so that system do not freeze even this clearing interrupts is done?"</p>
  
  <p>I did modify the previous example:</p>
  
  <p>I did give the code</p>
  
  <pre><code>    main(){
        _asm_("cli;");
        i=i/0;
        while(1);
      }
  </code></pre>
  
  <p>and explained it. </p>
  
  <p>Trivially: If we have demand paging i=i/0 causes <strong>first</strong> a page fault (the data page not present) and an other task can be scheduled to run interrupts enabled during the disk read and <strong>later</strong> on divide by zero will throw this task away for good.</p>
  
  <p>But the answers were based on UP. What about SMP? I must tell that answers are incomplete.
  It still easy enough to construct:</p>
  
  <pre><code>    int i;
      main(){
      for(i=0;i&lt;100;i++)// Suppose we have less than 100 CPUs
         if(fork())
          { sleep(5);//The generating task has (most probable) time to do all forks
           _asm_("cli;");
           while(1);
          }
       }
  </code></pre>
  
  <p>which will disable interrupts for all CPUs, because every CPU gets a poisonous task to run.</p>
  
  <p>Even so far a stupid question did reveal many things good to learn to a beginner: privileged instructions, paging, fault handling, scheduling during DMA, fork.....
  But a minor doubt remains (shame on me) about the first program running on a SMP.</p>
  
  <p>Will one CPU be out permanently or not?
  Other CPUs continue and can send <strong>re_schedule() IPI message</strong>.
  What happens then?
  It can be easy to speculate that the frozen CPU do not wake up, because interrupts are disabled.
  But to be perfectly sure must know more.</p>
  
  <p>My question was:
  Is the Inter Processor Interrupt (IPI) maskable or non-maskable?
  I mean in the most common "popular" implementations?</p>
  
  <p>Excuse my stupid question. It can't be very difficult to find an answer. I will seek it.
  I mean interrupt pin number (telling maskable, I <strong>guess</strong>).</p>
  
  <hr>
  
  <p>My own answer - correct?
  I studied the issue, because nobody else did like it, coming to following thoughts:</p>
  
  <p>With important real-time applications we have had for a long time a watchdog timer (HW interrupting cpu to answer somehow "I am alive").
  For example we have main control computer and standby computer taking care of the system if the main computer is down.</p>
  
  <p>What about Linux?
  What kind watchdog- have we one?
  We can compile the Linux kernel with or without watchdog.</p>
  
  <p>What the Linux watchdog does?
  On many(<strong>!</strong>) x86/x86-64 type hardware there is a feature that enables us to generate 'watchdog NMI interrupts'.
  It's even possible to disable the NMI watchdog in run-time by writing "0" to /proc/sys/kernel/nmi_watchdog.
  If any CPU in the system does not execute the period local timer interrupt for more than 5 seconds, APIC tries to fix the situation by a <strong>non-maskable interrupt</strong> (cpu executes the handler, and kills the process)!
  (SCC Linux is an different case as to NMI.)</p>
  
  <p>My answers (in the original question) were based on the system without watchdog!
  It is problematic to answer at a general level and give examples based on some fixed system. The answers can be correct or not depending the cpu and configuration and settings.</p>
  
  <p><strong>Anyway, talking about NMI did make some sense? Did it?</strong></p>