op_ici_install()
摘要
将指定 ICI 设置为已安装的 ICI,它会自动与调用进程调度的传出中断相关联。
语法
op_ici_install (iciptr)
| 参数 | 类型 | 说明 |
|---|---|---|
iciptr |
Ici * |
指向目标 ICI 的指针 [指向 ICI 的指针可以从两个内核过程获得: op_ici_create() 返回指向新分配 ICI 的指针(在 ICI 发送进程中),以及 op_intrpt_ici() 返回与传入中断关联的 ICI 的指针(在 ICI 接收进程中)。] |
返回类型
Ici *
先前已安装的 ICI;若没有则返回 OPC_NIL。
示例
节选自:示例模型(models\std\eth_net);进程模型(eth_gen);状态(ARRIVAL);进入执行(enter execs)。
/* determine the length of the packet to be generated */
pklen = op_dist_outcome (len_dist_ptr);
/* determine the destination of the packet... */
gen_packet: dest_addr = op_dist_outcome (dest_dist_ptr);
if (dest_addr != -1 && dest_addr == station_addr)
goto gen_packet;
/* create an unformatted packet to send to mac */
pkptr = op_pk_create (pklen);
/* place the destination address into the ICI... */
op_ici_attr_set (mac_iciptr, "dst_addr", dest_addr);
/* send the packet coupled with the ICI. Then deinstall the ICI to prevent */
/* it from being associated with other interrupts scheduled by this process.*/
op_ici_install (mac_iciptr);
op_pk_send (pkptr, MAC_LAYER_OUT_STREAM);
op_ici_install (OPC_NIL);
详情
对于任一进程,任何时刻最多只有一个 ICI 处于安装状态。安装在队列/处理器模块中各进程里的 ICI 分别独立维护。安装操作会通知仿真内核:调用进程调度的所有中断都应打上指定 ICI 指针的标记。这样,许多被调度的中断可以自动带有相关联的 ICI,而不必为每个中断单独创建 ICI 并打标记。
带有相关联 ICI 的被调度中断会始终保持这种关联,无论该 ICI 在调度与投递之间经历了何种变化,包括 ICI 内容的修改甚至 ICI 的销毁。在这种情况下,接收中断的进程可能收到并非预期的信息。为避免此类情况,建议始终由中断接收方负责销毁 ICI,并且一般由发起进程为每个单独的中断创建并安装新的 ICI。
文档没有显式提供卸载操作,因为如果中断的处理并不使用相关联的 ICI,让 ICI 与中断保持关联通常并不“有害”。因此常见做法是让 ICI 一直处于安装状态,直到需要为某个传出中断关联另一个 ICI 为止。不过该内核过程确实提供了卸载 ICI 的能力:将常量 OPC_NIL 作为参数 iciptr 传入,即可阻止该 ICI 继续与传出中断关联。
用途
提供了一种将已准备好的 ICI 与传出中断关联起来的机制。每个进程维护一个内部指针,指向已安装的 ICI。因此,当前安装的 ICI 在非强制状态和多次进程调用之间持续存在。
错误
- 程序中止:Segmentation violation。(由于无效的 ICI 指针或格式错误的 ICI 数据结构)
- 程序中止:内核过程需要进程上下文。
参考
- 使用内核过程 op_ici_create() 创建 ICI
- 使用内核过程 op_ici_attr_get_dbl()、op_ici_attr_get_int32()、op_ici_attr_get_int64() 和 op_ici_attr_get_ptr() 获取 ICI 属性的值
- 使用内核过程 op_ici_attr_set_dbl()、op_ici_attr_set_int32()、op_ici_attr_set_int64() 和 op_ici_attr_set_ptr() 设置 ICI 属性的值