diff mbox series

[3/4] gpio: sysfs: don't use sprintf() for 'value' attribute

Message ID 1fbada4f02475f69abbccd105c92dc3512dd6ab0.1513591276.git.christophe.leroy@c-s.fr
State New
Headers show
Series [1/4] gpio: sysfs: change 'value' attribute to prealloc | expand

Commit Message

Christophe Leroy Dec. 18, 2017, 10:08 a.m. UTC
A bench with 'perf record' shows that most of time spent in value_show()
is spent in sprintf()

--42.41%--sysfs_kf_read
          |
          |--39.73%--dev_attr_show
          |          |
          |          |--38.23%--value_show
          |          |          |
          |          |          |--29.22%--sprintf
          |          |          |
          |          |          |--2.94%--gpiod_get_value_cansleep
          |          |          |

value_show() only returns "0\n" or "1\n", therefore the use of
sprintf() can be avoided

With this patch we get the following result with 'perf record'

--13.89%--sysfs_kf_read
          |
          |--10.72%--dev_attr_show
          |          |
          |          |--9.44%--value_show
          |          |          |
          |          |          |--4.61%--gpiod_get_value_cansleep

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 drivers/gpio/gpiolib-sysfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Linus Walleij Dec. 20, 2017, 9:34 a.m. UTC | #1
On Mon, Dec 18, 2017 at 11:08 AM, Christophe Leroy
<christophe.leroy@c-s.fr> wrote:

> A bench with 'perf record' shows that most of time spent in value_show()
> is spent in sprintf()
>
> --42.41%--sysfs_kf_read
>           |
>           |--39.73%--dev_attr_show
>           |          |
>           |          |--38.23%--value_show
>           |          |          |
>           |          |          |--29.22%--sprintf
>           |          |          |
>           |          |          |--2.94%--gpiod_get_value_cansleep
>           |          |          |
>
> value_show() only returns "0\n" or "1\n", therefore the use of
> sprintf() can be avoided
>
> With this patch we get the following result with 'perf record'
>
> --13.89%--sysfs_kf_read
>           |
>           |--10.72%--dev_attr_show
>           |          |
>           |          |--9.44%--value_show
>           |          |          |
>           |          |          |--4.61%--gpiod_get_value_cansleep
>
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Patch applied.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 1b0f415df03b..bb10e8ed456e 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -110,7 +110,9 @@  static ssize_t value_show(struct device *dev,
 	if (status < 0)
 		goto err;
 
-	status = sprintf(buf, "%d\n", status);
+	buf[0] = '0' + status;
+	buf[1] = '\n';
+	status = 2;
 err:
 	mutex_unlock(&data->mutex);