[PATCH glibc] Use proc_getchildren_rusage when available in getrusage and times.
--- 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 + +_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 * 100 + t->microseconds; } +#ifdef HAVE_HURD_PROC_GETCHILDREN_RUSAGE +static inline clock_t +clock_from_timeval (const struct timeval *t) { + return t->tv_sec * 100 + 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
[PATCH hurd] Add proc_getchildren_rusage RPC and track rusage for children and descendants
--- hurd/process.defs | 6 ++ proc/info.c | 8 proc/proc.h | 4 +++- proc/wait.c | 2 ++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/hurd/process.defs b/hurd/process.defs index 9a8b3a1..007aa2b 100644 --- a/hurd/process.defs +++ b/hurd/process.defs @@ -466,3 +466,9 @@ simpleroutine proc_reauthenticate_reassign ( that the user has received from auth_user_authenticate call. */ simpleroutine proc_reauthenticate_complete ( process: process_t); + +/* Returns the rusage information for the children that were waited + * for plus all their descendants. */ +routine proc_getchildren_rusage ( + process: process_t; + out children_rusage: rusage_t); diff --git a/proc/info.c b/proc/info.c index 2d85662..e5b0f47 100644 --- a/proc/info.c +++ b/proc/info.c @@ -1093,3 +1093,11 @@ S_proc_get_exe (struct proc *callerp, return 0; } +kern_return_t +S_proc_getchildren_rusage (struct proc *p, struct rusage *ru) +{ + if (!p) +return EOPNOTSUPP; + *ru = p->p_child_rusage; + return 0; +} diff --git a/proc/proc.h b/proc/proc.h index a83a509..bbba095 100644 --- a/proc/proc.h +++ b/proc/proc.h @@ -76,7 +76,9 @@ struct proc int p_sigcode; struct rusage p_rusage; /* my usage if I'm dead, to return via wait */ - struct rusage p_child_rusage;/* accumulates p_rusage of all dead children */ + /* Accumulates p_rusage of all dead children, including + * grandchildren and their descendants. */ + struct rusage p_child_rusage; unsigned int p_exec:1; /* has called proc_mark_exec */ unsigned int p_stopped:1;/* has called proc_mark_stop */ diff --git a/proc/wait.c b/proc/wait.c index 4551d28..a31b0e7 100644 --- a/proc/wait.c +++ b/proc/wait.c @@ -156,6 +156,8 @@ alert_parent (struct proc *p) { /* We accumulate the aggregate usage stats of all our dead children. */ rusage_add (&p->p_parent->p_child_rusage, &p->p_rusage); + /* ... and descendants. */ + rusage_add (&p->p_parent->p_child_rusage, &p->p_child_rusage); send_signal (p->p_parent->p_msgport, SIGCHLD, CLD_EXITED, p->p_parent->p_task); -- 2.39.2
Patch series for children process resource accounting
These patches implement getrusage(RUSAGE_CHILDREN, _) and populate child related data in times(_). This should fix the problem we have with building the latest grep which uses times(_) to get the cpu cycles in the test suite: https://buildd.debian.org/status/fetch.php?pkg=grep&arch=hurd-i386&ver=3.11-4&stamp=1704383469&raw=0
Re: [PATCH hurd] Add proc_getchildren_rusage RPC and track rusage for children and descendants
Applied, thanks! Flavio Cruz, le ven. 16 févr. 2024 13:26:29 -0500, a ecrit: > --- > hurd/process.defs | 6 ++ > proc/info.c | 8 > proc/proc.h | 4 +++- > proc/wait.c | 2 ++ > 4 files changed, 19 insertions(+), 1 deletion(-) > > diff --git a/hurd/process.defs b/hurd/process.defs > index 9a8b3a1..007aa2b 100644 > --- a/hurd/process.defs > +++ b/hurd/process.defs > @@ -466,3 +466,9 @@ simpleroutine proc_reauthenticate_reassign ( > that the user has received from auth_user_authenticate call. */ > simpleroutine proc_reauthenticate_complete ( > process: process_t); > + > +/* Returns the rusage information for the children that were waited > + * for plus all their descendants. */ > +routine proc_getchildren_rusage ( > + process: process_t; > + out children_rusage: rusage_t); > diff --git a/proc/info.c b/proc/info.c > index 2d85662..e5b0f47 100644 > --- a/proc/info.c > +++ b/proc/info.c > @@ -1093,3 +1093,11 @@ S_proc_get_exe (struct proc *callerp, >return 0; > } > > +kern_return_t > +S_proc_getchildren_rusage (struct proc *p, struct rusage *ru) > +{ > + if (!p) > +return EOPNOTSUPP; > + *ru = p->p_child_rusage; > + return 0; > +} > diff --git a/proc/proc.h b/proc/proc.h > index a83a509..bbba095 100644 > --- a/proc/proc.h > +++ b/proc/proc.h > @@ -76,7 +76,9 @@ struct proc >int p_sigcode; >struct rusage p_rusage;/* my usage if I'm dead, to return via wait */ > > - struct rusage p_child_rusage; /* accumulates p_rusage of all dead > children */ > + /* Accumulates p_rusage of all dead children, including > + * grandchildren and their descendants. */ > + struct rusage p_child_rusage; > >unsigned int p_exec:1; /* has called proc_mark_exec */ >unsigned int p_stopped:1; /* has called proc_mark_stop */ > diff --git a/proc/wait.c b/proc/wait.c > index 4551d28..a31b0e7 100644 > --- a/proc/wait.c > +++ b/proc/wait.c > @@ -156,6 +156,8 @@ alert_parent (struct proc *p) > { >/* We accumulate the aggregate usage stats of all our dead children. */ >rusage_add (&p->p_parent->p_child_rusage, &p->p_rusage); > + /* ... and descendants. */ > + rusage_add (&p->p_parent->p_child_rusage, &p->p_child_rusage); > >send_signal (p->p_parent->p_msgport, SIGCHLD, CLD_EXITED, > p->p_parent->p_task); > > -- > 2.39.2 > > -- Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.
Re: [PATCH glibc] Use proc_getchildren_rusage when available in getrusage and times.
Flavio Cruz, le ven. 16 févr. 2024 13:26:30 -0500, a ecrit: > 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 Mach is not necessarily about hurd :) Better put it in sysdeps/mach/hurd/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 We probably want to make some m4 macro for this so it will be easy to add such compatibility? Samuel