This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ppc patch: gettimeofday, getrusage, and times support


hi folks.

i needed to run some ppc tests on the simulator that required the
concept of time.

here is a patch to add gettimeofday(), times(), and getrusage().  with these
patches it is possible to use clock() which depends on the last two
for usage, and on gettimeofday() for linking (same file).

i have tested this patch on powerpc-unknown-linux-gnu, by running the gcc 
testsuite on a combined tree with newlib/libgloss libraries built.  
the target was powerpc-eabi.  

i also tested on both sparc-sun-solaris2.7 and powerpc-unknow-linux-gnu
by building an eabi executable that called gettimeofday() and clock() to 
make sure it linked at returned sensible output.

with these patches i was able to run the EEMBC testsuite on powerpc-eabi.

is this ok to apply?

2002-07-19  Aldy Hernandez  <aldyh@redhat.com>

	* newlib/libc/machine/powerpc/time.c: New file.

	* newlib/libc/machine/powerpc/Makefile.am (lib_a_SOURCES): Add
	time.c.

	* libgloss/rs6000/simulator.S (gettimeofday): New.
	(getrusage): New.

	* newlib/libc/machine/powerpc/Makefile.in: Regenerate.

	* newlib/libc/machine/powerpc/configure: Regenerate.

Index: libgloss/rs6000/simulator.S
===================================================================
RCS file: /cvs/src/src/libgloss/rs6000/simulator.S,v
retrieving revision 1.3
diff -c -p -r1.3 simulator.S
*** libgloss/rs6000/simulator.S	9 Mar 2001 07:31:34 -0000	1.3
--- libgloss/rs6000/simulator.S	20 Jul 2002 07:03:01 -0000
*************** FUNC_START(dup)
*** 79,84 ****
--- 79,100 ----
  	b	FUNC_NAME(_cerror)
  FUNC_END(dup)
  
+ FUNC_START(gettimeofday)
+ 	li	r0,116
+ 	sc
+ 	bns+	0f
+ 	b	FUNC_NAME(_cerror)
+ 0:	blr
+ FUNC_END(gettimeofday)
+ 
+ FUNC_START(getrusage)
+ 	li	r0,117
+ 	sc
+ 	bns+	0f
+ 	b	FUNC_NAME(_cerror)
+ 0:	blr
+ FUNC_END(getrusage)
+ 
  FUNC_START(lseek)
  	li	r0,199
  	sc
Index: newlib/libc/machine/powerpc/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/powerpc/Makefile.am,v
retrieving revision 1.2
diff -c -p -r1.2 Makefile.am
*** newlib/libc/machine/powerpc/Makefile.am	19 Apr 2002 19:16:16 -0000	1.2
--- newlib/libc/machine/powerpc/Makefile.am	20 Jul 2002 07:03:02 -0000
*************** INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLA
*** 6,12 ****
  
  noinst_LIBRARIES = lib.a
  
! lib_a_SOURCES = setjmp.S
  lib_a_LIBADD = @extra_objs@
  EXTRA_lib_a_SOURCES = @extra_sources@
  lib_a_DEPENDENCIES = @extra_objs@
--- 6,12 ----
  
  noinst_LIBRARIES = lib.a
  
! lib_a_SOURCES = setjmp.S time.c
  lib_a_LIBADD = @extra_objs@
  EXTRA_lib_a_SOURCES = @extra_sources@
  lib_a_DEPENDENCIES = @extra_objs@
Index: newlib/libc/machine/powerpc/time.c
===================================================================
RCS file: newlib/libc/machine/powerpc/time.c
diff -N newlib/libc/machine/powerpc/time.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- newlib/libc/machine/powerpc/time.c	20 Jul 2002 07:03:02 -0000
***************
*** 0 ****
--- 1,36 ----
+ /* Time support routines for PowerPC.
+  *
+  * Written by Aldy Hernandez.
+  */
+ 
+ #include <_ansi.h>
+ #include <reent.h>
+ #include <sys/time.h>
+ #include <sys/times.h>
+ #include <sys/resource.h>
+ 
+ clock_t
+ times (struct tms *tp)
+ {
+   struct rusage usage;
+   union {
+     struct rusage r;
+     /* Newlib's rusage has only 2 fields.  We need to make room for
+        when we call the system's rusage.  This should be enough.  */
+     int filler[32];
+   } host_ru;
+ 
+   getrusage (RUSAGE_SELF, (void *)&host_ru);
+ 
+   if (tp)
+     {
+       tp->tms_utime = host_ru.r.ru_utime.tv_sec * 1000
+ 	+ host_ru.r.ru_utime.tv_usec;
+       tp->tms_stime = host_ru.r.ru_stime.tv_sec * 1000
+ 	+ host_ru.r.ru_stime.tv_usec;
+       tp->tms_cutime = 0;	/* user time, children */
+       tp->tms_cstime = 0;	/* system time, children */
+     }
+ 
+   return tp->tms_utime;
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]