diff options
Diffstat (limited to 'kernel/sched_fair.c')
| -rw-r--r-- | kernel/sched_fair.c | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c index 0566f2a03c42..3816f217f119 100644 --- a/kernel/sched_fair.c +++ b/kernel/sched_fair.c | |||
| @@ -1314,16 +1314,63 @@ out: | |||
| 1314 | } | 1314 | } |
| 1315 | #endif /* CONFIG_SMP */ | 1315 | #endif /* CONFIG_SMP */ |
| 1316 | 1316 | ||
| 1317 | static unsigned long wakeup_gran(struct sched_entity *se) | 1317 | /* |
| 1318 | * Adaptive granularity | ||
| 1319 | * | ||
| 1320 | * se->avg_wakeup gives the average time a task runs until it does a wakeup, | ||
| 1321 | * with the limit of wakeup_gran -- when it never does a wakeup. | ||
| 1322 | * | ||
| 1323 | * So the smaller avg_wakeup is the faster we want this task to preempt, | ||
| 1324 | * but we don't want to treat the preemptee unfairly and therefore allow it | ||
| 1325 | * to run for at least the amount of time we'd like to run. | ||
| 1326 | * | ||
| 1327 | * NOTE: we use 2*avg_wakeup to increase the probability of actually doing one | ||
| 1328 | * | ||
| 1329 | * NOTE: we use *nr_running to scale with load, this nicely matches the | ||
| 1330 | * degrading latency on load. | ||
| 1331 | */ | ||
| 1332 | static unsigned long | ||
| 1333 | adaptive_gran(struct sched_entity *curr, struct sched_entity *se) | ||
| 1334 | { | ||
| 1335 | u64 this_run = curr->sum_exec_runtime - curr->prev_sum_exec_runtime; | ||
| 1336 | u64 expected_wakeup = 2*se->avg_wakeup * cfs_rq_of(se)->nr_running; | ||
| 1337 | u64 gran = 0; | ||
| 1338 | |||
| 1339 | if (this_run < expected_wakeup) | ||
| 1340 | gran = expected_wakeup - this_run; | ||
| 1341 | |||
| 1342 | return min_t(s64, gran, sysctl_sched_wakeup_granularity); | ||
| 1343 | } | ||
| 1344 | |||
| 1345 | static unsigned long | ||
| 1346 | wakeup_gran(struct sched_entity *curr, struct sched_entity *se) | ||
| 1318 | { | 1347 | { |
| 1319 | unsigned long gran = sysctl_sched_wakeup_granularity; | 1348 | unsigned long gran = sysctl_sched_wakeup_granularity; |
| 1320 | 1349 | ||
| 1350 | if (cfs_rq_of(curr)->curr && sched_feat(ADAPTIVE_GRAN)) | ||
| 1351 | gran = adaptive_gran(curr, se); | ||
| 1352 | |||
| 1321 | /* | 1353 | /* |
| 1322 | * More easily preempt - nice tasks, while not making it harder for | 1354 | * Since its curr running now, convert the gran from real-time |
| 1323 | * + nice tasks. | 1355 | * to virtual-time in his units. |
| 1324 | */ | 1356 | */ |
| 1325 | if (!sched_feat(ASYM_GRAN) || se->load.weight > NICE_0_LOAD) | 1357 | if (sched_feat(ASYM_GRAN)) { |
| 1326 | gran = calc_delta_fair(sysctl_sched_wakeup_granularity, se); | 1358 | /* |
| 1359 | * By using 'se' instead of 'curr' we penalize light tasks, so | ||
| 1360 | * they get preempted easier. That is, if 'se' < 'curr' then | ||
| 1361 | * the resulting gran will be larger, therefore penalizing the | ||
| 1362 | * lighter, if otoh 'se' > 'curr' then the resulting gran will | ||
| 1363 | * be smaller, again penalizing the lighter task. | ||
| 1364 | * | ||
| 1365 | * This is especially important for buddies when the leftmost | ||
| 1366 | * task is higher priority than the buddy. | ||
| 1367 | */ | ||
| 1368 | if (unlikely(se->load.weight != NICE_0_LOAD)) | ||
| 1369 | gran = calc_delta_fair(gran, se); | ||
| 1370 | } else { | ||
| 1371 | if (unlikely(curr->load.weight != NICE_0_LOAD)) | ||
| 1372 | gran = calc_delta_fair(gran, curr); | ||
| 1373 | } | ||
| 1327 | 1374 | ||
| 1328 | return gran; | 1375 | return gran; |
| 1329 | } | 1376 | } |
| @@ -1350,7 +1397,7 @@ wakeup_preempt_entity(struct sched_entity *curr, struct sched_entity *se) | |||
| 1350 | if (vdiff <= 0) | 1397 | if (vdiff <= 0) |
| 1351 | return -1; | 1398 | return -1; |
| 1352 | 1399 | ||
| 1353 | gran = wakeup_gran(curr); | 1400 | gran = wakeup_gran(curr, se); |
| 1354 | if (vdiff > gran) | 1401 | if (vdiff > gran) |
| 1355 | return 1; | 1402 | return 1; |
| 1356 | 1403 | ||
