From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2BFFDCD8C9D for ; Thu, 11 Jun 2026 21:23:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7FF5C10E0B7; Thu, 11 Jun 2026 21:23:21 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="R7C0UA/R"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id C8C2810E0B7 for ; Thu, 11 Jun 2026 21:22:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1781212977; x=1812748977; h=date:message-id:from:to:cc:subject:in-reply-to: references:mime-version:content-transfer-encoding; bh=gX2xKgV9p+LpT37UBhm5uQGG9DMKd45MO5YwTi0wTlQ=; b=R7C0UA/R2xbBuLBWsAELPJxDQA7TSX/YDqU/hWE/Uf/aR/5vMmTvmuEh tYEV6GZC+ix9COGeoJLgfio2ki9a4zSYUTngpGbo4pZC4bZzgXRsWmdlX cs81cC3azamaZzQ4C0Fj6YyvV0kUNyP03dvf1Vm9TzNsadxWgdm7PDmB8 IkYUbBDF8lnfErL0G6xAjbfvOdPAGjjAkvToMM3g7kQbZCUlPJ2VAOmK1 MKPdMtCZcjFqSANEbRKuFTnBIPtz9pGzE9RsOQ+xtDuVk7dxuOzto/jtD blK+jfAZleoOgeMj6OA8uMNRNshbbq1iKj/HL9YMi0n/wnRievhTlOU3M g==; X-CSE-ConnectionGUID: 9rWa9khySa2+b05CDbxotg== X-CSE-MsgGUID: biGOk/VhTdqQj6bFvfZWFw== X-IronPort-AV: E=McAfee;i="6800,10657,11813"; a="93528951" X-IronPort-AV: E=Sophos;i="6.24,199,1774335600"; d="scan'208";a="93528951" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2026 14:22:56 -0700 X-CSE-ConnectionGUID: tC5yx6qmTRq4qEjkxyIMGA== X-CSE-MsgGUID: Cm0y0CWhSCKRzRQURsgiag== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,199,1774335600"; d="scan'208";a="244177569" Received: from eshober-mobl2.amr.corp.intel.com (HELO adixit-MOBL3.intel.com) ([10.125.160.117]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2026 14:22:56 -0700 Date: Thu, 11 Jun 2026 14:22:55 -0700 Message-ID: <87bjdgixg0.wl-ashutosh.dixit@intel.com> From: "Dixit, Ashutosh" To: "Bai, Zongyao" Cc: Jia Yao , Subject: Re: [PATCH] lib: replace libprocps/libproc2 with /proc-based process enumeration In-Reply-To: <18325ddb-1d87-4bec-bcd0-64686805d231@intel.com> References: <20260603182801.900747-1-jia.yao@intel.com> <18325ddb-1d87-4bec-bcd0-64686805d231@intel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" On Tue, 09 Jun 2026 10:51:13 -0700, Bai, Zongyao wrote: > > Hi Jia, > > LGTM > > =A0Reviewed-by: Zongyao Bai Hmm, not sure what's with the '_' (or space) before Reviewed-by, because of which R-b doesn't show if we retrieve/apply the patch. Anyway, I've fixed this up and merged it. Thanks for the patch and the review. -Ashutosh > > > On 6/3/2026 11:28 AM, Jia Yao wrote: > > The previous code used compile-time #ifdef HAVE_LIBPROCPS / HAVE_LIBPRO= C2 > > to select between two incompatible APIs, requiring separate builds for > > Ubuntu 22.04 (libprocps) and Ubuntu 24.04 (libproc2). > > Replace the platform-specific code with internal static helpers in > > igt_aux.c that read /proc//status directly, requiring no external > > library and working identically across distro versions. > > The libprocps/libproc2 meson dependencies have been removed entirely. > > > > Cc: Zongyao Bai > > Signed-off-by: Jia Yao > > --- > > lib/igt_aux.c | 203 +++++++++++++++++++++++++++++++----------------- > > lib/meson.build | 6 -- > > meson.build | 13 +--- > > 3 files changed, 131 insertions(+), 91 deletions(-) > > > > diff --git a/lib/igt_aux.c b/lib/igt_aux.c > > index 87c0593a4..0d250ae2f 100644 > > --- a/lib/igt_aux.c > > +++ b/lib/igt_aux.c > > @@ -53,12 +53,6 @@ > > #include > > #include > > -#ifdef HAVE_LIBPROCPS > > -# include > > -#elif HAVE_LIBPROC2 > > -# include > > -#endif > > - > > #include > > #ifdef __linux__ > > # include > > @@ -1285,93 +1279,156 @@ void igt_unlock_mem(void) > > locked_mem =3D NULL; > > } > > +/* > > + * Internal /proc-based process iterator. Reads /proc//status di= rectly > > + * so there is no dependency on libprocps or libproc2. > > + * > > + * /proc//status fields used: > > + * Name: - command name (kernel escapes spaces, so %s is sa= fe) > > + * Pid: > > + * Uid: ruid euid suid fsuid > > + * Gid: rgid egid sgid fsgid > > + */ > > +struct procps_iter { > > + DIR *procdir; > > + char comm[64]; > > + pid_t tid; > > + uid_t euid; > > + gid_t egid; > > +}; > > + > > +static struct procps_iter *procps_open(void) > > +{ > > + struct procps_iter *iter =3D calloc(1, sizeof(*iter)); > > + > > + if (!iter) > > + return NULL; > > + > > + iter->procdir =3D opendir("/proc"); > > + if (!iter->procdir) { > > + free(iter); > > + return NULL; > > + } > > + > > + return iter; > > +} > > + > > +static bool procps_next(struct procps_iter *iter, > > + pid_t *tid, uid_t *euid, gid_t *egid, > > + const char **comm) > > +{ > > + struct dirent *ent; > > + > > + if (!iter || !iter->procdir) > > + return false; > > + > > + while ((ent =3D readdir(iter->procdir))) { > > + char path[64]; > > + FILE *f; > > + pid_t _tid =3D 0; > > + uid_t _euid =3D 0; > > + gid_t _egid =3D 0; > > + char _comm[64] =3D ""; > > + int fields =3D 0; /* bit 0=3DName, 1=3DPid, 2=3DUid, 3=3DGid */ > > + char line[256]; > > + > > + if (ent->d_name[0] < '1' || ent->d_name[0] > '9') > > + continue; > > + > > + snprintf(path, sizeof(path), "/proc/%.20s/status", ent->d_name); > > + > > + f =3D fopen(path, "r"); > > + if (!f) > > + continue; > > + > > + while (fields !=3D 0xf && fgets(line, sizeof(line), f)) { > > + if (!(fields & 0x1) && strncmp(line, "Name:", 5) =3D=3D 0) { > > + if (sscanf(line + 5, " %63s", _comm) =3D=3D 1) > > + fields |=3D 0x1; > > + } else if (!(fields & 0x2) && strncmp(line, "Pid:", 4) =3D=3D 0) { > > + if (sscanf(line + 4, " %d", &_tid) =3D=3D 1) > > + fields |=3D 0x2; > > + } else if (!(fields & 0x4) && strncmp(line, "Uid:", 4) =3D=3D 0) { > > + /* skip ruid, read euid */ > > + unsigned int _e; > > + > > + if (sscanf(line + 4, " %*u %u", &_e) =3D=3D 1) { > > + _euid =3D (uid_t)_e; > > + fields |=3D 0x4; > > + } > > + } else if (!(fields & 0x8) && strncmp(line, "Gid:", 4) =3D=3D 0) { > > + /* skip rgid, read egid */ > > + unsigned int _e; > > + > > + if (sscanf(line + 4, " %*u %u", &_e) =3D=3D 1) { > > + _egid =3D (gid_t)_e; > > + fields |=3D 0x8; > > + } > > + } > > + } > > + > > + fclose(f); > > + > > + if (_tid <=3D 0) > > + continue; > > + > > + iter->tid =3D _tid; > > + iter->euid =3D _euid; > > + iter->egid =3D _egid; > > + snprintf(iter->comm, sizeof(iter->comm), "%s", _comm); > > + > > + *tid =3D iter->tid; > > + *euid =3D iter->euid; > > + *egid =3D iter->egid; > > + *comm =3D iter->comm; > > + return true; > > + } > > + > > + return false; > > +} > > + > > +static void procps_close(struct procps_iter *iter) > > +{ > > + if (!iter) > > + return; > > + > > + if (iter->procdir) > > + closedir(iter->procdir); > > + > > + free(iter); > > +} > > + > > struct igt_process { > > -#ifdef HAVE_LIBPROCPS > > - PROCTAB * proc; > > - proc_t *proc_info; > > -#elif HAVE_LIBPROC2 > > - struct pids_info *info; > > - struct pids_stack *stack; > > -#endif > > + struct procps_iter *iter; > > pid_t tid; > > - pid_t euid; > > - pid_t egid; > > - char *comm; > > + uid_t euid; > > + gid_t egid; > > + const char *comm; > > }; > > static void open_process(struct igt_process *prcs) > > { > > -#ifdef HAVE_LIBPROCPS > > - prcs->proc =3D openproc(PROC_FILLCOM | PROC_FILLSTAT | PROC_FILLARG); > > - igt_assert_f(prcs->proc !=3D NULL, "procps open failed\n"); > > - prcs->proc_info =3D NULL; > > -#elif HAVE_LIBPROC2 > > - enum pids_item Items[] =3D { PIDS_ID_PID, PIDS_ID_EUID, PIDS_ID_EGID,= PIDS_CMD }; > > - int err; > > - > > - prcs->info =3D NULL; > > - err =3D procps_pids_new(&prcs->info, Items, 4); > > - igt_assert_f(err >=3D 0, "procps-ng open failed\n"); > > - prcs->stack =3D NULL; > > -#endif > > + prcs->iter =3D procps_open(); > > + igt_assert_f(prcs->iter, "procps open failed (no /proc filesystem?)\n= "); > > prcs->tid =3D 0; > > prcs->comm =3D NULL; > > } > > static void close_process(struct igt_process *prcs) > > { > > -#ifdef HAVE_LIBPROCPS > > - if (prcs->proc_info) > > - freeproc(prcs->proc_info); > > - > > - closeproc(prcs->proc); > > - prcs->proc_info =3D NULL; > > - prcs->proc =3D NULL; > > -#elif HAVE_LIBPROC2 > > - procps_pids_unref(&prcs->info); > > - prcs->info =3D NULL; > > -#endif > > + procps_close(prcs->iter); > > + prcs->iter =3D NULL; > > prcs->tid =3D 0; > > prcs->comm =3D NULL; > > } > > static bool get_process_ids(struct igt_process *prcs) > > { > > -#ifdef HAVE_LIBPROCPS > > - if (prcs->proc_info) > > - freeproc(prcs->proc_info); > > - > > - prcs->tid =3D 0; > > - prcs->comm =3D NULL; > > - prcs->proc_info =3D readproc(prcs->proc, NULL); > > - > > - if (prcs->proc_info) { > > - prcs->tid =3D prcs->proc_info->tid; > > - prcs->euid =3D prcs->proc_info->euid; > > - prcs->egid =3D prcs->proc_info->egid; > > - prcs->comm =3D prcs->proc_info->cmd; > > - } > > -#elif HAVE_LIBPROC2 > > - enum rel_items { EU_PID, EU_EUID, EU_EGID, EU_CMD }; // order at open > > - > > prcs->tid =3D 0; > > prcs->comm =3D NULL; > > - prcs->stack =3D procps_pids_get(prcs->info, PIDS_FETCH_TASKS_ONLY); > > - if (prcs->stack) { > > -#if defined(HAVE_LIBPROC2_POST_4_0_5_API) > > - prcs->tid =3D PIDS_VAL(EU_PID, s_int, prcs->stack); > > - prcs->euid =3D PIDS_VAL(EU_EUID, s_int, prcs->stack); > > - prcs->egid =3D PIDS_VAL(EU_EGID, s_int, prcs->stack); > > - prcs->comm =3D PIDS_VAL(EU_CMD, str, prcs->stack); > > -#else > > - prcs->tid =3D PIDS_VAL(EU_PID, s_int, prcs->stack, prcs->info); > > - prcs->euid =3D PIDS_VAL(EU_EUID, s_int, prcs->stack, prcs->info); > > - prcs->egid =3D PIDS_VAL(EU_EGID, s_int, prcs->stack, prcs->info); > > - prcs->comm =3D PIDS_VAL(EU_CMD, str, prcs->stack, prcs->info); > > -#endif > > - } > > -#endif > > - return prcs->tid !=3D 0; > > + return procps_next(prcs->iter, > > + &prcs->tid, &prcs->euid, &prcs->egid, > > + &prcs->comm); > > } > > /** > > diff --git a/lib/meson.build b/lib/meson.build > > index a8d6566ae..f25ecd8b2 100644 > > --- a/lib/meson.build > > +++ b/lib/meson.build > > @@ -257,12 +257,6 @@ if build_xe_eudebug > > lib_sources +=3D 'xe/xe_eudebug.c' > > endif > > -if libprocps.found() > > - lib_deps +=3D libprocps > > -else > > - lib_deps +=3D libproc2 > > -endif > > - > > if get_option('srcdir') !=3D '' > > srcdir =3D join_paths(get_option('srcdir'), 'tests') > > else > > diff --git a/meson.build b/meson.build > > index e750f7a51..4def24cbc 100644 > > --- a/meson.build > > +++ b/meson.build > > @@ -133,18 +133,7 @@ build_info +=3D 'With libdrm: ' + ','.join(libdrm_= info) > > pciaccess =3D dependency('pciaccess', version : '>=3D0.10') > > libkmod =3D dependency('libkmod') > > -libprocps =3D dependency('libprocps', required : false) > > -libproc2 =3D dependency('libproc2', required : false) > > -if libprocps.found() > > - config.set('HAVE_LIBPROCPS', 1) > > -elif libproc2.found() > > - config.set('HAVE_LIBPROC2', 1) > > - if libproc2.version().version_compare('>=3D 4.0.5') > > - config.set('HAVE_LIBPROC2_POST_4_0_5_API', 1) > > - endif > > -else > > - error('Either libprocps or libproc2 is required') > > -endif > > +# igt_procps.c reads /proc directly; libprocps and libproc2 are not ne= eded. > > libunwind =3D dependency('libunwind', required : > > get_option('libunwind')) > > if libunwind.found()