Exemplo n.º 1
0
int
main(int argc, char *argv[])
{
   int pids[2];
   int ppid = getpid();
   int r, i, j;

   pids[0] = fork();
   if (pids[0] == 0) {
      r = settickets(2);
      if (r != 0) {
         printf(1, "settickets failed");
         kill(ppid);
      }
      spin();
   }

   pids[1] = fork();
   if (pids[1] == 0) {
      r = settickets(4);
      if (r != 0) {
         printf(1, "settickets failed");
         kill(ppid);
      }
      spin();
   }

   sleep(1000);

   int lticks[] = {-1, -1};
   int hticks[] = {-1, -1};
   struct pstat st;
   check(getpinfo(&st) == 0, "getpinfo");

   for(i = 0; i < NPROC; i++) {
      for(j = 0; j < 2; j++) {
         if (st.inuse[i] && st.pid[i] == pids[j]) {
            lticks[j] = st.lticks[i];
            hticks[j] = st.hticks[i];
         }
      }
   }

   for (i = 0; i < 2; i++) {
      kill(pids[i]);
      wait();
   }

   for (i = 0; i < 2; i++) {
      check(hticks[i] > 0 && lticks[i] > 0, "each process should have some hticks and lticks");
   }

   float ratio = (float)lticks[0] / (float)lticks[1];
   printf(1, "lticks child 1: %d\n", lticks[0]);
   printf(1, "lticks child 2: %d\n", lticks[1]);
   check(ratio > .25 && ratio < .75, "ratio should be about 1/2");

   printf(1, "TEST PASSED\n");
   exit();
}
Exemplo n.º 2
0
int
main(int argc, char *argv[])
{

   if (argc < 3) {
      printf(1, "Usage: usage ticks tickets1 [tickets2]...\n\n");
      printf(1, "Spawns subprocesses, each of which will run for \n"
            "approximately the given number of ticks. For each ticket\n"
            "ammount given, a child process will spawn and request that\n"
            "number of tickets.\n");
      exit();
   }

   int total = 0;
   int i;
   for (i = 0; i < argc - 2; i++) {
      total += atoi(argv[i+2]);
   }
   int ret = settickets(total);
   if (ret < 0) {
      printf(1, "settickets failed\n");
      exit();
   }

   // pids of children
   int pids[NPROC];

   // spawn children
   for (i = 0; i < argc - 2; i++) {
      pids[i] = fork();
      if (pids[i] == 0) {
         int ret = settickets(atoi(argv[i + 2]));
         if (ret < 0) {
            printf(1, "settickets failed\n");
            exit();
         }
         // spin so we get scheduled
         while(1) {
            spin();
         }
      }
   }

   // print usage info
   int ticks = atoi(argv[1]);
   int start = uptime();
   while(uptime() < start + ticks) {
      sleep(100);
      printf(1, "time: %d\n", uptime() - start);
      printinfo();
   }

   // kill children
   for (i = 0; i < argc - 2; i++) {
      kill(pids[i]);
      wait();
   }

   exit();
}
Exemplo n.º 3
0
int
main(int argc, char *argv[])
{
   int x = settickets(23);
   
   struct pstat *stat1;
   stat1 = malloc(sizeof(*stat1));   
   int y = getpinfo(stat1);


int counter = 0;
for(counter = 0; counter < NPROC; counter++){
   printf(1, "PID %d, \n", stat1->pid[counter]);
   printf(1, "INUSE %d, \n", stat1->inuse[counter]);
   printf(1, "TICKS %d, \n", stat1->ticks[counter]);   
}

      
   
// = malloc(sizeof(stat1));
   y = y+0;
   //printf(1, x);
   printf(1, "hello world %d, \n", x);
  exit();
}
int main(int argc, char *argvv[]) {

	//int tickettest;

	struct pstat * stats;
	stats = (struct pstat *) malloc(sizeof(struct pstat) * 64);
	int i;

	// (settickets(0) == -1) ? printf(1,"fail\n") : printf(1,"pass\n"); //you f****d
	// (settickets(10) == -1) ? printf(1,"fail\n") : printf(1,"pass\n"); //you good
	// (settickets(40) == -1) ? printf(1,"fail\n") : printf(1,"pass\n"); //you good
	// (settickets(38) == -1) ? printf(1,"fail\n") : printf(1,"pass\n"); //you f****d
	settickets(20); //you good
	// (settickets(160) == -1) ? printf(1,"fail\n") : printf(1,"fpass\n"); //you f****d
	//printf(1, "\n");

	int runtime;

	fork_kids();
	printf(1,",10,30,60,90,120,150\n");
	for(runtime = 0; runtime < 119 ;runtime++) {
		getpinfo(stats);
		printf(1,"%d,", runtime);
		for(i = 0; i < 64; i++) {
			if(stats[i].inuse == 1 && (stats[i].pid != 1 && stats[i].pid != 2 && stats[i].pid != 3)) {
				printf(1,"%d,", stats[i].n_schedule);
			}
		}
		printf(1, "\n");
		sleep(100);
	}
	exit();
}
Exemplo n.º 5
0
//added syscall
int
sys_settickets(void)
{
	int num;
	if(argint(0, &num) < 0){
		return -1;
	}
	return settickets(num);
}
Exemplo n.º 6
0
int
main(void)
{
//Adde
struct pstat ptr;
//Testing tickets syscall
if (settickets(1) == 0) {
   printf(0,"Set tickets success!\r\n");
} else {
   printf(0,"Set tickets failed!\r\n");
}
   
//Testing getpinfo
// getpinfo(ptr);
int inval = getpinfo(&ptr);

if (inval == 0) {
   int i;
   int max = 64;
   for(i=0;i<max;i++) {
      if ((ptr.inuse[i] == 0)&&(i < 10)) {
         printf(0,"Proc %d not in use pid=%d, hticks = %d, lticks = %d\r\n"
         ,i,ptr.pid[i],ptr.hticks[i],ptr.lticks[i]);
      }
      if(ptr.inuse[i] == 1) {
         printf(0,"Proc %d running!!! pid=%d, hticks = %d, lticks = %d\r\n"
            ,i,ptr.pid[i],ptr.hticks[i],ptr.lticks[i]);
      } else {
         //printf(0,"Proc %d not in use pid=%d, hticks = %d, lticks = %d\r\n"
          //  ,i,ptr.pid[i],ptr.hticks[i],ptr.lticks[i]);
      }
      if (i == 60) printf(0,"lotto = %d\r\n",ptr.lticks[i]);
      if (i == 61) printf(0,"qlevel = %d\r\n",ptr.lticks[i]);
      if (i == 62) printf(0,"tix = %d\r\n",ptr.lticks[i]);
      if (i == 63) printf(0,"lo_tix= %d\r\n",ptr.lticks[i]);
      if (i == 59) printf(0,"hi_tix = %d\r\n",ptr.lticks[i]);
      if (i == 58) printf(0,"Second loop ran %d times\r\n",ptr.lticks[i]);
      if (i == 57) printf(0,"First loop ran %d times\r\n",ptr.lticks[i]);
   }
   printf(0,"\r\n");
   printf(0,"Print out finished \r\n");
} else {
   printf(0,"Failed to call getpinfo!! \r\n");
   printf(0,"fail val= %d  \r\n",inval);
}


  if(fork() > 0)
    sleep(5);  // Let child exit before parent.

  exit();
}
void fork_kids() {

	int i;
	int rc;

	for(i = 1; i < 7; i++) {
		rc = fork();
		if(rc == 0) {
			int tmp, sum = 0;

			switch (i) {
				case 1:
					if(settickets(10) < 0)
						exit();
					break;
				case 2:
					if(settickets(30) < 0)
						exit();
					break;
				case 3: 
					if(settickets(60) < 0)
						exit();
					break;
				case 4:
					if(settickets(90) < 0)
						exit();
					break;
				case 5:
					if(settickets(120) < 0)
						exit();
					break;					
				case 6:
					if(settickets(150) < 0)
						exit();
					break;
			}

			for(tmp = 0; ;tmp++) {
				sum += tmp;
			}

			exit();
		}
	}
}
Exemplo n.º 8
0
int
main(int argc, char **argv)
{
	/*//printf(1,"getsyscallinfo is returning %d\n", getsyscallinfo()); //User program calling system call
	int i;
	for(i=-2; i<10; i+=1)
	{
	//	printf(1,"Set tickets is returning %d as and we are setting %d\n", settickets(i),i); 
		  //printf(1,"Ticket was set to %d\n")i
			//
			getpinfo(pt); 
	}
	*/

	 struct p_info
	 {
		 int pids;
		 int tk;
	 };

	 struct p_info p_table[N];

	 int i,r,j,k;
	 int ppid = getpid();
  
	 for(i = 0; i < N; i++)
	 {
		p_table[i].pids = fork();
		if (p_table[i].pids == 0) 
		{
			p_table[i].tk = i * N + N;
      r = settickets(i * N + N);
      if (r != 0) 
			{
         printf(1, "settickets failed");
         kill(ppid);
      }
      spin();
		}
	 }
	 //sleep(10);

	 int lticks[10] ;
	 int hticks[10];
   struct pstat st;
	 getpinfo(&st);	

	
   for(k = 0; i < NPROC; k++)
	 {
      for(j = 0; j < N; j++)
			{
         if (st.inuse[i] && (st.pid[i] == p_table[j].pids)) {
					  lticks[j] = st.lticks[i];
            hticks[j] = st.hticks[i];
						printf(1,"pid: %d\t tickets: %d\t ltick: %d\t hticks: %d\n",p_table[j].pids, p_table[j].tk, hticks[j], lticks[j]);
         }
      }
   }

   for (i = 0; i < N; i++) {
      kill(p_table[i].pids);
      wait();
   }
	 exit();
}