0

This question is a continuation of a previously asked question:

Slow communication using shared memory between user mode and kernel

I am running a thread in the Windows kernel communicating with an application over shared memory. I am wondering if the current way to loop and wait for a change in the BOOLEAN variable is the most efficient? Requirement is to get it down to 50-100 microseconds or lower if possible.

KERNEL CODE

typedef struct _SHARED_MEMORY
{
    BOOLEAN mutex;
    CHAR data[BUFFER_SIZE];
} SHARED_MEMORY, *PSHARED_MEMORY;

ZwCreateSection(...)
ZwMapViewOfSection(...)

while (TRUE) {
    if (((PSHARED_MEMORY)SharedSection)->mutex == TRUE) {
      //... do work...
      ((PSHARED_MEMORY)SharedSection)->mutex = FALSE;
    }
    KeDelayExecutionThread(KernelMode, FALSE, &PollingInterval);
}

I have considered KeStallExecutionProcessor since its supposed to be used for less than 50 microseconds loops but in my understanding it still hogs the processor's resources.

Also since the BOOLEAN is used in volatile way do you see any short comings or problems with the current read/write procedure? Perhaps changing the thread priority to low?

illion
  • 31
  • 1
  • 7
  • I'm not a windows kernel expert. Would usage of KeWaitForSingleObject an option? https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-kewaitforsingleobject – user743414 Mar 07 '19 at 14:00
  • Yes if you want to wait for mutex or event, so then you would need to change the datatype to a MUTEX from a BOOLEAN for instance but how do you use the same variable to wait on both sides? Right now FALSE means app is executing and kernel is waiting meanwhile TRUE means kernel is working and app is waiting. – illion Mar 07 '19 at 23:29
  • It's possible to create it on either side and pass it to the other. http://www.osronline.com/article.cfm?id=108 https://sureshkumarct.wordpress.com/2016/09/05/sharing-events-between-kernel-mode-and-user-mode/ – user743414 Mar 08 '19 at 14:56

0 Answers0