Flight Gear Periodic Event Manager and Scheduler
Curtis L. Olson
1 IntroductionMany tasks within the simulator need to only run periodically. These are typically tasks that calculate values that don't change significantly in 1/60th of a second, but instead change noticeably on the order of seconds, minutes, or hours. Running these tasks every iteration would needless degrade performance. Instead, we would like to spread these out over time to minimize the impact they might have on frame rates, and minimize the chance of pauses and hesitations.
2 OverviewThe goal of the event manager is to provide a way for events to be run periodically, and to spread this load out so that the processing time spent at any particular iteration is minimized. The scheduler consists of two parts. The first part is simply a list of registered events along with any management information associated with that event. The second part is a run queue. When events are triggered, they are placed in the run queue. The system executes only one pending event per iteration in order to balance the load.
3 The Events List
3.1 Event List StructureAll registered events are maintained in a list. Currently, this list is simply an array of event structures. Each event structure stores the following information.
3.2 Event List OperationTo use the event list, you must first initialize it by calling fgEventInit(). Once the list has been initialized, you can register events by calling fgEventRegister(). A typical usage might be: fgEventRegister(``fgUpdateWeather()'', fgUpdateWeather, FG_EVENT_READY, 60000). This tells the event manager to schedule and run the event, fgUpdateWeather(), every 60 seconds. The first field is an ASCII description of the function, the second field is a pointer to the function, the third field is the status flag, and the last field is the time interval. Event functions should return void and accept no parameters. The status flag can set to either FG_EVENT_SUSP, FG_EVENT_READY, or FG_EVENT_QUEUED. FG_EVENT_SUSP means register the event, but never schedule it to run. FG_EVENT_READY means register the event and schedule and run it normally. FG_EVENT_QUEUED is mostly used internally so that an event will never have more than one entry in the run queue. Finally, in your main loop, you must add a call to fgEventProcess() to run it every iteration. This routine will schedule all pending events (push them onto the run queue) and then execute the first thing in the run queue.
4 The Run QueueThe run queue is a very simple queue who's elements are just a pointer to an event list element. When an event needs to be scheduled, a pointer to that event is pushed onto the back of the queue. Each time fgEventProcess() is called, the first element on the run queue will be executed.
5 Profiling EventsAs stated before, each event record contains simple event statistics such as the total time spent running this event, the quickest run, the slowest run, and the total number of times run. We can output the list of events along with these statistics in order to determine if any of them are consuming an excessive amount of time, or if there is any chance that a particular event could run slow enough to be responsible for a perceived hesitation or pause in the flow of the simulation.
About this document ...Flight Gear Periodic Event Manager and Scheduler This document was generated using the LaTeX2HTML translator Version 96.1 (Feb 5, 1996) Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds. The command line arguments were: The translation was initiated by Curtis L. Olson on Wed Dec 31 15:09:37 CST 1997 Curtis L. Olson Wed Dec 31 15:09:37 CST 1997 |
|