procTemp.c
void
scheduler(void)
{
  struct proc *p;
  struct cpu *c = mycpu();
  
  for(;;){
    // Enable interrupts on this processor.
    sti();
	//PROJECT 1 : Will sum all process tickets here and will random select after for the winning process!

    cprintf("%d :: is the totalTickets\n", TICKETS);
   //Now generate a random number using the portable implementation on 
    // rand. MAX will be totalCount. https://wiki.osdev.org/Random_Number_Generator
  //  unsigned int seed = 1;
    unsigned int randNum = 0;
 //   srand(seed, TICKETS);
 //   randNum = rand();
   // unsigned int currTickets = 0;
    cprintf("%d :: is randNum\n", randNum);
    acquire(&ptable.lock);
/*    for( p = ptable.proc; p < &ptable.proc[NPROC]; p++){
       	 if(p->state != RUNNABLE)
	   continue;
         currTickets+=p->tickets;
//	 if(currTickets < randNum)
//		continue;
	
	cprintf("We have now continued with the value of %d, for currTix", currTickets);
    

*/
// Loop over process table looking for process to run.
  //  acquire(&ptable.lock);
    for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
      if(p->state != RUNNABLE)
        continue;
 
      // Switch to chosen process.  It is the process's job
      // to release ptable.lock and then reacquire it
      // before jumping back to us.
      int ticks1,ticks2;
      cprintf("tickets: %d", p->tickets);
      c->proc = p;
      switchuvm(p);
      p->state = RUNNING;
      ticks1 = ticks;

      swtch(&(c->scheduler), p->context);
      ticks2 = ticks;
      p->ticks = ticks2-ticks1;
      switchkvm();

      // Process is done running for now.
      // It should have changed its p->state before coming back.
      c->proc = 0;
 
   
    }
    release(&ptable.lock);
  }

}
//PAGEBREAK: 42
// Per-CPU process scheduler.
// Each CPU calls scheduler() after setting itself up.
// Scheduler never returns.  It loops, doing:
//  - choose a process to run
//  - swtch to start running that process
//  - eventually that process transfers control
//      via swtch back to the scheduler.
42
Per-CPU process scheduler.
Each CPU calls scheduler() after setting itself up.
Scheduler never returns.  It loops, doing:
choose a process to run
swtch to start running that process
eventually that process transfers control
via swtch back to the scheduler.
42 Per - CPU process scheduler . Each CPU calls scheduler () after setting itself up . Scheduler never returns . It loops doing : choose a process to run swtch to start running that process eventually that process transfers control via swtch back to the scheduler .
void
scheduler(void)
{
  struct proc *p;
  struct cpu *c = mycpu();
  for(;;){
    sti();
    cprintf("%d :: is the totalTickets\n", TICKETS);
    unsigned int randNum = 0;
    cprintf("%d :: is randNum\n", randNum);
    acquire(&ptable.lock);
    for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
      if(p->state != RUNNABLE)
        continue;
      int ticks1,ticks2;
      cprintf("tickets: %d", p->tickets);
      c->proc = p;
      switchuvm(p);
      p->state = RUNNING;
      ticks1 = ticks;
      swtch(&(c->scheduler), p->context);
      ticks2 = ticks;
      p->ticks = ticks2-ticks1;
      switchkvm();
      c->proc = 0;
    }
    release(&ptable.lock);
  }
}
void scheduler ( void ) { struct proc * p ; struct cpu * c = mycpu ( ) ; for ( ; ; ) { sti ( ) ; cprintf ( " \n " , TICKETS ) ; unsigned int randNum = 0 ; cprintf ( " \n " , randNum ) ; acquire ( & ptable . lock ) ; for ( p = ptable . proc ; p < & ptable . proc [ NPROC ] ; p ++ ) { if ( p -> state != RUNNABLE ) continue ; int ticks1 , ticks2 ; cprintf ( " " , p -> tickets ) ; c -> proc = p ; switchuvm ( p ) ; p -> state = RUNNING ; ticks1 = ticks ; swtch ( & ( c -> scheduler ) , p -> context ) ; ticks2 = ticks ; p -> ticks = ticks2 - ticks1 ; switchkvm ( ) ; c -> proc = 0 ; } release ( & ptable . lock ) ; } }
PAGEBREAK: 42
Per-CPU process scheduler.
PAGEBREAK : 42 Per - CPU process scheduler .
// Enable interrupts on this processor. //PROJECT 1 : Will sum all process tickets here and will random select after for the winning process! //Now generate a random number using the portable implementation on  // rand. MAX will be totalCount. https://wiki.osdev.org/Random_Number_Generator //  unsigned int seed = 1; //   srand(seed, TICKETS); //   randNum = rand(); // unsigned int currTickets = 0; /*    for( p = ptable.proc; p < &ptable.proc[NPROC]; p++){
       	 if(p->state != RUNNABLE)
	   continue;
         currTickets+=p->tickets;
//	 if(currTickets < randNum)
//		continue;
	
	cprintf("We have now continued with the value of %d, for currTix", currTickets);
    

*/ // Loop over process table looking for process to run. //  acquire(&ptable.lock); // Switch to chosen process.  It is the process's job // to release ptable.lock and then reacquire it // before jumping back to us. // Process is done running for now. // It should have changed its p->state before coming back.