Ejemplo n.º 1
0
static void restart_task(rtems_task_argument arg)
{
  rtems_status_code sc;

  if (arg == 0) {
    rtems_test_assert(set_prio(RTEMS_SELF, 3) == 2);

    rtems_task_restart(RTEMS_SELF, 1);
  } else if (arg == 1) {
    rtems_id scheduler_id;

    rtems_test_assert(set_prio(RTEMS_SELF, 3) == 2);

    sc = rtems_task_get_scheduler(RTEMS_SELF, &scheduler_id);
    rtems_test_assert(sc == RTEMS_SUCCESSFUL);

    sc = rtems_task_set_scheduler(RTEMS_SELF, scheduler_id, 4);
    rtems_test_assert(sc == RTEMS_SUCCESSFUL);

    rtems_test_assert(set_prio(RTEMS_SELF, 3) == 4);

    rtems_task_restart(RTEMS_SELF, 2);
  } else {
    rtems_test_assert(set_prio(RTEMS_SELF, 3) == 4);

    rtems_task_resume(master_id);
  }

  rtems_test_assert(0);
}
Ejemplo n.º 2
0
int main(int argc, char **argv) {
  int n = 20, pid, i, j, h;
  int time[3]; // time[0] priority1, time[1] priority 2...
  time[0] = time [1] = time[2] = 0;
  int retime, rutime, stime;
  enum priority prio;

  if(argc > 1)
    n = atoi(argv[1]);
  for(i = 0; i < 3*n; ++i){
    pid = fork();
    if(pid == 0) { // Child
      set_prio((getpid() % 3)+1);
      for(j = 0; j < 100; ++j) 
        for(h = 0; h < 1000000; ++h){}
      exit();
    }
  }
  while( (pid = wait2(&retime, &rutime, &stime)) > 0 ) {
      prio = pid % 3; // To know which priority the child has
      printf(1, "process id: %d, priority: %s \n", pid, get_prio_name(prio));
      printf(1, "Time it took to complete: %d \n", rutime + retime + stime);
      time[prio] += rutime + retime + stime ;
  }
  turnaroundtime(PRIO_1, n, time[PRIO_1]);
  turnaroundtime(PRIO_2, n, time[PRIO_2]);
  turnaroundtime(PRIO_3, n, time[PRIO_3]);

  exit();
}
Ejemplo n.º 3
0
int select_prio(struct config *conf, struct path *pp)
{
	char *origin;
	struct mpentry * mpe;
	struct prio * p = &pp->prio;

	if (pp->detect_prio == DETECT_PRIO_ON) {
		detect_prio(conf, pp);
		if (prio_selected(p)) {
			origin = "(setting: array autodetected)";
			goto out;
		}
	}
	mpe = find_mpe(conf->mptable, pp->wwid);
	set_prio(conf->multipath_dir, mpe, "(setting: multipath.conf multipaths section)");
	set_prio(conf->multipath_dir, conf->overrides, "(setting: multipath.conf overrides section)");
	set_prio(conf->multipath_dir, pp->hwe, "(setting: array configuration)");
	set_prio(conf->multipath_dir, conf, "(setting: multipath.conf defaults/devices section)");
	prio_get(conf->multipath_dir, p, DEFAULT_PRIO, DEFAULT_PRIO_ARGS);
	origin = "(setting: multipath internal)";
out:
	/*
	 * fetch tpgs mode for alua, if its not already obtained
	 */
	if (!strncmp(prio_name(p), PRIO_ALUA, PRIO_NAME_LEN)) {
		int tpgs = 0;
		unsigned int timeout = conf->checker_timeout;

		if(!pp->tpgs &&
		   (tpgs = get_target_port_group_support(pp->fd, timeout)) >= 0)
			pp->tpgs = tpgs;
	}
	condlog(3, "%s: prio = %s %s", pp->dev, prio_name(p), origin);
	condlog(3, "%s: prio args = \"%s\" %s", pp->dev, prio_args(p), origin);
	return 0;
}
Ejemplo n.º 4
0
static void test_task_get_set_scheduler(void)
{
  rtems_status_code sc;
  rtems_id self_id = rtems_task_self();
  rtems_name name = BLUE;
  rtems_id scheduler_id;
  rtems_id scheduler_by_name;
  rtems_id task_id;
  rtems_id mtx_id;

  sc = rtems_scheduler_ident(name, &scheduler_by_name);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_get_scheduler(RTEMS_SELF, NULL);
  rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);

  sc = rtems_task_get_scheduler(invalid_id, &scheduler_id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  scheduler_id = 0;
  sc = rtems_task_get_scheduler(RTEMS_SELF, &scheduler_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(scheduler_id == scheduler_by_name);

  scheduler_id = 0;
  sc = rtems_task_get_scheduler(self_id, &scheduler_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(scheduler_id == scheduler_by_name);

  sc = rtems_task_set_scheduler(invalid_id, scheduler_id, 1);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  sc = rtems_task_set_scheduler(self_id, invalid_id, 1);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  sc = rtems_task_set_scheduler(self_id, scheduler_id, UINT32_C(0x80000000));
  rtems_test_assert(sc == RTEMS_INVALID_PRIORITY);

  sc = rtems_task_set_scheduler(self_id, scheduler_id, 1);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_semaphore_create(
    rtems_build_name(' ', 'M', 'T', 'X'),
    0,
    RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY,
    0,
    &mtx_id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_set_scheduler(self_id, scheduler_id, 1);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_semaphore_release(mtx_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(set_prio(self_id, RTEMS_CURRENT_PRIORITY) == 1);

  sc = rtems_task_set_scheduler(self_id, scheduler_id, 2);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(set_prio(self_id, RTEMS_CURRENT_PRIORITY) == 2);

  sc = rtems_task_set_scheduler(self_id, scheduler_id, 1);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(set_prio(self_id, RTEMS_CURRENT_PRIORITY) == 1);

  sc = rtems_semaphore_delete(mtx_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_create(
    rtems_build_name('T', 'A', 'S', 'K'),
    2,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  scheduler_id = 0;
  sc = rtems_task_get_scheduler(task_id, &scheduler_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(scheduler_id == scheduler_by_name);

  sc = rtems_task_set_scheduler(task_id, scheduler_id, 2);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_start(task_id, forbidden_task, 0);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_set_scheduler(task_id, scheduler_id, 2);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_delete(task_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_create(
    rtems_build_name('T', 'A', 'S', 'K'),
    2,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_start(task_id, restart_task, 0);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_suspend(self_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_delete(task_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_semaphore_create(
    rtems_build_name('S', 'E', 'M', 'A'),
    0,
    RTEMS_COUNTING_SEMAPHORE,
    0,
    &sema_id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_create(
    rtems_build_name('T', 'A', 'S', 'K'),
    1,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_start(task_id, sema_task, 0);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_set_scheduler(task_id, scheduler_id, 1);
  rtems_test_assert(sc == RTEMS_RESOURCE_IN_USE);

  sc = rtems_semaphore_delete(sema_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_delete(task_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
Ejemplo n.º 5
0
int sys_set_prio(void){
	int n;
	argint(0,&n);
	return set_prio(n);
}
Ejemplo n.º 6
0
int
main(int argc, char *argv[]) {
    
    //char* h ="12345678 \n";
    //printf(1,"sizeof: %d strlen: %d \n" , sizeof(h) ,strlen(h));
    
    
    char tmp[10];
    int n, i, j, s;
    //printf(1, "%d", argc);
    if (argc != 2) {
        printf(1, "error with number of args \n");
        exit();
    }
    int pid = 1;
    n = atoi(argv[1]);
    //printf(1, "n:%d\n", n);

    if (n == -1) {
        printf(1, "error with number \n");
        exit();
    }
    for (i = 0; i < 3 * n && pid; i++) {
        set_prio(3);
        pid = fork();
        
    }
    if (pid == 0) {
        pid = getpid();
        if (pid % 3 == 0) {
            for (j = 0; j < 100; j++)
                for (s = 0; s < 1000000; s++);
        } else if (pid % 3 == 1) {
            //set_prio(1);
            for (j = 0; j < 100; j++) {
                for (s = 0; s < 1000000; s++);
                yield();
            }
        } else {
            for (j = 0; j < 100; j++)
                sleep(1);
        }
    } else {
        int retime, setime, rutime, total_retime_type1, total_setime_type1, total_rutime_type1;
        int total_retime_type2, total_setime_type2, total_rutime_type2;
        int total_retime_type3, total_setime_type3, total_rutime_type3;
        for (i = 0; i < 3*n; i++) {
            pid = wait2(&retime, &rutime, &setime);
            match_number(pid%3, tmp);                    
            printf(1, "pid:%d  type:%s wait_time:%d sleep_time:%d run_time:%d\n", pid, tmp, retime, setime, rutime);

            if (pid % 3 == 0) {
                total_retime_type1 += retime;
                total_setime_type1 += setime;
                total_rutime_type1 += rutime;
            } else if (pid % 3 == 1) {
                total_retime_type2 += retime;
                total_setime_type2 += setime;
                total_rutime_type2 += rutime;

            } else {
                total_retime_type3 += retime;
                total_setime_type3 += setime;
                total_rutime_type3 += rutime;
            }
        }
        printf(1, "CPU bound :  ready time:%d , sleep time:%d, Turnaround Time:%d\n", total_retime_type1 / n, total_setime_type1 / n, (total_setime_type1 + total_retime_type1 + total_rutime_type1)/n);
        printf(1, "SCPU bound:  ready time:%d , sleep time:%d, Turnaround Time:%d\n", total_retime_type2 / n, total_setime_type2 / n, (total_setime_type2 + total_retime_type2 + total_rutime_type2)/n);
        printf(1, "IO bound  :  ready time:%d , sleep time:%d, Turnaround Time:%d\n", total_retime_type3 / n, total_setime_type3 / n, (total_setime_type3 + total_retime_type3 + total_rutime_type3)/n);
    }
    exit();
}