/* * 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 #include #ifdef CONFIG_UTIME #include #endif #include void finish_process(void) { struct rtparams rt_params; /* Now switch the kernel to the normal mode and then make this * a normal process */ sleep(1); if (switch_to_normal(0)) { perror("switch_to_normal failed in finish_process"); } rt_params.rt_id = 0; if (set_rtparams(0,SCHED_OTHER,&rt_params)) { perror("set_rtparams failed in finish_process"); } else { printf("Unregistered rt_proc.\n"); } } void IntProc(int i) { printf("Intproc called for rt_test\n"); finish_process(); } int main(int argc, char **argv) { int type, rt_mode; struct rtparams rt_params; signal(SIGINT, IntProc); signal(SIGABRT, IntProc); if (argc != 6) { fprintf(stderr, "Usage : %s bin_filename " " " " \n", argv[0]); exit(1); } rt_params.rt_id = 0; rt_params.proc_req = 0; rt_params.period = 0; rt_params.priority = (MAX_KURT_PRIORITY - MIN_KURT_PRIORITY)/2 + MIN_KURT_PRIORITY; /* set the scheduler to be SCHED_KURT and set the rt_id to be 0 */ if (set_rtparams(0, SCHED_KURT, &rt_params)) { perror("set_rtparams:"); exit(1); } else { get_rtparams(0, &rt_params); printf("process rt_id = %d.\n", rt_params.rt_id); } if (!strcmp(argv[2],"rt-1")) rt_mode = SCHED_KURT_PROCS; else if (!strcmp(argv[2],"rt-2")) rt_mode = SCHED_ALL_PROCS; else { fprintf(stderr, "Usage : %s bin_filename " " " " \n", argv[0]); exit(1); } /* Find out the mode of scheduling and then schedule * these events */ if (!strcmp(argv[3], "from_disk")) type = RT_FROM_DISK; else if (!strcmp(argv[3], "from_mem")) type = RT_FROM_MEM; else { fprintf(stderr,"Invalid scheduling mode.\n"); exit(1); } /* Wait for all the other real time processes to register themselves */ printf("Waiting for other realtime processes to register...\n"); while (get_num_rtprocs() < atoi(argv[5])) { sleep(1); } printf("number of real-time processes = %d\n", get_num_rtprocs()); /* Now switch the kernel to real time mode * Depending on whether UTIME is installed or not we need to tell * the kernel to switch the timer to oneshot mode */ system("cat /proc/meminfo"); printf("\n\n"); #ifdef CONFIG_UTIME if (switch_to_rt(timer_chip_oneshot, 0, rt_mode, NULL, 0)) { perror("switch_to_rt:"); exit(1); } #else if (switch_to_rt(0, 0, rt_mode, NULL, 0)) { perror("switch_to_rt:"); exit(1); } #endif system("cat /proc/meminfo"); if (rt_schedule_events(NULL, type, atoi(argv[4]), argv[1])) { perror("rt_schedule_events : "); exit(1); } finish_process(); return 0; }