gpt4 book ai didi

c++ - io_getevents 在短于超时的时间内返回的作业数量少于请求的数量

转载 作者:太空宇宙 更新时间:2023-11-04 11:23:57 25 4
gpt4 key购买 nike

我正在读取 SSD,请求 20 个异步作业。 io_getevents 返回值 7 表示超时。超时设置为 10 秒,如下所示。调用的耗时实际上是 4.89e-05 秒,例如,几乎还剩下 10 秒。问题:有人遇到过这样的事件吗?如果找到了,那么您找到解决方案了吗?

部分代码如下:

struct timespec ts = { 10, 0 } ; /* ten seconds delay */
const long ec = io_getevents( ctx, num_jobs, num_jobs, &events[ 0 ], &ts ) ;

当ec返回7时,ts.tv_sec = 10, ts.tv_nsec = 0

Linux 内核:

Linux VTL80-G-1J4-823-21 2.6.18-274.18.1.el5 #1 SMP Thu Feb 9 12:20:03 EST 2012 x86_64 x86_64 x86_64 GNU/Linux

非常感谢您的帮助!顺便提一句。几个小时后我将无法查看帖子。

最佳答案

通过额外的步骤和调试输出,我们发现我们的 linux 上的 aio 驱动程序存在问题(5.3 Carthage,2.6.18-128.el5)

我们应用的解决方案(我把它放在以防万一有人遇到同样的问题)是这样的:
(我们自己计算调用经过的秒数。)

1) 如果我们看到从 io_getevents() 返回的错误,我们会报告它。完成。

2) 如果我们看到 0 个作业完成并且经过的秒数我们自己计算超过预期的秒数,我们报告错误。完毕。否则我们继续(我们不更改 io_getevents() 的超时)

3) 如果某些作业已完成,我们会分析它们的 res 是否有错误(负值),如果有任何失败的作业,我们会报告它。完成。

4) 如果还有一些剩余的工作,我们重置计时器(是的,我们将再次等待“预期”时间)并继续。

使用此方法,如果 io_getevents() 报告错误或任何作业报告错误,我们将报告错误。在最坏的情况下,当每个作业在整个 T-epsilon 等待时间后返回 ok 时,整个过程将花费 N * T 时间完成。

我希望有人会发现它有用。
祝福,
格雷格。

例子:

struct timespec       tmCountStart ;
unsigned seconds_delay = SECONDS_DELAY ;

clock_gettime( CLOCK_REALTIME, &tmCountStart ) ;
while ( num_remaining_jobs > 0 )
{
struct timespec ts = { seconds_delay, 0 } ;
struct io_event events[ num_remaining_jobs ] ;
long ec ;

do
{
ec = io_getevents( ctx, num_remaining_jobs, num_remaining_jobs, &events[ 0 ], &ts ) ;
}
while( ec == -EINTR ) ;

if ( ec < 0 )
throw exception reporting error ec. cancel all remaining jobs
else if ( ec == 0 )
{
const double elapsed = count elapsed seconds from tmCountStart
seconds_delay = SECONDS_DELAY - static_cast< unsigned >( elapsed ) ;
if ( seconds_delay > SECONDS_DELAY )
throw exception reporting timeout. cancel all remaining jobs
}
else // we got some jobs back. may not all of them
{
for ( int i = 0 ; i < ec ; i++ )
if (( int64_t )events[ i ].res < 0 )
throw exception reporting failing job. cancel all remaining jobs.

num_remaining_jobs -= ec ;
if ( num_remaining_jobs > 0 )
{
clock_gettime( CLOCK_REALTIME, &tmCountStart ) ; // reset timer.
seconds_delay = SECONDS_DELAY ;
}
}
}

关于c++ - io_getevents 在短于超时的时间内返回的作业数量少于请求的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16114435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com