Ejemplo n.º 1
0
 OS_PROCESS void TProc1::exec()
 {
     for(;;)
     {
         sleep(10);
         green_led::On();
         event.signal();
         // waste time (2x Proc0)
         waste_time();
         waste_time();
     }
 }
Ejemplo n.º 2
0
Archivo: pr13.c Proyecto: kura-pl/priry
void *thread_func_1(void *ptr){
	cpu_set_t mask; 
	CPU_ZERO(&mask);
    	CPU_SET(0, &mask);
	if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) <0)perror("pthread_setaffinity_np");
	printf("Policzylem %f na CPU %d\n", waste_time(10000), sched_getcpu());
	CPU_ZERO(&mask);
    	CPU_SET(1, &mask);
	if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) <0)perror("pthread_setaffinity_np");
	printf("Policzylem %f na CPU %d\n", waste_time(10000), sched_getcpu());
	return NULL;
}
Ejemplo n.º 3
0
init_fn() {
	int i, j, stat;
	printf("Created init function: ");
	printf("pid %d / niceval: %d\n",current->pid, current->stat_prio);
	sched_waitq_init(&wq1);
	sched_waitq_init(&wq2);
	
	// Parent process forks 9 CPU-bound processes
	for (i=1; i<10; i++) {
		switch(sched_fork()) {
		case -1: 
			fprintf(stderr,"Fork failed in pid %d\n",current->pid);
			return -1;
			break;
		case 0:
			sched_nice(20+i*2);
			child_fn();
			sched_exit(0);
			break;
		}
	}
	// Parent process waits for a long time before it 
	//	does its own CPU-bound operations
	kill(getpid(),SIGABRT);
	for (;;) {
		for (i=0; i<40; i++)
			sched_sleep(&wq1);
		kill(getpid(),SIGABRT);
		waste_time(10);
		kill(getpid(),SIGABRT);
	}
}
Ejemplo n.º 4
0
/*
 * wear:
 *	The player wants to wear something, so let him/her put it on.
 */
