User space client thread- readfile- CPU usage ~ 30%

Hi,

My driver has to handle 1- 4 connected USB high speed devices and max of 2 clients can access the driver.

I am using overlapped IO with timeout. still CPU utilization is high just for one client thread. How to optimize the read operation from ReadFile API? What has to be tuned ?

while(1)
{

success = ReadFile(hDEV, pdataBuf, ReadLen, (PULONG)&nBytesRead, &ovRead);
if (success == FALSE && GetLastError() != ERROR_IO_PENDING)
{
printf(“\n error …”);
break;
}
if (WaitForSingleObject(ovRead.hEvent, 1000) == WAIT_OBJECT_0)
{
if (GetOverlappedResult(hDEV, &ovRead, (PULONG)&nBytesRead, FALSE))
{
// process the data … callbacks… etc
}
}
}

Have your looked a perf trace to see where you are spending your CPU cycles? Until you have data, you are blindly guessing as what needs fixing/rearchitecting

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of srinivaskumar.r@in.bosch.com
Sent: Monday, August 22, 2016 10:58 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] User space client thread- readfile- CPU usage ~ 30%

Hi,

My driver has to handle 1- 4 connected USB high speed devices and max of 2 clients can access the driver.

I am using overlapped IO with timeout. still CPU utilization is high just for one client thread. How to optimize the read operation from ReadFile API? What has to be tuned ?

while(1)
{

success = ReadFile(hDEV, pdataBuf, ReadLen, (PULONG)&nBytesRead, &ovRead); if (success == FALSE && GetLastError() != ERROR_IO_PENDING) {
printf(“\n error …”);
break;
}
if (WaitForSingleObject(ovRead.hEvent, 1000) == WAIT_OBJECT_0)
{
if (GetOverlappedResult(hDEV, &ovRead, (PULONG)&nBytesRead, FALSE))
{
// process the data … callbacks… etc
}
}
}


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

What do you do if a timeout happens?