/* * KURT: KU Real Time Linux * $ProductId: KURT/linux/rt:rt.c 1.4 $ * * Copyright (C) 1997 by the University of Kansas Center for Research, * Inc. This software was developed by the Information and * Telecommunication Technology Center (ITTC) at the University of * Kansas. Partial funding for this project was provided by Sprint. This * software may be used and distributed according to the terms of the GNU * Public License, incorporated herein by reference. Neither ITTC nor * Sprint accept any liability whatsoever for this product. * * This project was developed under the direction of Dr. Douglas Niehaus. * * Authors: Balaji S. * * Please send bug-reports/suggestions/comments to realtime@ittc.ukans.edu * * Further details about this project can be obtained at * http://hegel.ittc.ukans.edu/projects/kurt/ */ #include #include #include #include #include #include #include #include #include #include #include #ifdef CONFIG_UTIME #include #endif #include #include #include #include int is_realtime=0; void IntProc(int i) { struct rtparams param; if (is_realtime) { if (!get_rtparams(0, ¶m)) { printf("IntProc called for process with rt_id %d\n", param.rt_id); /* Make this a normal process */ param.rt_id = 0; if (set_rtparams(0, SCHED_OTHER, ¶m)) { perror("set_rtparams failed in IntProc "); exit(1); } switch_to_normal(1); } } exit(0); } struct timeval *event_time=NULL; inline void do_stuff(FILE *out) { static int i = 0; /* Just get the time and print it */ if (!event_time) return; gettimeofday(&event_time[i++], NULL); } void do_realtime(int num_procs, int num_iters, int rt_id, int proc_req, char *out_dir, unsigned long period) { struct rtparams rt_param; struct rtstats info; int i, j, pid, retval; /* set the scheduler for this process to be sched_kurt * and then set the rt_id of this procss properly */ rt_param.rt_id = ASSIGN_RT_ID_FROM_TOP; rt_param.proc_req = 0; rt_param.period = 0; rt_param.priority = (MAX_KURT_PRIORITY-MIN_KURT_PRIORITY)/2 + MIN_KURT_PRIORITY; if (set_rtparams(0, SCHED_KURT, &rt_param) < 0){ perror("set_rtparams:"); fprintf(stderr,"set_rtparams failed for parent\n"); exit(1); } rt_param.rt_id = rt_id; rt_param.proc_req = proc_req; rt_param.period = period; rt_param.priority = MAX_KURT_PRIORITY; for (i=0;i0) { rt_param.rt_id++; continue; } else if (childpid==0) { FILE *out; char filename[80]; sprintf(filename,"%s/%d_rt-%d.timing",out_dir,getpid(), is_realtime); out = fopen(filename,"w"); if (!out) { perror("fopen"); exit(1); } if (set_rtparams(0, SCHED_KURT, &rt_param) < 0){ perror("set_rtparams:"); fprintf(stderr,"set_rtparams failed for" " process with rt_id %d\n", rt_param.rt_id); exit(1); } else { get_rtparams(0, &rt_param); printf("process rt_id = %d, proc_req = %lu.\n", rt_param.rt_id, rt_param.proc_req); } event_time = (struct timeval*) malloc(sizeof(struct timeval) * num_iters); if (!event_time) { fprintf(stderr,"Ran out of memory\n"); exit(1); } for (j=0;j0) { /* do nothing */ } /* Now switch it to normal mode */ switch_to_normal(1); return; } void do_non_realtime(int num_procs, int num_iters, char *out_dir, unsigned long period) { int i, j, pid; struct sched_param scheduler; /* mark the process as a sched_fifo process */ scheduler.sched_priority = 99; sched_setscheduler(0,SCHED_FIFO, &scheduler); for (i=0;i0) { continue; } else if (childpid==0) { FILE *out; char filename[80]; sprintf(filename,"%s/%d_nrt.timing",out_dir,getpid()); out = fopen(filename,"w"); if (!out) { perror("fopen"); exit(1); } event_time = (struct timeval*) malloc(sizeof(struct timeval) * num_iters); if (!event_time) { fprintf(stderr,"Ran out of memory\n"); exit(1); } for (j=0;jdiff) { tv.tv_usec = period - diff; select(0, NULL, NULL, NULL, &tv); } } for (j=0;j0) { /* do nothing */ } return; } int main(int argc, char **argv) { int num_iters, num_procs, rt_id, proc_req; int period; signal(SIGINT, IntProc); if (argc != 8) { fprintf(stderr, "Usage : %s " " " " \n", argv[0]); exit(1); } if (!strcmp(argv[6],"rt-1")) is_realtime = SCHED_KURT_PROCS; else if (!strcmp(argv[6],"rt-2")) is_realtime = SCHED_ALL_PROCS; else is_realtime = 0; num_procs = atoi(argv[4]); period = atoi(argv[7]); num_iters = atoi(argv[3]); rt_id =atoi(argv[1]); proc_req = atoi(argv[2]); if (is_realtime) { fflush(stdout); do_realtime(num_procs, num_iters, rt_id, proc_req, argv[5], period); } else { fflush(stdout); do_non_realtime(num_procs, num_iters,argv[5],period); } return 0; }