From patchwork Sat Feb 17 16:48:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Cruz X-Patchwork-Id: 1900512 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=frmasBRw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TcZX14M4dz23j9 for ; Sun, 18 Feb 2024 03:49:21 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 85554385E457 for ; Sat, 17 Feb 2024 16:49:18 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by sourceware.org (Postfix) with ESMTPS id A1292385E005 for ; Sat, 17 Feb 2024 16:48:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A1292385E005 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A1292385E005 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708188542; cv=none; b=GHmulMY791sooEVXqGFkNQXbYQt+ZjUF0fknpibixm+UVpkZZb5Q98/fSC83HnBsQiCukGsonROzsa3IFc+qcsRNgPKX8Sm9+6WiKl3qrXLscnrSptG65JKFMm7DL03iWZrPDcvt+XJ7BqDV/l9H0TvnMMHgMdXiAvOgroUVDas= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708188542; c=relaxed/simple; bh=8E9A1CgcFft30Ye9JCjN075+BDzHwYz8ATFGiihtw1k=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=EQDsLgLEcAbMZ8CTD2FbfbFX6qzLFzjVvP7hOEASuWvdZgM26KsAq16wffzzIkuhclXBHifnLfvCQKnYweWYNtCS2Hv9+lW3QypTg+/tgdw14NLhaODErn5H3gRFZD/q1zcKAcxD7xixt/MgbnJubt0MloqpesWIGKRyIy0vNR8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf32.google.com with SMTP id 6a1803df08f44-6860ff3951aso14517956d6.1 for ; Sat, 17 Feb 2024 08:48:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708188539; x=1708793339; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hUvVpjVZra/E8ZnH1rRP8YMDApSalPiR6Z7G8JUrUWs=; b=frmasBRwTUXPYOAfM+a/BlwPB04iyRDgPH9ywLvgVjhQ3rb8xHm8dogaMvVGnieVLu hEJDLuATsBLD4+s2we3gywwiRF87CSpp2KA4wZS+yQaz/CpqELvlF/mqdg40naocwrdT hfmz18PVaIOhp5P2fhA7byWCOO2NLmcV1SNm7AciK/K3tfKQJHOca3hHnrQXFAuumuz2 pVM7dC/8XxI4mPqGnz53wJ+ulqhJLIlReaNK930RXsK7jaItVzS/NPM1T4r1HvHVRT5Y VB0NcD1c0mvaQDZYe72CegJ80JpSkST54aWNRQFicI4txBHiwcRBlfmfOk2cG+fBhUdV plAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708188539; x=1708793339; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hUvVpjVZra/E8ZnH1rRP8YMDApSalPiR6Z7G8JUrUWs=; b=MWbdHykXnQzsEd6M9snn6kZLAQ7pepTKG9CwRa4xmLumGl6g0RyhFMBTxm6wsyN42a SNyM5p5rkNv1UsmL/X8mUxRx1camfHa4XHc7Vj7jVrp7DURRA/LP1LHyhh4LhjR6mzBg aw/IXBFSl2z0GmiMZjngWQWNPzDQKdZFYJfagIexpMWuxvXr7olBbjWT5oct/15Awt1b R76h5IpAID1W3yanrJ/f3IIK/fc86MCdrF7kCtAT6+aA6xa36khlYd5VnDWNvYJ7V8+t XMcKRxb1uN7A21rRA5NbfJyg/GABWWwtVkQ+YKBD8T6/17n5FNTQHLZNzZ2+5HY/zP72 lBaQ== X-Forwarded-Encrypted: i=1; AJvYcCXwoQi+ts7JbIkYrNbaXVMx2an028CGboiBWwzXhX5bkRZIVPrgF0x5omCr+3zbTvcJMtv6S7OQV9lLvidU3YHcPPjp5gl8HTEi X-Gm-Message-State: AOJu0YzcrSU9kIGcSeLv4fyvqYJzkvzCwkOrhZMlDFuvDUUio2k6IwSH 23r9VZdkHs1q3MAu1IGtv5YxvUyNfznSnB33AX8b5PnuPJt+LBikfY2RA8o= X-Google-Smtp-Source: AGHT+IF7ZzCKfuWW0Geq92yJRq+mSZ84BGvpEf9YaMaxSu4vnheRdw7EooXQ514b2Z/DFOw4tadqow== X-Received: by 2002:a05:6214:2502:b0:68c:8f22:1a67 with SMTP id gf2-20020a056214250200b0068c8f221a67mr10108836qvb.5.1708188538739; Sat, 17 Feb 2024 08:48:58 -0800 (PST) Received: from jupiter.tail36e24.ts.net (dynamic-acs-24-154-253-225.zoominternet.net. [24.154.253.225]) by smtp.gmail.com with ESMTPSA id oq18-20020a056214461200b0068f52e8cd2bsm336726qvb.68.2024.02.17.08.48.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 08:48:58 -0800 (PST) From: Flavio Cruz To: bug-hurd@gnu.org Cc: samuel.thibault@gnu.org, libc-alpha@sourceware.org, Flavio Cruz Subject: [PATCH glibc] Use proc_getchildren_rusage when available in getrusage and times. Date: Sat, 17 Feb 2024 11:48:46 -0500 Message-Id: <20240217164846.1837223-1-flaviocruz@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240217013619.cwrb2dr3j7zj7yja@begin> References: <20240217013619.cwrb2dr3j7zj7yja@begin> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org --- config.h.in | 3 + sysdeps/mach/hurd/configure | 174 +++++++++++++++++++++++++++++++++ sysdeps/mach/hurd/configure.ac | 19 ++++ sysdeps/mach/hurd/getrusage.c | 8 +- sysdeps/mach/hurd/times.c | 18 +++- 5 files changed, 219 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/hurd/configure b/sysdeps/mach/hurd/configure index 33d3e1fc..cd5af1cd 100644 --- a/sysdeps/mach/hurd/configure +++ b/sysdeps/mach/hurd/configure @@ -45,6 +45,180 @@ if test "x$libc_cv_hurd_version" != xok; then as_fn_error $? "Hurd headers not installed or too old" "$LINENO" 5 fi + + + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +printf %s "checking for grep that handles long lines and -e... " >&6; } +if test ${ac_cv_path_GREP+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -z "$GREP"; then + ac_path_GREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_prog in grep ggrep + do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_GREP" || continue +# Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + printf %s 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + printf "%s\n" 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_GREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_GREP"; then + as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_GREP=$GREP +fi + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +printf "%s\n" "$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +printf %s "checking for egrep... " >&6; } +if test ${ac_cv_path_EGREP+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 + then ac_cv_path_EGREP="$GREP -E" + else + if test -z "$EGREP"; then + ac_path_EGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_prog in egrep + do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_EGREP="$as_dir$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_EGREP" || continue +# Check for GNU ac_path_EGREP and select it if it is found. + # Check for GNU $ac_path_EGREP +case `"$ac_path_EGREP" --version 2>&1` in +*GNU*) + ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; +*) + ac_count=0 + printf %s 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + printf "%s\n" 'EGREP' >> "conftest.nl" + "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_EGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_EGREP="$ac_path_EGREP" + ac_path_EGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_EGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_EGREP"; then + as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_EGREP=$EGREP +fi + + fi +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +printf "%s\n" "$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" + + +{ 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_rpc_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_rpc_proc_getchildren_rusage=yes +else $as_nop + libc_cv_hurd_rpc_proc_getchildren_rusage=no +fi +rm -rf conftest* + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_hurd_rpc_proc_getchildren_rusage" >&5 +printf "%s\n" "$libc_cv_hurd_rpc_proc_getchildren_rusage" >&6; } +if test $libc_cv_hurd_rpc_proc_getchildren_rusage = yes; then + printf "%s\n" "#define HAVE_HURD_PROC_GETCHILDREN_RUSAGE 1" >>confdefs.h + +fi + + if test -n "$sysheaders"; then CPPFLAGS=$OLD_CPPFLAGS fi diff --git a/sysdeps/mach/hurd/configure.ac b/sysdeps/mach/hurd/configure.ac index 82d085af..1695e94e 100644 --- a/sysdeps/mach/hurd/configure.ac +++ b/sysdeps/mach/hurd/configure.ac @@ -23,6 +23,25 @@ if test "x$libc_cv_hurd_version" != xok; then AC_MSG_ERROR(Hurd headers not installed or too old) fi +dnl +dnl hurd_RPC_CHECK(interface.defs, rpc_method, define) +dnl +dnl Check if rpc_method RPC is defined by interface.defs +dnl and define `define`. +dnl +AC_DEFUN([hurd_RPC_CHECK], [dnl +AC_CACHE_CHECK(for $2 in $1, libc_cv_hurd_rpc_$2, [dnl +AC_EGREP_HEADER($2, hurd/$1, + libc_cv_hurd_rpc_$2=yes, + libc_cv_hurd_rpc_$2=no)]) +if test $libc_cv_hurd_rpc_$2 = yes; then + AC_DEFINE([$3]) +fi +]) + +hurd_RPC_CHECK(process.defs, proc_getchildren_rusage, + HAVE_HURD_PROC_GETCHILDREN_RUSAGE) + if test -n "$sysheaders"; then CPPFLAGS=$OLD_CPPFLAGS fi 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);