Example #1
0
int
main(int argc, char *argv[])
{
   check(setpri(1) == 0, "setpri to 1");
   check(setpri(2) == 0, "setpri to 2");
   check(setpri(-1) == -1, "setpri to <0");
   check(setpri(10) == -1, "setpri to 10");
   printf(1, "Should print 1 then 2");
   exit();
}
Example #2
0
int
main(int argc, char *argv[])
{
 
   struct pstat st_before, st_after;
   int pid = getpid();
   int lowpriorityrun = 0;
   int  highpriorityrun = 0;
   int i;
   check(setpri(2) == 0, "setpri");
   // check if process run in high priority mode once set to high
  
   check(getpinfo(&st_before) == 0, "getpinfo");
   printf(1, "\n ****PInfo before**** \n");
   print(&st_before);
   spin();
   check(getpinfo(&st_after) == 0, "getpinfo");
   printf(1, "\n ****PInfo after**** \n");
   print(&st_after);
   for(i = 0; i < NPROC; ++i)
   {
	if(st_before.pid[i] == pid && st_after.pid[i] == pid)
	{
		if(st_before.hticks[i] < st_after.hticks[i] && st_before.lticks[i] == st_after.lticks[i])
			highpriorityrun = 1;
	}		
   }
   check(highpriorityrun == 1, "Expected process to have run in high priority mode once priority changed to high");

   check(setpri(1) == 0, "setpri");
 
  // check if process run in low priority mode once changed back
   check(getpinfo(&st_before) == 0, "getpinfo");
   printf(1, "\n ****PInfo before**** \n");
   print(&st_before);
   spin();
   check(getpinfo(&st_after) == 0, "getpinfo");
   printf(1, "\n ****PInfo after**** \n");
   print(&st_after);
   for(i = 0; i < NPROC; ++i)
   {
	if(st_before.pid[i] == pid && st_after.pid[i] == pid)
	{
		if(st_before.lticks[i] < st_after.lticks[i] && st_before.hticks[i] == st_after.hticks[i])
			lowpriorityrun = 1;
	}		
   }
   check(lowpriorityrun == 1, "Expected process to have run in low priority mode once priority changed back to low");
   printf(1, "Should print 1 then 2"); 
   exit();
}
Example #3
0
int
main(int argc, char *argv[])
{
  //int x = settickets(23);
   
  //const clock_t start = clock();
  // do stuff here
  //clock_t now = clock();
  //clock_t delta = now - start;
  //return (int) start;
  struct pstat *stat1;
  stat1 = malloc(sizeof(*stat1));   
  //int y = getpinfo(stat1);
  int y = getpinfo(NULL);

  int z = setpri(1);
  printf(stdout, "SETPRI, %d\n", z);

  int counter = 0;
  //for(counter = 0; counter < NPROCS; counter++){
  printf(stdout, "aux %s, \n", stat1->aux[counter]);
    printf(stdout, "PID %d, \n", stat1->pid[counter]);
    printf(stdout, "INUSE %d, \n", stat1->inuse[counter]);
    printf(stdout, "LTICKS %d, \n", stat1->hticks[counter]);   
    printf(stdout, "HTICKS %d, \n", stat1->lticks[counter]);   
    //}     
   
  // = malloc(sizeof(stat1));
  //y = y+0;
  //printf(1, x);
    printf(stdout, "hello you, %d\n", y);
  //return 0;
  exit();
}
Example #4
0
int
main(int argc, char *argv[])
{
	//printf(1,"hello this is a program\n");
	printf(1,"%d\n",setpri(2));	
	exit();
}
Example #5
0
/*---------------------------------------------------------------------+
|                                 main                                 |
| ==================================================================== |
|                                                                      |
| Function:  ...                                                       |
|                                                                      |
+---------------------------------------------------------------------*/
int main (int argc, char **argv)
{
	long	start_time;      /* time at start of testcase */
	int	i;

	/*
	 * Setup signal handler & setup alarm so we do not loop forever...
	 */
	signal (SIGUSR1, signal_handler);
	signal (SIGALRM, signal_handler);
	alarm  (600);	/* wait 10 minutes before aborting */

	/*
	 * Process command line arguments...
	 */
	parse_args (argc, argv);
	if (verbose) printf ("%s: Scheduler TestSuite program\n\n", *argv);
	if (debug) {
		printf ("\tpriority:       %s\n", priority);
	}

	/*
	 * Adjust the priority of this process if the real time flag is set
	 */
	if (!strcmp (priority, "fixed")) {
#ifndef __linux__
                if (setpri (0, DEFAULT_PRIORITY) < 0)
                        sys_error ("setpri failed", __FILE__, __LINE__);
#else
                if (setpriority(PRIO_PROCESS, 0, 0) < 0)
                        sys_error ("setpri failed", __FILE__, __LINE__);
#endif
	}

	/*
	 * Continuously multiply matrix as time permits...
	 */
	i = 0;
	start_time = time ((long *) 0);

	/*
	 * Continuously read through file until interrupted...
	 */
	if (debug) printf ("\n");
	while (!signaled) {
		if (debug) {
			printf ("\r\tmultiplying matrix [%d]", i++);
			fflush (stdout);
		}
		multiply_matrices ();
	}
	if (debug) printf ("\n");

	/*
	 * Exit with success!
	 */
	if (verbose) printf ("\nsuccessful!\n");
	return (0);
}
Example #6
0
int
main(int argc, char *argv[])
{
 
  struct pstat st_before, st_after;
  int lowpriorityrun = 0, highpriorityrun = 0;
  printf(1, "1 - PID #%d\n", getpid());
  int rc = fork();
  int i;
  int pid = getpid();
  if(rc == 0)
    {
      printf(1, "2 - PID #%d (bout to spin 1)\n", getpid());
      spin();
      printf(1, "2 - PID #%d (bout to sleep)\n", getpid());
      sleep(200);
      printf(1, "2 - PID #%d (bout to spin 2)\n", getpid());
      spin();
      exit();
    }
  check(setpri(2) == 0, "setpri");
  if(fork() == 0)
    {
      printf(1, "3 - PID #%d (bout to sleep 1)\n", getpid());
      sleep(200);
      printf(1, "3 - PID #%d (bout to spin)\n", getpid());
      spin();
      printf(1, "3 - PID #%d (bout to sleep 2)\n", getpid());
      sleep(100);
      printf(1, " then 2");
      exit();
    }
  printf(1, "4 - PID #%d (bout to sleep)\n", getpid());
  sleep(200);
  printf(1, "5 - PID #%d\n", getpid());
  check(getpinfo(&st_before) == 0, "getpinfo");
  printf(1, "\n ****PInfo before**** \n");
  print(&st_before);
  printf(1, "5 - PID #%d (bout to spin 1)\n", getpid());
  spin();
  printf(1, "5 - PID #%d (bout to spin 2)\n", getpid());
  spin();
  check(getpinfo(&st_after) == 0, "getpinfo");
  printf(1, "\n ****PInfo after**** \n");
  print(&st_after);
  for(i = 0; i < NPROC; ++i)
    {
      if(st_before.pid[i] != pid && st_before.lticks[i] < st_after.lticks[i] && st_before.hticks[i] < st_after.hticks[i])
	lowpriorityrun++;
      if(st_before.hticks[i] < st_after.hticks[i])
	highpriorityrun++;
    }
  check(lowpriorityrun == 0, "Expected only the high priority process to run once it is awake");
  check(highpriorityrun == 1, "Expected one high priority process to run once it is awake");
  printf(1, "Should print 1"); 
  wait();
  wait();
  exit();
}
Example #7
0
int
sys_setpri(void)
{
    int priority;
    if(argint(0,&priority)<0)
        return -1;
    return setpri(priority);

}
Example #8
0
/*---------------------------------------------------------------------+
|                                 main                                 |
| ==================================================================== |
|                                                                      |
| Function:  ...                                                       |
|                                                                      |
+---------------------------------------------------------------------*/
int main (int argc, char **argv)
{
    long	start_time;      /* time at start of testcase */
    int	i;

    /*
     * Process command line arguments...
     */
    if (argc < 2) {
        fprintf (stderr, USAGE, *argv);
        exit (0);
    }

    parse_args (argc, argv);
    if (verbose) printf ("%s: Scheduler TestSuite program\n\n", *argv);
    if (debug) {
        printf ("\tpriority:       %s\n", priority);
        printf ("\texecution_time: %ld (sec)\n", execution_time);
    }

    /*
     * Adjust the priority of this process if the real time flag is set
     */
    if (!strcmp (priority, "fixed")) {
#ifndef __linux__
        if (setpri (0, DEFAULT_PRIORITY) < 0)
            sys_error ("setpri failed", __FILE__, __LINE__);
#else
        if (setpriority(PRIO_PROCESS, 0, 0) < 0)
            sys_error ("setpri failed", __FILE__, __LINE__);
#endif
    }

    /*
     * Continuously multiply matrix as time permits...
     */
    i = 0;
    start_time = time ((long *) 0);

    if (debug) printf ("\n");
    while  ( (time ((long *)0) - start_time) < execution_time) {
        if (debug) {
            printf ("\r\tmultiplying matrix [%d], time left: %ld",
                    i++,
                    execution_time - (time ((long *)0)-start_time));
            fflush (stdout);
        }
        multiply_matrices ();
    }
    if (debug) printf ("\n");

    /*
     * Exit with success!
     */
    if (verbose) printf ("\nsuccessful!\n");
    return (0);
}
Example #9
0
File: sched_tc1.c Project: 1587/ltp
/*---------------------------------------------------------------------+
|                                 main                                 |
| ==================================================================== |
|                                                                      |
| Function:  ...                                                       |
|                                                                      |
+---------------------------------------------------------------------*/
int main(int argc, char **argv)
{
	char *filename = NULL;

	if ((filename = getenv("KERNEL")) == NULL) {
		errno = ENODATA;
		sys_error("environment variable KERNEL not set", __FILE__,
			  __LINE__);
	}
	/*
	 * Setup signal handler & setup alarm so we do not loop forever...
	 */
	signal(SIGUSR1, signal_handler);
	signal(SIGALRM, signal_handler);
	alarm(600);		/* wait 10 minutes before aborting */

	/*
	 * Process command line arguments...
	 */
	parse_args(argc, argv);
	if (verbose)
		printf("%s: Scheduler TestSuite program\n\n", *argv);
	if (debug) {
		printf("\tpriority:       %s\n", priority);
	}

	/*
	 * Adjust the priority of this process if the real time flag is set
	 */
	if (!strcmp(priority, "fixed")) {
#ifndef __linux__
		if (setpri(0, DEFAULT_PRIORITY) < 0)
			sys_error("setpri failed", __FILE__, __LINE__);
#else
		if (setpriority(PRIO_PROCESS, 0, 0) < 0)
			sys_error("setpri failed", __FILE__, __LINE__);
#endif
	}

	/*
	 * Continuously read through file until interrupted...
	 */
	while (!signaled)
		process_file(filename);

	/*
	 * Exit with success!
	 */
	if (verbose)
		printf("\nsuccessful!\n");
	return (0);
}
Example #10
0
static void dbgproc(void *)
{
	Dbgkey *dp;

	setpri(PriRealtime);
	for (;;) {
		do {
			rendez_sleep(&dbg, dbgwork, 0);
			dp = dbg.work;
		} while (dp == NULL);
		dp->f(dp->r);
		dbg.work = NULL;
	}
}
Example #11
0
File: devcons.c Project: 8l/inferno
static void
dbgproc(void *)
{
	Dbgkey *dp;

	setpri(PriRealtime);
	for(;;) {
		do {
			sleep(&dbg, dbgwork, 0);
			dp = dbg.work;
		} while(dp == nil);
		dp->f(dp->r);
		dbg.work = nil;
	}
}
Example #12
0
File: random.c Project: 8l/inferno
static void
genrandom(void*)
{
	setpri(PriBackground);

	for(;;) {
		for(;;)
			if(++rb.randomcount > 100000)
				break;
		if(anyhigher())
			sched();
		if(rb.filled || !rbnotfull(0))
			sleep(&rb.producer, rbnotfull, 0);
	}
}
int
main(int argc, char *argv[])
{
 
   struct pstat st_before, st_after;
   int lowpriorityrun = 0;
   int highpriorityrun = 0;
   int rc = fork();
   int i;
   if(rc == 0)
   {
	spin();
	spin();
	sleep(500);
	exit();
   }
   sleep(100);
   check(setpri(2) == 0, "setpri");
   check(getpinfo(&st_before) == 0, "getpinfo");
   printf(1, "\n ****PInfo before**** \n");
   print(&st_before);
   sleep(500);  
   check(getpinfo(&st_after) == 0, "getpinfo");
   printf(1, "\n ****PInfo after**** \n");
   print(&st_after);
   for(i = 0; i < NPROC; ++i)
   {
	if(st_before.pid[i] == rc && st_after.pid[i] == rc)
	{
		if(st_before.lticks[i] < st_after.lticks[i])
			lowpriorityrun = 1;
		if(st_before.hticks[i] < st_after.hticks[i])
			highpriorityrun = 1;
	}		
   }
   check(highpriorityrun == 0, "Expected no high priority ticks when low priority running");
   check(lowpriorityrun == 1, "Expected low priority process to have run when high priority process was put to sleep");
   wait();
   printf(1, "Should print 1 then 2"); 
   exit();
}
Example #14
0
static void pppreader(void *a)
{
	Ipifc *ifc;
	Block *bp;
	PPP *ppp;

	ifc = a;
	ppp = ifc->arg;
	ppp->readp = up;	/* hide identity under a rock for unbind */
	setpri(PriHi);

	if (waserror()) {
		netlog(ppp->f, Logppp, "pppreader: %I: %s\n", ppp->local,
			   up->env->errstr);
		ppp->readp = 0;
		deadremote(ifc);
		pexit("hangup", 1);
	}

	for (;;) {
		bp = pppread(ppp);
		if (bp == nil)
			error("hungup");
		if (!canrlock(ifc)) {
			freeb(bp);
			continue;
		}
		if (waserror()) {
			runlock(ifc);
			nexterror();
		}
		ifc->in++;
		if (ifc->lifc == nil)
			freeb(bp);
		else
			ipiput(ppp->f, ifc, bp);
		runlock(ifc);
		poperror();
	}
}
int
main(int argc, char *argv[])
{
   if(fork() == 0)
   {
   	struct pstat st_before, st_after;
	check(setpri(2) == 0, "setpri");
	check(getpinfo(&st_before) == 0, "getpinfo");
	printf(1, "\n ****PInfo before**** \n");
	print(&st_before);
	spin();
	spin();
	check(getpinfo(&st_after) == 0, "getpinfo");
	printf(1, "\n ****PInfo after**** \n");
	print(&st_after);
	compare(&st_before, &st_after);
	printf(1, "Should print 1"); 
	exit();
   }
   spin();
   printf(1, " then 2");
   exit();
}
Example #16
0
/*---------------------------------------------------------------------+
|                                 main                                 |
| ==================================================================== |
|                                                                      |
| Function:  ...                                                       |
|                                                                      |
+---------------------------------------------------------------------*/
int main (int argc, char **argv)
{
	FILE	*statfile;
	int	i;
	clock_t	start_time;		/* start & stop times */
	clock_t	stop_time;
	float	elapsed_time;
	struct tms timer_info;		/* time accounting info */

	/*
	 * Process command line arguments...
	 */
	parse_args (argc, argv);
	if (verbose) printf ("%s: Scheduler TestSuite program\n\n", *argv);
	if (debug) {
		printf ("\tpriority type:  %s\n", priority_type);
		printf ("\tpriority:       %d\n", priority);
		printf ("\tlogfile:        %s\n", logfile);
	}

	/*
	 * Adjust the priority of this process if the real time flag is set
	 */
	if (!strcmp (priority_type, "fixed")) {
#ifndef __linux__
                if (setpri (0, DEFAULT_PRIORITY) < 0)
                        sys_error ("setpri failed", __FILE__, __LINE__);
#else
                if (setpriority(PRIO_PROCESS, 0, 0) < 0)
                        sys_error ("setpri failed", __FILE__, __LINE__);
#endif
	} else {
		if (nice ((priority - 50) - (nice (0) + 20)) < 0 && errno != 0)
			sys_error ("nice failed", __FILE__, __LINE__);
	}

	/*
	 * Read from raw I/O device and record elapsed time...
	 */
	start_time = time ((time_t*)&timer_info);

	for (i=0; i < TIMES; i++)
		invert_matrix ();

	stop_time = time ((time_t*)&timer_info);
	elapsed_time = (float) (stop_time - start_time) / 100.0;

	if ((statfile = fopen (logfile, "w")) == NULL)
		sys_error ("fopen failed", __FILE__, __LINE__);

	fprintf (statfile, "%f\n", elapsed_time);
	if (debug) printf ("\n\telapsed time: %f\n", elapsed_time);

	if (fclose (statfile) < 0)
		sys_error ("fclose failed", __FILE__, __LINE__);

	/*
	 * Exit with success!
	 */
	if (verbose) printf ("\nsuccessful!\n");
	return (0);
}
Example #17
0
static void
sit_and_spin(int child_index)

