MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rctl_pcpu_available

Function rctl_pcpu_available

freebsd/kern/kern_rctl.c:426–464  ·  view source on GitHub ↗

* Special version of rctl_get_available() for the %CPU resource. * We slightly cheat here and return less than we normally would. */

Source from the content-addressed store, hash-verified

424 * We slightly cheat here and return less than we normally would.
425 */
426int64_t
427rctl_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
466static uint64_t
467xadd(uint64_t a, uint64_t b)

Callers 1

racct_pcpu_availableFunction · 0.85

Calls 1

rctl_available_resourceFunction · 0.85

Tested by

no test coverage detected