2023-04-03 20:06:12

by Mark Brown

[permalink] [raw]
Subject: [PATCH] regmap: Use mas_walk() instead of mas_find()

Liam recommends using mas_walk() instead of mas_find() for our use case so
let's do that, it avoids some minor overhead associated with being able to
restart the operation which we don't need since we do a simple search.

Suggested-by: Liam R. Howlett <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
---
drivers/base/regmap/regcache-maple.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/base/regmap/regcache-maple.c b/drivers/base/regmap/regcache-maple.c
index 497cc708d277..5d1bc3691830 100644
--- a/drivers/base/regmap/regcache-maple.c
+++ b/drivers/base/regmap/regcache-maple.c
@@ -22,7 +22,9 @@ static int regcache_maple_read(struct regmap *map,

rcu_read_lock();

- entry = mas_find(&mas, reg);
+ mas.index = reg;
+ mas.last = reg;
+ entry = mas_walk(&mas);
if (!entry) {
rcu_read_unlock();
return -ENOENT;
@@ -47,7 +49,9 @@ static int regcache_maple_write(struct regmap *map, unsigned int reg,

rcu_read_lock();

- entry = mas_find(&mas, reg);
+ mas.index = reg;
+ mas.last = reg;
+ entry = mas_walk(&mas);
if (entry) {
entry[reg - mas.index] = val;
rcu_read_unlock();

---
base-commit: f033c26de5a5734625d2dd1dc196745fae186f1b
change-id: 20230403-regmap-maple-walk-fine-982bbd2dcfe5

Best regards,
--
Mark Brown <[email protected]>


2023-04-03 20:11:31

by Liam R. Howlett

[permalink] [raw]
Subject: Re: [PATCH] regmap: Use mas_walk() instead of mas_find()

* Mark Brown <[email protected]> [230403 16:00]:
> Liam recommends using mas_walk() instead of mas_find() for our use case so
> let's do that, it avoids some minor overhead associated with being able to
> restart the operation which we don't need since we do a simple search.
>
> Suggested-by: Liam R. Howlett <[email protected]>
> Signed-off-by: Mark Brown <[email protected]>
> ---
> drivers/base/regmap/regcache-maple.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/regmap/regcache-maple.c b/drivers/base/regmap/regcache-maple.c
> index 497cc708d277..5d1bc3691830 100644
> --- a/drivers/base/regmap/regcache-maple.c
> +++ b/drivers/base/regmap/regcache-maple.c
> @@ -22,7 +22,9 @@ static int regcache_maple_read(struct regmap *map,
>
> rcu_read_lock();
>
> - entry = mas_find(&mas, reg);
> + mas.index = reg;
> + mas.last = reg;

You don't need to set mas.index/mas.last here. You have done so with
MA_STATE(mas, mt, reg, reg); above with the last two arguments.

> + entry = mas_walk(&mas);
> if (!entry) {
> rcu_read_unlock();
> return -ENOENT;
> @@ -47,7 +49,9 @@ static int regcache_maple_write(struct regmap *map, unsigned int reg,
>
> rcu_read_lock();
>
> - entry = mas_find(&mas, reg);
> + mas.index = reg;
> + mas.last = reg;

Same here.

> + entry = mas_walk(&mas);
> if (entry) {
> entry[reg - mas.index] = val;
> rcu_read_unlock();
>
> ---
> base-commit: f033c26de5a5734625d2dd1dc196745fae186f1b
> change-id: 20230403-regmap-maple-walk-fine-982bbd2dcfe5
>
> Best regards,
> --
> Mark Brown <[email protected]>
>