[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH glibc] Use proc_getchildren_rusage when available in getrusage an
From: |
Flavio Cruz |
Subject: |
[PATCH glibc] Use proc_getchildren_rusage when available in getrusage and times. |
Date: |
Fri, 16 Feb 2024 13:26:30 -0500 |
---
config.h.in | 3 +++
sysdeps/mach/configure | 28 ++++++++++++++++++++++++++++
sysdeps/mach/configure.ac | 9 +++++++++
sysdeps/mach/hurd/getrusage.c | 8 ++++++--
sysdeps/mach/hurd/times.c | 18 +++++++++++++++++-
5 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/config.h.in b/config.h.in
index 44a34072..2f0669e1 100644
--- a/config.h.in
+++ b/config.h.in
@@ -159,6 +159,9 @@
/* Mach/i386 specific: define if the `i386_set_gdt' RPC is available. */
#undef HAVE_I386_SET_GDT
+/* Hurd specific; define if the `proc_getchildren_rusage' RPC is available. */
+#undef HAVE_HURD_PROC_GETCHILDREN_RUSAGE
+
/* Define if inlined system calls are available. */
#undef HAVE_INLINED_SYSCALLS
diff --git a/sysdeps/mach/configure b/sysdeps/mach/configure
index f15160d0..d579c301 100644
--- a/sysdeps/mach/configure
+++ b/sysdeps/mach/configure
@@ -521,5 +521,33 @@ if test $libc_cv_mach_i386_gdt = yes; then
fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for
proc_getchildren_rusage in process.defs" >&5
+printf %s "checking for proc_getchildren_rusage in process.defs... " >&6; }
+if test ${libc_cv_hurd_proc_getchildren_rusage+y}
+then :
+ printf %s "(cached) " >&6
+else $as_nop
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <hurd/process.defs>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "proc_getchildren_rusage" >/dev/null 2>&1
+then :
+ libc_cv_hurd_proc_getchildren_rusage=yes
+else $as_nop
+ libc_cv_hurd_proc_getchildren_rusage=no
+fi
+rm -rf conftest*
+
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result:
$libc_cv_hurd_proc_getchildren_rusage" >&5
+printf "%s\n" "$libc_cv_hurd_proc_getchildren_rusage" >&6; }
+if test $libc_cv_hurd_proc_getchildren_rusage = yes; then
+ printf "%s\n" "#define HAVE_HURD_PROC_GETCHILDREN_RUSAGE 1" >>confdefs.h
+
+fi
+
CPPFLAGS=$OLD_CPPFLAGS
diff --git a/sysdeps/mach/configure.ac b/sysdeps/mach/configure.ac
index 730fb25d..db1e453f 100644
--- a/sysdeps/mach/configure.ac
+++ b/sysdeps/mach/configure.ac
@@ -104,4 +104,13 @@ if test $libc_cv_mach_i386_gdt = yes; then
AC_DEFINE([HAVE_I386_SET_GDT])
fi
+AC_CACHE_CHECK(for proc_getchildren_rusage in process.defs,
+ libc_cv_hurd_proc_getchildren_rusage, [dnl
+AC_EGREP_HEADER(proc_getchildren_rusage, hurd/process.defs,
+ libc_cv_hurd_proc_getchildren_rusage=yes,
+ libc_cv_hurd_proc_getchildren_rusage=no)])
+if test $libc_cv_hurd_proc_getchildren_rusage = yes; then
+ AC_DEFINE([HAVE_HURD_PROC_GETCHILDREN_RUSAGE])
+fi
+
CPPFLAGS=$OLD_CPPFLAGS
diff --git a/sysdeps/mach/hurd/getrusage.c b/sysdeps/mach/hurd/getrusage.c
index 7be4dd17..8151c297 100644
--- a/sysdeps/mach/hurd/getrusage.c
+++ b/sysdeps/mach/hurd/getrusage.c
@@ -75,9 +75,13 @@ __getrusage (enum __rusage_who who, struct rusage *usage)
break;
case RUSAGE_CHILDREN:
- /* XXX Not implemented yet. However, zero out USAGE to be
- consistent with the wait3 and wait4 functions. */
+#ifdef HAVE_HURD_PROC_GETCHILDREN_RUSAGE
+ err = __USEPORT (PROC, __proc_getchildren_rusage (port, usage));
+ if (err)
+ return __hurd_fail (err);
+#else
memset (usage, 0, sizeof (struct rusage));
+#endif
break;
diff --git a/sysdeps/mach/hurd/times.c b/sysdeps/mach/hurd/times.c
index 0c3880d5..3e384dd6 100644
--- a/sysdeps/mach/hurd/times.c
+++ b/sysdeps/mach/hurd/times.c
@@ -32,6 +32,13 @@ clock_from_time_value (const time_value_t *t)
return t->seconds * 1000000 + t->microseconds;
}
+#ifdef HAVE_HURD_PROC_GETCHILDREN_RUSAGE
+static inline clock_t
+clock_from_timeval (const struct timeval *t) {
+ return t->tv_sec * 1000000 + t->tv_usec;
+}
+#endif
+
/* Store the CPU time used by this process and all its
dead children (and their dead children) in BUFFER.
Return the elapsed real time, or (clock_t) -1 for errors.
@@ -62,8 +69,17 @@ __times (struct tms *tms)
tms->tms_stime = (clock_from_time_value (&bi.system_time)
+ clock_from_time_value (&tti.system_time));
- /* XXX This can't be implemented until getrusage(RUSAGE_CHILDREN) can be. */
+#ifdef HAVE_HURD_PROC_GETCHILDREN_RUSAGE
+ struct rusage child_rusage;
+ err = __USEPORT (PROC, __proc_getchildren_rusage (port, &child_rusage));
+ if (err)
+ return __hurd_fail (err);
+
+ tms->tms_cutime = clock_from_timeval (&child_rusage.ru_utime);
+ tms->tms_cstime = clock_from_timeval (&child_rusage.ru_stime);
+#else
tms->tms_cutime = tms->tms_cstime = 0;
+#endif
__host_get_time (__mach_host_self (), &now);
--
2.39.2