kingsh
驱动牛犊
驱动牛犊
  • 注册日期2001-11-21
  • 最后登录2001-12-15
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1135回复:4

Set_VM_Time_Out()怎么用?帮帮我呀!

楼主#
更多 发布于:2002-01-09 09:36
这是VToolsD关于Set_VM_Time_Out函数的介绍
Set_VM_Time_Out
TIMEOUTHANDLE Set_VM_Time_Out(DWORD Time, VMHANDLE hVM, CONST VOID * Refdata, PTIMEOUT_HANDLER TimeoutCallback, PTIMEOUT_THUNK pThunk) ;
The Set_VM_Time_Out service schedules a time out that occurs after the specified virtual machine has run for the specified length of time. The system calls the time-out callback procedure only after the virtual machine has run for Time milliseconds. Time that elapses while other virtual machines run is not counted.
This is an asynchronous service.
Parameter Description
Time Number of milliseconds to wait until calling the time-out callback procedure.
hVM Handle identifying the virtual machine.
Refdata Points to reference data to be passed to the callback procedure.
TimeoutCallback Points to the callback procedure. For more information about the callback procedure, see the following \"Comments\" section.
pThunk Points to the locked memory block to be used for the thunk. See Thunks for more information.
Returns
The return value is the handle of the time out if the service is successful. Otherwise, the service returns NULL indicating that the time out is not scheduled.
Comments
The system calls the time-out callback procedure when the virtual machine runs for the specified number of milliseconds. The system calls the procedure as follows:

TimeOutCallback(VMHANDLE hVM, PCLIENT_STRUCT pcrs, PVOID RefData, DWORD Extra);
The VM parameter is a handle specifying the virtual machine for which the time out was scheduled. The RefData parameter points to the reference data for the callback procedure, and the crs parameter points to a Client_Reg_Struc structure that contains the register values for the virtual machine.
The Extra parameter specifies the number of milliseconds that have elapsed since the actual time out occurred. Time outs are often delayed by 10 milliseconds or more, because the normal system timer runs at 20 milliseconds or slower.
If a virtual device needs more accurate time outs, it must increase the timer interrupt frequency using virtual timer device (VTD) services.
See Also
Set_Global_Time_Out
但是我编的代码
PTIMEOUT_THUNK pThunk;
TIMEOUTHANDLE myHandle;
VMHANDLE currentVM;
static DWORD count;

VOID _stdcall TimeOutCallBack(VMHANDLE hVM, PCLIENT_STRUCT pcrs, PVOID RefData, DWORD Extra)
{
count++;
VTD_Disable_Trapping(hVM);
currentVM=Get_Cur_VM_Handle();
VTD_Enable_Trapping(currentVM);
myHandle=Set_VM_Time_Out(1, currentVM, NULL, TimeOutCallBack,pThunk);
}

BOOL VmtmoutDevice::OnSysDynamicDeviceInit()
{
count=0;
VTD_Begin_Min_Int_Period(1);
currentVM=Get_Cur_VM_Handle();
VTD_Enable_Trapping(currentVM);
myHandle=Set_VM_Time_Out(2, currentVM, NULL,
TimeOutCallBack,pThunk);
if (!myHandle){
return FALSE;}
return TRUE;
}

BOOL VmtmoutDevice::OnSysDynamicDeviceExit()
{
Cancel_Time_Out(myHandle);
VTD_Disable_Trapping(currentVM);
VTD_End_Min_Int_Period(1);

return TRUE;
}

编译成功后,运行时可以执行TimeOutCallBack,但返回时总是立刻出现SOFTICE,即回调完成时系统出错,softice显示break due to page fault(0Eh), fault=0002,MSR LastExceptionFromIp=c00040bb MSR LastExceptionToIp=00000000,然后就怎么也回不到WINDOWS系统了,只能重启机,这个问题困扰我多时了,弄得我头也大了,那位高手能不吝赐教,帮小弟一把.
志勇
zdhe
驱动太牛
驱动太牛
  • 注册日期2001-12-26
  • 最后登录2018-06-02
  • 粉丝0
  • 关注0
  • 积分72362分
  • 威望362260点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
  • 社区居民
沙发#
发布于:2002-01-09 23:12
why you has not allocate memory for you pchunk. if you use

TIMEOUT_THUNK Thunk;
and change all pThunk to &Thunk, the program runs well.

although there is no meaning of this program.
kingsh
驱动牛犊
驱动牛犊
  • 注册日期2001-11-21
  • 最后登录2001-12-15
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2002-01-10 09:32
首先万分感谢zdhe的拨刀相助,我的程序现在运转良好。
如果不算麻烦的话,我想请zdhe在回答一个问题:我的这段程序目的是实现毫秒级精度的定时,按照这个方法我试了一下,用VToolsD3.0带的debug monitor测试,定时精度为0.5毫秒左右,请问用这种办法是否能实现毫秒级的定时,我的程序精度不高的症结在那?
打扰了!
志勇
zdhe
驱动太牛
驱动太牛
  • 注册日期2001-12-26
  • 最后登录2018-06-02
  • 粉丝0
  • 关注0
  • 积分72362分
  • 威望362260点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
  • 社区居民
地板#
发布于:2002-01-11 01:20
使用的服务是异步服务.

如果你要精确应该去写中断服务.

如果你的要求可以低些可以在TimeoutCallback 里调一下VTD_Get_Date_And_Time,以取得实效时间.

不太建议debug monitor来监视这类实时服务,因为这个工具无非是定时从的设备里取一下dprint,DebugPrint,DbgPrint的结果,这个处理排它,当debugoutput的结果很多的时候, 它直接影响你的程序的运行.

kingsh
驱动牛犊
驱动牛犊
  • 注册日期2001-11-21
  • 最后登录2001-12-15
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2002-01-11 09:33
zdhe先生,我听说异步延时的定时精度是不准的,但是华中理工和南航的几位硕士生在文章中都推崇利用Set_VM_Time_Out来达到毫秒级精度的延时,我按此一试但确实如你所说不是很准确,我也用系统板上的CMOS实时钟做定时器中断源用,并写其中断服务程序,定时还是很精确的,但是我使用Debug Monitor测试时,按照每次中断计数一次的方法,结果Debug Monitor总是隔一段时间给我计丢一些数,我担心是CMOS实时中断被其他中断级高的中断所中断造成的,使用CMOS实时钟做中断源实现定时是否可行呢?另外如果写中断服务还有那些方法可以实现高精度的定时呢?
非常高兴能够认识zdhe先生,我的eMail是kingsh@0451.com,QQ是40817544,向zdhe先生诚表谢意!
志勇
游客

返回顶部