I have some code that needs to run at PASSIVE_LEVEL (or APC_LEVEL), but it is indirectly delaying a DPC - i.e. while this code runs, a DPC may not be able to finish a task and will reschedule itself later.
This doesn’t seem to be a big deal usually, but sometimes when the CPU load is high, my passive thread gets preempted, and now my DPC is at the mercy of the scheduler. That’s… less than ideal.
In the typical case, I’d use KeSetPriorityThread() on the passive thread to make sure it doesn’t get indefinitely preempted by other passive threads. However, per MSDN:
KPRIORITY KeSetPriorityThread(
Inout PKTHREAD Thread,
In KPRIORITY Priority
);
Thread [in, out] Pointer to the driver-created thread.
“driver-created thread”
Does this mean calling that on a user thread that entered kernelmode through e.g. DeviceIoControl() is not valid? What about system workitem thread pool?
If that’s the case, is there some universal way to prevent passive threads from being scheduled out in favor of other passive threads, except when explicitly making a blocking call, such as accessing paged memory? Raising the IRQL isn’t really an option here.
Thanks!
Milo