Skip to content

Commit 3aa5136

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: #6854 [1] https://lwn.net/Articles/960024/ Signed-off-by: Phil Elwell <[email protected]>
1 parent d25181f commit 3aa5136

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
@@ -52,6 +52,42 @@
5252

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

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

0 commit comments

Comments
 (0)