📄 c-iosys6.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title> I/O System </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-iosys.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-iosys5.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-iosys7.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="84052">3.6 Asynchronous Input/Output</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84054"> </a>Asynchronous Input/Output (AIO) is the ability to perform input and output operations concurrently with ordinary internal processing. AIO enables you to decouple I/O operations from the activities of a particular task when these are logically independent. </p><dd><p class="Body"><a name="84055"> </a>The benefit of AIO is greater processing efficiency: it permits I/O operations to take place whenever resources are available, rather than making them await arbitrary events such as the completion of independent operations. AIO eliminates some of the unnecessary blocking of tasks that is caused by ordinary synchronous I/O; this decreases contention for resources between input/output and internal processing, and expedites throughput. </p><dd><p class="Body"><a name="84057"> </a>The VxWorks AIO implementation meets the specification in the POSIX 1003.1b standard. To include AIO in your VxWorks configuration, select <b class="symbol_UC">INCLUDE_POSIX_AIO</b> and <b class="symbol_UC">INCLUDE_POSIX_AIO_SYSDRV</b> in the project facility VxWorks view; see <i class="title">Tornado User's Guide: Projects</i> for information on configuring VxWorks. The second configuration constant enables the auxiliary AIO system driver, required for asynchronous I/O on all current VxWorks devices.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84061">3.6.1 The POSIX AIO Routines</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84063"> </a>The VxWorks library <b class="library">aioPxLib</b> provides the POSIX AIO routines. To access a file asynchronously, open it with the <b class="routine"><i class="routine">open</i></b><b>( )</b> routine, like any other file. Thereafter, use the file descriptor returned by <b class="routine"><i class="routine">open</i></b><b>( )</b> in calls to the AIO routines. The POSIX AIO routines (and two associated non-POSIX routines) are listed in <a href="c-iosys6.html#87680">Table 3-4</a>.<p class="table"><h4 class="EntityTitle"><a name="87680"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 3-4: Asynchronous Input/Output Routines</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="87684"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Function</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="87686"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Description</font></b></div></th></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="87689"> </a><b class="routine"><i class="routine">aioPxLibInit</i></b><b>( )</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="87691"> </a>Initialize the AIO library (non-POSIX). </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="87694"> </a><b class="routine"><i class="routine">aioShow</i></b><b>( )</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="87702"> </a>Display the outstanding AIO requests (non-POSIX).<sup><b class="FootnoteMarker">1</b></sup> </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="87705"> </a><b class="routine"><i class="routine">aio_read</i></b><b>( )</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="87707"> </a>Initiate an asynchronous read operation. </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="87710"> </a><b class="routine"><i class="routine">aio_write</i></b><b>( )</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="87712"> </a>Initiate an asynchronous write operation. </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="87715"> </a><b class="routine"><i class="routine">aio_listio</i></b><b>( )</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="87717"> </a>Initiate a list of up to <b class="symbol_UC">LIO_MAX</b> asynchronous I/O requests. </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="87720"> </a><b class="routine"><i class="routine">aio_error</i></b><b>( )</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="87722"> </a>Retrieve the error status of an AIO operation. </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="87725"> </a><b class="routine"><i class="routine">aio_return</i></b><b>( )</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="87727"> </a>Retrieve the return status of a completed AIO operation. </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="87730"> </a><b class="routine"><i class="routine">aio_cancel</i></b><b>( )</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="87732"> </a>Cancel a previously submitted AIO operation. </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="87735"> </a><b class="routine"><i class="routine">aio_suspend</i></b><b>( )</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="87737"> </a>Wait until an AIO operation is done, interrupted, or timed out. </div></td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"><p class="FootnoteNumberMarker">1: <span class="TableFootnote"><a name="87698"> </a>This function is not built into the Tornado shell. To use it from the Tornado shell, you must select <b class="symbol_UC">INCLUDE_POSIX_AIO_SHOW</b> for inclusion in the project facility VxWorks view. When you invoke the function, its output is sent to the standard output device.</span></p></td></tr></table></p> </p><dd><p class="Body"><a name="84138"> </a>The default VxWorks initialization code calls <b class="routine"><i class="routine">aioPxLibInit</i></b><b>( )</b> automatically when <b class="symbol_UC">INCLUDE_POSIX_AIO </b>is selected for inclusion in the project facility VxWorks view. This routine takes one parameter, the maximum number of <b class="routine"><i class="routine">lio_listio</i></b><b>( )</b>calls that can be outstanding at one time. By default this parameter is <b class="symbol_UC">MAX_LIO_CALLS</b> (which can be seen on the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Params</font></b> tab of the properties window to be 0 by default). When the parameter is 0, the value is taken from <b class="symbol_UC">AIO_CLUST_MAX</b> (defined in <i class="textVariable">installDir</i><b class="file">/target/h/private/aioPxLibP.h</b>). </p><dd><p class="Body"><a name="84143"> </a>The AIO system driver, <b class="library">aioSysDrv</b>, is initialized by default with the routine <b class="routine"><i class="routine">aioSysInit</i></b><b>( )</b> when both <b class="symbol_UC">INCLUDE_POSIX_AIO</b> and <b class="symbol_UC">INCLUDE_POSIX_AIO_SYSDRV</b> are included. The purpose of <b class="library">aioSysDrv</b> is to provide request queues independent of any particular device driver, so that you can use any VxWorks device driver with AIO. </p><dd><p class="Body"><a name="93598"> </a>The routine <b class="routine"><i class="routine">aioSysInit</i></b><b>( )</b> takes three parameters: the number of AIO system tasks to spawn, and the priority and stack size for these system tasks. The number of AIO system tasks spawned equals the number of AIO requests that can be handled in parallel. The default initialization call<b>( )</b>uses three constants, all defined in <b class="file">configAll.h</b>:</p><dl class="margin"><dd><pre class="Code2"><b><a name="93599">aioSysInit( MAX_AIO_SYS_TASKS, AIO_TASK_PRIORITY, AIO_TASK_STACK_SIZE )</a></b></pre></dl><dd><p class="Body"><a name="93600"> </a>When any of the parameters passed to <b class="routine"><i class="routine">aioSysInit</i></b><b>( )</b>is 0, the corresponding value is taken from <b class="symbol_UC">AIO_IO_TASKS_DFLT</b>, <b class="symbol_UC">AIO_IO_PRIO_DFLT</b>, and <b class="symbol_UC">AIO_IO_STACK_DFLT</b> (all defined in <i class="textVariable">installDir</i><b class="file">/target/h/aioSysDrv.h</b>).</p><dd><p class="Body"><a name="84152"> </a><a href="c-iosys6.html#91386">Table 3-5</a> lists the names of the constants called from <b class="file">usrConfig.c</b> and their default values (which can be seen on the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Params</font></b> tab of the properties window). It also shows the constants used within initialization routines when the parameters are left at their default values of 0, and where these constants are defined.<p class="table"><h4 class="EntityTitle"><a name="91386"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 3-5: AIO Initialization Functions and Related Constants</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="91398"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Initialization <br>Function</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="91400"> </a><font face="Helvetica, sans-serif" size="-1" class="sans"><b class="file">configAll.h </b>Constant</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeadingC" align="center"><a name="91402"> </a><b><font face="Helvetica, sans-serif" size="-1" class="sans">Def. <br>Value</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="91404"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Header File Constant used when arg = 0</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeadingC" align="center"><a name="91406"> </a><b><font face="Helvetica, sans-serif" size="-1" class="sans">Def. <br>Value</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="91408"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Header File <br>(all in <i class="textVariable">installDir</i><b class="file">/target</b> </font></b></div></th></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="91411"> </a><b class="routine"><i class="routine">aioPxLibInit</i></b><b>( )</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="91414"> </a><b class="symbol_UC">MAX_LIO_CALLS</b> </div></td><td colspan=1 rowspan=1><div class="CellBodyC" align="center"><a name="91416"> </a>0</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="91419"> </a><b class="symbol_UC">AIO_CLUST_MAX</b> </div></td><td colspan=1 rowspan=1><div class="CellBodyC" align="center"><a name="91421"> </a>100</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="91423"> </a><b class="file">h/private/aioPxLibP.h</b> </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="91426"> </a><b class="routine"><i class="routine">aioSysInit</i></b><b>( )</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="91429"> </a><b class="symbol_UC">MAX_AIO_SYS_TASKS</b> </div></td><td colspan=1 rowspan=1><div class="CellBodyC" align="center"><a name="91431"> </a>0</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="91434"> </a><b class="symbol_UC">AIO_IO_TASKS_DFLT</b> </div></td><td colspan=1 rowspan=1><div class="CellBodyC" align="center"><a name="91436"> </a>2</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="91439"> </a><b class="file">h/aioSysDrv.h</b> </div></td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -