Advertisement
Guest User

hlt if no processes are runnable

a guest
Dec 28th, 2013
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. diff --git a/proc.c b/proc.c
  2. index bcdbfea..a32a672 100644
  3. --- a/proc.c
  4. +++ b/proc.c
  5. @@ -257,18 +257,29 @@ wait(void)
  6. void
  7. scheduler(void)
  8. {
  9. + int no_runnable;
  10. struct proc *p;
  11.  
  12. - for(;;){
  13. + for(no_runnable = 0;;){
  14. // Enable interrupts on this processor.
  15. sti();
  16.  
  17. + // If no runnable processes were found last pass then halt
  18. + // the processor
  19. + if(no_runnable) hlt();
  20. +
  21. + // Set no_runnable
  22. + no_runnable = 1;
  23. +
  24. // Loop over process table looking for process to run.
  25. acquire(&ptable.lock);
  26. for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
  27. if(p->state != RUNNABLE)
  28. continue;
  29.  
  30. + // We found at least one runnable proc
  31. + no_runnable = 0;
  32. +
  33. // Switch to chosen process. It is the process's job
  34. // to release ptable.lock and then reacquire it
  35. // before jumping back to us.
  36. diff --git a/x86.h b/x86.h
  37. index 3949900..7d14145 100644
  38. --- a/x86.h
  39. +++ b/x86.h
  40. @@ -117,6 +117,12 @@ sti(void)
  41. asm volatile("sti");
  42. }
  43.  
  44. +static inline void
  45. +hlt(void)
  46. +{
  47. + asm volatile("hlt");
  48. +}
  49. +
  50. static inline uint
  51. xchg(volatile uint *addr, uint newval)
  52. {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement