Except for the fact that if the work thread runs in the same CPU as the thread queuing the work, it’s likely to preempt the queuing thread.
After considering that for awhile, if you’re good with that, party on!
The point that is, IMHO, worth considering here is that the OP speaks about the ingress network packets that are getting processed by a NDIS miniport driver. These packets are more than likely to get enqueued in context of a DPC, rather than the one of a thread,right. Therefore, the scenario that you have described above simply never occurs under these circumstances, so that it is simply a non-issue. This is the only reason why the OP seems to be so happy about the performance - he just has not yet encountered the potential drawbacks of this approach in so far.
However, if he tries the same approach with the egress ones, the things are not necessarily going to work THAT well, because these packets may get enqueued not only in context of a DPC but in the one of a thread as well. Once we are speaking about the thread priority that falls into the realtime range, the scenario that you have described may, indeed, arise just naturally, and I am not sure the OP will be too happy about the performance.
Therefore, some extra considerations may be needed indeed. The very first thing that gets into my head is simply making the worker thread wait (probably,with a timeout) on some event that gets signaled (which may be done in context of either a thread or a DPC) only if the number of packets in the queue exceeds some minimal threshold, which will solve the issue of the superfluous context switches.
This is , apparently, the most simplistic (and,probably reasonable) approach that can be taken. If you want something more complex, you may, probably, want to experiment with playing around with the thread priorities, i.e. to take the approach that has been mentioned by Mr.Howard. However, it seems (at least to me) to be simply an overkill here…
Anton Bassov