head 1.5; access; symbols pkgsrc-2023Q3:1.2.0.4 pkgsrc-2023Q3-base:1.2 pkgsrc-2023Q2:1.2.0.2 pkgsrc-2023Q2-base:1.2; locks; strict; comment @ * @; 1.5 date 2026.04.07.05.49.12; author fox; state Exp; branches; next 1.4; commitid MRNKzyeLJ8awnZAG; 1.4 date 2026.04.06.16.53.12; author fox; state Exp; branches; next 1.3; commitid Ai8SVPjWGKyh5VAG; 1.3 date 2023.10.18.08.53.08; author adam; state dead; branches; next 1.2; commitid qKZ2ZKZYIRAko5JE; 1.2 date 2023.04.18.22.14.58; author wiz; state Exp; branches; next 1.1; commitid pOaBEYU468t9IDlE; 1.1 date 2023.04.18.22.11.08; author wiz; state Exp; branches; next ; commitid qI3OgakHLTXQGDlE; desc @@ 1.5 log @sysutils/psutil: Remove dependency on kvm(3). Depend on uvm(9) sysctl to derive the values. @ text @$NetBSD: patch-psutil_arch_netbsd_cpu.c,v 1.4 2026/04/06 16:53:12 fox Exp $ Remove dependency on procfs. Upstream: https://github.com/giampaolo/psutil/pull/2805 --- psutil/arch/netbsd/cpu.c.orig 2025-11-06 17:44:47.000000000 +0000 +++ psutil/arch/netbsd/cpu.c @@@@ -22,7 +22,6 @@@@ original(ish) implementations: - CPU stats: a991494e4502e1235ebc62b5ba450287d0dedec0 (Jan 2016) */ - PyObject * psutil_cpu_stats(PyObject *self, PyObject *args) { struct uvmexp_sysctl uv; @@@@ -30,15 +29,16 @@@@ psutil_cpu_stats(PyObject *self, PyObjec if (psutil_sysctl(uvmexp_mib, 2, &uv, sizeof(uv)) != 0) return NULL; + return Py_BuildValue( - "IIIIIII", - uv.swtch, // ctx switches - uv.intrs, // interrupts - XXX always 0, will be determined via /proc - uv.softs, // soft interrupts - uv.syscalls, // syscalls - XXX always 0 - uv.traps, // traps - uv.faults, // faults - uv.forks // forks + "KKKKKKK", + (uint64_t)uv.swtch, // ctx switches + (uint64_t)uv.intrs, // interrupts (summed across CPUs by sysctl handler) + (uint64_t)uv.softs, // soft interrupts + (uint64_t)uv.syscalls, // syscalls - XXX always 0 + (uint64_t)uv.traps, // traps + (uint64_t)uv.faults, // faults + (uint64_t)uv.forks // forks ); } @ 1.4 log @sysutils/psutil: Patch to remove procfs dependency Replace procfs depdendency in the following sections - cpu stats calculation - memory usage calculation While here also handle EBUSY failures gracefully. @ text @d1 1 a1 1 $NetBSD$ d9 3 a11 2 @@@@ -6,6 +6,10 @@@@ */ a12 13 #include +#include +#include +#include +#include #include #include #include @@@@ -20,25 +24,59 @@@@ already) from cset 84219ad. For referenc original(ish) implementations: - per CPU times: 312442ad2a5b5d0c608476c5ab3e267735c3bc59 (Jan 2016) - CPU stats: a991494e4502e1235ebc62b5ba450287d0dedec0 (Jan 2016) -*/ a13 5 +Interrupts are now taken by reading the kvm_open and reading +the CPU counter there. We no longer need /proc/stat dependency. +- https://github.com/NetBSD/src/blob/trunk/sys/miscfs/procfs/procfs_linux.c#L342 +*/ d17 1 a17 3 int uvmexp_mib[] = {CTL_VM, VM_UVMEXP2}; + const int cpu_count_nintr = 3; + char errbuf[_POSIX2_LINE_MAX]; a21 29 + kvm_t *kd = kvm_open(NULL, NULL, NULL, O_RDONLY, errbuf); + if (!kd) { + fprintf(stderr, "kvm_open: %s\n", errbuf); + return NULL; + } + + struct nlist nl[] = { + { .n_name = "_cpu_counts" }, + { .n_name = NULL } + }; + + if (kvm_nlist(kd, nl) != 0 || nl[0].n_value == 0) { + fprintf(stderr, "kvm_nlist(_cpu_counts): %s\n", kvm_geterr(kd)); + kvm_close(kd); + return NULL; + } + + /* Read cpu_counts[CPU_COUNT_NINTR] — a single int64_t */ + uintptr_t addr = nl[0].n_value + cpu_count_nintr * sizeof(int64_t); + int64_t nintr = 0; + + if (kvm_read(kd, addr, &nintr, sizeof(nintr)) != sizeof(nintr)) { + fprintf(stderr, "kvm_read(cpu_counts[NINTR]): %s\n", kvm_geterr(kd)); + kvm_close(kd); + return NULL; + } + + kvm_close(kd); + d33 1 a33 1 + (uint64_t)nintr, // interrupts @ 1.3 log @py-psutil: updated to 5.9.6 5.9.6 ===== 2023-10-14 **Enhancements** - 1703_: `cpu_percent()`_ and `cpu_times_percent()`_ are now thread safe, meaning they can be called from different threads and still return meaningful and independent results. Before, if (say) 10 threads called ``cpu_percent(interval=None)`` at the same time, only 1 thread out of 10 would get the right result. - 2266_: if `Process`_ class is passed a very high PID, raise `NoSuchProcess`_ instead of OverflowError. (patch by Xuehai Pan) - 2246_: drop python 3.4 & 3.5 support. (patch by Matthieu Darbois) - 2290_: PID reuse is now pre-emptively checked for `Process.ppid()`_ and `Process.parents()`_. - 2312_: use ``ruff`` Python linter instead of ``flake8 + isort``. It's an order of magnitude faster + it adds a ton of new code quality checks. **Bug fixes** - 2195_, [Linux]: no longer print exception at import time in case /proc/stat can't be read due to permission error. Redirect it to ``PSUTIL_DEBUG`` instead. - 2241_, [NetBSD]: can't compile On NetBSD 10.99.3/amd64. (patch by Thomas Klausner) - 2245_, [Windows]: fix var unbound error on possibly in `swap_memory()`_ (patch by student_2333) - 2268_: ``bytes2human()`` utility function was unable to properly represent negative values. - 2252_, [Windows]: `disk_usage()`_ fails on Python 3.12+. (patch by Matthieu Darbois) - 2284_, [Linux]: `Process.memory_full_info()`_ may incorrectly raise `ZombieProcess`_ if it's determined via ``/proc/pid/smaps_rollup``. Instead we now fallback on reading ``/proc/pid/smaps``. - 2287_, [OpenBSD], [NetBSD]: `Process.is_running()`_ erroneously return ``False`` for zombie processes, because creation time cannot be determined. - 2288_, [Linux]: correctly raise `ZombieProcess`_ on `Process.exe()`_, `Process.cmdline()`_ and `Process.memory_maps()`_ instead of returning a "null" value. - 2290_: differently from what stated in the doc, PID reuse is not pre-emptively checked for `Process.nice()`_ (set), `Process.ionice()`_, (set), `Process.cpu_affinity()`_ (set), `Process.rlimit()`_ (set), `Process.parent()`_. - 2308_, [OpenBSD]: `Process.threads()`_ always fail with AccessDenied (also as root). @ text @d1 1 a1 1 $NetBSD: patch-psutil_arch_netbsd_cpu.c,v 1.2 2023/04/18 22:14:58 wiz Exp $ d3 1 a3 2 Add missing header. https://github.com/giampaolo/psutil/pull/2241 d5 3 a7 1 --- psutil/arch/netbsd/cpu.c.orig 2023-04-17 15:01:41.000000000 +0000 d9 1 a9 1 @@@@ -6,6 +6,7 @@@@ d13 5 a17 1 +#include d20 69 @ 1.2 log @py-psutil: add upstream pull request URL @ text @d1 1 a1 1 $NetBSD: patch-psutil_arch_netbsd_cpu.c,v 1.1 2023/04/18 22:11:08 wiz Exp $ @ 1.1 log @py-psutil: fix build on NetBSD @ text @d1 1 a1 1 $NetBSD$ d4 1 @