This is the mail archive of the newlib@sourceware.org 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]

Re: [PATCH] SPU Add support for nanosleep, sleep and usleep


Modified patch checked in (i.e. prototype in libc/include/sys/unistd.h moved).

2007-06-13 Patrick Mansfield <patmans@us.ibm.com>

        * libc/include/sys/features.h: Define _POSIX_TIMERS for spu.
        * libc/include/sys/unistd.h: Change usleep prototype to Posix
        form and move outside of OS flag checks.
        * libc/machine/spu/Makefile.am: Add sleep and usleep.
        * libc/machine/spu/Makefile.in: Regenerate.
        * libc/machine/spu/sleep.c: Copy libc/posix/sleep.c.
        * libc/machine/spu/usleep.c: Copy libc/posix/usleep.c.

-- Jeff J.

Patrick Mansfield wrote:
Add support for SPU nanosleep, sleep and usleep.

The SPU can only use 3 of the 19 files in libc/posix, so just copy the
ones we want (another patch is needed to add/use creat.c).

Depends on previous patch (newlib libc/machine/spu/Makefile.am change).

Note the libc/include/sys/unistd.h: to change from:
	unsigned _EXFUN(usleep, (unsigned int __useconds));
To:
	int _EXFUN(usleep, (useconds_t __useconds));

So we match both the existing usleep.c and POSIX.

libgloss ChangeLog:

2007-06-07 Patrick Mansfield <patmans@us.ibm.com>

	* spu/Makefile.in: Add nanosleep.c.
	* spu/jsre.h: Add JSRE_NANOSLEEP.
	* spu/nanosleep.c: New file, supply nanosleep via an assist call.

newlib ChangeLog:

2007-06-07 Patrick Mansfield <patmans@us.ibm.com>

	* libc/include/sys/features.h: Define _POSIX_TIMERS for spu.
	* libc/include/sys/unistd.h: Allow usleep() for spu, and update
	usleep to match the actual interface of "int usleep(useconds_t)".
	* libc/machine/spu/Makefile.am: Add sleep and usleep.
	* libc/machine/spu/Makefile.in: Regenerate.
	* libc/machine/spu/sleep.c: Copy libc/posix/sleep.c.
	* libc/machine/spu/usleep.c: Copy libc/posix/usleep.c.

