diff options
author | Paul Turner <pjt@google.com> | 2011-07-21 12:43:33 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2011-08-14 06:03:34 -0400 |
commit | 85dac906bec3bb41bfaa7ccaa65c4706de5cfdf8 (patch) | |
tree | 5d3f71d409fe002b0dfd2cdfb7ef09a9d5851f66 /kernel/sched_fair.c | |
parent | a9cf55b2861057a213e610da2fec52125439a11d (diff) |
sched: Add support for throttling group entities
Now that consumption is tracked (via update_curr()) we add support to throttle
group entities (and their corresponding cfs_rqs) in the case where this is no
run-time remaining.
Throttled entities are dequeued to prevent scheduling, additionally we mark
them as throttled (using cfs_rq->throttled) to prevent them from becoming
re-enqueued until they are unthrottled. A list of a task_group's throttled
entities are maintained on the cfs_bandwidth structure.
Note: While the machinery for throttling is added in this patch the act of
throttling an entity exceeding its bandwidth is deferred until later within
the series.
Signed-off-by: Paul Turner <pjt@google.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20110721184757.480608533@google.com
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/sched_fair.c')
-rw-r--r-- | kernel/sched_fair.c | 89 |
1 files changed, 85 insertions, 4 deletions
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c index 9d1adbd0b615..72c9d4ed5991 100644 --- a/kernel/sched_fair.c +++ b/kernel/sched_fair.c | |||
@@ -1291,7 +1291,8 @@ static void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth *cfs_b) | |||
1291 | cfs_b->runtime_expires = now + ktime_to_ns(cfs_b->period); | 1291 | cfs_b->runtime_expires = now + ktime_to_ns(cfs_b->period); |
1292 | } | 1292 | } |
1293 | 1293 | ||
1294 | static void assign_cfs_rq_runtime(struct cfs_rq *cfs_rq) | 1294 | /* returns 0 on failure to allocate runtime */ |
1295 | static int assign_cfs_rq_runtime(struct cfs_rq *cfs_rq) | ||
1295 | { | 1296 | { |
1296 | struct task_group *tg = cfs_rq->tg; | 1297 | struct task_group *tg = cfs_rq->tg; |
1297 | struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(tg); | 1298 | struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(tg); |
@@ -1332,6 +1333,8 @@ static void assign_cfs_rq_runtime(struct cfs_rq *cfs_rq) | |||
1332 | */ | 1333 | */ |
1333 | if ((s64)(expires - cfs_rq->runtime_expires) > 0) | 1334 | if ((s64)(expires - cfs_rq->runtime_expires) > 0) |
1334 | cfs_rq->runtime_expires = expires; | 1335 | cfs_rq->runtime_expires = expires; |
1336 | |||
1337 | return cfs_rq->runtime_remaining > 0; | ||
1335 | } | 1338 | } |
1336 | 1339 | ||
1337 | /* | 1340 | /* |
@@ -1378,7 +1381,12 @@ static void __account_cfs_rq_runtime(struct cfs_rq *cfs_rq, | |||
1378 | if (likely(cfs_rq->runtime_remaining > 0)) | 1381 | if (likely(cfs_rq->runtime_remaining > 0)) |
1379 | return; | 1382 | return; |
1380 | 1383 | ||
1381 | assign_cfs_rq_runtime(cfs_rq); | 1384 | /* |
1385 | * if we're unable to extend our runtime we resched so that the active | ||
1386 | * hierarchy can be throttled | ||
1387 | */ | ||
1388 | if (!assign_cfs_rq_runtime(cfs_rq) && likely(cfs_rq->curr)) | ||
1389 | resched_task(rq_of(cfs_rq)->curr); | ||
1382 | } | 1390 | } |
1383 | 1391 | ||
1384 | static __always_inline void account_cfs_rq_runtime(struct cfs_rq *cfs_rq, | 1392 | static __always_inline void account_cfs_rq_runtime(struct cfs_rq *cfs_rq, |
@@ -1390,6 +1398,47 @@ static __always_inline void account_cfs_rq_runtime(struct cfs_rq *cfs_rq, | |||
1390 | __account_cfs_rq_runtime(cfs_rq, delta_exec); | 1398 | __account_cfs_rq_runtime(cfs_rq, delta_exec); |
1391 | } | 1399 | } |
1392 | 1400 | ||
1401 | static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq) | ||
1402 | { | ||
1403 | return cfs_rq->throttled; | ||
1404 | } | ||
1405 | |||
1406 | static __used void throttle_cfs_rq(struct cfs_rq *cfs_rq) | ||
1407 | { | ||
1408 | struct rq *rq = rq_of(cfs_rq); | ||
1409 | struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(cfs_rq->tg); | ||
1410 | struct sched_entity *se; | ||
1411 | long task_delta, dequeue = 1; | ||
1412 | |||
1413 | se = cfs_rq->tg->se[cpu_of(rq_of(cfs_rq))]; | ||
1414 | |||
1415 | /* account load preceding throttle */ | ||
1416 | update_cfs_load(cfs_rq, 0); | ||
1417 | |||
1418 | task_delta = cfs_rq->h_nr_running; | ||
1419 | for_each_sched_entity(se) { | ||
1420 | struct cfs_rq *qcfs_rq = cfs_rq_of(se); | ||
1421 | /* throttled entity or throttle-on-deactivate */ | ||
1422 | if (!se->on_rq) | ||
1423 | break; | ||
1424 | |||
1425 | if (dequeue) | ||
1426 | dequeue_entity(qcfs_rq, se, DEQUEUE_SLEEP); | ||
1427 | qcfs_rq->h_nr_running -= task_delta; | ||
1428 | |||
1429 | if (qcfs_rq->load.weight) | ||
1430 | dequeue = 0; | ||
1431 | } | ||
1432 | |||
1433 | if (!se) | ||
1434 | rq->nr_running -= task_delta; | ||
1435 | |||
1436 | cfs_rq->throttled = 1; | ||
1437 | raw_spin_lock(&cfs_b->lock); | ||
1438 | list_add_tail_rcu(&cfs_rq->throttled_list, &cfs_b->throttled_cfs_rq); | ||
1439 | raw_spin_unlock(&cfs_b->lock); | ||
1440 | } | ||
1441 | |||
1393 | /* | 1442 | /* |
1394 | * Responsible for refilling a task_group's bandwidth and unthrottling its | 1443 | * Responsible for refilling a task_group's bandwidth and unthrottling its |
1395 | * cfs_rqs as appropriate. If there has been no activity within the last | 1444 | * cfs_rqs as appropriate. If there has been no activity within the last |
@@ -1425,6 +1474,11 @@ out_unlock: | |||
1425 | #else | 1474 | #else |
1426 | static void account_cfs_rq_runtime(struct cfs_rq *cfs_rq, | 1475 | static void account_cfs_rq_runtime(struct cfs_rq *cfs_rq, |
1427 | unsigned long delta_exec) {} | 1476 | unsigned long delta_exec) {} |
1477 | |||
1478 | static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq) | ||
1479 | { | ||
1480 | return 0; | ||
1481 | } | ||
1428 | #endif | 1482 | #endif |
1429 | 1483 | ||
1430 | /************************************************** | 1484 | /************************************************** |
@@ -1503,7 +1557,17 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) | |||
1503 | break; | 1557 | break; |
1504 | cfs_rq = cfs_rq_of(se); | 1558 | cfs_rq = cfs_rq_of(se); |
1505 | enqueue_entity(cfs_rq, se, flags); | 1559 | enqueue_entity(cfs_rq, se, flags); |
1560 | |||
1561 | /* | ||
1562 | * end evaluation on encountering a throttled cfs_rq | ||
1563 | * | ||
1564 | * note: in the case of encountering a throttled cfs_rq we will | ||
1565 | * post the final h_nr_running increment below. | ||
1566 | */ | ||
1567 | if (cfs_rq_throttled(cfs_rq)) | ||
1568 | break; | ||
1506 | cfs_rq->h_nr_running++; | 1569 | cfs_rq->h_nr_running++; |
1570 | |||
1507 | flags = ENQUEUE_WAKEUP; | 1571 | flags = ENQUEUE_WAKEUP; |
1508 | } | 1572 | } |
1509 | 1573 | ||
@@ -1511,11 +1575,15 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) | |||
1511 | cfs_rq = cfs_rq_of(se); | 1575 | cfs_rq = cfs_rq_of(se); |
1512 | cfs_rq->h_nr_running++; | 1576 | cfs_rq->h_nr_running++; |
1513 | 1577 | ||
1578 | if (cfs_rq_throttled(cfs_rq)) | ||
1579 | break; | ||
1580 | |||
1514 | update_cfs_load(cfs_rq, 0); | 1581 | update_cfs_load(cfs_rq, 0); |
1515 | update_cfs_shares(cfs_rq); | 1582 | update_cfs_shares(cfs_rq); |
1516 | } | 1583 | } |
1517 | 1584 | ||
1518 | inc_nr_running(rq); | 1585 | if (!se) |
1586 | inc_nr_running(rq); | ||
1519 | hrtick_update(rq); | 1587 | hrtick_update(rq); |
1520 | } | 1588 | } |
1521 | 1589 | ||
@@ -1535,6 +1603,15 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) | |||
1535 | for_each_sched_entity(se) { | 1603 | for_each_sched_entity(se) { |
1536 | cfs_rq = cfs_rq_of(se); | 1604 | cfs_rq = cfs_rq_of(se); |
1537 | dequeue_entity(cfs_rq, se, flags); | 1605 | dequeue_entity(cfs_rq, se, flags); |
1606 | |||
1607 | /* | ||
1608 | * end evaluation on encountering a throttled cfs_rq | ||
1609 | * | ||
1610 | * note: in the case of encountering a throttled cfs_rq we will | ||
1611 | * post the final h_nr_running decrement below. | ||
1612 | */ | ||
1613 | if (cfs_rq_throttled(cfs_rq)) | ||
1614 | break; | ||
1538 | cfs_rq->h_nr_running--; | 1615 | cfs_rq->h_nr_running--; |
1539 | 1616 | ||
1540 | /* Don't dequeue parent if it has other entities besides us */ | 1617 | /* Don't dequeue parent if it has other entities besides us */ |
@@ -1557,11 +1634,15 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) | |||
1557 | cfs_rq = cfs_rq_of(se); | 1634 | cfs_rq = cfs_rq_of(se); |
1558 | cfs_rq->h_nr_running--; | 1635 | cfs_rq->h_nr_running--; |
1559 | 1636 | ||
1637 | if (cfs_rq_throttled(cfs_rq)) | ||
1638 | break; | ||
1639 | |||
1560 | update_cfs_load(cfs_rq, 0); | 1640 | update_cfs_load(cfs_rq, 0); |
1561 | update_cfs_shares(cfs_rq); | 1641 | update_cfs_shares(cfs_rq); |
1562 | } | 1642 | } |
1563 | 1643 | ||
1564 | dec_nr_running(rq); | 1644 | if (!se) |
1645 | dec_nr_running(rq); | ||
1565 | hrtick_update(rq); | 1646 | hrtick_update(rq); |
1566 | } | 1647 | } |
1567 | 1648 | ||