{
  long *my_counter_ptr;

 /* only use C stuff if we are not WIN32 unless and until we */
 /* switch from CreateThread to _beginthread. raj 1/96 */
#ifndef WIN32
  /* we are the child. we could decide to exec some separate */
  /* program, but that doesn't really seem worthwhile - raj 4/95 */
  if (debug > 1) {
    fprintf(where,
            "Looper child %d is born, pid %d\n",
            child_index,
            getpid());
    fflush(where);
  }
  
#endif /* WIN32 */

  /* reset our base pointer to be at the appropriate offset */
  my_counter_ptr = (long *) ((char *)lib_base_pointer + 
                             (netlib_get_page_size() * 
                              PAGES_PER_CHILD * child_index));
  
  /* in the event we are running on an MP system, it would */
  /* probably be good to bind the soaker processes to specific */
  /* processors. I *think* this is the most reasonable thing to */
  /* do, and would be closes to simulating the information we get */
  /* on HP-UX with pstat. I could put all the system-specific code */
  /* here, but will "abstract it into another routine to keep this */
  /* area more readable. I'll probably do the same thine with the */
  /* "low pri code" raj 10/95 */
  
  /* NOTE. I do *NOT* think it would be appropriate for the actual */
  /* test processes to be bound to a  particular processor - that */
  /* is something that should be left up to the operating system. */
  
  bind_to_processor(child_index);
  
  for (*my_counter_ptr = 0L;
       ;
       (*my_counter_ptr)++) {
    if (!(*lib_base_pointer % 1)) {
      /* every once and again, make sure that our process priority is */
      /* nice and low. also, by making system calls, it may be easier */
      /* for us to be pre-empted by something that needs to do useful */
      /* work - like the thread of execution actually sending and */
      /* receiving data across the network :) */
#ifdef _AIX
      int pid,prio;

      prio = PRIORITY;
      pid = getpid();
      /* if you are not root, this call will return EPERM - why one */
      /* cannot change one's own priority to  lower value is beyond */
      /* me. raj 2/26/96 */  
      setpri(pid, prio);
#else /* _AIX */
#ifdef __sgi
      int pid,prio;

      prio = PRIORITY;
      pid = getpid();
      schedctl(NDPRI, pid, prio);
      sginap(0);
#else /* __sgi */
#ifdef WIN32
      SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_IDLE);
#else /* WIN32 */
#if defined(__sun) && defined(__SVR4)
#include <sys/types.h>
#include <sys/priocntl.h>
#include <sys/rtpriocntl.h>
#include <sys/tspriocntl.h>
      /* I would *really* like to know how to use priocntl to make the */
      /* priority low for this looper process. however, either my mind */
      /* is addled, or the manpage in section two for priocntl is not */
      /* terribly helpful - for one, it has no examples :( so, if you */
      /* can help, I'd love to hear from you. in the meantime, we will */
      /* rely on nice(39). raj 2/26/96 */
      nice(39);
#else /* __sun && __SVR4 */
      nice(39);
#endif /* __sun && _SVR4 */
#endif /* WIN32 */
#endif /* __sgi */
#endif /* _AIX */
    }
  }
}
Example #18
0
File: sched_tc6.c Project: 1587/ltp
/*---------------------------------------------------------------------+
|                                 main                                 |
| ==================================================================== |
|                                                                      |
| Function:  ...                                                       |
|                                                                      |
+---------------------------------------------------------------------*/
int main(int argc, char **argv)
{
	char *filename = NULL;
	FILE *statfile;
	pid_t pid = 0;
	int fd;
	int rc;
	clock_t start_time;	/* start & stop times */
	clock_t stop_time;
	float elapsed_time;
#ifdef __linux__
	time_t timer_info;
#else
	struct tms timer_info;	/* time accounting info */
#endif

	if ((filename = getenv("KERNEL")) == NULL) {
		errno = ENODATA;
		sys_error("environment variable KERNEL not set", __FILE__,
			  __LINE__);
	}

	/* Process command line arguments...  */
	parse_args(argc, argv);
	if (verbose)
		printf("%s: Scheduler TestSuite program\n\n", *argv);
	if (debug) {
		printf("\tpriority type:  %s\n", priority_type);
		printf("\tpriority:       %d\n", priority);
		printf("\tlogfile:        %s\n", logfile);
	}

	/* Adjust the priority of this process if the real time flag is set */
	if (!strcmp(priority_type, "fixed")) {
#ifndef __linux__
		if (setpri(0, DEFAULT_PRIORITY) < 0)
			sys_error("setpri failed", __FILE__, __LINE__);
#else
		if (setpriority(PRIO_PROCESS, 0, 0) < 0)
			sys_error("setpri failed", __FILE__, __LINE__);
#endif
	} else {
		if (nice((priority - 50) - (nice(0) + 20)) < 0 && errno != 0)
			sys_error("nice failed", __FILE__, __LINE__);
	}

	/* Read from raw I/O device and record elapsed time...  */
	start_time = time(&timer_info);

	/* Open and lock file file...  */
	fd = open_file(filename, O_RDWR);
	if (!lock_file(fd, F_WRLCK, filename))	/* set exclusive lock */
		error("lock_file failed", __FILE__, __LINE__);

	/* If fork flag set, fork a real process */
	if (fork_flag)
		pid = fork_realtime(argv);

	/* Read file */
	if (debug) {
		printf("\tprocess id %d successfully locked %s\n",
		       getpid(), filename);
		printf("\tprocess id %d starting to read %s\n",
		       getpid(), filename);
	}

	if (!read_file(fd, filename))
		error("read_file failed", __FILE__, __LINE__);

	/* Stop the timer and calculate the elapsed time */
	stop_time = time(&timer_info);
	elapsed_time = (float)(stop_time - start_time) / 100.0;

	/* Write the elapsed time to the temporary file...  */
	if ((statfile = fopen(logfile, "w")) == NULL)
		sys_error("fopen failed", __FILE__, __LINE__);

	fprintf(statfile, "%f\n", elapsed_time);
	if (debug)
		printf("\n\telapsed time: %f\n", elapsed_time);

	if (fclose(statfile) < 0)
		sys_error("fclose failed", __FILE__, __LINE__);

	/* Unlock file at latest possible time to prevent real time child from
	 * writing throughput results before user process parent */
	unlock_file(fd, filename);
	close(fd);

	if (debug)
		printf("\tprocess id %d completed read and unlocked file\n",
		       getpid());

	/* The parent waits for child process to complete before exiting
	 * so the driver will not read the throughput results file before
	 * child writes to the file */
	if (pid != 0) {		/* if parent process ... *//* wait for child process */
		if (debug)
			printf
			    ("parent waiting on child process %d to complete\n",
			     pid);

		while ((rc = wait(NULL)) != pid)
			if (rc == -1)
				sys_error("wait failed", __FILE__, __LINE__);
/*
DARA: which one to use
1st -- hangs
2nd -- ERROR message

	    while (wait((void *) 0) != pid) ;
	    while ((rc=wait ((void *) 0)) != pid)
	       if (rc == -1)
	          sys_error ("wait failed", __FILE__, __LINE__);
*/
	}

	/* Exit with success! */
	if (verbose)
		printf("\nsuccessful!\n");
	return (0);
}