From: Jarek Poplawski <jarkao2@gmail.com>
To: Stephen Hemminger <shemminger@vyatta.com>
Cc: David Miller <davem@davemloft.net>,
Patrick McHardy <kaber@trash.net>,
netdev@vger.kernel.org
Subject: [PATCH] pkt_sched: gen_estimator: Optimize gen_estimator_active()
Date: Wed, 26 Nov 2008 11:10:22 +0000 [thread overview]
Message-ID: <20081126111021.GA12337@ff.dom.local> (raw)
In-Reply-To: <20081125102113.371db7b1@extreme>
pkt_sched: gen_estimator: Optimize gen_estimator_active()
Since all other gen_estimator functions use bstats and rate_est params
together, and searching for them is optimized now, let's use this also
in gen_estimator_active(). The return type of gen_estimator_active()
is changed to bool, and gen_find_node() parameters to const, btw.
In tcf_act_police_locate() a check for ACT_P_CREATED is added before
calling gen_estimator_active().
Signed-off-by: Jarek Poplawski <jarkao2@gmail.com>
---
include/net/gen_stats.h | 4 ++--
net/core/gen_estimator.c | 25 ++++++++-----------------
net/sched/act_police.c | 4 +++-
3 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/include/net/gen_stats.h b/include/net/gen_stats.h
index dcf5bfa..d136b52 100644
--- a/include/net/gen_stats.h
+++ b/include/net/gen_stats.h
@@ -45,6 +45,6 @@ extern void gen_kill_estimator(struct gnet_stats_basic *bstats,
extern int gen_replace_estimator(struct gnet_stats_basic *bstats,
struct gnet_stats_rate_est *rate_est,
spinlock_t *stats_lock, struct nlattr *opt);
-extern int gen_estimator_active(const struct gnet_stats_rate_est *rate_est);
-
+extern bool gen_estimator_active(const struct gnet_stats_basic *bstats,
+ const struct gnet_stats_rate_est *rate_est);
#endif
diff --git a/net/core/gen_estimator.c b/net/core/gen_estimator.c
index 3885550..9cc9f95 100644
--- a/net/core/gen_estimator.c
+++ b/net/core/gen_estimator.c
@@ -163,8 +163,9 @@ static void gen_add_node(struct gen_estimator *est)
rb_insert_color(&est->node, &est_root);
}
-static struct gen_estimator *gen_find_node(struct gnet_stats_basic *bstats,
- struct gnet_stats_rate_est *rate_est)
+static
+struct gen_estimator *gen_find_node(const struct gnet_stats_basic *bstats,
+ const struct gnet_stats_rate_est *rate_est)
{
struct rb_node *p = est_root.rb_node;
@@ -301,26 +302,16 @@ EXPORT_SYMBOL(gen_replace_estimator);
/**
* gen_estimator_active - test if estimator is currently in use
+ * @bstats: basic statistics
* @rate_est: rate estimator statistics
*
- * Returns 1 if estimator is active, and 0 if not.
+ * Returns true if estimator is active, and false if not.
*/
-int gen_estimator_active(const struct gnet_stats_rate_est *rate_est)
+bool gen_estimator_active(const struct gnet_stats_basic *bstats,
+ const struct gnet_stats_rate_est *rate_est)
{
- int idx;
- struct gen_estimator *e;
-
ASSERT_RTNL();
- for (idx=0; idx <= EST_MAX_INTERVAL; idx++) {
- if (!elist[idx].timer.function)
- continue;
-
- list_for_each_entry(e, &elist[idx].list, list) {
- if (e->rate_est == rate_est)
- return 1;
- }
- }
- return 0;
+ return gen_find_node(bstats, rate_est) != NULL;
}
EXPORT_SYMBOL(gen_estimator_active);
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index 40df1d0..40f9a81 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -183,7 +183,9 @@ override:
if (R_tab == NULL)
goto failure;
- if (!est && !gen_estimator_active(&police->tcf_rate_est)) {
+ if (!est && (ret == ACT_P_CREATED ||
+ !gen_estimator_active(&police->tcf_bstats,
+ &police->tcf_rate_est))) {
err = -EINVAL;
goto failure;
}
next prev parent reply other threads:[~2008-11-26 11:10 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-25 18:16 [PATCH 1/2] tc: check for errors from gen_replace_estimator Stephen Hemminger
2008-11-25 18:21 ` [PATCH 2/2] tc: policing requires a rate estimator Stephen Hemminger
2008-11-25 18:32 ` Patrick McHardy
2008-11-25 18:33 ` Stephen Hemminger
2008-11-25 18:38 ` Patrick McHardy
2008-11-26 5:14 ` David Miller
2008-11-26 11:10 ` Jarek Poplawski [this message]
2008-11-26 16:29 ` [PATCH] pkt_sched: gen_estimator: Optimize gen_estimator_active() Stephen Hemminger
2008-11-26 23:24 ` David Miller
2008-11-25 18:28 ` [PATCH 1/2] tc: check for errors from gen_replace_estimator Patrick McHardy
2008-11-25 18:57 ` [PATCH 1a/2] tc: propogate errors from tcf_hash_create Stephen Hemminger
2008-11-26 5:12 ` David Miller
2008-11-25 18:58 ` [PATCH 1b/2] tc: check for errors in gen_rate_estimator creation Stephen Hemminger
2008-11-25 19:05 ` Patrick McHardy
2008-11-25 19:14 ` Stephen Hemminger
2008-11-25 19:19 ` Patrick McHardy
2008-11-25 19:25 ` Stephen Hemminger
2008-11-26 5:13 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081126111021.GA12337@ff.dom.local \
--to=jarkao2@gmail.com \
--cc=davem@davemloft.net \
--cc=kaber@trash.net \
--cc=netdev@vger.kernel.org \
--cc=shemminger@vyatta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.