Example #1
0
void clock_routine()
{
char buffer [9];
tics++;

	if (tics%18==0){
		tics -=18;
		segons ++;
		if (segons%60==0){
		minuts++;
		segons =0;
		
		if (minuts%60==0){
		horas++;
		minuts =0;
		}
		}
	itoa (horas,buffer);
	itoa(minuts, &buffer[3]);
	itoa(segons, &buffer[6]);
	buffer[2]=':';
	buffer[5]=':';
	buffer[8]='\0';
		printk_xy(71,0,buffer);
	}
   roundrobin();
}
int main() {

  pptr head=NULL;
  pptr tail=NULL;
  int i=0;
  int tpid,tarr_time,tburst_time;
  pptr tprocess;
  FILE *read;
  read=fopen("input","r");
  write=fopen("write","w");
  //trace=fopen("trace","w");
  for(i=1;i<=3;i++) {
    //fscanf(read,"%d",&tpid);
    tpid=++g_pid;
    fscanf(read,"%d",&tarr_time);
    fscanf(read,"%d",&tburst_time);
    tprocess=create_process(tpid,tarr_time,tburst_time);
    add_to_queue(&head,&tail,tprocess);
  } fclose(read);

  tprocess=head;
  i=0;
  while(tprocess!=NULL) {
    ++i;
    tprocess=tprocess->next;
  }
  roundrobin(&head,&tail,i);
  return 0;
}
Example #3
0
int main(){
	mythread_init();
	timer_init();
	struct mythread_t t1, t2;
	mythread_create(&t1, test, 0);
	mythread_create(&t2, test2, 0);
	roundrobin();
	printf("all threads completed\n");
}
Example #4
0
File: spair.c Project: daersc/spair
static void
pair_roundrobin(void)
{
	Player *list = NULL, *lptr = NULL;
	Round  *hist = NULL, *rptr = NULL;
	char   *buffer = NULL;
	size_t buflen  = 0;
	unsigned int i;
	while (getline(&buffer, &buflen, stdin) != -1) {
		Player *player = malloc(sizeof(Player));
		size_t pos;
		if (!player) {
			perror(_("Could not allocate memory for player"));
			goto cleanup;
		}
		for (pos = 0; pos < buflen; pos++) {
			if (buffer[pos] == '\n') {
				buffer[pos] = '\0';
				break;
			}
		}
		player->next = NULL;
		player->name = malloc(sizeof(char) * (strlen(buffer)+1));
		if (!player->name) {
			perror(_("Could not allocate memory for player's name"));
			free(player);
			goto cleanup;
		}
		strcpy(player->name, buffer);
		if (lptr) lptr->next = player;
		else list = player;
		lptr = player;
	}

	hist = rptr = roundrobin(list);
	i = 1;
	while (rptr) {
		Pairing *pptr = rptr->pairings;
		printf(i==1 ? "%s %u\n" : "\n%s %u\n", _("Round"), i);
		while (pptr) {
			printf(" %20s : %-20s\n", pptr->white ? pptr->white->name : _("<bye>"),
			                          pptr->black ? pptr->black->name : _("<bye>"));
			pptr = pptr->next;
		}
		rptr = rptr->next;
		i++;
	}

	cleanup:
	free(buffer);
	free_players(list);
	free_rounds(hist);
}
Example #5
0
/*
 * The real-time timer, interrupting hz times per second.
 */
void
hardclock(struct clockframe *frame)
{
	struct proc *p;
	struct cpu_info *ci = curcpu();

	p = curproc;
	if (p && ((p->p_flag & (P_SYSTEM | P_WEXIT)) == 0)) {
		struct process *pr = p->p_p;

		/*
		 * Run current process's virtual and profile time, as needed.
		 */
		if (CLKF_USERMODE(frame) &&
		    timerisset(&pr->ps_timer[ITIMER_VIRTUAL].it_value) &&
		    itimerdecr(&pr->ps_timer[ITIMER_VIRTUAL], tick) == 0) {
			atomic_setbits_int(&p->p_flag, P_ALRMPEND);
			need_proftick(p);
		}
		if (timerisset(&pr->ps_timer[ITIMER_PROF].it_value) &&
		    itimerdecr(&pr->ps_timer[ITIMER_PROF], tick) == 0) {
			atomic_setbits_int(&p->p_flag, P_PROFPEND);
			need_proftick(p);
		}
	}

	/*
	 * If no separate statistics clock is available, run it from here.
	 */
	if (stathz == 0)
		statclock(frame);

	if (--ci->ci_schedstate.spc_rrticks <= 0)
		roundrobin(ci);

	/*
	 * If we are not the primary CPU, we're not allowed to do
	 * any more work.
	 */
	if (CPU_IS_PRIMARY(ci) == 0)
		return;

	tc_ticktock();
	ticks++;

	/*
	 * Update real-time timeout queue.
	 * Process callouts at a very low cpu priority, so we don't keep the
	 * relatively high clock interrupt priority any longer than necessary.
	 */
	if (timeout_hardclock_update())
		softintr_schedule(softclock_si);
}
Example #6
0
File: spair.c Project: daersc/spair
static void
print_pairing_table(unsigned int count)
{
	Player *list = NULL, *lptr = NULL;
	Round  *hist = NULL, *rptr = NULL;
	char   buffer[32];
	unsigned int i;
	for (i=1; i<=count; i++) {
		Player *player = malloc(sizeof(Player));
		if (!player) {
			perror(_("Could not allocate memory for player"));
			goto cleanup;
		}
		sprintf(buffer, "%u", i);
		player->next = NULL;
		player->name = malloc(sizeof(char)*(strlen(buffer)+1));
		if (!player->name) {
			perror(_("Could not allocate memory for player's name"));
			free(player);
			goto cleanup;
		}
		strcpy(player->name, buffer);
		if (lptr) lptr->next = player;
		else list = player;
		lptr = player;
	}

	hist = rptr = roundrobin(list);
	i = 1;
	while (rptr) {
		Pairing *pptr = rptr->pairings;
		printf("%s %u:", _("Round"), i);
		while (pptr) {
			printf("\t%s-%s", pptr->white ? pptr->white->name : "/",
			                 pptr->black ? pptr->black->name : "/");
			pptr = pptr->next;
		}
		printf("\n");
		rptr = rptr->next;
		i++;
	}

	cleanup:
	free_players(list);
	free_rounds(hist);
}
Example #7
0
int main (void )
{
  int valor;

  printf ("Digite um escalonamento: \n\n");
  printf ("1) FCFS \n");
  printf ("2) SJF \n");
  printf ("3) SRTF \n");
  printf ("4) ROUND ROBIN \n");
  printf ("5) MULTINIVEL \n");
  printf ("6) SAIR \n\n");
  scanf("%d", &valor);

  switch ( valor )
  {
     case 1 :
       fcfs();
     break;

     case 2 :
       sjf();;
     break;

     case 3 :
        srtf();;
     break;

     case 4 :
        roundrobin();
     break;

     case 5 :
        multinivel();
     break;

     case 6 :
        printf ("\nFim.\n");
     break;

     default :
       printf ("Valor invalido!\n");
  }

  return 0;
}
void roundrobin(int pid, int cpu, int io){
	 struct reg *atual;
	 atual=inicio;
	 while (atual != NULL){
	 	   
	 	   if(atual->pid < pid->prox)
	 	   
	 
	 
	 







main() {
  int op;
  do {


    printf("MENU - ESCALONADOR DE PROCESSOS\n\n");
    printf("----------------------\n");
    printf("Processos-----\n");
    printf("1. Adicionar\n");
    printf("2. Remover\n");
    printf("3. Listar\n");
    printf("4. Limpar\n\n");
    printf("Escalonadores ------\n");
    printf("5. Round Robin\n\n\n");


    printf("0. Sair\n\n");
    printf("Opcao: "); scanf("%d",&op);

    switch (op) {
      case 1: {
	  
	  int pid, pri, tipo, cpu, io;

	printf("Digite o PID: ");
	scanf("%d",&pid);
	printf("Digite o PRI: ");
	scanf("%d",&pri);

	while((tipo>3)||(tipo<1))
	{
	printf("Digite o TIPO (1-system/2-user/3-batch): ");
	scanf("%d",&tipo);
	}

	printf("Digite o CPU: ");
	scanf("%d",&cpu);
	printf("Digite o I/O: ");
	scanf("%d",&io);

	adiciona(pid, pri, tipo, cpu, io);


	break;
      }
      case 2: {
	if (inicio!=NULL) {
	  printf("Removendo... ");
	  apaga();
	  getch();
	}
	break;
      }
      case 3: {
	lista();
        getch();
	break;
      }
      case 4: {
	printf("Limpando...");
	limpar();
	getch();
	break;
      }
    
    case 5: {
		 
		 roundrobin(pid, cpu, io);
		 
		 getch();
		 break;
		 }
		 
    
	}
    
  } while (op!=0);
  limpar();
}
Example #9
0
function main(in mode, in params0, io msg, io result) {

	//output:
	//empty = ok
	//result
	//msg if any error

	//eg 60 60 60 DOS EMAILS.DAT
	//means window of 60*60 seconds rolling every 60 seconds
	//max events 60 and store in DOS EMAILS.DAT file so per installation
	//could be DEFINITIONS EMAILS.ROUNDROBIN to be per database

	result = "";
	msg = "";

	//roundrobin
	//minutes are the number of minutes since 1/1/1970 provided by date()/time()
	//field 1 = the last minute that was updated
	//field 2 = 60 multivalues for minutes of the hour

	var params;
	if (params0.unassigned())
		params="";
	else
		params=params0;

	if (mode == "TEST") {

		//here we have maximum of 6 events per last 6x6 seconds
		params = "";
		params.r(1, 6);
		params.r(2, 6);
		params.r(3, 6);
		params.r(4, "DOS");
		params.r(5, "TEST.DAT");
		//osdelete params<5>

		printl();
		while (true) {
		///BREAK;
		if (not(not esctoexit())) break;;
			ossleep(int(rnd(3000)));
			call roundrobin("ONEVENT", params, result, msg);
		}//loop;

		return 1;
	}
	if (mode == "ONEVENT") {

		var verbs;
		if (not(verbs.open("VERBS", ""))) {
			msg = "ROUNDROBIN: CANNOT OPEN VERBS";
			return 0;
		}

		var roundrobinfile;
		if (not(roundrobinfile.open(params.a(4), ""))) {
			msg = "ROUNDROBIN: CANNOT OPEN " ^ params.a(4);
			return 0;
		}

		var roundrobinlock = "ROUNDROBIN*" ^ params.a(4) ^ "*" ^ params.a(5);

		//try to lock for 9 seconds since other locks should be brief
		if (not(lockrecord("VERBS", verbs, roundrobinlock, "", 9))) {
			msg = "ROUNDROBIN: CANNOT LOCK VERBS," ^ roundrobinlock;
			return 0;
		}

		//garbagecollect;

		//get the round robin data
		var roundrobin;
		if (not(roundrobin.read(roundrobinfile, params.a(5)))) {
			roundrobin = "";
		}
		if (roundrobin.index(0x00, 1)) {
			roundrobin.converter(0x00, "");
			var(var().date() ^ FM ^ var().time()).oswrite("RRR");
		}

		//determine current and last timeperiod
		//currentperiodn=date()*24*secsperperiod+mod(time(),secsperperiod)
		var currentperiodn = ((var().date() * 24 * 60 * 60 + var().time()) / params.a(1)).floor();
		var lastperiodn = roundrobin.a(1);

		//prevent catch up longer than periodsperwindow (add 2 for safety)
		if (currentperiodn - lastperiodn > params.a(2) + 2) {
			lastperiodn = currentperiodn - params.a(2) - 2;
		}

		//clear any skipped periods since last update
		//nb start from lastperiodn+1 to avoid clearing current period multiple times
		//ie clear only on the first time that we arrive in it
		for (var periodn = lastperiodn + 1; periodn <= currentperiodn; ++periodn) {
			roundrobin.r(2, periodn % params.a(2) + 1, "");
		};//periodn;

		//record the current period as the last period so that in the next call
		//we can clear skipped periods (but not the current period again)
		roundrobin.r(1, currentperiodn);
		var currentbreakn = currentperiodn % params.a(2) + 1;

		if ((roundrobin.a(2)).sum() < params.a(3)) {

			result = 1;

			//increment the current number of events in the current period
			roundrobin.r(2, currentbreakn, roundrobin.a(2, currentbreakn) + 1);

		}else{
			result = 0;
		}

		//garbagecollect;

		if (roundrobin.index(0x00, 1)) {
			roundrobin.converter(0x00, "");
			var(var().date() ^ FM ^ var().time()).oswrite("RRW");
		}
		roundrobin.write(roundrobinfile, params.a(5));

	//for testing
	//print lastperiodn,currentperiodn,currentbreakn,result,roundrobin<2>

		call unlockrecord("VERBS", verbs, roundrobinlock);

	}

	return 0;

}
Example #10
0
int main(int argc, char **argv)
{

	FILE * inputf;
	if (argc == 3)
	{
		verbose = 1;
		inputf = fopen(argv[2], "r");
	}
	else if (argc == 2)
	{
		verbose = 0;
		inputf = fopen(argv[1], "r");
	}

	random_ints = fopen(RANDOM_INTS, "r");
	int pool_sz;
	int a;
	int b;
	int c;
	int io;
	fscanf(inputf, "%d", &pool_sz);
	int p_ind;
	process pool[pool_sz];
	process pool_copy[pool_sz];
	process sorted_pool[pool_sz];
	process sorted_copy[pool_sz];
	process proc;


	int state[pool_sz];

	char * list_output;
	char * process_format = " ( %d %d %d %d )";
	printf("The original input was: %d", pool_sz);
	for (p_ind = 0; p_ind < pool_sz; p_ind ++)
	{
		fscanf(inputf, process_format, &a, &b, &c, &io);
		asprintf(&list_output, process_format, a, b, c, io);
		printf(list_output);
		proc = init_process(p_ind, a, b, c, io);
		pool[p_ind] = proc;	
		sorted_pool[p_ind] = proc;	
		state[p_ind] = UNSTARTED;
	}
	printf("\n");

	qsort(sorted_pool, pool_sz, sizeof(process), process_cmp);
	printf("The (sorted) input is: %d", pool_sz);
	for (p_ind = 0; p_ind < pool_sz; p_ind ++)
	{
		proc = sorted_pool[p_ind];
		asprintf(&list_output, process_format, proc.arrival_time, proc.cpu_burst_gen, proc.cpu_time_left, proc.io_burst_gen);
		printf(list_output);
	}
	printf("\n\n");


	list_output = NULL;
	process_format = NULL;

	memcpy(pool_copy, pool, sizeof(process) * pool_sz);
	memcpy(sorted_copy, sorted_pool, sizeof(process) * pool_sz);
	uni(state, pool_copy, sorted_copy, pool_sz);
	fclose(random_ints);
	random_ints = fopen(RANDOM_INTS, "r");


	int i = 0;
	for (i = 0; i < pool_sz; i ++)
	{
		state[i] = UNSTARTED;
	}	
	memcpy(pool_copy, pool, sizeof(process) * pool_sz);
	fcfs(state, pool_copy, pool_sz);
	fclose(random_ints);
	random_ints = fopen(RANDOM_INTS, "r");

	for (i = 0; i < pool_sz; i ++)
	{
		state[i] = UNSTARTED;
	}	
	memcpy(pool_copy, pool, sizeof(process) * pool_sz);
	sjf(state, pool_copy, pool_sz);
	fclose(random_ints);
	random_ints = fopen(RANDOM_INTS, "r");

	for (i = 0; i < pool_sz; i ++)
	{
		state[i] = UNSTARTED;
	}	
	memcpy(pool_copy, pool, sizeof(process) * pool_sz);
	roundrobin(2, state, pool_copy, pool_sz);

	fclose(random_ints);

	return 0;
}