Remove dead getrusage replacement code.
authorThomas Munro <tmunro@postgresql.org>
Sat, 23 Jul 2022 21:21:57 +0000 (09:21 +1200)
committerThomas Munro <tmunro@postgresql.org>
Sat, 23 Jul 2022 21:29:48 +0000 (09:29 +1200)
getrusage() is in SUSv2 and all targeted Unix systems have it.

Note that POSIX only covers ru_utime and ru_stime and we rely on many
more fields without any kind of configure probe, but that predates this
commit.

The only supported system we need replacement code for now is Windows,
and that can be done without a configure probe.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Greg Stark <stark@mit.edu>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Discussion: https://postgr.es/m/CA+hUKGJ3LHeP9w5Fgzdr4G8AnEtJ=z=p6hGDEm4qYGEUX5B6fQ@mail.gmail.com

configure
configure.ac
src/backend/tcop/postgres.c
src/include/pg_config.h.in
src/include/rusagestub.h
src/port/getrusage.c
src/tools/msvc/Solution.pm

index 66513212086197464a06829a4a1c84eb100c1d82..52bcb9d498a857c3c33b1862fab18fb2e2072b72 100755 (executable)
--- a/configure
+++ b/configure
@@ -16797,19 +16797,6 @@ esac
 
 fi
 
-ac_fn_c_check_func "$LINENO" "getrusage" "ac_cv_func_getrusage"
-if test "x$ac_cv_func_getrusage" = xyes; then :
-  $as_echo "#define HAVE_GETRUSAGE 1" >>confdefs.h
-
-else
-  case " $LIBOBJS " in
-  *" getrusage.$ac_objext "* ) ;;
-  *) LIBOBJS="$LIBOBJS getrusage.$ac_objext"
- ;;
-esac
-
-fi
-
 ac_fn_c_check_func "$LINENO" "inet_aton" "ac_cv_func_inet_aton"
 if test "x$ac_cv_func_inet_aton" = xyes; then :
   $as_echo "#define HAVE_INET_ATON 1" >>confdefs.h
@@ -17125,6 +17112,12 @@ esac
  ;;
 esac
 
+  case " $LIBOBJS " in
+  *" getrusage.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS getrusage.$ac_objext"
+ ;;
+esac
+
   case " $LIBOBJS " in
   *" kill.$ac_objext "* ) ;;
   *) LIBOBJS="$LIBOBJS kill.$ac_objext"
