* Special version of rctl_get_available() for the %CPU resource. * We slightly cheat here and return less than we normally would. */
| 424 | * We slightly cheat here and return less than we normally would. |
| 425 | */ |
| 426 | int64_t |
| 427 | rctl_pcpu_available(const struct proc *p) { |
| 428 | struct rctl_rule *rule; |
| 429 | struct rctl_rule_link *link; |
| 430 | int64_t available, minavailable, limit; |
| 431 | |
| 432 | ASSERT_RACCT_ENABLED(); |
| 433 | RACCT_LOCK_ASSERT(); |
| 434 | |
| 435 | minavailable = INT64_MAX; |
| 436 | limit = 0; |
| 437 | |
| 438 | LIST_FOREACH(link, &p->p_racct->r_rule_links, rrl_next) { |
| 439 | rule = link->rrl_rule; |
| 440 | if (rule->rr_resource != RACCT_PCTCPU) |
| 441 | continue; |
| 442 | if (rule->rr_action != RCTL_ACTION_DENY) |
| 443 | continue; |
| 444 | available = rctl_available_resource(p, rule); |
| 445 | if (available < minavailable) { |
| 446 | minavailable = available; |
| 447 | limit = rule->rr_amount; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | /* |
| 452 | * Return slightly less than actual value of the available |
| 453 | * %cpu resource. This makes %cpu throttling more aggressive |
| 454 | * and lets us act sooner than the limits are already exceeded. |
| 455 | */ |
| 456 | if (limit != 0) { |
| 457 | if (limit > 2 * RCTL_PCPU_SHIFT) |
| 458 | minavailable -= RCTL_PCPU_SHIFT; |
| 459 | else |
| 460 | minavailable -= (limit / 2); |
| 461 | } |
| 462 | |
| 463 | return (minavailable); |
| 464 | } |
| 465 | |
| 466 | static uint64_t |
| 467 | xadd(uint64_t a, uint64_t b) |
no test coverage detected