Exemplo n.º 1
0
/**
 * krbtree_modulate_prio()
 * modulate/perturb the priority of the current thread
 * by some random amount. It might be useful to convert
 * some processes to RT priority as well. 
 */
int krbtree_modulate_prio(void){
   struct sched_param prio;
   unsigned int randval;
   if(modulate_priority){
     randval = get_osa_random()%50;
     if(randval > 40){
       /* turn the thread into a real time process */
       prio.sched_priority = SCHED_RR;
       sys_sched_setscheduler(0,(randval*11)%99,&prio);
       return 0;
     }
     
     /* just change the process priority, leaving
      * it with it's current scheduler. */
     randval -= 20;
     sys_setpriority(PRIO_PROCESS,0,randval);
     return 0;
   }
   
   // Don't modulate priority
   /* turn the thread into a real time process at highest priority*/
   prio.sched_priority = SCHED_RR;
   sys_sched_setscheduler(0,99,&prio);
   return 0;
}
Exemplo n.º 2
0
ulong lrand(privprng * p) { return get_osa_random() % RMAX; }
Exemplo n.º 3
0
/** 
 * thread_proc()
 * thread function executing 
 * parallel increment of a shared counter. 
 */
int 
krbtree_thread_proc(void * data) {
#if defined (KTHCBM_VERBOSE)
  int nstnum = (int) data;
#endif
  int done = 0;
  int my_share = gnTargetValue / gnThreadCount;
  int nFinishNumber = 0;
  unsigned int randval1, randval2;
  char buf[OSA_OUTBUF_SIZE];
  krbtree_modulate_prio();
  down( &scsembarrier );
  gnAwakeCount++;
  // Reset the stats when the last process is ready to go
  if(gnAwakeCount == gnThreadCount){
    OSA_MAGIC(OSA_CLEAR_STAT);
  }
  up( &scsembarrier );

#ifdef KTHCBM_VERBOSE
  printk( KERN_ERR "Awaiting sync for shared counter thread %d\n", nstnum );
#endif
  while( gnAwakeCount < gnThreadCount ) {
    msleep(KTHCBM_BACKOFF_WAIT);
  }
#ifdef KTHCBM_VERBOSE
  printk( KERN_ERR "Barrier crossed shared counter kthread #%d\n", nstnum );
#endif
  while( !kthread_should_stop() && !done ) {

    // Work goes here
    randval1 = (unsigned int) (max_val * (get_osa_random()%RMAX) / (RMAX + 1));
    randval2 = (unsigned int) (100 * (get_osa_random()%RMAX) / (RMAX + 1));
    
    if(randval2 > insert_delete_balance){
      remove(randval1);
    } else {
      insert(randval1);
    }

    done = !--my_share;

    // yield after roughly every 30 iterations
    // This number was picked because we are trying to use a window of
    // 1024 and 32 threads.  1024/32 = 32, 30 gives us some wiggle
    // room
    if(done % 30 == 0){
      yield();
    }

    if( done ) {
      down( &semdone );
      nFinishNumber = ++gnThreadsComplete;
      up( &semdone );

      // Stop the stats as soon as we are finished - avoid counting
      // tear down costs
      if(gnThreadsComplete >= gnThreadCount){
	snprintf(buf, OSA_OUTBUF_SIZE, "rbtree microbenchmark: %lu threads performing %lu ops, %d deletes",
		 gnThreadCount, gnTargetValue, successful_deletes);
	OSA_PRINT(buf, strlen(buf));
	OSA_MAGIC(OSA_OUTPUT_STAT);
      }
    }
  }
#ifdef KTHCBM_VERBOSE
  printk(KERN_ERR "Thread %d finished\n", nstnum);
#endif
  while( !kthread_should_stop() )
    schedule_timeout_uninterruptible(1);
  return 0;
}