Index: quilt/libgloss/spu/jsre.h
===================================================================
--- quilt.orig/libgloss/spu/jsre.h
+++ quilt/libgloss/spu/jsre.h
@@ -1,5 +1,5 @@
/*
-(C) Copyright IBM Corp. 2005, 2006
+(C) Copyright IBM Corp. 2005, 2006, 2007
All rights reserved.
@@ -49,6 +49,7 @@ Author: Andreas Neukoetter (ti95neuk@de.
#define JSRE_FTRUNCATE 28
#define JSRE_ACCESS 29
#define JSRE_DUP 30
+#define JSRE_NANOSLEEP 32
typedef struct {
unsigned int dev;
Index: quilt/libgloss/spu/nanosleep.c
===================================================================
--- /dev/null
+++ quilt/libgloss/spu/nanosleep.c
@@ -0,0 +1,52 @@
+/*
+ Copyright 2007
+ International Business Machines Corporation,
+ Sony Computer Entertainment, Incorporated,
+ Toshiba Corporation,
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the names of the copyright holders nor the names of their
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <time.h>
+#include "jsre.h"
+
+typedef struct {
+ unsigned int req;
+ unsigned int pad0[3];
+ unsigned int rem;
+ unsigned int pad1[3];
+} syscall_nanosleep_t;
+
+int
+nanosleep(const struct timespec *req, struct timespec *rem)
+{
+ syscall_nanosleep_t sys;
+
+ sys.req = (unsigned int) req;
+ sys.rem = (unsigned int) rem;
+ return __send_to_ppe(JSRE_POSIX1_SIGNALCODE, JSRE_NANOSLEEP, &sys);
+}
Index: quilt/libgloss/spu/Makefile.in
===================================================================
--- quilt.orig/libgloss/spu/Makefile.in
+++ quilt/libgloss/spu/Makefile.in
@@ -55,7 +55,7 @@ OBJCOPY = `t='$(program_transform_name)'
# object files needed
OBJS = syscalls.o exit.o sbrk.o close.o fstat.o getpid.o isatty.o \
- kill.o lseek.o open.o read.o unlink.o write.o stat.o \
+ kill.o lseek.o nanosleep.o open.o read.o unlink.o write.o stat.o \
ftruncate.o dup.o access.o gettimeofday.o
# Object files specific to particular targets.
Index: quilt/newlib/libc/machine/spu/Makefile.am
===================================================================
--- quilt.orig/newlib/libc/machine/spu/Makefile.am
+++ quilt/newlib/libc/machine/spu/Makefile.am
@@ -14,10 +14,10 @@ lib_a_SOURCES = setjmp.S clearerr.c fclo
fsetpos.c ftell.c fwrite.c getc.c getchar.c gets.c iprintf.c \
iscanf.c memcpy.c memmove.c memset.c mktemp.c perror.c printf.c \
putc.c putchar.c puts.c remove.c rename.c rewind.c scanf.c \
- setbuf.c setvbuf.c siprintf.c siscanf.c sniprintf.c snprintf.c \
- sprintf.c sscanf.c stdio.c strcat.c strchr.c strcmp.c strcpy.c \
- strcspn.c strlen.c strncat.c strncmp.c strncpy.c strpbrk.c \
- strrchr.c strspn.c strxfrm.c tmpfile.c tmpnam.c ungetc.c \
+ setbuf.c setvbuf.c siprintf.c siscanf.c sleep.c sniprintf.c \
+ snprintf.c sprintf.c sscanf.c stdio.c strcat.c strchr.c strcmp.c \
+ strcpy.c strcspn.c strlen.c strncat.c strncmp.c strncpy.c strpbrk.c \
+ strrchr.c strspn.c strxfrm.c tmpfile.c tmpnam.c ungetc.c usleep.c \
vfiprintf.c vfiscanf.c vfprintf.c vfscanf.c viprintf.c viscanf.c \
vprintf.c vscanf.c vsiprintf.c vsiscanf.c vsniprintf.c vsnprintf.c \
vsprintf.c vsscanf.c
Index: quilt/newlib/libc/machine/spu/Makefile.in
===================================================================
--- quilt.orig/newlib/libc/machine/spu/Makefile.in
+++ quilt/newlib/libc/machine/spu/Makefile.in
@@ -79,6 +79,7 @@ DIST_COMMON = $(srcdir)/../../../../conf
$(srcdir)/../../../../compile $(srcdir)/../../../../compile \
$(srcdir)/../../../../compile $(srcdir)/../../../../compile \
$(srcdir)/../../../../compile $(srcdir)/../../../../compile \
+ $(srcdir)/../../../../compile $(srcdir)/../../../../compile \
$(srcdir)/../../../../compile
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -116,17 +117,18 @@ am_lib_a_OBJECTS = lib_a-setjmp.$(OBJEXT
lib_a-rename.$(OBJEXT) lib_a-rewind.$(OBJEXT) \
lib_a-scanf.$(OBJEXT) lib_a-setbuf.$(OBJEXT) \
lib_a-setvbuf.$(OBJEXT) lib_a-siprintf.$(OBJEXT) \
- lib_a-siscanf.$(OBJEXT) lib_a-sniprintf.$(OBJEXT) \
- lib_a-snprintf.$(OBJEXT) lib_a-sprintf.$(OBJEXT) \
- lib_a-sscanf.$(OBJEXT) lib_a-stdio.$(OBJEXT) \
- lib_a-strcat.$(OBJEXT) lib_a-strchr.$(OBJEXT) \
- lib_a-strcmp.$(OBJEXT) lib_a-strcpy.$(OBJEXT) \
- lib_a-strcspn.$(OBJEXT) lib_a-strlen.$(OBJEXT) \
- lib_a-strncat.$(OBJEXT) lib_a-strncmp.$(OBJEXT) \
- lib_a-strncpy.$(OBJEXT) lib_a-strpbrk.$(OBJEXT) \
- lib_a-strrchr.$(OBJEXT) lib_a-strspn.$(OBJEXT) \
- lib_a-strxfrm.$(OBJEXT) lib_a-tmpfile.$(OBJEXT) \
- lib_a-tmpnam.$(OBJEXT) lib_a-ungetc.$(OBJEXT) \
+ lib_a-siscanf.$(OBJEXT) lib_a-sleep.$(OBJEXT) \
+ lib_a-sniprintf.$(OBJEXT) lib_a-snprintf.$(OBJEXT) \
+ lib_a-sprintf.$(OBJEXT) lib_a-sscanf.$(OBJEXT) \
+ lib_a-stdio.$(OBJEXT) lib_a-strcat.$(OBJEXT) \
+ lib_a-strchr.$(OBJEXT) lib_a-strcmp.$(OBJEXT) \
+ lib_a-strcpy.$(OBJEXT) lib_a-strcspn.$(OBJEXT) \
+ lib_a-strlen.$(OBJEXT) lib_a-strncat.$(OBJEXT) \
+ lib_a-strncmp.$(OBJEXT) lib_a-strncpy.$(OBJEXT) \
+ lib_a-strpbrk.$(OBJEXT) lib_a-strrchr.$(OBJEXT) \
+ lib_a-strspn.$(OBJEXT) lib_a-strxfrm.$(OBJEXT) \
+ lib_a-tmpfile.$(OBJEXT) lib_a-tmpnam.$(OBJEXT) \
+ lib_a-ungetc.$(OBJEXT) lib_a-usleep.$(OBJEXT) \
lib_a-vfiprintf.$(OBJEXT) lib_a-vfiscanf.$(OBJEXT) \
lib_a-vfprintf.$(OBJEXT) lib_a-vfscanf.$(OBJEXT) \
lib_a-viprintf.$(OBJEXT) lib_a-viscanf.$(OBJEXT) \
@@ -266,10 +268,10 @@ lib_a_SOURCES = setjmp.S clearerr.c fclo
fsetpos.c ftell.c fwrite.c getc.c getchar.c gets.c iprintf.c \
iscanf.c memcpy.c memmove.c memset.c mktemp.c perror.c printf.c \
putc.c putchar.c puts.c remove.c rename.c rewind.c scanf.c \
- setbuf.c setvbuf.c siprintf.c siscanf.c sniprintf.c snprintf.c \
- sprintf.c sscanf.c stdio.c strcat.c strchr.c strcmp.c strcpy.c \
- strcspn.c strlen.c strncat.c strncmp.c strncpy.c strpbrk.c \
- strrchr.c strspn.c strxfrm.c tmpfile.c tmpnam.c ungetc.c \
+ setbuf.c setvbuf.c siprintf.c siscanf.c sleep.c sniprintf.c \
+ snprintf.c sprintf.c sscanf.c stdio.c strcat.c strchr.c strcmp.c \
+ strcpy.c strcspn.c strlen.c strncat.c strncmp.c strncpy.c strpbrk.c \
+ strrchr.c strspn.c strxfrm.c tmpfile.c tmpnam.c ungetc.c usleep.c \
vfiprintf.c vfiscanf.c vfprintf.c vfscanf.c viprintf.c viscanf.c \
vprintf.c vscanf.c vsiprintf.c vsiscanf.c vsniprintf.c vsnprintf.c \
vsprintf.c vsscanf.c
@@ -611,6 +613,12 @@ lib_a-siscanf.o: siscanf.c
lib_a-siscanf.obj: siscanf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-siscanf.obj `if test -f 'siscanf.c'; then $(CYGPATH_W) 'siscanf.c'; else $(CYGPATH_W) '$(srcdir)/siscanf.c'; fi`
+lib_a-sleep.o: sleep.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sleep.o `test -f 'sleep.c' || echo '$(srcdir)/'`sleep.c
+
+lib_a-sleep.obj: sleep.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sleep.obj `if test -f 'sleep.c'; then $(CYGPATH_W) 'sleep.c'; else $(CYGPATH_W) '$(srcdir)/sleep.c'; fi`
+
lib_a-sniprintf.o: sniprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sniprintf.o `test -f 'sniprintf.c' || echo '$(srcdir)/'`sniprintf.c
@@ -737,6 +745,12 @@ lib_a-ungetc.o: ungetc.c
lib_a-ungetc.obj: ungetc.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ungetc.obj `if test -f 'ungetc.c'; then $(CYGPATH_W) 'ungetc.c'; else $(CYGPATH_W) '$(srcdir)/ungetc.c'; fi`
+lib_a-usleep.o: usleep.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-usleep.o `test -f 'usleep.c' || echo '$(srcdir)/'`usleep.c
+
+lib_a-usleep.obj: usleep.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-usleep.obj `if test -f 'usleep.c'; then $(CYGPATH_W) 'usleep.c'; else $(CYGPATH_W) '$(srcdir)/usleep.c'; fi`
+
lib_a-vfiprintf.o: vfiprintf.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-vfiprintf.o `test -f 'vfiprintf.c' || echo '$(srcdir)/'`vfiprintf.c
Index: quilt/newlib/libc/machine/spu/sleep.c
===================================================================
--- /dev/null
+++ quilt/newlib/libc/machine/spu/sleep.c
@@ -0,0 +1,18 @@
+/* Copied from libc/posix/sleep.c, removed the check for HAVE_NANOSLEEP */
+
+/* Written 2000 by Werner Almesberger */
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+unsigned sleep(unsigned seconds)
+{
+ struct timespec ts;
+
+ ts.tv_sec = seconds;
+ ts.tv_nsec = 0;
+ if (!nanosleep(&ts,&ts)) return 0;
+ if (errno == EINTR) return ts.tv_sec;
+ return -1;
+}
Index: quilt/newlib/libc/machine/spu/usleep.c
===================================================================
--- /dev/null
+++ quilt/newlib/libc/machine/spu/usleep.c
@@ -0,0 +1,18 @@
+/* Copied from libc/posix/usleep.c, removed the check for HAVE_NANOSLEEP */
+
+/* Written 2002 by Jeff Johnston */
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+int usleep(useconds_t useconds)
+{
+ struct timespec ts;
+
+ ts.tv_sec = (long int)useconds / 1000000;
+ ts.tv_nsec = ((long int)useconds % 1000000) * 1000;
+ if (!nanosleep(&ts,&ts)) return 0;
+ if (errno == EINTR) return ts.tv_sec;
+ return -1;
+}
Index: quilt/newlib/libc/include/sys/features.h
===================================================================
--- quilt.orig/newlib/libc/include/sys/features.h
+++ quilt/newlib/libc/include/sys/features.h
@@ -166,6 +166,11 @@ extern "C" {
#endif
+#ifdef __SPU__
+/* Not much for now! */
+#define _POSIX_TIMERS 1
+#endif
+
#ifdef __cplusplus
}
#endif
Index: quilt/newlib/libc/include/sys/unistd.h
===================================================================
--- quilt.orig/newlib/libc/include/sys/unistd.h
+++ quilt/newlib/libc/include/sys/unistd.h
@@ -196,11 +196,15 @@ int _EXFUN(ftruncate, (int __fd, off
int _EXFUN(truncate, (const char *, off_t __length));
#endif
#endif
+
+#if defined(__CYGWIN__) || defined(__rtems__) || defined(__SPU__)
+int _EXFUN(usleep, (useconds_t __useconds));
+#endif
+
#if defined(__CYGWIN__) || defined(__rtems__)
int _EXFUN(getdtablesize, (void));
int _EXFUN(setdtablesize, (int));
useconds_t _EXFUN(ualarm, (useconds_t __useconds, useconds_t __interval));
-unsigned _EXFUN(usleep, (unsigned int __useconds));
#if !(defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS))
/* winsock[2].h defines as __stdcall, and with int as 2nd arg */
int _EXFUN(gethostname, (char *__name, size_t __len));


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