bcache: Optimize sysfs_hprint()

Message ID 9b82413f1ca0b924cc139d945777e32dd22ffe41.1698575385.git.christophe.jaillet@wanadoo.fr
State New
Headers
Series bcache: Optimize sysfs_hprint() |

Commit Message

Christophe JAILLET Oct. 29, 2023, 10:30 a.m. UTC
  The size of what is in 'buf' is already computed by bch_hprint(), so skip
these bytes when calling strcat().

This easily saves a few cycles. (should it matter)

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/md/bcache/sysfs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Coly Li Oct. 30, 2023, 7:38 a.m. UTC | #1
> 2023年10月29日 18:30,Christophe JAILLET <christophe.jaillet@wanadoo.fr> 写道:
> 
> The size of what is in 'buf' is already computed by bch_hprint(), so skip
> these bytes when calling strcat().
> 
> This easily saves a few cycles. (should it matter)
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Your change does save several cpu cycles, but hurts the readability. This is not hot code path, just let strcat to do what it was designed for. 

Thanks.

Coly Li

> ---
> drivers/md/bcache/sysfs.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/md/bcache/sysfs.h b/drivers/md/bcache/sysfs.h
> index 65b8bd975ab1..798bcbeab0bb 100644
> --- a/drivers/md/bcache/sysfs.h
> +++ b/drivers/md/bcache/sysfs.h
> @@ -78,7 +78,7 @@ do { \
> do { \
> if (attr == &sysfs_ ## file) { \
> ssize_t ret = bch_hprint(buf, val); \
> - strcat(buf, "\n"); \
> + strcat(buf + ret, "\n"); \
> return ret + 1; \
> } \
> } while (0)
> -- 
> 2.34.1
>
  

Patch

diff --git a/drivers/md/bcache/sysfs.h b/drivers/md/bcache/sysfs.h
index 65b8bd975ab1..798bcbeab0bb 100644
--- a/drivers/md/bcache/sysfs.h
+++ b/drivers/md/bcache/sysfs.h
@@ -78,7 +78,7 @@  do {									\
 do {									\
 	if (attr == &sysfs_ ## file) {					\
 		ssize_t ret = bch_hprint(buf, val);			\
-		strcat(buf, "\n");					\
+		strcat(buf + ret, "\n");				\
 		return ret + 1;						\
 	}								\
 } while (0)