From: Konstantin Khorenko <khore...@virtuozzo.com> Signed-off-by: Konstantin Khorenko <khore...@virtuozzo.com> Reviewed-by: Andrey Ryabinin <aryabi...@virtuozzo.com>
(cherry-picked from vz8 commit 93bea3d83126 ("kernel/stat: Introduce kernel_cpustat operation wrappers")) Signed-off-by: Nikita Yushchenko <nikita.yushche...@virtuozzo.com> --- include/linux/kernel_stat.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h index 44ae1a7eb9e3..fb6149076cc5 100644 --- a/include/linux/kernel_stat.h +++ b/include/linux/kernel_stat.h @@ -35,6 +35,42 @@ struct kernel_cpustat { u64 cpustat[NR_STATS]; }; +static inline u64 kernel_cpustat_total_usage(const struct kernel_cpustat *p) +{ + return p->cpustat[CPUTIME_USER] + p->cpustat[CPUTIME_NICE] + + p->cpustat[CPUTIME_SYSTEM]; +} + +static inline u64 kernel_cpustat_total_idle(const struct kernel_cpustat *p) +{ + return p->cpustat[CPUTIME_IDLE] + p->cpustat[CPUTIME_IOWAIT]; +} + +static inline void kernel_cpustat_zero(struct kernel_cpustat *p) +{ + memset(p, 0, sizeof(*p)); +} + +static inline void kernel_cpustat_add(const struct kernel_cpustat *lhs, + const struct kernel_cpustat *rhs, + struct kernel_cpustat *res) +{ + int i; + + for (i = 0; i < NR_STATS; i++) + res->cpustat[i] = lhs->cpustat[i] + rhs->cpustat[i]; +} + +static inline void kernel_cpustat_sub(const struct kernel_cpustat *lhs, + const struct kernel_cpustat *rhs, + struct kernel_cpustat *res) +{ + int i; + + for (i = 0; i < NR_STATS; i++) + res->cpustat[i] = lhs->cpustat[i] - rhs->cpustat[i]; +} + struct kernel_stat { unsigned long irqs_sum; unsigned int softirqs[NR_SOFTIRQS]; -- 2.30.2 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel