Open
support displaying bandwidth information #99
support displaying bandwidth information #99
Open
hailianguniontechAdd on Aug 25
Total: 2 files changed+686-1
@@ -0,0 +1,681 @@
1+From 1f72eca9331b308b0bafbd9e095381c684f9df5a Mon Sep 17 00:00:00 2001
2+From: hy <941973499@qq.com>
3+Date: Mon, 25 Aug 2025 21:22:55 +0800
4+Subject: [PATCH] support displaying bandwidth information
5+ 
6+---
7+ src/Makefile.am | 4 +-
8+ src/domain.c | 67 ++++++++++++++++
9+ src/domain.h | 3 +
10+ src/field.c | 26 ++++++-
11+ src/field.h | 18 +++++
12+ src/resctrl.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++++
13+ src/resctrl.h | 47 +++++++++++
14+ src/type.h | 5 ++
15+ src/utils.c | 1 +
16+ src/utils.h | 2 +
17+ src/vmtop.c | 57 +++++++++++++-
18+ 11 files changed, 426 insertions(+), 5 deletions(-)
19+ create mode 100644 src/resctrl.c
20+ create mode 100644 src/resctrl.h
21+ 
22+diff --git a/src/Makefile.am b/src/Makefile.am
23+index 24a8016..fe9bfba 100644
24+--- a/src/Makefile.am
25++++ b/src/Makefile.am
26+@@ -8,4 +8,6 @@ libdomain_a_SOURCES= \
27+ vcpu_stat.c \
28+ vcpu_stat.h \
29+ utils.c \
30+- utils.h
31++ utils.h \
32++ resctrl.c \
33++ resctrl.h
34+diff --git a/src/domain.c b/src/domain.c
35+index 977cabe..859c72d 100644
36+--- a/src/domain.c
37++++ b/src/domain.c
38+@@ -19,6 +19,7 @@
39+ #include "utils.h"
40+ #include "proc.h"
41+ #include "vcpu_stat.h"
42++#include "resctrl.h"
43+
44+ #define VAR_RUN_QEMU_PATH "/var/run/libvirt/qemu"
45+ #define PID_STRING_MAX 12
46+@@ -33,7 +34,12 @@ void init_domains(struct domain_list *list)
47+ {
48+ list->domains = NULL;
49+ list->num = 0;
50++
51++ for (int i = 0; i < MAX_NODE_NUM; i++) {
52++ list->bandwidth[i] = 0;
53++ }
54+ }
55++
56+ void clear_domains(struct domain_list *list)
57+ {
58+ for (int i = 0; i < list->num; i++) {
59+@@ -306,6 +312,67 @@ int refresh_domains(struct domain_list *now, struct domain_list *pre)
60+ return num;
61+ }
62+
63++static void calculate_all_bandwidth(struct domain_list *now,
64++ int *sample_times_vms, int sample_times_host)
65++{
66++ unsigned int node_vms;
67++ struct domain *dom;
68++ int i, node;
69++
70++ for (node = 0; node < now->node_num; node++) {
71++ if (sample_times_host > 0) {
72++ now->bandwidth[node] /= sample_times_host;
73++ }
74++ node_vms = 0;
75++
76++ for (i = 0; i < now->num; i++) {
77++ if (sample_times_vms[i] > 0) {
78++ dom = &now->domains[i];
79++ dom->ctl_bandwidth[node] /= sample_times_vms[i];
80++ dom->bandwidth_updated_succ = 1;
81++
82++ now->bandwidth[node] += dom->ctl_bandwidth[node];
83++ node_vms += dom->ctl_bandwidth[node];
84++ }
85++ }
86++
87++ /* fix if host bandwidth less tahn all VMs */
88++ if (now->bandwidth[node] < node_vms) {
89++ now->bandwidth[node] = node_vms;
90++ }
91++ }
92++}
93++
94++void refresh_domains_bandwidth(struct domain_list *now, struct domain_list *pre)
95++{
96++ int sample_times_vms[MAX_VM_TASKS_NUM] = {0};
97++ int r, sample_times_host = 0;
98++
99++ if (get_numa_num(&now->node_num) < 0) {
100++ return;
@@ -1,6 +1,6 @@
1Name: vmtop1Name: vmtop
2Version: 1.12Version: 1.1
3-Release: 93+Release: 10
4Summary: A tool for collecting and analyzing data of virtual machine4Summary: A tool for collecting and analyzing data of virtual machine
5License: MulanPSL-2.05License: MulanPSL-2.0
6Group: Application/System6Group: Application/System
@@ -40,6 +40,7 @@ Patch0029: proc-del-loop-sscanf-for-proc-pid-stat-file.patch
40Patch0030: utils-del-realpath-from-read_file.patch40Patch0030: utils-del-realpath-from-read_file.patch
41Patch0031: add-README.zh.md.-update-README.md.patch41Patch0031: add-README.zh.md.-update-README.md.patch
42Patch0032: bugfix-fixed-display-error-caused-by-missing-signal_exits.patch42Patch0032: bugfix-fixed-display-error-caused-by-missing-signal_exits.patch
43+Patch0033: support-displaying-bandwidth-information.patch
43 44 
44Requires: libvirt, ncurses45Requires: libvirt, ncurses
45 46 
@@ -80,6 +81,9 @@ install -m 550 vmtop ${RPM_BUILD_ROOT}/usr/bin/%{name}
80%{_bindir}/vmtop81%{_bindir}/vmtop
81 82 
82%changelog83%changelog
84+* Mon Sep 1 2025 huyu <huyu70@h-partners.com> - 1.1-10
85+- support displaying bandwidth information
86+ 
83* Thu Jun 19 2025 lutong <lutong14@huawei.com> - 1.1-987* Thu Jun 19 2025 lutong <lutong14@huawei.com> - 1.1-9
84- bugfix:fixed display error caused by missing signal_exits & revert change method of getting domain id88- bugfix:fixed display error caused by missing signal_exits & revert change method of getting domain id
85 89