Re: [PATCH v3] dell-rbtn: Ignore ACPI notifications if device is suspended

From: Darren Hart
Date: Tue Mar 29 2016 - 01:24:53 EST


On Mon, Mar 28, 2016 at 09:41:09PM +0200, Gabriele Mazzotta wrote:
> 2016-03-28 20:56 GMT+02:00 Darren Hart <dvhart@xxxxxxxxxxxxx>:
> > On Mon, Mar 28, 2016 at 07:58:09PM +0200, Gabriele Mazzotta wrote:
> >> 2016-03-28 19:33 GMT+02:00 Darren Hart <dvhart@xxxxxxxxxxxxx>:
> >> > On Thu, Mar 24, 2016 at 12:24:56PM +0100, Gabriele Mazzotta wrote:
> >> >> 2016-03-24 10:39 GMT+01:00 Pali Rohár <pali.rohar@xxxxxxxxx>:
> >> >> > On Monday 21 March 2016 16:13:34 Gabriele Mazzotta wrote:
> >> >> >> 2016-03-21 13:17 GMT+01:00 Pali Rohár <pali.rohar@xxxxxxxxx>:
> >> >> >> > On Friday 18 March 2016 23:44:23 Gabriele Mazzotta wrote:
> >> >> >> >> +#ifdef CONFIG_PM_SLEEP
> >> >> >> >> +static void ACPI_SYSTEM_XFACE rbtn_acpi_clear_flag(void *context)
> >> >> >> >> +{
> >> >> >> >> + struct rbtn_data *rbtn_data = context;
> >> >> >> >> +
> >> >> >> >> + rbtn_data->suspended = false;
> >> >> >> >> +}
> >> >> >> >> +
> >> >> >> >> +static int rbtn_suspend(struct device *dev)
> >> >> >> >> +{
> >> >> >> >> + struct acpi_device *device = to_acpi_device(dev);
> >> >> >> >> + struct rbtn_data *rbtn_data = acpi_driver_data(device);
> >> >> >> >> +
> >> >> >> >> + rbtn_data->suspended = true;
> >> >> >> >> +
> >> >> >> >> + return 0;
> >> >> >> >> +}
> >> >> >> >> +
> >> >> >> >> +static int rbtn_resume(struct device *dev)
> >> >> >> >> +{
> >> >> >> >> + struct acpi_device *device = to_acpi_device(dev);
> >> >> >> >> + struct rbtn_data *rbtn_data = acpi_driver_data(device);
> >> >> >> >> + acpi_status status;
> >> >> >> >> +
> >> >> >> >> + /*
> >> >> >> >> + * Clear the flag only after we received the extra
> >> >> >> >> + * ACPI notification.
> >> >> >> >> + */
> >> >> >> >> + status = acpi_os_execute(OSL_NOTIFY_HANDLER,
> >> >> >> >> + rbtn_acpi_clear_flag, rbtn_data);
> >> >> >> >> + if (ACPI_FAILURE(status))
> >> >> >> >> + rbtn_data->suspended = false;
> >> >> >> >
> >> >> >> > I case when acpi_os_execute success it calls rbtn_acpi_clear_flag,
> >> >> >> > right? And that will set suspended to false. When acpi_os_execute fails,
> >> >> >> > then it set suspended too to false... Then whole acpi_os_execute doing
> >> >> >> > just "barrier" after which suspended flag can be set to false. So I
> >> >> >> > think rbtn_acpi_clear_flag function is not needed here.
> >> >> >> >
> >> >> >> > Cannot you pass NULL or empty function pointer as callback? Or what was
> >> >> >> > reason to do that flag clearing at "two places"?
> >> >> >>
> >> >> >> acpi_os_execute doesn't wait for the callback to be executed, so
> >> >> >> I can't clear the flag from rbtn_resume.
> >> >> >
> >> >> > acpi_os_execute calls callback asynchronously later? Or what exactly do it?
> >> >>
> >> >> In this case, it adds the callback to the kacpi_notify_wq workqueue
> >> >> for deferred execution.
> >> >
> >> > +Rafael for context/advice on the use of acpi_os_execute here.
> >> >
> >> > This is true, but a quick scan through that call path doesn't tell me why we
> >> > would need to call it here instead of just setting rbtn_data->suspended = false.
> >> > The comment suggests waiting for the event, but is that what this is doing? It
> >> > appears to me to be immediately scheduling the function to a work queue, not
> >> > waiting for the event notifier.
> >> >
> >> > Also, since there is no indication to the user that a failure occurs, this
> >> > function is basically equivalent in the success and failure case (the success
> >> > case is just slower).
> >> >
> >> > Am I missing something critical here?
> >>
> >> Maybe saying that we are waiting for the extra event is not really
> >> correct. Since the extra ACPI notification is processed by means
> >> of kacpi_notify_wq, or at least that's my understanding, our callback
> >> is likely going to be executed after we received the extra ACPI
> >> notification. This was suggested by Rafael [2].
> >
> > I see, the workqueue is run after the event is issued. If that's the case, how
> > are we ensured that it will get cleared? Isn't it only some systems that have
> > this problem?
> >
> > What happens to the systems that do not send this event at resume? Does the
> > suspended flag remain set?
>
> The callback should be executed as long as acpi_os_execute doesn't
> return an error. If the BIOS doesn't send the extra notification,
> we uselessly wait for whatever was queued before our callback.
>
> On my laptop, the interval between the call to acpi_os_execute and
> the callback execution is ~200ms (rough existimation using a couple
> of printks), so not really noticeable. It might be more on some other
> systems, but I doubt anyone would notice.

And what triggers the callback then? Some unrelated event triggering the
workqueue I presume? I don't care to tie the masking of these events to
unrelated ones. What guarantee do we have that they will fire? Is it possible
for that workqueue to be otherwise empty and not get triggered, effectively
disabling our events?

>
> >>
> >> The problem with setting the flag directly from the resume callback
> >> is that the extra notification might arrive after we cleared the
> >> flag, causing spurious input events [1].
> >>
> >> [1] http://article.gmane.org/gmane.linux.drivers.platform.x86.devel/8001
> >> [2] http://article.gmane.org/gmane.linux.drivers.platform.x86.devel/8201
> >>

--
Darren Hart
Intel Open Source Technology Center