linux/drivers/platform/chrome
Douglas Anderson 37a186225a platform/chrome: cros_ec_spi: Transfer messages at high priority
The software running on the Chrome OS Embedded Controller (cros_ec)
handles SPI transfers in a bit of a wonky way.  Specifically if the EC
sees too long of a delay in a SPI transfer it will give up and the
transfer will be counted as failed.  Unfortunately the timeout is
fairly short, though the actual number may be different for different
EC codebases.

We can end up tripping the timeout pretty easily if we happen to
preempt the task running the SPI transfer and don't get back to it for
a little while.

Historically this hasn't been a _huge_ deal because:
1. On old devices Chrome OS used to run PREEMPT_VOLUNTARY.  That meant
   we were pretty unlikely to take a big break from the transfer.
2. On recent devices we had faster / more processors.
3. Recent devices didn't use "cros-ec-spi-pre-delay".  Using that
   delay makes us more likely to trip this use case.
4. For whatever reasons (I didn't dig) old kernels seem to be less
   likely to trip this.
5. For the most part it's kinda OK if a few transfers to the EC fail.
   Mostly we're just polling the battery or doing some other task
   where we'll try again.

Even with the above things, this issue has reared its ugly head
periodically.  We could solve this in a nice way by adding reliable
retries to the EC protocol [1] or by re-designing the code in the EC
codebase to allow it to wait longer, but that code doesn't ever seem
to get changed.  ...and even if it did, it wouldn't help old devices.

It's now time to finally take a crack at making this a little better.
This patch isn't guaranteed to make every cros_ec SPI transfer
perfect, but it should improve things by a few orders of magnitude.
Specifically you can try this on a rk3288-veyron Chromebook (which is
slower and also _does_ need "cros-ec-spi-pre-delay"):
  md5sum /dev/zero &
  md5sum /dev/zero &
  md5sum /dev/zero &
  md5sum /dev/zero &
  while true; do
    cat /sys/class/power_supply/sbs-20-000b/charge_now > /dev/null;
  done
...before this patch you'll see boatloads of errors.  After this patch I
don't see any in the testing I did.

The way this patch works is by effectively boosting the priority of
the cros_ec transfers.  As far as I know there is no simple way to
just boost the priority of the current process temporarily so the way
we accomplish this is by queuing the work on the system_highpri_wq.

NOTE: this patch relies on the fact that the SPI framework attempts to
push the messages out on the calling context (which is the one that is
boosted to high priority).  As I understand from earlier (long ago)
discussions with Mark Brown this should be a fine assumption.  Even if
it isn't true sometimes this patch will still not make things worse.

[1] https://crbug.com/678675

Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2019-04-15 12:13:24 +02:00
..
wilco_ec platform/chrome: Fix locking pattern in wilco_ec_mailbox() 2019-03-18 10:29:40 -07:00
chromeos_laptop.c platform/chrome: chromeos_laptop: fix touchpad button mapping on Celes 2018-05-29 15:11:04 -07:00
chromeos_pstore.c platform/chrome: cromeos_pstore: switch to SPDX identifier 2019-02-01 10:13:05 +01:00
chromeos_tbmc.c platform/chrome: chromeos_tbmc - Remove unneeded const 2018-10-09 22:40:12 -07:00
cros_ec_debugfs.c platform/chrome: cros_ec_debugfs: no need to check return value of debugfs_create functions 2019-04-15 12:11:35 +02:00
cros_ec_i2c.c platform/chrome: cros_ec_i2c: switch to SPDX identifier 2019-02-01 10:13:06 +01:00
cros_ec_lightbar.c platform/chrome: cros_ec_lightbar: remove pr_fmt() define 2019-02-01 10:13:06 +01:00
cros_ec_lpc.c platform/chrome: cros_ec_lpc: switch to SPDX identifier 2019-02-01 10:13:06 +01:00
cros_ec_lpc_mec.c platform/chrome: cros_ec: Remove cros_ec dependency in lpc_mec 2019-02-11 10:07:40 +01:00
cros_ec_lpc_mec.h platform/chrome: cros_ec: Remove cros_ec dependency in lpc_mec 2019-02-11 10:07:40 +01:00
cros_ec_lpc_reg.c platform/chrome: cros_ec: Remove cros_ec dependency in lpc_mec 2019-02-11 10:07:40 +01:00
cros_ec_lpc_reg.h platform/chrome: cros_ec_lpc: switch to SPDX identifier 2019-02-01 10:13:06 +01:00
cros_ec_proto.c platform/chrome: cros_ec_proto: switch to SPDX identifier 2019-02-01 10:13:06 +01:00
cros_ec_spi.c platform/chrome: cros_ec_spi: Transfer messages at high priority 2019-04-15 12:13:24 +02:00
cros_ec_sysfs.c platform/chrome: cros_ec_sysfs: remove pr_fmt() define 2019-02-01 10:13:06 +01:00
cros_ec_vbc.c platform/chrome: cros_ec_vbc: switch to SPDX identifier 2019-02-01 10:13:06 +01:00
cros_kbd_led_backlight.c platform/chrome: cros_kbd_led_backlight: switch to SPDX identifier 2019-02-01 10:13:06 +01:00
Kconfig platform/chrome: Add new driver for Wilco EC 2019-02-21 21:35:59 +01:00
Makefile platform/chrome: Add new driver for Wilco EC 2019-02-21 21:35:59 +01:00