commit: eff05da8cc90c5451dc22e5bd5722220baeda5fd Author: Z. Liu <zhixu.liu <AT> gmail <DOT> com> AuthorDate: Thu Jul 24 10:21:00 2025 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Sat Oct 18 14:36:53 2025 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=eff05da8
sys-process/atop: enable support for nvidia gpu Signed-off-by: Z. Liu <zhixu.liu <AT> gmail.com> Part-of: https://github.com/gentoo/gentoo/pull/43138 Closes: https://github.com/gentoo/gentoo/pull/43138 Signed-off-by: Sam James <sam <AT> gentoo.org> sys-process/atop/atop-2.12.0-r1.ebuild | 150 ++++++++++++++++++++++ sys-process/atop/files/atop-2.12.0-atopgpud.patch | 112 ++++++++++++++++ sys-process/atop/files/atopgpud.initd | 12 ++ 3 files changed, 274 insertions(+) diff --git a/sys-process/atop/atop-2.12.0-r1.ebuild b/sys-process/atop/atop-2.12.0-r1.ebuild new file mode 100644 index 000000000000..8b1a6583307a --- /dev/null +++ b/sys-process/atop/atop-2.12.0-r1.ebuild @@ -0,0 +1,150 @@ +# Copyright 1999-2025 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +# Check on bumps of atop +# https://www.atoptool.nl/downloadnetatop.php +NETATOP_VER=3.2.2 + +# Controls 'netatop' kernel module +MODULES_OPTIONAL_IUSE="modules" +NETATOP_P=netatop-${NETATOP_VER} +NETATOP_S="${WORKDIR}"/${NETATOP_P} + +PYTHON_COMPAT=( python3_{11..14} ) + +inherit linux-mod-r1 python-single-r1 systemd toolchain-funcs flag-o-matic + +DESCRIPTION="Resource-specific view of processes" +HOMEPAGE="https://www.atoptool.nl/ https://github.com/Atoptool/atop" +SRC_URI="https://github.com/Atoptool/atop/releases/download/v${PV}/${P}.tar.gz" +SRC_URI+=" modules? ( https://www.atoptool.nl/download/${NETATOP_P}.tar.gz )" + +# Module is GPL-2 as well +LICENSE="GPL-2" +SLOT="0" +KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~mips ~ppc ~ppc64 ~riscv ~x86 ~amd64-linux ~x86-linux" +IUSE="video_cards_nvidia" +REQUIRED_USE="${PYTHON_REQUIRED_USE}" + +RDEPEND=" + dev-libs/glib + sys-libs/ncurses:= + sys-libs/zlib + >=sys-process/acct-6.6.4-r1 + amd64? ( video_cards_nvidia? ( + ${PYTHON_DEPS} + $(python_gen_cond_dep ' + dev-python/nvidia-ml-py[${PYTHON_USEDEP}] + ') + ) ) +" +DEPEND="${RDEPEND}" +BDEPEND="virtual/pkgconfig" + +PATCHES=( + "${FILESDIR}"/${PN}-2.11.0-build.patch + "${FILESDIR}"/${PN}-2.12.0-respect-opt.patch + "${FILESDIR}"/${PN}-2.12.0-atopgpud.patch +) + +pkg_setup() { + if use modules; then + linux-mod-r1_pkg_setup + fi + + if use amd64 && use video_cards_nvidia ; then + python-single-r1_pkg_setup + fi +} + +pkg_pretend() { + if use kernel_linux ; then + CONFIG_CHECK="~BSD_PROCESS_ACCT" + check_extra_config + fi +} + +src_prepare() { + append-cflags -std=gnu17 # bug 945250 + default + + if use modules ; then + cd "${WORKDIR}"/${NETATOP_P} || die + eapply "${FILESDIR}/netatop-3.2.2-strict-prototype.patch" + + sed \ + -e "s#\`uname -r\`#${KV_FULL}#g" \ + -e "s#\$(shell uname -r)#${KV_FULL}#g" \ + -i Makefile || die + + grep -rq "uname -r" && die "found uname calls" + + cd "${S}" || die + fi + + tc-export CC PKG_CONFIG + + # bug #191926 + sed -i 's: root : :' atop.cronsysv || die + + # Prefixify + sed -i "s:/\(usr\|etc\|var\):${EPREFIX}/\1:g" Makefile || die +} + +src_compile() { + default + + local modlist=( "netatop=:../${NETATOP_P}::netatop.ko" ) + linux-mod-r1_src_compile + + if use modules ; then + # Don't let the Makefile try to build the module for us + emake -C "${NETATOP_S}" netatopd + fi +} + +src_install() { + linux-mod-r1_src_install + + if use modules ; then + dosbin "${NETATOP_S}"/netatopd + doman "${NETATOP_S}"/man/* + + systemd_dounit "${NETATOP_S}"/netatop.service + + newinitd "${NETATOP_S}"/netatop.rc netatop + fi + + emake DESTDIR="${D}" genericinstall + + if use video_cards_nvidia ; then + systemd_dounit "${S}"/atopgpu.service + + newinitd "${FILESDIR}"/atopgpud.initd atopgpud + + python_fix_shebang ${ED}"/usr/sbin/atopgpud" + else + rm "${ED}"/usr/sbin/atopgpud || die + fi + + # useless -${PV} copies ? + rm "${ED}"/usr/bin/atop*-${PV} || die + + newinitd atop.rc.openrc ${PN} + newinitd atopacct.rc.openrc atopacct + + systemd_dounit "${S}"/${PN}.service + systemd_dounit "${S}"/atopacct.service + + dodoc atop.cronsysv AUTHORS README + + exeinto /usr/share/${PN} + doexe ${PN}.daily + + insinto /etc/default + newins ${PN}{.default,} + + keepdir /var/log/${PN} +} diff --git a/sys-process/atop/files/atop-2.12.0-atopgpud.patch b/sys-process/atop/files/atop-2.12.0-atopgpud.patch new file mode 100644 index 000000000000..b6cd86640c46 --- /dev/null +++ b/sys-process/atop/files/atop-2.12.0-atopgpud.patch @@ -0,0 +1,112 @@ +https://github.com/Atoptool/atop/pull/345 + +From aae92fe43b4f3577d7bf84f347514e432071f282 Mon Sep 17 00:00:00 2001 +From: "Z. Liu" <[email protected]> +Date: Thu, 24 Jul 2025 11:47:10 +0800 +Subject: [PATCH 1/2] atopgpud: fork before any thread action + +since python 3.12, os.fork now raise a DeprecationWarning, see +https://docs.python.org/3/whatsnew/3.12.html#deprecated: + +> /usr/bin/atopgpud:283: DeprecationWarning: This process (pid=64696) +> is multi-threaded, use of fork() may lead to deadlocks in the child. + +so let's fork as early as possible, before any thread action (gpulock & +"import pynvml"). + +Signed-off-by: Z. Liu <[email protected]> + +diff --git a/atopgpud b/atopgpud +index 84517fe..4f8f0e5 100755 +--- a/atopgpud ++++ b/atopgpud +@@ -66,7 +66,7 @@ cliterm = {} # dict with one entry per client (client + # that still have to be received by this client + # (pid of terminated process as key) + +-gpulock = threading.Lock() # mutex for access to gpulist/cliterm ++gpulock = None + + + # ================================= +@@ -275,15 +275,8 @@ def main(): + logging.error("Socket binding to port %d fails", GPUDPORT) + sys.exit(1) + +- # ----------------------------- +- # release parent process +- # (daemonize) +- # ----------------------------- +- try: +- if os.fork(): +- sys.exit(0) # parent process exits; child continues... +- except Exception: +- logging.error("Failed to fork child") ++ global gpulock ++ gpulock = threading.Lock() # mutex for access to gpulist/cliterm + + # ----------------------------- + # initialize GPU access for the +@@ -589,6 +582,16 @@ lg = logging.getLogger() # root logger + lg.addHandler(fh) + lg.setLevel(loglevel) + ++# ----------------------------- ++# release parent process ++# (daemonize) ++# ----------------------------- ++try: ++ if os.fork(): ++ sys.exit(0) # parent process exits; child continues... ++except Exception: ++ logging.error("Failed to fork child") ++ + # ----------------------------- + # load module pynvml + # ----------------------------- +-- +2.45.2 + + +From 1a226186868d806809cc8486eae46f5df28290b6 Mon Sep 17 00:00:00 2001 +From: "Z. Liu" <[email protected]> +Date: Thu, 24 Jul 2025 17:31:44 +0800 +Subject: [PATCH 2/2] atopgpud: don't daemonize if has arg "-f" + +so we can handle it by openrc + +Signed-off-by: Z. Liu <[email protected]> + +diff --git a/atopgpud b/atopgpud +index 4f8f0e5..a0e9a3f 100755 +--- a/atopgpud ++++ b/atopgpud +@@ -582,15 +582,16 @@ lg = logging.getLogger() # root logger + lg.addHandler(fh) + lg.setLevel(loglevel) + +-# ----------------------------- +-# release parent process +-# (daemonize) +-# ----------------------------- +-try: +- if os.fork(): +- sys.exit(0) # parent process exits; child continues... +-except Exception: +- logging.error("Failed to fork child") ++if '-f' not in sys.argv: ++ # ----------------------------- ++ # release parent process ++ # (daemonize) ++ # ----------------------------- ++ try: ++ if os.fork(): ++ sys.exit(0) # parent process exits; child continues... ++ except Exception: ++ logging.error("Failed to fork child") + + # ----------------------------- + # load module pynvml +-- +2.45.2 + diff --git a/sys-process/atop/files/atopgpud.initd b/sys-process/atop/files/atopgpud.initd new file mode 100644 index 000000000000..dbcc52398a28 --- /dev/null +++ b/sys-process/atop/files/atopgpud.initd @@ -0,0 +1,12 @@ +#!/sbin/openrc-run +# Copyright 1999-2025 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 +supervisor=supervise-daemon +name="atopgpud" +command="/usr/sbin/atopgpud" +command_args="-f" +pidfile="/run/${RC_SVCNAME}.pid" + +depend() { + before atop atopacct +}
