diff options
author | Christophe Leroy <christophe.leroy@c-s.fr> | 2017-12-18 05:08:35 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2017-12-20 04:34:58 -0500 |
commit | 1efba35afae43094d3f26093f5f1ab8a46686a6f (patch) | |
tree | 5f0cc54ea8cd6826f8daa5d17410b7c9e6f19f8f | |
parent | 7a94b88cb7087aa3184161bedccfea25e5502c62 (diff) |
gpio: sysfs: avoid using kstrtol() in 'value' attribute write
A 'perf record' on an app continuously writing in the 'value'
attribute show that most of the time is spent in kstrtol()
--17.99%--value_store
|
|--10.17%--kstrtoint
| |
| |--8.82%--kstrtoll
|
|--2.50%--gpiod_set_value_cansleep
|
|--1.82%--u16_gpio_set
|
|--1.46%--value_store
The normal case is to write 0 or 1 in the attribute, therefore
this patch avoids the call to kstrtol() in the most common cases
Then 'perf record' shows
--7.21%--value_store
|
|--2.69%--u16_gpio_set
|
|--1.47%--value_store
|
|--1.08%--gpiod_set_value_cansleep
|
|--0.60%--mutex_lock
|
--0.58%--mutex_unlock
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r-- | drivers/gpio/gpiolib-sysfs.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index ad7173df72eb..3dbaf489a8a5 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <linux/interrupt.h> | 8 | #include <linux/interrupt.h> |
9 | #include <linux/kdev_t.h> | 9 | #include <linux/kdev_t.h> |
10 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
11 | #include <linux/ctype.h> | ||
11 | 12 | ||
12 | #include "gpiolib.h" | 13 | #include "gpiolib.h" |
13 | 14 | ||
@@ -124,7 +125,7 @@ static ssize_t value_store(struct device *dev, | |||
124 | { | 125 | { |
125 | struct gpiod_data *data = dev_get_drvdata(dev); | 126 | struct gpiod_data *data = dev_get_drvdata(dev); |
126 | struct gpio_desc *desc = data->desc; | 127 | struct gpio_desc *desc = data->desc; |
127 | ssize_t status; | 128 | ssize_t status = 0; |
128 | 129 | ||
129 | mutex_lock(&data->mutex); | 130 | mutex_lock(&data->mutex); |
130 | 131 | ||
@@ -133,7 +134,11 @@ static ssize_t value_store(struct device *dev, | |||
133 | } else { | 134 | } else { |
134 | long value; | 135 | long value; |
135 | 136 | ||
136 | status = kstrtol(buf, 0, &value); | 137 | if (size <= 2 && isdigit(buf[0]) && |
138 | (size == 1 || buf[1] == '\n')) | ||
139 | value = buf[0] - '0'; | ||
140 | else | ||
141 | status = kstrtol(buf, 0, &value); | ||
137 | if (status == 0) { | 142 | if (status == 0) { |
138 | gpiod_set_value_cansleep(desc, value); | 143 | gpiod_set_value_cansleep(desc, value); |
139 | status = size; | 144 | status = size; |