diff -u -r -N -b --exclude-from=diff_exclude xanim-ref/Imakefile xanim-work/Imakefile --- xanim-ref/Imakefile Thu Jun 6 09:34:05 1996 +++ xanim-work/Imakefile Thu Feb 5 16:22:51 1998 @@ -2,6 +2,11 @@ #ifndef XCOMM #define XCOMM # #endif +XCOMM Modified for use with KURT: KU Real Time Linux +XCOMM $ProductId: KURT/Apps/xanim:Imakefile 1.18 $ +XCOMM See http://hegel.ittc.ukans.edu/projects/kurt for further details +XCOMM + XCOMM ********************************************************************** XCOMM XCOMM Imakefile for XAnim Rev 2.70.4 Beta @@ -350,10 +355,10 @@ PROGRAMS = xanim -INCLUDES = -I$(INCDIR) $(XA_INCS) +INCLUDES = -I$(INCDIR) $(XA_INCS) -I/usr/include/X11/ LIBS1 = $(XA_LIBS) $(EXTENSIONLIB) $(XA_REMOTE_LIBS) $(XTOOLLIB) \ - $(XLIB) -lm + $(XLIB) -lm -lrt DEPLIBS1 = $(DEPEXTENSIONLIB) $(XA_REMOTE_DEP_LIBS) $(DEPXTOOLLIB) \ $(DEPXLIB) XCOMM xa_pfx.c temporarily removed diff -u -r -N -b --exclude-from=diff_exclude xanim-ref/xanim.c xanim-work/xanim.c --- xanim-ref/xanim.c Thu Jun 6 09:34:00 1996 +++ xanim-work/xanim.c Thu Feb 5 16:22:50 1998 @@ -48,6 +48,10 @@ * is movies listed later on the command line. * *******************************/ +/* Modified for use with KURT: KU Real Time Linux + * $ProductId: KURT/Apps/xanim:xanim.c 1.18 $ + * See http://hegel.ittc.ukans.edu/projects/kurt for further details + */ #define DA_REV 2.70 #define DA_MINOR_REV 6 @@ -71,6 +75,18 @@ #include #endif +/* Include rt.h for use with linux + */ +#ifdef linux +#include +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) +#include +#include +#define OVERHEAD_PER_INVOCATION 150 +#define RT_SCHEDULING_OVERHEAD 150 +#endif +#endif + #ifdef MSDOS #include #else /* not MSDOS */ @@ -225,6 +241,13 @@ xaULONG mbuf = 0; +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) +int real_time_mode = 0; +int Xpid = 0; +int proc_is_realtime=0; +unsigned long kurt_period = 0; +unsigned long kurt_proc_req = 0; +#endif #ifdef VMS /* * Provide the UNIX gettimeofday() function for VMS C. @@ -584,6 +607,11 @@ { fprintf(stdout,"Usage:\n\n"); fprintf(stdout,"xanim [+V#] [ [+|-]opts ...] animfile [ [ [+|-opts] animfile] ... ]\n"); +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) + fprintf(stdout, "-rt flag can be specified if you want xanim to be run in realtime mode\n"); + fprintf(stdout, "If the -rt flag is specified, you should also use -Xpid to make sure the Xserver also runs in periodic mode\n"); +#endif + fprintf(stdout,"\n"); #ifdef VMS fprintf(stdout,"VMS users need to enclose opts in double qotes: \"+Cn\".\n"); @@ -928,7 +956,16 @@ for(i=1;i= '0') && (in[2] <= '9') ) /* number */ @@ -1023,6 +1060,20 @@ for(i=1; i < argc; i++) { in = argv[i]; +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) + if (!strcmp(in,"-rt")) { + real_time_mode = 1; + kurt_period = atol(argv[i+1]); + kurt_proc_req = atol(argv[i+2]); + i += 2; + continue; + } + if (!strcmp(in,"-Xpid")) { + Xpid = atoi(argv[i+1]); + i += 1; + continue; + } +#endif if ( ((in[0] == '-') || (in[0] == '+')) && (in[1] != '\0')) { xaLONG len,opt_on; @@ -1547,6 +1598,7 @@ break; } } + if (xa_verbose) fprintf(stdout,"Reading %s File %s\n", cur_file->desc, filename); result = cur_file->Read_File(filename,cur_file,audio_attempt); @@ -1852,19 +1904,116 @@ xa_anim_ready = xaTRUE; /* allow expose event to start animation */ } +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) +void exit_rt(void) +{ + struct rtstats stats; + struct rtparams params; + + get_rtstats(0, &stats); + printf("RT Stats: Suspended %d, Woken Up %lu, Missed %lu, Abort %lu\n", + stats.rt_num_suspended, stats.rt_num_woken_up, + stats.rt_num_missed, stats.rt_abort); + switch_to_normal(1); + /* Now set the X server to have the lowest KURT priority, + */ + if (Xpid) { + get_rtparams(Xpid, ¶ms); + params.priority = MIN_KURT_PRIORITY; + set_rtparams(Xpid, SCHED_KURT, ¶ms); + } +} + +void set_process_rtparams(void) +{ + struct rtparams params; + if (!Xpid) { + fprintf(stderr,"Pid of X is not specified\n"); + exit(1); + } + /* now set the processing requirements of + * xanim + */ + params.period = kurt_period; + params.priority = MAX_KURT_PRIORITY; + params.rt_id = ASSIGN_RT_ID; + params.proc_req = kurt_proc_req; + + if (set_rtparams(0,SCHED_KURT, ¶ms)) { + perror("set_rtparams"); + exit(1); + } else { + /* see if set_rtparmas has been succesfull + */ + params.rt_id = -2; + if (get_rtparams(0,¶ms)) { + perror("get_rtparams"); + exit(1); + } + printf("rtid %d, period %lu, priority %d\n", + params.rt_id, params.period, + params.priority); + proc_is_realtime = 1; + switch_to_rt(timer_chip_oneshot,0, SCHED_ALL_PROCS,NULL,0); + printf("Switched to realtime mode\n"); + } + /* Now switch the Xserver to have MAX_KURT_PRIORITY + */ + if (get_rtparams(Xpid,¶ms) < 0) { + params.period = 0; + params.rt_id = ASSIGN_RT_ID; + params.proc_req = 0; + } + params.priority = MAX_KURT_PRIORITY; + if (set_rtparams(Xpid,SCHED_KURT, ¶ms)) { + perror("set_rtparams"); + exit(1); + } else { + /* see if set_rtparmas has been succesfull + */ + params.rt_id = -2; + if (get_rtparams(0,¶ms)) { + perror("get_rtparams"); + exit(1); + } + printf("Xserver rtid %d, period %lu," + " priority %d\n", + params.rt_id, params.period, + params.priority); + } +} +#endif + /* * This is the heart of this program. It does each action and then calls * itself with a timeout via the XtAppAddTimeOut call. */ +/* NOTE: This routine adds its own timer and executes once every + * 10ms or so ..atleast its supposed to + */ void XAnim_Looped(dptr,id) XtPointer dptr; XtIntervalId *id; { xaULONG command = (xaULONG)dptr; xaLONG t_time_delta = 0; xaLONG snd_speed_now_ok = xaFALSE; + /* NOTE: This can be removed. This is just to show how much time + * each loop takes + */ + struct timeval start_time, end_time; + unsigned long delta; XAnim_Looped_Sneak_Entry: +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) + if (real_time_mode && (proc_is_realtime)) { + rt_suspend(START_SCHED); + } +#endif + + /* NOTE: This can be removed too. + */ + gettimeofday(&start_time, NULL); DEBUG_LEVEL2 fprintf(stdout,"SHOWACTION\n"); if (command == XA_SHOW_NORM) @@ -1878,6 +2027,15 @@ (XtPointer)(XA_SHOW_NORM)); return; } + printf("XA_BEGINNING"); + /* Here is where we register this process as a realtime process + * and set the period and the processing requirement + */ +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) + if (real_time_mode) { + set_process_rtparams(); + } +#endif xa_anim_status = XA_RUN_NEXT; /* drop through */ case XA_STEP_NEXT: case XA_RUN_NEXT: @@ -1922,6 +2080,12 @@ case XA_UNSTARTED: case XA_STOP_NEXT: case XA_STOP_PREV: + +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) + if (real_time_mode) { + exit_rt(); + } +#endif #ifdef XA_AUDIO XA_AUDIO_OFF(0); xa_audio_start = 0; #endif @@ -1932,6 +2096,11 @@ return; break; default: +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) + if (real_time_mode) { + exit_rt(); + } +#endif #ifdef XA_AUDIO XA_AUDIO_OFF(0); xa_audio_start = 0; #endif @@ -2267,14 +2436,32 @@ */ /* if time is short and no events take a short cut */ /* 10 is chosen because on most systems 10ms is the time slice */ - if ( (t_time_delta < 10) - && (!XtAppPending(theContext)) ) goto XAnim_Looped_Sneak_Entry; +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) + if (!real_time_mode) { +#endif + if ((t_time_delta < 10) && (!XtAppPending(theContext)) ) + goto XAnim_Looped_Sneak_Entry; else XtAppAddTimeOut(theContext,t_time_delta, - (XtTimerCallbackProc)XAnim_Looped,(XtPointer)(XA_SHOW_NORM)); + (XtTimerCallbackProc)XAnim_Looped, + (XtPointer)(XA_SHOW_NORM)); +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) + } +#endif } else xa_anim_holdoff = xaFALSE; xa_old_status = xa_anim_status; + /* NOTE: Remove this if you dont want to know time taken for each + * iteration + */ + gettimeofday(&end_time, NULL); + delta = (end_time.tv_sec- start_time.tv_sec) * 1000000 + end_time.tv_usec - + start_time.tv_usec; + printf("End Delta = %lu usec\n", delta); +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) + if (real_time_mode) + goto XAnim_Looped_Sneak_Entry; +#endif } /* @@ -3116,6 +3303,11 @@ ***************/ void Hard_Death() { +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) + if (real_time_mode) { + exit_rt(); + } +#endif if (xa_vaudio_present==XA_AUDIO_OK) XA_AUDIO_KILL(); if (xa_vid_fd >= 0) { close(xa_vid_fd); xa_vid_fd = -1; } if (xa_aud_fd >= 0) { close(xa_aud_fd); xa_aud_fd = -1; } @@ -3199,7 +3391,11 @@ void TheEnd() { - +#if defined(CONFIG_RT) || defined(CONFIG_RT_MODULE) + if (real_time_mode) { + exit_rt(); + } +#endif /*POD TEMP eventually move into free chain*/ jpg_free_stuff();