Re: [PATCH RESEND] rtsx_usb_ms: Use msleep_interruptible() in polling loop

From: Andrew Morton
Date: Mon May 02 2016 - 16:56:45 EST


On Mon, 02 May 2016 23:17:41 +0300 Oleksandr Natalenko <oleksandr@xxxxxxxxxxxxxx> wrote:

> This patch has already been posted to LKML by Ben Hutchings ~6 months
> ago, but AFAIK no further action were performed. However, this patch
> really fixes weird loadavg with RTS5129 card reader, so I would wonder
> if this could be merged. AFAIK, it has been applied to some distros'
> kernels, e.g., Ubuntu.
>
> Original Ben's message goes below.
>
> rtsx_usb_ms creates a task that mostly sleeps, but tasks in
> uninterruptible sleep still contribute to the load average (for
> bug-compatibility with Unix). A load average of ~1 on a system that
> should be idle is somewhat alarming.
>
> Change the sleep to be interruptible, but still ignore signals.
>
> A better fix might be to replace this loop with a delayed work item.
>

hm.

> index 1105db2..645dede 100644
> --- a/drivers/memstick/host/rtsx_usb_ms.c
> +++ b/drivers/memstick/host/rtsx_usb_ms.c
> @@ -706,7 +706,8 @@ poll_again:
> if (host->eject)
> break;
>
> - msleep(1000);
> + if (msleep_interruptible(1000))
> + flush_signals(current);
> }
>
> complete(&host->detect_ms_exit);

flush_signals() is a bit scary. If this was a userspace task and it
had (say) SIGINT pending then it would be very rude for a device driver
to rub that out.

But this isn't a userspace task - it's a kthread. So I don't *think*
it can get any signals anyway?

And looking at Oleg's 9e7c8f8c62c1e1cda203b it appears that
flush_signals() is for flushing signals of a userspace task, not a
kthread? Despite the comment "Flush all pending signals for this
kthread".

Confused. It's been a while since I looked at this stuff and people
have mucked with it. Oleg, can you please sort me out?