void
wear()
{
    register THING *obj;
    register char *sp;

    if ((obj = get_item("wear", ARMOR)) == NULL)
	return;
    if (cur_armor != NULL)
    {
	addmsg("you are already wearing some");
	if (!terse)
	    addmsg(".  You'll have to take it off first");
	endmsg();
	after = FALSE;
	return;
    }
    if (obj->o_type != ARMOR)
    {
	msg("you can't wear that");
	return;
    }
    waste_time();
    obj->o_flags |= ISKNOW;
    sp = inv_name(obj, TRUE);
    cur_armor = obj;
    if (!terse)
	addmsg("you are now ");
    msg("wearing %s", sp);
}
Ejemplo n.º 5
0
void test_task
   (
      uint_32 initial_data
   )
{
   MQX_TICK_STRUCT ticks;
   _mqx_uint       result;
   _mqx_uint       n;

   _time_init_ticks(&ticks, 10);

   result = _watchdog_create_component(BSP_TIMER_INTERRUPT_VECTOR, 
      handle_watchdog_expiry);
   if (result != MQX_OK) {
      printf("\nError creating watchdog component.");
      _task_block();
   }

   n = 100;
   while (TRUE) {
      result = _watchdog_start_ticks(&ticks);
      n = waste_time(n);
      _watchdog_stop();
      printf("\n %d", n);
   }

}
Ejemplo n.º 6
0
void *thread_func(void *param)
{
    unsigned long mask = 1;
   
    if (pthread_setaffinity_np(pthread_self(), sizeof(mask),
        &mask) <0) {
        perror("pthread_setaffinity_np");
    }
   
    printf("result: %f\n", waste_time(2000));
    mask = 2;  
    if (pthread_setaffinity_np(pthread_self(), sizeof(mask),
        &mask) <0) {
        perror("pthread_setaffinity_np");
    }
   
    printf("result: %f\n", waste_time(2000));
}
Ejemplo n.º 7
0
template<> void TProc3::exec()
{
    for(;;) {
        PROC3.Off();
        ef.wait();
        PROC3.On();
        waste_time(500);
    }
} // TProc3::exec()
Ejemplo n.º 8
0
int main(int argc, char **argv)
{
    unsigned long mask = 1; /* processor 0 */
 
    /* bind process to processor 0 */
    if (sched_setaffinity(0, sizeof(mask), &mask) <0) {
        perror("sched_setaffinity");
    }
 
    /* waste some time so the work is visible with "top" */
    printf ("result: %f\n", waste_time (2000));
 
    mask = 2; /* process switches to processor 1 now */
    if (sched_setaffinity(0, sizeof(mask), &mask) <0) {
        perror("sched_setaffinity");
    }
 
    /* waste some more time to see the processor switch */
    printf ("result: %f\n", waste_time (2000));
}
Ejemplo n.º 9
0
child_fn() {
	// Child process does some computations and when done, sends a SIGUSR1
	int i, j;
	printf("Forked new process: ");
	printf("pid %d / niceval: %d\n",current->pid, current->stat_prio);
	for (;;) {
		waste_time(1);
		kill(getpid(),SIGABRT);
		kill(getpid(),SIGUSR1);
	}
}
Ejemplo n.º 10
0
template<> void TProc2::exec()
{
    for(;;) {
        PROC2.Off();
        sleep(4);
        PROC2.On();
        ef.signal();
        uint8_t request = (OS::get_tick_count() / 1024) % 8;
        waste_time(request * 100);
    }
} // TProc2::exec()
Ejemplo n.º 11
0
int main(void)
{
	clock_t start;
	clock_t spend;

	start = clock();
	waste_time();
	spend = (clock() - start) / CLOCKS_PER_SEC;

	printf("Spend %ld seconds.\n", spend);

	return 0;
}
Ejemplo n.º 12
0
int main()
{
  int i;

  for(i = 0; i < 8; i++) {
    set_gpio_pin_direction(i, DIR_IN);
    set_pin_function(i, FUNC_GPIO);
  }

  for(i = 8; i < 16; i++) {
    set_gpio_pin_direction(i, DIR_OUT);
    set_pin_function(i, FUNC_GPIO);
  }

  for(i = 16; i < 20; i++) {
    set_gpio_pin_direction(i, DIR_IN);
    set_pin_function(i, FUNC_GPIO);
  }

  while(1) {
    left_to_right_on_slow(LED_1, LED_7);
    left_to_right_off_slow(LED_1, LED_7);

    waste_time();

    left_to_right_on(LED_1, LED_7);
    left_to_right_off(LED_1, LED_7);

    waste_time();

    left_to_right_single(LED_1, LED_7);
    left_to_right_single(LED_1, LED_7);
    left_to_right_single(LED_1, LED_7);
  }

  return 0;
}
Ejemplo n.º 13
0
void left_to_right_single(unsigned int first, unsigned int last) {
  unsigned int i;
  unsigned int j;

  for(i = first; i <= last; i++) {

    for(j = first; j <= last; j++) {
      set_gpio_pin_value(j, 0);
    }

    set_gpio_pin_value(i, 1);

    waste_time();
  }
}
Ejemplo n.º 14
0
void *thread_func(void *param)
{
    unsigned long mask = 1; /* processor 0 */
	unsigned long core;
    /* bind process to processor 0 */
    if (pthread_setaffinity_np(pthread_self(), sizeof(mask),
        &mask) < 0) {
        perror("pthread_setaffinity_np");
    }
	core = pthread_getaffinity_np(pthread_self(), sizeof(mask),&mask);
	printf("CPU Core %ld\t" , core);
    /* waste some time so the work is visible with "top" */
    printf("result: %f\n", waste_time(2000));
 
    mask = 2;   /* process switches to processor 1 now */
    if (core = pthread_setaffinity_np(pthread_self(), sizeof(mask),
        &mask) < 0) {
        perror("pthread_setaffinity_np");
    }
	core = pthread_getaffinity_np(pthread_self(), sizeof(mask),&mask);
	printf("CPU Core %ld\t" , core);
    /* waste some more time to see the processor switch */
    printf("result: %f\n", waste_time(200));
}
Ejemplo n.º 15
0
int fib (x, depth)
{
  int a, b;
  waste_time ();
  log_transition (&context, depth);
  if (x < 2)
    return 1;
  else
    {
      a = fib (x-1, depth+1);
      log_transition (&context, depth);
      b = fib (x-2, depth+1);
      log_transition (&context, depth);
      return a+b;
    }
}
Ejemplo n.º 16
0
    OS_PROCESS void TProc2::exec()
    {
        for (;;)
        {
            timer_event.wait();

            // increase load, one step at every 5 seconds after start,
            // resetting at 8th step.
            tick_count_t t = (OS::get_tick_count() % 40000) / 5000;
            for (uint32_t i = 0; i < t; i++)
                waste_time();

            // led "ON" time ~ Proc2 load
            red_led::Off();
        }
    }
Ejemplo n.º 17
0
    OS_PROCESS void TProc0::exec()
    {
        for(;;)
        {
            // green led "ON" time = context switch time (~9.6us at 24MHz)
            event.wait();
            green_led::Off();

            // waste some time (imitate payload)
            waste_time();

            // waste some stack (increasing with time)
            tick_count_t t = (OS::get_tick_count() % 40000) / 5000;
            waste_stack(t);
        }
    }
