* [PATCH] drivers/mtd/ubi/wl.c: optimization for in_wl_tree()
@ 2012-06-10 1:57 Daniel Santos
2012-06-10 2:02 ` Daniel Santos
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Santos @ 2012-06-10 1:57 UTC (permalink / raw)
To: Richard Weinberger; +Cc: LKML, Daniel Santos
Essentially, instead of performing a search through the tree from the
top down, like we would when doing a lookup, we can just search from the
node up and then check to see if the root of the tree that the node is
in is the same as the one supplied. Note that if you call this passing
a ubi_wl_entry who's u.rb member has not been inited with rb_init_node()
or added to a tree, the results are undefined.
This should be a little faster, but mostly, it'll be smaller.
---
drivers/mtd/ubi/wl.c | 32 ++++++++------------------------
1 files changed, 8 insertions(+), 24 deletions(-)
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 9df100a..d415011 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -287,33 +287,17 @@ static int produce_free_peb(struct ubi_device *ubi)
*/
static int in_wl_tree(struct ubi_wl_entry *e, struct rb_root *root)
{
- struct rb_node *p;
-
- p = root->rb_node;
- while (p) {
- struct ubi_wl_entry *e1;
+ struct rb_node *p = &e->u.rb, *parent = rb_parent(&e->u.rb);
- e1 = rb_entry(p, struct ubi_wl_entry, u.rb);
-
- if (e->pnum == e1->pnum) {
- ubi_assert(e == e1);
- return 1;
- }
+ if (parent == p)
+ return 0;
- if (e->ec < e1->ec)
- p = p->rb_left;
- else if (e->ec > e1->ec)
- p = p->rb_right;
- else {
- ubi_assert(e->pnum != e1->pnum);
- if (e->pnum < e1->pnum)
- p = p->rb_left;
- else
- p = p->rb_right;
- }
- }
+ do {
+ p = parent;
+ parent = rb_parent(parent);
+ } while (parent);
- return 0;
+ return p == root->rb_node;
}
/**
--
1.7.3.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drivers/mtd/ubi/wl.c: optimization for in_wl_tree()
2012-06-10 1:57 [PATCH] drivers/mtd/ubi/wl.c: optimization for in_wl_tree() Daniel Santos
@ 2012-06-10 2:02 ` Daniel Santos
2012-06-10 9:58 ` Richard Weinberger
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Santos @ 2012-06-10 2:02 UTC (permalink / raw)
To: Richard Weinberger; +Cc: LKML
Oh, and I forgot to mention that I haven't tested it (don't have this
device), but it does compile.
On 06/09/2012 08:57 PM, Daniel Santos wrote:
> Essentially, instead of performing a search through the tree from the
> top down, like we would when doing a lookup, we can just search from the
> node up and then check to see if the root of the tree that the node is
> in is the same as the one supplied. Note that if you call this passing
> a ubi_wl_entry who's u.rb member has not been inited with rb_init_node()
> or added to a tree, the results are undefined.
>
> This should be a little faster, but mostly, it'll be smaller.
> ---
> drivers/mtd/ubi/wl.c | 32 ++++++++------------------------
> 1 files changed, 8 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
> index 9df100a..d415011 100644
> --- a/drivers/mtd/ubi/wl.c
> +++ b/drivers/mtd/ubi/wl.c
> @@ -287,33 +287,17 @@ static int produce_free_peb(struct ubi_device *ubi)
> */
> static int in_wl_tree(struct ubi_wl_entry *e, struct rb_root *root)
> {
> - struct rb_node *p;
> -
> - p = root->rb_node;
> - while (p) {
> - struct ubi_wl_entry *e1;
> + struct rb_node *p = &e->u.rb, *parent = rb_parent(&e->u.rb);
>
> - e1 = rb_entry(p, struct ubi_wl_entry, u.rb);
> -
> - if (e->pnum == e1->pnum) {
> - ubi_assert(e == e1);
> - return 1;
> - }
> + if (parent == p)
> + return 0;
>
> - if (e->ec < e1->ec)
> - p = p->rb_left;
> - else if (e->ec > e1->ec)
> - p = p->rb_right;
> - else {
> - ubi_assert(e->pnum != e1->pnum);
> - if (e->pnum < e1->pnum)
> - p = p->rb_left;
> - else
> - p = p->rb_right;
> - }
> - }
> + do {
> + p = parent;
> + parent = rb_parent(parent);
> + } while (parent);
>
> - return 0;
> + return p == root->rb_node;
> }
>
> /**
--
Daniel
"Just because you go to church on Sunday, it doesn't absolve you from
where you put your dick during the week" -- Michele Q.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drivers/mtd/ubi/wl.c: optimization for in_wl_tree()
2012-06-10 2:02 ` Daniel Santos
@ 2012-06-10 9:58 ` Richard Weinberger
0 siblings, 0 replies; 3+ messages in thread
From: Richard Weinberger @ 2012-06-10 9:58 UTC (permalink / raw)
To: daniel.santos; +Cc: Daniel Santos, LKML
[-- Attachment #1: Type: text/plain, Size: 423 bytes --]
Am 10.06.2012 04:02, schrieb Daniel Santos:
> Oh, and I forgot to mention that I haven't tested it (don't have this
> device), but it does compile.
Sure you have this device. :-)
modprobe nandsim
modprobe ubi mtd=0
ubimkvol /dev/ubi0 -n 0 -N test -m
mkfs.ubifs /dev/ubi0_0
mount -t ubifs /dev/ubi0_0 /mnt/ubifs
testing....
umount /mnt/ubifs
Thanks,
//richard
P.s: Please send use get_maintainer.pl.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-06-10 9:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-10 1:57 [PATCH] drivers/mtd/ubi/wl.c: optimization for in_wl_tree() Daniel Santos
2012-06-10 2:02 ` Daniel Santos
2012-06-10 9:58 ` Richard Weinberger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox