Skip to content

Commit a8a08f6

Browse files
committed
gpiolib: Avoid the hotplug performance reduction
The 6.9 kernel introduced a large patchset [1] designed to make gpiochip usage safe in the presence of potential hotplugging events. The changes included protecting every gpiochip access with a claim of an interlock. Running on a Pi 5 these changes reduce GPIO performance from userspace by around 10%. The penalty would be proportionally higher from kernel, as seen by SPI speed reductions. Patch the gpiolib implementation to remove the protection of gpiochip accesses. By providing alternative implementations of the relevant macros, the changes are localised and therefore easier to verify. See: raspberrypi#6854 [1] https://lwn.net/Articles/960024/ Signed-off-by: Phil Elwell <[email protected]>
1 parent f5726fb commit a8a08f6

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

drivers/gpio/gpiolib.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,42 @@
5353

5454
#define dont_test_bit(b,d) (0)
5555

56+
#define REJECT_HOTPLUG_TAX 1
57+
58+
#if REJECT_HOTPLUG_TAX
59+
60+
#undef srcu_dereference
61+
#define srcu_dereference(obj, srcu) obj
62+
63+
#undef srcu_dereference_check
64+
#define srcu_dereference_check(obj, srcu, held) obj
65+
66+
#undef guard
67+
#define guard(srcu) (void)
68+
69+
#undef scoped_guard
70+
#define scoped_guard(x, y)
71+
#undef list_for_each_entry_srcu
72+
#define list_for_each_entry_srcu(pos, head, member, srcu) \
73+
list_for_each_entry(pos, head, member)
74+
75+
#undef CLASS
76+
#define CLASS(gcg, gd) \
77+
struct gcg gd = gcg ## _init
78+
79+
static struct gpio_chip_guard gpio_chip_guard_init(struct gpio_desc *desc)
80+
{
81+
struct gpio_chip_guard _guard;
82+
83+
_guard.gdev = desc->gdev;
84+
_guard.idx = 0;
85+
_guard.gc = _guard.gdev->chip;
86+
87+
return _guard;
88+
}
89+
90+
#endif
91+
5692
/* Device and char device-related information */
5793
static DEFINE_IDA(gpio_ida);
5894
static dev_t gpio_devt;

0 commit comments

Comments
 (0)