index 1e92fd6abd66c605c249e871b7efd42cf16a7b28..9a3483f206ba3fa9ac38e4b82885fa9ed706d35e 100644 (file)
@@ -1911,7 +1911,6 @@ AC_REPLACE_FUNCS(m4_normalize([
    explicit_bzero
    getopt
    getpeereid
-   getrusage
    inet_aton
    link
    mkdtemp
@@ -1986,6 +1985,7 @@ if test "$PORTNAME" = "win32"; then
   AC_REPLACE_FUNCS(gettimeofday)
   AC_LIBOBJ(dirmod)
   AC_LIBOBJ(fdatasync)
+  AC_LIBOBJ(getrusage)
   AC_LIBOBJ(kill)
   AC_LIBOBJ(open)
   AC_LIBOBJ(system)
index 8ba1c170f02773d8c5d02953b717b1111a7b1240..bdb11f430fd2344392e609e1f9afa0576763c7d8 100644 (file)
@@ -32,7 +32,7 @@
 #include <sys/resource.h>
 #endif
 
-#ifndef HAVE_GETRUSAGE
+#ifdef WIN32
 #include "rusagestub.h"
 #endif
 
@@ -4860,7 +4860,14 @@ ShowUsage(const char *title)
                     (long) user.tv_usec,
                     (long) sys.tv_sec,
                     (long) sys.tv_usec);
-#if defined(HAVE_GETRUSAGE)
+#ifndef WIN32
+
+   /*
+    * The following rusage fields are not defined by POSIX, but they're
+    * present on all current Unix-like systems so we use them without any
+    * special checks.  Some of these could be provided in our Windows
+    * emulation in src/port/getrusage.c with more work.
+    */
    appendStringInfo(&str,
                     "!\t%ld kB max resident size\n",
 #if defined(__darwin__)
@@ -4896,7 +4903,7 @@ ShowUsage(const char *title)
                     r.ru_nvcsw - Save_r.ru_nvcsw,
                     r.ru_nivcsw - Save_r.ru_nivcsw,
                     r.ru_nvcsw, r.ru_nivcsw);
-#endif                         /* HAVE_GETRUSAGE */
+#endif                         /* !WIN32 */
 
    /* remove trailing newline */
    if (str.data[str.len - 1] == '\n')
index 000ed9bde27ecdd4200e6e05a6d357ab1efe532c..9061f301b0516918767bfb42f5ef9a8ff0329b2d 100644 (file)
 /* Define to 1 if you have the `getrlimit' function. */
 #undef HAVE_GETRLIMIT
 
-/* Define to 1 if you have the `getrusage' function. */
-#undef HAVE_GETRUSAGE
-
 /* Define to 1 if you have the `gettimeofday' function. */
 #undef HAVE_GETTIMEOFDAY
 
index b887effa3e9c28746cd2bd16a1856cce80ac214b..be26f849a59d5e2a3ab19fd17ad3be78a5be039e 100644 (file)
@@ -15,9 +15,6 @@
 #define RUSAGESTUB_H
 
 #include <sys/time.h>          /* for struct timeval */
-#ifndef WIN32
-#include <sys/times.h>         /* for struct tms */
-#endif
 #include <limits.h>                /* for CLK_TCK */
 
 #define RUSAGE_SELF        0
index 02665f4032d5696050caeec1ca0186a3225296a2..2ba59ade2c3cf981f152dc600c2dbb0f9546a02d 100644 (file)
 
 #include "rusagestub.h"
 
-/* This code works on:
- *     solaris_i386
- *     solaris_sparc
- *     win32
- * which currently is all the supported platforms that don't have a
- * native version of getrusage().  So, if configure decides to compile
- * this file at all, we just use this version unconditionally.
+/*
+ * This code works on Windows, which is the only supported platform without a
+ * native version of getrusage().
  */
 
 int
 getrusage(int who, struct rusage *rusage)
 {
-#ifdef WIN32
    FILETIME    starttime;
    FILETIME    exittime;
    FILETIME    kerneltime;
@@ -66,44 +61,6 @@ getrusage(int who, struct rusage *rusage)
    li.QuadPart /= 10L;         /* Convert to microseconds */
    rusage->ru_utime.tv_sec = li.QuadPart / 1000000L;
    rusage->ru_utime.tv_usec = li.QuadPart % 1000000L;
-#else                          /* all but WIN32 */
-
-   struct tms  tms;
-   int         tick_rate = CLK_TCK;    /* ticks per second */
-   clock_t     u,
-               s;
-
-   if (rusage == (struct rusage *) NULL)
-   {
-       errno = EFAULT;
-       return -1;
-   }
-   if (times(&tms) < 0)
-   {
-       /* errno set by times */
-       return -1;
-   }
-   switch (who)
-   {
-       case RUSAGE_SELF:
-           u = tms.tms_utime;
-           s = tms.tms_stime;
-           break;
-       case RUSAGE_CHILDREN:
-           u = tms.tms_cutime;
-           s = tms.tms_cstime;
-           break;
-       default:
-           errno = EINVAL;
-           return -1;
-   }
-#define TICK_TO_SEC(T, RATE)   ((T)/(RATE))
-#define TICK_TO_USEC(T,RATE)   (((T)%(RATE)*1000000)/RATE)
-   rusage->ru_utime.tv_sec = TICK_TO_SEC(u, tick_rate);
-   rusage->ru_utime.tv_usec = TICK_TO_USEC(u, tick_rate);
-   rusage->ru_stime.tv_sec = TICK_TO_SEC(s, tick_rate);
-   rusage->ru_stime.tv_usec = TICK_TO_USEC(u, tick_rate);
-#endif                         /* WIN32 */
 
    return 0;
 }
index f8df6acabe5e86c9a564f870cc6e16453fad2067..5fa8626af7ff5deff0bd5b70211c84274e93492f 100644 (file)
@@ -277,7 +277,6 @@ sub GenerateFiles
        HAVE_GETPEERUCRED                           => undef,
        HAVE_GETPWUID_R                             => undef,
        HAVE_GETRLIMIT                              => undef,
-       HAVE_GETRUSAGE                              => undef,
        HAVE_GETTIMEOFDAY                           => undef,
        HAVE_GSSAPI_GSSAPI_H                        => undef,
        HAVE_GSSAPI_H                               => undef,