Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_racct.c
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | |||||
static uma_zone_t racct_zone; | static uma_zone_t racct_zone; | ||||
static void racct_sub_racct(struct racct *dest, const struct racct *src); | static void racct_sub_racct(struct racct *dest, const struct racct *src); | ||||
static void racct_sub_cred_locked(struct ucred *cred, int resource, | static void racct_sub_cred_locked(struct ucred *cred, int resource, | ||||
uint64_t amount); | uint64_t amount); | ||||
static void racct_add_cred_locked(struct ucred *cred, int resource, | static void racct_add_cred_locked(struct ucred *cred, int resource, | ||||
uint64_t amount); | uint64_t amount); | ||||
static uint64_t racct_estimate_pcpu(uint64_t runtime, struct timeval *wallclock); | |||||
SDT_PROVIDER_DEFINE(racct); | SDT_PROVIDER_DEFINE(racct); | ||||
SDT_PROBE_DEFINE3(racct, , rusage, add, | SDT_PROBE_DEFINE3(racct, , rusage, add, | ||||
"struct proc *", "int", "uint64_t"); | "struct proc *", "int", "uint64_t"); | ||||
SDT_PROBE_DEFINE3(racct, , rusage, add__failure, | SDT_PROBE_DEFINE3(racct, , rusage, add__failure, | ||||
"struct proc *", "int", "uint64_t"); | "struct proc *", "int", "uint64_t"); | ||||
SDT_PROBE_DEFINE3(racct, , rusage, add__buf, | SDT_PROBE_DEFINE3(racct, , rusage, add__buf, | ||||
"struct proc *", "const struct buf *", "int"); | "struct proc *", "const struct buf *", "int"); | ||||
SDT_PROBE_DEFINE3(racct, , rusage, add__cred, | SDT_PROBE_DEFINE3(racct, , rusage, add__cred, | ||||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | fixpt_t ccpu_exp[] = { | ||||
[108] = FSCALE * 0.00451658094261266798, | [108] = FSCALE * 0.00451658094261266798, | ||||
[109] = FSCALE * 0.00429630469075234057, | [109] = FSCALE * 0.00429630469075234057, | ||||
[110] = FSCALE * 0.00408677143846406699, | [110] = FSCALE * 0.00408677143846406699, | ||||
}; | }; | ||||
#endif | #endif | ||||
#define CCPU_EXP_MAX 110 | #define CCPU_EXP_MAX 110 | ||||
static uint64_t | |||||
racct_estimate_pcpu(uint64_t runtime, struct timeval *wallclock) | |||||
{ | |||||
if (wallclock->tv_sec > 0 || wallclock->tv_usec > 0) { | |||||
return ((runtime * 100) / | |||||
((uint64_t)wallclock->tv_sec * 1000000 + | |||||
wallclock->tv_usec)); | |||||
} else | |||||
return (0); | |||||
markj: Style: missing parens around the return value. | |||||
} | |||||
/* | /* | ||||
* This function is analogical to the getpcpu() function in the ps(1) command. | * This function is analogical to the getpcpu() function in the ps(1) command. | ||||
* They should both calculate in the same way so that the racct %cpu | * They should both calculate in the same way so that the racct %cpu | ||||
* calculations are consistent with the values showed by the ps(1) tool. | * calculations are consistent with the values showed by the ps(1) tool. | ||||
* The calculations are more complex in the 4BSD scheduler because of the value | * The calculations are more complex in the 4BSD scheduler because of the value | ||||
* of the ccpu variable. In ULE it is defined to be zero which saves us some | * of the ccpu variable. In ULE it is defined to be zero which saves us some | ||||
* work. | * work. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 681 Lines • ▼ Show 20 Lines | |||||
#ifdef notyet | #ifdef notyet | ||||
KASSERT(runtime >= p->p_prev_runtime, ("runtime < p_prev_runtime")); | KASSERT(runtime >= p->p_prev_runtime, ("runtime < p_prev_runtime")); | ||||
#else | #else | ||||
if (runtime < p->p_prev_runtime) | if (runtime < p->p_prev_runtime) | ||||
runtime = p->p_prev_runtime; | runtime = p->p_prev_runtime; | ||||
#endif | #endif | ||||
microuptime(&wallclock); | microuptime(&wallclock); | ||||
timevalsub(&wallclock, &p->p_stats->p_start); | timevalsub(&wallclock, &p->p_stats->p_start); | ||||
if (wallclock.tv_sec > 0 || wallclock.tv_usec > 0) { | pct_estimate = racct_estimate_pcpu(runtime, &wallclock); | ||||
pct_estimate = (1000000 * runtime * 100) / | |||||
((uint64_t)wallclock.tv_sec * 1000000 + | |||||
wallclock.tv_usec); | |||||
} else | |||||
pct_estimate = 0; | |||||
pct = racct_getpcpu(p, pct_estimate); | pct = racct_getpcpu(p, pct_estimate); | ||||
RACCT_LOCK(); | RACCT_LOCK(); | ||||
racct_set_locked(p, RACCT_CPU, runtime, 0); | racct_set_locked(p, RACCT_CPU, runtime, 0); | ||||
racct_add_cred_locked(p->p_ucred, RACCT_PCTCPU, pct); | racct_add_cred_locked(p->p_ucred, RACCT_PCTCPU, pct); | ||||
KASSERT(p->p_racct->r_resources[RACCT_RSS] == 0, | KASSERT(p->p_racct->r_resources[RACCT_RSS] == 0, | ||||
("process reaped with %ju allocated for RSS\n", | ("process reaped with %ju allocated for RSS\n", | ||||
▲ Show 20 Lines • Show All 248 Lines • ▼ Show 20 Lines | |||||
#ifdef notyet | #ifdef notyet | ||||
KASSERT(runtime >= p->p_prev_runtime, | KASSERT(runtime >= p->p_prev_runtime, | ||||
("runtime < p_prev_runtime")); | ("runtime < p_prev_runtime")); | ||||
#else | #else | ||||
if (runtime < p->p_prev_runtime) | if (runtime < p->p_prev_runtime) | ||||
runtime = p->p_prev_runtime; | runtime = p->p_prev_runtime; | ||||
#endif | #endif | ||||
p->p_prev_runtime = runtime; | p->p_prev_runtime = runtime; | ||||
if (wallclock.tv_sec > 0 || wallclock.tv_usec > 0) { | pct_estimate = racct_estimate_pcpu(runtime, &wallclock); | ||||
pct_estimate = (1000000 * runtime * 100) / | |||||
((uint64_t)wallclock.tv_sec * 1000000 + | |||||
wallclock.tv_usec); | |||||
} else | |||||
pct_estimate = 0; | |||||
pct = racct_getpcpu(p, pct_estimate); | pct = racct_getpcpu(p, pct_estimate); | ||||
RACCT_LOCK(); | RACCT_LOCK(); | ||||
#ifdef RCTL | #ifdef RCTL | ||||
rctl_throttle_decay(p->p_racct, RACCT_READBPS); | rctl_throttle_decay(p->p_racct, RACCT_READBPS); | ||||
rctl_throttle_decay(p->p_racct, RACCT_WRITEBPS); | rctl_throttle_decay(p->p_racct, RACCT_WRITEBPS); | ||||
rctl_throttle_decay(p->p_racct, RACCT_READIOPS); | rctl_throttle_decay(p->p_racct, RACCT_READIOPS); | ||||
rctl_throttle_decay(p->p_racct, RACCT_WRITEIOPS); | rctl_throttle_decay(p->p_racct, RACCT_WRITEIOPS); | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |
Style: missing parens around the return value.