diff options
| author | Jarek Poplawski <jarkao2@o2.pl> | 2006-12-08 03:26:56 -0500 |
|---|---|---|
| committer | David S. Miller <davem@sunset.davemloft.net> | 2006-12-08 20:19:32 -0500 |
| commit | 160d5e10f87b1dc88fd9b84b31b1718e0fd76398 (patch) | |
| tree | ea217c1de9670e4fd4407b6f267d6236b0d3d54a /net/sched | |
| parent | a37ef2e3258d65e43ec876233bba0b288a9d3260 (diff) | |
[NET_SCHED] sch_htb: turn intermediate classes into leaves
- turn intermediate classes into leaves again when their
last child is deleted (struct htb_class changed)
Signed-off-by: Jarek Poplawski <jarkao2@o2.pl>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/sched')
| -rw-r--r-- | net/sched/sch_htb.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c index 215e68c2b615..15f23c5511a8 100644 --- a/net/sched/sch_htb.c +++ b/net/sched/sch_htb.c | |||
| @@ -147,6 +147,10 @@ struct htb_class { | |||
| 147 | psched_tdiff_t mbuffer; /* max wait time */ | 147 | psched_tdiff_t mbuffer; /* max wait time */ |
| 148 | long tokens, ctokens; /* current number of tokens */ | 148 | long tokens, ctokens; /* current number of tokens */ |
| 149 | psched_time_t t_c; /* checkpoint time */ | 149 | psched_time_t t_c; /* checkpoint time */ |
| 150 | |||
| 151 | int prio; /* For parent to leaf return possible here */ | ||
| 152 | int quantum; /* we do backup. Finally full replacement */ | ||
| 153 | /* of un.leaf originals should be done. */ | ||
| 150 | }; | 154 | }; |
| 151 | 155 | ||
| 152 | /* TODO: maybe compute rate when size is too large .. or drop ? */ | 156 | /* TODO: maybe compute rate when size is too large .. or drop ? */ |
| @@ -1271,6 +1275,38 @@ static void htb_destroy_filters(struct tcf_proto **fl) | |||
| 1271 | } | 1275 | } |
| 1272 | } | 1276 | } |
| 1273 | 1277 | ||
| 1278 | static inline int htb_parent_last_child(struct htb_class *cl) | ||
| 1279 | { | ||
| 1280 | if (!cl->parent) | ||
| 1281 | /* the root class */ | ||
| 1282 | return 0; | ||
| 1283 | |||
| 1284 | if (!(cl->parent->children.next == &cl->sibling && | ||
| 1285 | cl->parent->children.prev == &cl->sibling)) | ||
| 1286 | /* not the last child */ | ||
| 1287 | return 0; | ||
| 1288 | |||
| 1289 | return 1; | ||
| 1290 | } | ||
| 1291 | |||
| 1292 | static void htb_parent_to_leaf(struct htb_class *cl, struct Qdisc *new_q) | ||
| 1293 | { | ||
| 1294 | struct htb_class *parent = cl->parent; | ||
| 1295 | |||
| 1296 | BUG_TRAP(!cl->level && cl->un.leaf.q && !cl->prio_activity); | ||
| 1297 | |||
| 1298 | parent->level = 0; | ||
| 1299 | memset(&parent->un.inner, 0, sizeof(parent->un.inner)); | ||
| 1300 | INIT_LIST_HEAD(&parent->un.leaf.drop_list); | ||
| 1301 | parent->un.leaf.q = new_q ? new_q : &noop_qdisc; | ||
| 1302 | parent->un.leaf.quantum = parent->quantum; | ||
| 1303 | parent->un.leaf.prio = parent->prio; | ||
| 1304 | parent->tokens = parent->buffer; | ||
| 1305 | parent->ctokens = parent->cbuffer; | ||
| 1306 | PSCHED_GET_TIME(parent->t_c); | ||
| 1307 | parent->cmode = HTB_CAN_SEND; | ||
| 1308 | } | ||
| 1309 | |||
| 1274 | static void htb_destroy_class(struct Qdisc *sch, struct htb_class *cl) | 1310 | static void htb_destroy_class(struct Qdisc *sch, struct htb_class *cl) |
| 1275 | { | 1311 | { |
| 1276 | struct htb_sched *q = qdisc_priv(sch); | 1312 | struct htb_sched *q = qdisc_priv(sch); |
| @@ -1328,6 +1364,8 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg) | |||
| 1328 | struct htb_sched *q = qdisc_priv(sch); | 1364 | struct htb_sched *q = qdisc_priv(sch); |
| 1329 | struct htb_class *cl = (struct htb_class *)arg; | 1365 | struct htb_class *cl = (struct htb_class *)arg; |
| 1330 | unsigned int qlen; | 1366 | unsigned int qlen; |
| 1367 | struct Qdisc *new_q = NULL; | ||
| 1368 | int last_child = 0; | ||
| 1331 | 1369 | ||
| 1332 | // TODO: why don't allow to delete subtree ? references ? does | 1370 | // TODO: why don't allow to delete subtree ? references ? does |
| 1333 | // tc subsys quarantee us that in htb_destroy it holds no class | 1371 | // tc subsys quarantee us that in htb_destroy it holds no class |
| @@ -1335,6 +1373,12 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg) | |||
| 1335 | if (!list_empty(&cl->children) || cl->filter_cnt) | 1373 | if (!list_empty(&cl->children) || cl->filter_cnt) |
| 1336 | return -EBUSY; | 1374 | return -EBUSY; |
| 1337 | 1375 | ||
| 1376 | if (!cl->level && htb_parent_last_child(cl)) { | ||
| 1377 | new_q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops, | ||
| 1378 | cl->parent->classid); | ||
| 1379 | last_child = 1; | ||
| 1380 | } | ||
| 1381 | |||
| 1338 | sch_tree_lock(sch); | 1382 | sch_tree_lock(sch); |
| 1339 | 1383 | ||
| 1340 | /* delete from hash and active; remainder in destroy_class */ | 1384 | /* delete from hash and active; remainder in destroy_class */ |
| @@ -1349,6 +1393,9 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg) | |||
| 1349 | if (cl->prio_activity) | 1393 | if (cl->prio_activity) |
| 1350 | htb_deactivate(q, cl); | 1394 | htb_deactivate(q, cl); |
| 1351 | 1395 | ||
| 1396 | if (last_child) | ||
| 1397 | htb_parent_to_leaf(cl, new_q); | ||
| 1398 | |||
| 1352 | if (--cl->refcnt == 0) | 1399 | if (--cl->refcnt == 0) |
| 1353 | htb_destroy_class(sch, cl); | 1400 | htb_destroy_class(sch, cl); |
| 1354 | 1401 | ||
| @@ -1483,6 +1530,10 @@ static int htb_change_class(struct Qdisc *sch, u32 classid, | |||
| 1483 | cl->un.leaf.quantum = hopt->quantum; | 1530 | cl->un.leaf.quantum = hopt->quantum; |
| 1484 | if ((cl->un.leaf.prio = hopt->prio) >= TC_HTB_NUMPRIO) | 1531 | if ((cl->un.leaf.prio = hopt->prio) >= TC_HTB_NUMPRIO) |
| 1485 | cl->un.leaf.prio = TC_HTB_NUMPRIO - 1; | 1532 | cl->un.leaf.prio = TC_HTB_NUMPRIO - 1; |
| 1533 | |||
| 1534 | /* backup for htb_parent_to_leaf */ | ||
| 1535 | cl->quantum = cl->un.leaf.quantum; | ||
| 1536 | cl->prio = cl->un.leaf.prio; | ||
| 1486 | } | 1537 | } |
| 1487 | 1538 | ||
| 1488 | cl->buffer = hopt->buffer; | 1539 | cl->buffer = hopt->buffer; |
