📄 real-time experiment #1 timing.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0065)http://www.rt.db.erau.edu/experiments/vx/timing/Experiment-1.html -->
<HTML><HEAD><TITLE>Real-Time Experiment #1: Timing</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.2873" name=GENERATOR></HEAD>
<BODY>
<CENTER>
<H1>Embry-Riddle Real-Time Laboratory Experiment<BR>Experiment #1<BR>Timing
</H1></CENTER>
<HR SIZE=3>
<H2>Introduction</H2>To understand and optimize the performance of a real-time
system, it can be useful to time some of the VxWorks and application functions.
VxWorks provides a number of timing facilities to help with this task.
<P></P>The VxWorks execution timer can time any subroutine or group of
subroutines. To time very fast subroutines, the timer can also repeatedly
execute a group of functions until the time of a single iteration is known with
reasonable certainty.
<P></P>
<HR SIZE=3>
<H2>Objectives</H2>The following are the primary objectives of this experiment:
<UL>
<LI>To demonstrate how to time a single subroutine using the VxWorks
<EM>timex()</EM> routine. </LI></UL>
<P></P>
<HR SIZE=3>
<H2>Description</H2>The <EM>timex()</EM> routine times a single execution of a
specified function with up to eight integer arguments to be passed to the
function. When execution us complete, <EM>timex()</EM> routine displays the
execution time and a margin of error in miliseconds. If the execution was so
fast relative to the clock rate that the time is meaningless(error > 50%), a
warning message will appear. In such cases, use <EM>timexN()</EM> which will
repeatedly execute the function until the time of a single iteration is known
with reasonable certainty.
<P></P>1. Syntax
<P></P>void <EM>timex(FUNCPTR function_name, int arg1, .., int arg8)</EM>
<P></P>Note: the first argument in <EM>timex()</EM> routine is a pointer to the
function to be timed.
<P></P>2. Example This small example has two subroutines. The first subroutine
"timing" makes a call to <EM>timex()</EM> with the function name "printit" which
is the subroutine to be timed. The arguments are all NULL, so no parameters are
being passed to "printit".
<P></P>The second subroutine, "printit", which is being timed iterates 200 times
while printing its task id(using <EM>taskIdSelf()</EM>) and the increment
variable "i". <PRE>-------------------------------------------------------------------------------------
#include "vxWorks.h" /* Always include this as the first thing in every program */
#include "timexLib.h"
#include "stdio.h"
#define ITERATIONS 200
int printit(void);
void timing() /* Function to perform the timing */
{
FUNCPTR function_ptr = printit; /* a pointer to the function "printit" */
timex(function_ptr,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); /* Timing the "print" function */
}
int printit(void) /* Function being timed */
{
int i;
for(i=0; i < ITERATIONS; i++) /* Printing the task id number and the increment variable "i" */
printf("Hello, I am task %d and is i = %d\n",taskIdSelf(),i);
return 0;
}
-------------------------------------------------------------------------------------
</PRE>
<P></P>
<HR SIZE=3>
<H2>Procedures</H2>1. Copy the source code in the example and compile it.
<P></P>2. Load the object file onto the target machine.
<P></P>3. Run the example by executing "timing" on the WindSh.
<P></P>Note: Make sure you have redirected I/O, otherwise you won't see the
results of the printf commands.
<HR SIZE=3>
<H2>Follow On Experiment</H2>Experiment 1. Vary the number of ITERATIONS in the
loop(300,400,500,600,700) and note the changes in execution speed.
<P></P>Experiment 2. Decrease the number of the iteration to 5, note what
happens(you should get a warning message). Write a program to get the timing in
this case.
<P></P>
<HR SIZE=3>
<H2>Additional Information</H2>The timings measure the execution time of the
routine body, without the usual subroutine entry and exit code. Also, the time
required to set up the arguments and call the routines is not included in the
reported times. This is because the timing routines automatically calibrate
themselves by timing the invocation of a null routine, and thereafter
subtracting that constant overhead.
<P></P>Refer to the VxWorks Programmer's Manual and Reference Manual(timexLib).
<HR SIZE=3>
<CENTER>
<H4><A
href="http://www.rt.db.erau.edu/experiments/vx/toc/TableOfContents.html">Return
to Primary Table of Contents </A></H4></CENTER>
<HR SIZE=3>
<CENTER>Last Updated: 17 March 1997<BR><EM>Created by: Dan Eyassu</EM><BR><A
href="mailto:eyassud@db.erau.edu">eyassud@db.erau.edu</A><BR></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -