On 2019-08-12 10:31 a.m., Christoph Hellwig wrote:
On Wed, Aug 07, 2019 at 01:42:40PM +0200, Douglas Gilbert wrote:
Track the number of submitted and waiting (for read/receive)
requests on each file descriptor with two atomic integers.
This speeds sg_poll() and ioctl(SG_GET_NUM_WAITING) which
are oft used with the asynchronous (non-blocking) interfaces.
The idea of just tracking a count here seems sensible.
With the added benefit of ioctl(SG_GET_NUM_WAITING) becoming O(1).
I clocked it an 500 nanoseconds per invocation on my laptop.
Tiny nitpick below:
+ else if (likely(sfp->cmd_q))
+ p_res |= EPOLLOUT | EPOLLWRNORM;
+ else if (atomic_read(&sfp->submitted) == 0)
p_res |= EPOLLOUT | EPOLLWRNORM;
Why not simply:
else if (sfp->cmd_q || atomic_read(&sfp->submitted)
p_res |= EPOLLOUT | EPOLLWRNORM;
Loses the "likely", doesn't compile, and is logically wrong.
Brown paper bag :-)
And this is getting beyond a joke. I have had to repeatedly rebuild
dev kernels because:
1) Torvalds forces Martin to use buggy "rc1" kernels in his
scsi-queue branches, and
2) in lk 5.3-rc1 there is your snafu in scsi_lib.c
Please go light on such "optimizations".
Doug Gilbert