diff mbox

[04/29] Allow rusage work on a big-endian 32bit-on-64bit target

Message ID 1414396793-9005-5-git-send-email-apinski@cavium.com
State New
Headers show

Commit Message

Andrew Pinski Oct. 27, 2014, 7:59 a.m. UTC
Right now rusage works for x32 like ABIs but only for little-endian.
Since AARCH64:ILP32 is a big-endian ABI also.  We need to invent a
new way to handle big-endian ABIs also.  This adds __RUSAGE_LONG
which is used for this purpose.

* sysdeps/unix/sysv/linux/bits/resource.h (__RUSAGE_LONG): New define.
(struct rusage): Use __RUSAGE_LONG instead of unions.
---
 sysdeps/unix/sysv/linux/bits/resource.h |   99 ++++++++----------------------
 1 files changed, 27 insertions(+), 72 deletions(-)

Comments

Mike Frysinger Oct. 28, 2014, 8:04 p.m. UTC | #1
On 27 Oct 2014 00:59, Andrew Pinski wrote:
> +#ifndef __RUSAGE_LONG
> +/* This definition works where __syscall_slong_t is the same as 'long int'
> +   and on little-endian when __syscall_slong_t is not 'long int' like x32. */

two spaces after the period

> +# define __RUSAGE_LONG(__field) 		\

there's a bad space after the ) and before the tabs

> +    __extension__ union				\
> +      {						\
> +	long int __field;			\
> +	__syscall_slong_t __##__field##_word;	\
> +      }

couldn't we also handle big endian here ?  we check __BYTE_ORDER in many common 
headers, so seems like we should be able to also provide a sensible default 
here.

otherwise, i like the clean up in this file.
-mike
diff mbox

Patch

diff --git a/sysdeps/unix/sysv/linux/bits/resource.h b/sysdeps/unix/sysv/linux/bits/resource.h
index 95c1702..698069d 100644
--- a/sysdeps/unix/sysv/linux/bits/resource.h
+++ b/sysdeps/unix/sysv/linux/bits/resource.h
@@ -182,8 +182,19 @@  enum __rusage_who
 
 /* The purpose of all the unions is to have the kernel-compatible layout
    while keeping the API type as 'long int', and among machines where
-   __syscall_slong_t is not 'long int', this only does the right thing
-   for little-endian ones, like x32.  */
+   __syscall_slong_t is not 'long int'.  */
+
+#ifndef __RUSAGE_LONG
+/* This definition works where __syscall_slong_t is the same as 'long int'
+   and on little-endian when __syscall_slong_t is not 'long int' like x32. */
+# define __RUSAGE_LONG(__field) 		\
+    __extension__ union				\
+      {						\
+	long int __field;			\
+	__syscall_slong_t __##__field##_word;	\
+      }
+#endif
+
 struct rusage
   {
     /* Total amount of user time used.  */
@@ -191,96 +202,40 @@  struct rusage
     /* Total amount of system time used.  */
     struct timeval ru_stime;
     /* Maximum resident set size (in kilobytes).  */
-    __extension__ union
-      {
-	long int ru_maxrss;
-	__syscall_slong_t __ru_maxrss_word;
-      };
+    __RUSAGE_LONG(ru_maxrss);
     /* Amount of sharing of text segment memory
        with other processes (kilobyte-seconds).  */
     /* Maximum resident set size (in kilobytes).  */
-    __extension__ union
-      {
-	long int ru_ixrss;
-	__syscall_slong_t __ru_ixrss_word;
-      };
+    __RUSAGE_LONG(ru_ixrss);
     /* Amount of data segment memory used (kilobyte-seconds).  */
-    __extension__ union
-      {
-	long int ru_idrss;
-	__syscall_slong_t __ru_idrss_word;
-      };
+    __RUSAGE_LONG(ru_idrss);
     /* Amount of stack memory used (kilobyte-seconds).  */
-    __extension__ union
-      {
-	long int ru_isrss;
-	 __syscall_slong_t __ru_isrss_word;
-      };
+    __RUSAGE_LONG(ru_isrss);
     /* Number of soft page faults (i.e. those serviced by reclaiming
        a page from the list of pages awaiting reallocation.  */
-    __extension__ union
-      {
-	long int ru_minflt;
-	__syscall_slong_t __ru_minflt_word;
-      };
+    __RUSAGE_LONG(ru_minflt);
     /* Number of hard page faults (i.e. those that required I/O).  */
-    __extension__ union
-      {
-	long int ru_majflt;
-	__syscall_slong_t __ru_majflt_word;
-      };
+    __RUSAGE_LONG(ru_majflt);
     /* Number of times a process was swapped out of physical memory.  */
-    __extension__ union
-      {
-	long int ru_nswap;
-	__syscall_slong_t __ru_nswap_word;
-      };
+    __RUSAGE_LONG(ru_nswap);
     /* Number of input operations via the file system.  Note: This
        and `ru_oublock' do not include operations with the cache.  */
-    __extension__ union
-      {
-	long int ru_inblock;
-	__syscall_slong_t __ru_inblock_word;
-      };
+    __RUSAGE_LONG(ru_inblock);
     /* Number of output operations via the file system.  */
-    __extension__ union
-      {
-	long int ru_oublock;
-	__syscall_slong_t __ru_oublock_word;
-      };
+    __RUSAGE_LONG(ru_oublock);
     /* Number of IPC messages sent.  */
-    __extension__ union
-      {
-	long int ru_msgsnd;
-	__syscall_slong_t __ru_msgsnd_word;
-      };
+    __RUSAGE_LONG(ru_msgsnd);
     /* Number of IPC messages received.  */
-    __extension__ union
-      {
-	long int ru_msgrcv;
-	__syscall_slong_t __ru_msgrcv_word;
-      };
+    __RUSAGE_LONG(ru_msgrcv);
     /* Number of signals delivered.  */
-    __extension__ union
-      {
-	long int ru_nsignals;
-	__syscall_slong_t __ru_nsignals_word;
-      };
+    __RUSAGE_LONG(ru_nsignals);
     /* Number of voluntary context switches, i.e. because the process
        gave up the process before it had to (usually to wait for some
        resource to be available).  */
-    __extension__ union
-      {
-	long int ru_nvcsw;
-	__syscall_slong_t __ru_nvcsw_word;
-      };
+    __RUSAGE_LONG(ru_nvcsw);
     /* Number of involuntary context switches, i.e. a higher priority process
        became runnable or the current process used up its time slice.  */
-    __extension__ union
-      {
-	long int ru_nivcsw;
-	__syscall_slong_t __ru_nivcsw_word;
-      };
+    __RUSAGE_LONG(ru_nivcsw);
   };
 
 /* Priority limits.  */