summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarek Poplawski <jarkao2@gmail.com>2008-11-27 02:24:32 +0300
committerDavid S. Miller <davem@davemloft.net>2008-11-27 02:24:32 +0300
commit244e6c2d0724bc4908a1995804704bdee3b31528 (patch)
treee208a765607733401302bf8582b37d1adab63c08
parent3d4cd60ed0533d3b33832e298530c7b021da982b (diff)
downloadlinux-244e6c2d0724bc4908a1995804704bdee3b31528.tar.xz
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> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/gen_stats.h4
-rw-r--r--net/core/gen_estimator.c25
-rw-r--r--net/sched/act_police.c4
3 files changed, 13 insertions, 20 deletions
diff --git a/include/net/gen_stats.h b/include/net/gen_stats.h
index dcf5bfa7d4f1..d136b5240ef2 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 3885550f0187..9cc9f95b109e 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 c39f60cea6ee..5c72a116b1a4 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;
}