public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Sascha Westermann via pve-devel <pve-devel@lists.proxmox.com>
To: Daniel Kral <d.kral@proxmox.com>,
	Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Cc: Sascha Westermann <sascha.westermann@hl-services.de>
Subject: Re: [pve-devel] [PATCH pve-manager 2/3] Fix #5708: Add CPU raw counters
Date: Mon, 30 Sep 2024 08:17:32 +0200	[thread overview]
Message-ID: <mailman.153.1727769306.332.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <69e71cf0-a8c4-42a6-a1a5-36024e903687@proxmox.com>

[-- Attachment #1: Type: message/rfc822, Size: 14165 bytes --]

[-- Attachment #1.1.1: Type: text/plain, Size: 2315 bytes --]

If the data is also to be processed by external metric servers, I think
the integration in `PVE::ProcFSTools::read_proc_stat()` makes sense. The
term `cpustat` would no longer conflict in this case, as the content
would be virtually the same. I would create a new patch series for this,
but when looking at `read_proc_stat` a few questions arose for me:

> sub read_proc_stat {
>     my $res = { user => 0, nice => 0, system => 0, idle => 0 , iowait => 0, irq => 0, softirq => 0, steal => 0, guest => 0, guest_nice => 0, sum => 0};

In order to remain consistent with the structure, the same fields per
CPU would also need to be initialized with 0. However, this is only
done when I find an entry of the form cpu<num>, which implicitly gives
me values - so the initialization would not do anything. In this
context, I wonder whether there are any situations where no values can
be set? I would actually say that this is not the case and that the
initialization can be removed.

Side note: `sum` is not used, it probably means `total`, right?

>    if (my $fh = IO::File->new ("/proc/stat", "r")) {
>	while (defined (my $line = <$fh>)) {
>	    if ($line =~ m|^cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)(?:\s+(\d+)\s+(\d+))?|) {
>		$res->{user} = $1 - ($9 // 0);
>		$res->{nice} = $2 - ($10 // 0);
>		$res->{system} = $3;

`user` contains `guest` and `nice` contains `guest_nice`, so I
understand that the values are subtracted. Wouldn't it be better to use
the original values here? Especially when these are passed out as raw
values via API, it would certainly be helpful if they correspond 1:1
with the documentation from /proc/stat.

The values are output as a string in the JSON output. Is there anything
against casting them to int?

>    my $diff = ($ctime - $last_proc_stat->{ctime}) * $clock_ticks * $cpucount;
>
>    if ($diff > 1000) { # don't update too often

I don't understand the condition. `$ctime - $last_proc_stat->{ctime}`
corresponds to the elapsed time in seconds as a float, `clock_ticks`
would normally be 100. So that would mean that on a system with one CPU
core an update may only take place every 10 seconds, but with 8 cores
every 1.25 seconds? Is that an error? Is it even necessary to suppress
updates if $diff > 0?

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

  parent reply	other threads:[~2024-10-01  7:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240917055020.10507-1-sascha.westermann@hl-services.de>
2024-09-17  5:50 ` [pve-devel] [PATCH pve-common 1/3] " Sascha Westermann via pve-devel
2024-09-17  5:50 ` [pve-devel] [PATCH pve-manager 2/3] " Sascha Westermann via pve-devel
2024-09-24 12:25   ` Daniel Kral
2024-09-24 14:00     ` Lukas Wagner
2024-09-30  6:17     ` Sascha Westermann via pve-devel [this message]
     [not found]     ` <63c737f2-21cd-4fff-bf86-2369de65f886@hl-services.de>
2024-10-03  9:40       ` Daniel Kral
2024-09-17  5:50 ` [pve-devel] [PATCH qemu-server 3/3] " Sascha Westermann via pve-devel
2024-09-24 12:25   ` Daniel Kral

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mailman.153.1727769306.332.pve-devel@lists.proxmox.com \
    --to=pve-devel@lists.proxmox.com \
    --cc=d.kral@proxmox.com \
    --cc=sascha.westermann@hl-services.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal