[Devel] [PATCH RHEL8 COMMIT] kernel/stat: Introduce kernel_cpustat operation wrappers
Konstantin Khorenko
khorenko at virtuozzo.com
Tue Nov 3 16:00:02 MSK 2020
The commit is pushed to "branch-rh8-4.18.0-193.6.3.vz8.4.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-193.6.3.vz8.4.15
------>
commit 851926bdeb67516d0673e8582accc6a396c716ee
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date: Wed Oct 28 14:08:19 2020 +0300
kernel/stat: Introduce kernel_cpustat operation wrappers
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
Reviewed-by: Andrey Ryabinin <aryabinin at 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 7ee2bb43b251..47b75b4be3d5 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];
More information about the Devel
mailing list