qga-win32-pull-2022-07-13
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEwsLBCepDxjwUI+uE711egWG6hOcFAmLOmswACgkQ711egWG6 hOcnlA/+JejQ1F/Xhmi8b4KWE/U1+G8CbhOmk69XzLO+TsG5hmrPXr/oCtK/DMK8 raWFnoEmSR03X0T6vwLJxcmS+m+FaC7Bpfq+BYbqmWKvO5SvA6/CPkyBszEgOwTd ufLjy5UZTXmeMneJdpKGm24E6AGr8SJSZEc/18SH4Na8LTt5muS1OniwvSBQCRrQ /vO/E1njV+fvRFVkKKmu3Wridb9A8KL7/K6jmbsdmubOHAVJfGVvzyVonCR1MyTH 4qODKuvQT7Jo4XTekx8CcdRPFRSrvfq85tXp+pi80prnRmUZOTbMwD7+6jC3DM4n 6r79CLzn39oZppDgupIdizwhI2f482UUu0Gs1c1VVP3grEB3LsdDZbNwFESuOSgm 7+/P88HmqueKKokK6T6EcGHyBqBbx3FjG0efuNPGCc2uE24sCA6x/PZL78psczfI uNhd8waZE7LVNAu2cbWmtWxqxuR8pxrnar9H2u/gwoq2yIKWOi4fCPyozwFfSFOs /8f3rpuBETNw9JR3Pb96BeLGEetBGZIBvDSGHvJhB9EgBtrngdZ/fOQMDOdErROS ujx4JvT3hBwZllt12vJ0ABxUFh8A/Usu8mN0+1mildfp/v+nA+kF0tHd4CH26Uul z6NywOc4HAdXPzURH0m51fTC0RoVTcO6r8iH7QrTQxEOS7r75j4= =qtih -----END PGP SIGNATURE----- Merge tag 'qga-win32-pull-2022-07-13' of github.com:kostyanf14/qemu into staging qga-win32-pull-2022-07-13 # gpg: Signature made Wed 13 Jul 2022 11:13:32 BST # gpg: using RSA key C2C2C109EA43C63C1423EB84EF5D5E8161BA84E7 # gpg: Good signature from "Kostiantyn Kostiuk (Upstream PR sign) <kkostiuk@redhat.com>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: C2C2 C109 EA43 C63C 1423 EB84 EF5D 5E81 61BA 84E7 * tag 'qga-win32-pull-2022-07-13' of github.com:kostyanf14/qemu: qga: add command 'guest-get-cpustats' qapi: Avoid generating C identifier 'linux' MAINTAINERS: Add myself as Guest Agent reviewer Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
8482ab545e
@ -2880,6 +2880,7 @@ T: git https://repo.or.cz/qemu/armbru.git qapi-next
|
||||
|
||||
QEMU Guest Agent
|
||||
M: Michael Roth <michael.roth@amd.com>
|
||||
R: Konstantin Kostiuk <kkostiuk@redhat.com>
|
||||
S: Maintained
|
||||
F: qga/
|
||||
F: docs/interop/qemu-ga.rst
|
||||
|
@ -2893,6 +2893,90 @@ GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp)
|
||||
return guest_get_diskstats(errp);
|
||||
}
|
||||
|
||||
GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp)
|
||||
{
|
||||
GuestCpuStatsList *head = NULL, **tail = &head;
|
||||
const char *cpustats = "/proc/stat";
|
||||
int clk_tck = sysconf(_SC_CLK_TCK);
|
||||
FILE *fp;
|
||||
size_t n;
|
||||
char *line = NULL;
|
||||
|
||||
fp = fopen(cpustats, "r");
|
||||
if (fp == NULL) {
|
||||
error_setg_errno(errp, errno, "open(\"%s\")", cpustats);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (getline(&line, &n, fp) != -1) {
|
||||
GuestCpuStats *cpustat = NULL;
|
||||
GuestLinuxCpuStats *linuxcpustat;
|
||||
int i;
|
||||
unsigned long user, system, idle, iowait, irq, softirq, steal, guest;
|
||||
unsigned long nice, guest_nice;
|
||||
char name[64];
|
||||
|
||||
i = sscanf(line, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
|
||||
name, &user, &nice, &system, &idle, &iowait, &irq, &softirq,
|
||||
&steal, &guest, &guest_nice);
|
||||
|
||||
/* drop "cpu 1 2 3 ...", get "cpuX 1 2 3 ..." only */
|
||||
if ((i == EOF) || strncmp(name, "cpu", 3) || (name[3] == '\0')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i < 5) {
|
||||
slog("Parsing cpu stat from %s failed, see \"man proc\"", cpustats);
|
||||
break;
|
||||
}
|
||||
|
||||
cpustat = g_new0(GuestCpuStats, 1);
|
||||
cpustat->type = GUEST_CPU_STATS_TYPE_LINUX;
|
||||
|
||||
linuxcpustat = &cpustat->u.q_linux;
|
||||
linuxcpustat->cpu = atoi(&name[3]);
|
||||
linuxcpustat->user = user * 1000 / clk_tck;
|
||||
linuxcpustat->nice = nice * 1000 / clk_tck;
|
||||
linuxcpustat->system = system * 1000 / clk_tck;
|
||||
linuxcpustat->idle = idle * 1000 / clk_tck;
|
||||
|
||||
if (i > 5) {
|
||||
linuxcpustat->has_iowait = true;
|
||||
linuxcpustat->iowait = iowait * 1000 / clk_tck;
|
||||
}
|
||||
|
||||
if (i > 6) {
|
||||
linuxcpustat->has_irq = true;
|
||||
linuxcpustat->irq = irq * 1000 / clk_tck;
|
||||
linuxcpustat->has_softirq = true;
|
||||
linuxcpustat->softirq = softirq * 1000 / clk_tck;
|
||||
}
|
||||
|
||||
if (i > 8) {
|
||||
linuxcpustat->has_steal = true;
|
||||
linuxcpustat->steal = steal * 1000 / clk_tck;
|
||||
}
|
||||
|
||||
if (i > 9) {
|
||||
linuxcpustat->has_guest = true;
|
||||
linuxcpustat->guest = guest * 1000 / clk_tck;
|
||||
}
|
||||
|
||||
if (i > 10) {
|
||||
linuxcpustat->has_guest = true;
|
||||
linuxcpustat->guest = guest * 1000 / clk_tck;
|
||||
linuxcpustat->has_guestnice = true;
|
||||
linuxcpustat->guestnice = guest_nice * 1000 / clk_tck;
|
||||
}
|
||||
|
||||
QAPI_LIST_APPEND(tail, cpustat);
|
||||
}
|
||||
|
||||
free(line);
|
||||
fclose(fp);
|
||||
return head;
|
||||
}
|
||||
|
||||
#else /* defined(__linux__) */
|
||||
|
||||
void qmp_guest_suspend_disk(Error **errp)
|
||||
@ -3247,6 +3331,11 @@ GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp)
|
||||
{
|
||||
error_setg(errp, QERR_UNSUPPORTED);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_FSFREEZE */
|
||||
|
||||
|
@ -2543,3 +2543,9 @@ GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp)
|
||||
error_setg(errp, QERR_UNSUPPORTED);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp)
|
||||
{
|
||||
error_setg(errp, QERR_UNSUPPORTED);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1576,3 +1576,84 @@
|
||||
{ 'command': 'guest-get-diskstats',
|
||||
'returns': ['GuestDiskStatsInfo']
|
||||
}
|
||||
|
||||
##
|
||||
# @GuestCpuStatsType:
|
||||
#
|
||||
# An enumeration of OS type
|
||||
#
|
||||
# Since: 7.1
|
||||
##
|
||||
{ 'enum': 'GuestCpuStatsType',
|
||||
'data': [ 'linux' ] }
|
||||
|
||||
|
||||
##
|
||||
# @GuestLinuxCpuStats:
|
||||
#
|
||||
# CPU statistics of Linux
|
||||
#
|
||||
# @cpu: CPU index in guest OS
|
||||
#
|
||||
# @user: Time spent in user mode
|
||||
#
|
||||
# @nice: Time spent in user mode with low priority (nice)
|
||||
#
|
||||
# @system: Time spent in system mode
|
||||
#
|
||||
# @idle: Time spent in the idle task
|
||||
#
|
||||
# @iowait: Time waiting for I/O to complete (since Linux 2.5.41)
|
||||
#
|
||||
# @irq: Time servicing interrupts (since Linux 2.6.0-test4)
|
||||
#
|
||||
# @softirq: Time servicing softirqs (since Linux 2.6.0-test4)
|
||||
#
|
||||
# @steal: Stolen time by host (since Linux 2.6.11)
|
||||
#
|
||||
# @guest: ime spent running a virtual CPU for guest operating systems under
|
||||
# the control of the Linux kernel (since Linux 2.6.24)
|
||||
#
|
||||
# @guestnice: Time spent running a niced guest (since Linux 2.6.33)
|
||||
#
|
||||
# Since: 7.1
|
||||
##
|
||||
{ 'struct': 'GuestLinuxCpuStats',
|
||||
'data': {'cpu': 'int',
|
||||
'user': 'uint64',
|
||||
'nice': 'uint64',
|
||||
'system': 'uint64',
|
||||
'idle': 'uint64',
|
||||
'*iowait': 'uint64',
|
||||
'*irq': 'uint64',
|
||||
'*softirq': 'uint64',
|
||||
'*steal': 'uint64',
|
||||
'*guest': 'uint64',
|
||||
'*guestnice': 'uint64'
|
||||
} }
|
||||
|
||||
##
|
||||
# @GuestCpuStats:
|
||||
#
|
||||
# Get statistics of each CPU in millisecond.
|
||||
#
|
||||
# - @linux: Linux style CPU statistics
|
||||
#
|
||||
# Since: 7.1
|
||||
##
|
||||
{ 'union': 'GuestCpuStats',
|
||||
'base': { 'type': 'GuestCpuStatsType' },
|
||||
'discriminator': 'type',
|
||||
'data': { 'linux': 'GuestLinuxCpuStats' } }
|
||||
|
||||
##
|
||||
# @guest-get-cpustats:
|
||||
#
|
||||
# Retrieve information about CPU stats.
|
||||
# Returns: List of CPU stats of guest.
|
||||
#
|
||||
# Since: 7.1
|
||||
##
|
||||
{ 'command': 'guest-get-cpustats',
|
||||
'returns': ['GuestCpuStats']
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ def c_name(name: str, protect: bool = True) -> str:
|
||||
'and', 'and_eq', 'bitand', 'bitor', 'compl', 'not',
|
||||
'not_eq', 'or', 'or_eq', 'xor', 'xor_eq'])
|
||||
# namespace pollution:
|
||||
polluted_words = set(['unix', 'errno', 'mips', 'sparc', 'i386'])
|
||||
polluted_words = set(['unix', 'errno', 'mips', 'sparc', 'i386', 'linux'])
|
||||
name = re.sub(r'[^A-Za-z0-9_]', '_', name)
|
||||
if protect and (name in (c89_words | c99_words | c11_words | gcc_words
|
||||
| cpp_words | polluted_words)
|
||||
|
Loading…
Reference in New Issue
Block a user