Ejemplo n.º 18
0
static int
do_work_unit (int who, int n)
{
  int		i;
  static int	nchars = 0;
  double	f = 0.0;

  if (quiet)
    i = 0;
  else {
    /*
     * get lock on stdout
     */
    assert(pthread_mutex_lock (&mutex_stdout) == 0);

    /*
     * do our job
     */
    i = printf ("%c", "0123456789abcdefghijklmnopqrstuvwxyz"[who]);

    if (!(++nchars % 50))
      printf ("\n");

    fflush (stdout);

    /*
     * release lock on stdout
     */
    assert(pthread_mutex_unlock (&mutex_stdout) == 0);
  }

  n = rand () % 10000;	/* ignore incoming 'n' */
  f = waste_time (n);

  /* This prevents the statement above from being optimised out */
  if (f > 0.0)
    return(n);

  return (n);
}
Ejemplo n.º 19
0
static int WSS_testport(struct mpxplay_audioout_info_s *aui)
{
 unsigned int baseport=aui->card_port;
 unsigned int ver1,ver2;
 unsigned int i;
 //char sout[100];

 for(i=0;i<1000;i++){
  if(wssinp(WSS_COMMAND_PORT)&0x80){
   waste_time(1);
  }else{
   WSS_writeDSP(baseport,0x0c,0);
   //old
   //ver1=wssinp(WSS_DATA_PORT)&0xf;
   //new
   ver1=wssinp(WSS_COMMAND_PORT)&0xf;
   //fprintf(stderr,"1. %d. try  port:%X ver:%d\n",i,baseport,ver1);
   if((ver1>=1)&&(ver1<15))
    break;
  }
 }
 if(i==1000)
  return 0;

 WSS_writeDSP(baseport,0x0c,0);
 ver1=wssinp(WSS_DATA_PORT);
 wssoutp(WSS_DATA_PORT,0);
 ver2=wssinp(WSS_DATA_PORT);
 if(ver1!=ver2)
  return 0;
 if(wssinp(WSS_COMMAND_PORT)&0x80)
  return 0;
 WSS_writeDSP(baseport,0x49,4);
 wssoutp(WSS_COMMAND_PORT, 0x09);
 WSS_writeDSP(baseport,0x0c,0);
 return 1;
}
Ejemplo n.º 20
0
template<> void TProc1::exec()
{
    const int max_request = 10;
    const int increment_period = 1000;
    int increment_div = increment_period;
    volatile uint8_t dev_null;
    uint8_t request = 0;

    for(;;) {
        PROC1.Off();
        Timer3_Ovf.wait();
        PROC1.On();
        TIMER3_TO_PROC1.Off();
        if (request < max_request) {
            dev_null = waste_stack(request);
            if (--increment_div == 0) {
                increment_div = increment_period;
                ++request;
	    }
        } else {
           waste_time(50);
        }
    }
} // TProc1::exec()
Ejemplo n.º 21
0
// Simulates a basic epoch processing loop. Since the functions have to be used in a very
// specific way, we try to emulate actual use as much as possible.
//! \todo need to throw in some fail_*.
bool t_epoch_para_worker (yarn_word_t pool_id, void* task) {
    (void) pool_id;
    (void) task;

    for (yarn_word_t i = 0; i < 2000; ++i) {

        DBG printf("<%zu> - NEXT - START\n", pool_id);

        // Grab the next epoch to execute.
        enum yarn_epoch_status old_status;
        yarn_word_t epoch;
        if(!yarn_epoch_next(&epoch, &old_status)) {
            break;
        }

        // Rollback phase
        //   Rollback our epoch if necessary.
        {
            if (old_status == yarn_epoch_rollback) {
                DBG printf("<%zu> - NEXT=%zu -> ROLLBACK\n", pool_id, epoch);
                waste_time();
                yarn_epoch_rollback_done(epoch);
            }
            else {
                DBG printf("<%zu> - NEXT=%zu\n", pool_id, epoch);
            }
        }

        // Execution phase.
        //   Executes our epoch or randomly trigger rollbacks.
        {
            waste_time();
            if (rand() % 5 == 0) {
                DBG printf("<%zu> - ROLLBACK=%zu - START\n", pool_id, epoch+1);
                yarn_epoch_do_rollback(epoch+1);
                DBG printf("<%zu> - ROLLBACK=%zu - END\n", pool_id, epoch+1);
            }

            if (i == 1000 + pool_id) {
                DBG printf("[%zu] - STOP\n", epoch);
                yarn_epoch_stop(epoch);
            }

            yarn_epoch_set_done(epoch);
        }

        // Commit phase
        //   Commit any finished epochs including our own.
        {
            yarn_word_t to_commit;
            void* task;
            while(yarn_epoch_get_next_commit(&to_commit, &task)) {
                waste_time();
                DBG printf("<%zu> - COMMIT=%zu\n", pool_id, to_commit);
                yarn_epoch_commit_done(to_commit);
            }
        }
    }

    return true;
}