linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc: wire up preadv and pwritev
@ 2009-04-07  3:19 Stephen Rothwell
  2009-04-07  6:51 ` Subrata Modak
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Rothwell @ 2009-04-07  3:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras
  Cc: Gerd, LKML, linuxppc-dev, Hoffmann, Andrew Morton, Linus


Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
---
 arch/powerpc/include/asm/systbl.h |    2 ++
 arch/powerpc/include/asm/unistd.h |    4 +++-
 2 files changed, 5 insertions(+), 1 deletions(-)

Tested on pseries_defconfig (verified using strace{,64} and inspecting
the files).  Test program (modified from the original because the API and
ABI changed and I added a test with larger offsets):

#if 0
set -x
gcc -Wall -O2 -m32 -o preadv $0
gcc -Wall -O2 -m32 -D_FILE_OFFSET_BITS=64 -DLARGE_TEST -o preadv32 $0
gcc -Wall -O2 -m64 -DLARGE_TEST -o preadv64 $0
./preadv
./preadv32
./preadv64
exit 0
#endif
/*
 * preadv demo / test
 *
 * (c) 2008 Gerd Hoffmann <kraxel@redhat.com>
 * Modified for new ABI and large offset test by Stephen Rothwell
 *
 * build with "sh $thisfile"
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <inttypes.h>
#include <sys/uio.h>

/* ----------------------------------------------------------------- */
/* syscall windup                                                    */

#include <sys/syscall.h>
#if 1
/* WARNING: Be sure you know what you are doing if you enable this.
 * linux syscall code isn't upstream yet, syscall numbers are subject
 * to change */
# ifndef __NR_preadv
#  ifdef __i386__
#   define __NR_preadv  333
#   define __NR_pwritev 334
#  endif
#  ifdef __x86_64__
#   define __NR_preadv  295
#   define __NR_pwritev 296
#  endif
#  ifdef __powerpc__
#   define __NR_preadv	319
#   define __NR_pwritev	320
#  endif
# endif
#endif
#ifndef __NR_preadv
# error preadv/pwritev syscall numbers are unknown
#endif

#define HALF_BITS (sizeof(unsigned long)*4)

static ssize_t preadv(int fd, const struct iovec *iov, int iovcnt,
		      off_t offset)
{
	return syscall(__NR_preadv, fd, iov, iovcnt,
		       (unsigned long)offset,
		       (unsigned long)((offset >> HALF_BITS) >> HALF_BITS));
}

static ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt,
		       off_t offset)
{
	return syscall(__NR_pwritev, fd, iov, iovcnt,
		       (unsigned long)offset,
		       (unsigned long)((offset >> HALF_BITS) >> HALF_BITS));
}

/* ----------------------------------------------------------------- */
/* demo/test app                                                     */

static char filename[] = "/tmp/preadv-XXXXXX";
static char outbuf[11] = "0123456789";
static char inbuf[11]  = "----------";

static struct iovec ovec[2] = {{
		.iov_base = outbuf + 5,
		.iov_len  = 5,
	},{
		.iov_base = outbuf + 0,
		.iov_len  = 5,
	}};

static struct iovec ivec[3] = {{
		.iov_base = inbuf + 6,
		.iov_len  = 2,
	},{
		.iov_base = inbuf + 4,
		.iov_len  = 2,
	},{
		.iov_base = inbuf + 2,
		.iov_len  = 2,
	}};

void cleanup(void)
{
	unlink(filename);
}

int main(int argc, char **argv)
{
	int fd, rc;

	fd = mkstemp(filename);
	if (-1 == fd) {
		perror("mkstemp");
		exit(1);
	}
	atexit(cleanup);

	/* write to file: "56789-01234" */
	rc = pwritev(fd, ovec, 2, 0);
	if (rc < 0) {
		perror("pwritev");
		exit(1);
	}

	/* read from file: "78-90-12" */
	rc = preadv(fd, ivec, 3, 2);
	if (rc < 0) {
		perror("preadv");
		exit(1);
	}

	printf("result  : %s\n", inbuf);
	printf("expected: %s\n", "--129078--");

#ifdef LARGE_TEST

	/* write to file: "56789-01234" */
	rc = pwritev(fd, ovec, 2, 0x300000000ULL);
	if (rc < 0) {
		perror("pwritev");
		exit(1);
	}

	/* read from file: "78-90-12" */
	rc = preadv(fd, ivec, 3, 0x300000000ULL + 2);
	if (rc < 0) {
		perror("preadv");
		exit(1);
	}

	printf("result  : %s\n", inbuf);
	printf("expected: %s\n", "--129078--");

#endif

	exit(0);
}


diff --git a/arch/powerpc/include/asm/systbl.h b/arch/powerpc/include/asm/systbl.h
index fe16649..3fb6d9e 100644
--- a/arch/powerpc/include/asm/systbl.h
+++ b/arch/powerpc/include/asm/systbl.h
@@ -322,3 +322,5 @@ SYSCALL_SPU(epoll_create1)
 SYSCALL_SPU(dup3)
 SYSCALL_SPU(pipe2)
 SYSCALL(inotify_init1)
+COMPAT_SYS_SPU(preadv)
+COMPAT_SYS_SPU(pwritev)
diff --git a/arch/powerpc/include/asm/unistd.h b/arch/powerpc/include/asm/unistd.h
index e07d0c7..7e03ebe 100644
--- a/arch/powerpc/include/asm/unistd.h
+++ b/arch/powerpc/include/asm/unistd.h
@@ -341,10 +341,12 @@
 #define __NR_dup3		316
 #define __NR_pipe2		317
 #define __NR_inotify_init1	318
+#define __NR_preadv		319
+#define __NR_pwritev		320
 
 #ifdef __KERNEL__
 
-#define __NR_syscalls		319
+#define __NR_syscalls		321
 
 #define __NR__exit __NR_exit
 #define NR_syscalls	__NR_syscalls
-- 
1.6.2.1

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] powerpc: wire up preadv and pwritev
  2009-04-07  3:19 [PATCH] powerpc: wire up preadv and pwritev Stephen Rothwell
@ 2009-04-07  6:51 ` Subrata Modak
  2009-04-07  7:30   ` Stephen Rothwell
  2009-04-07  7:52   ` Gerd Hoffmann
  0 siblings, 2 replies; 5+ messages in thread
From: Subrata Modak @ 2009-04-07  6:51 UTC (permalink / raw)
  To: Stephen Rothwell
  Cc: ltp-list, maknayak, linuxppc-dev, Paul Mackerras, Gerd Hoffmann

[-- Attachment #1: Type: text/plain, Size: 6117 bytes --]

Hi Stephen,

On Tue, Apr 7, 2009 at 8:49 AM, Stephen Rothwell <sfr@canb.auug.org.au>wrote:

>
> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
> ---
>  arch/powerpc/include/asm/systbl.h |    2 ++
>  arch/powerpc/include/asm/unistd.h |    4 +++-
>  2 files changed, 5 insertions(+), 1 deletions(-)
>
> Tested on pseries_defconfig (verified using strace{,64} and inspecting
> the files).  Test program (modified from the original because the API and
> ABI changed and I added a test with larger offsets):
>
> #if 0
> set -x
> gcc -Wall -O2 -m32 -o preadv $0
> gcc -Wall -O2 -m32 -D_FILE_OFFSET_BITS=64 -DLARGE_TEST -o preadv32 $0
> gcc -Wall -O2 -m64 -DLARGE_TEST -o preadv64 $0
> ./preadv
> ./preadv32
> ./preadv64
> exit 0
> #endif
> /*
>  * preadv demo / test
>  *
>  * (c) 2008 Gerd Hoffmann <kraxel@redhat.com>
>  * Modified for new ABI and large offset test by Stephen Rothwell
>  *
>  * build with "sh $thisfile"
>  */
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <errno.h>
> #include <inttypes.h>
> #include <sys/uio.h>
>
> /* ----------------------------------------------------------------- */
> /* syscall windup                                                    */
>
> #include <sys/syscall.h>
> #if 1
> /* WARNING: Be sure you know what you are doing if you enable this.
>  * linux syscall code isn't upstream yet, syscall numbers are subject
>  * to change */
> # ifndef __NR_preadv
> #  ifdef __i386__
> #   define __NR_preadv  333
> #   define __NR_pwritev 334
> #  endif
> #  ifdef __x86_64__
> #   define __NR_preadv  295
> #   define __NR_pwritev 296
> #  endif
> #  ifdef __powerpc__
> #   define __NR_preadv  319
> #   define __NR_pwritev 320
> #  endif
> # endif
> #endif
> #ifndef __NR_preadv
> # error preadv/pwritev syscall numbers are unknown
> #endif
>
> #define HALF_BITS (sizeof(unsigned long)*4)
>
> static ssize_t preadv(int fd, const struct iovec *iov, int iovcnt,
>                      off_t offset)
> {
>        return syscall(__NR_preadv, fd, iov, iovcnt,
>                       (unsigned long)offset,
>                       (unsigned long)((offset >> HALF_BITS) >> HALF_BITS));
> }
>
> static ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt,
>                       off_t offset)
> {
>        return syscall(__NR_pwritev, fd, iov, iovcnt,
>                       (unsigned long)offset,
>                       (unsigned long)((offset >> HALF_BITS) >> HALF_BITS));
> }
>
> /* ----------------------------------------------------------------- */
> /* demo/test app                                                     */
>
> static char filename[] = "/tmp/preadv-XXXXXX";
> static char outbuf[11] = "0123456789";
> static char inbuf[11]  = "----------";
>
> static struct iovec ovec[2] = {{
>                .iov_base = outbuf + 5,
>                .iov_len  = 5,
>        },{
>                .iov_base = outbuf + 0,
>                .iov_len  = 5,
>        }};
>
> static struct iovec ivec[3] = {{
>                .iov_base = inbuf + 6,
>                .iov_len  = 2,
>        },{
>                .iov_base = inbuf + 4,
>                .iov_len  = 2,
>        },{
>                .iov_base = inbuf + 2,
>                .iov_len  = 2,
>        }};
>
> void cleanup(void)
> {
>        unlink(filename);
> }
>
> int main(int argc, char **argv)
> {
>        int fd, rc;
>
>        fd = mkstemp(filename);
>        if (-1 == fd) {
>                perror("mkstemp");
>                exit(1);
>        }
>        atexit(cleanup);
>
>        /* write to file: "56789-01234" */
>        rc = pwritev(fd, ovec, 2, 0);
>        if (rc < 0) {
>                perror("pwritev");
>                exit(1);
>        }
>
>        /* read from file: "78-90-12" */
>        rc = preadv(fd, ivec, 3, 2);
>        if (rc < 0) {
>                perror("preadv");
>                exit(1);
>        }
>
>        printf("result  : %s\n", inbuf);
>        printf("expected: %s\n", "--129078--");
>
> #ifdef LARGE_TEST
>
>        /* write to file: "56789-01234" */
>        rc = pwritev(fd, ovec, 2, 0x300000000ULL);
>        if (rc < 0) {
>                perror("pwritev");
>                exit(1);
>        }
>
>        /* read from file: "78-90-12" */
>        rc = preadv(fd, ivec, 3, 0x300000000ULL + 2);
>        if (rc < 0) {
>                perror("preadv");
>                exit(1);
>        }
>
>        printf("result  : %s\n", inbuf);
>        printf("expected: %s\n", "--129078--");
>
> #endif
>
>        exit(0);
> }
>

How about contributing the above test to LTP(http://ltp.sourceforge.net/)
under GPL ? If you agree, i would soon send you a Patch integrating the same
to LTP.

Regards--
Subrata


>
> diff --git a/arch/powerpc/include/asm/systbl.h
> b/arch/powerpc/include/asm/systbl.h
> index fe16649..3fb6d9e 100644
> --- a/arch/powerpc/include/asm/systbl.h
> +++ b/arch/powerpc/include/asm/systbl.h
> @@ -322,3 +322,5 @@ SYSCALL_SPU(epoll_create1)
>  SYSCALL_SPU(dup3)
>  SYSCALL_SPU(pipe2)
>  SYSCALL(inotify_init1)
> +COMPAT_SYS_SPU(preadv)
> +COMPAT_SYS_SPU(pwritev)
> diff --git a/arch/powerpc/include/asm/unistd.h
> b/arch/powerpc/include/asm/unistd.h
> index e07d0c7..7e03ebe 100644
> --- a/arch/powerpc/include/asm/unistd.h
> +++ b/arch/powerpc/include/asm/unistd.h
> @@ -341,10 +341,12 @@
>  #define __NR_dup3              316
>  #define __NR_pipe2             317
>  #define __NR_inotify_init1     318
> +#define __NR_preadv            319
> +#define __NR_pwritev           320
>
>  #ifdef __KERNEL__
>
> -#define __NR_syscalls          319
> +#define __NR_syscalls          321
>
>  #define __NR__exit __NR_exit
>  #define NR_syscalls    __NR_syscalls
> --
> 1.6.2.1
>
> --
> Cheers,
> Stephen Rothwell                    sfr@canb.auug.org.au
> http://www.canb.auug.org.au/~sfr/ <http://www.canb.auug.org.au/%7Esfr/>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>



-- 
Regards & Thanks--
Subrata

[-- Attachment #2: Type: text/html, Size: 8487 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] powerpc: wire up preadv and pwritev
  2009-04-07  6:51 ` Subrata Modak
@ 2009-04-07  7:30   ` Stephen Rothwell
  2009-04-07  7:52   ` Gerd Hoffmann
  1 sibling, 0 replies; 5+ messages in thread
From: Stephen Rothwell @ 2009-04-07  7:30 UTC (permalink / raw)
  To: Subrata Modak
  Cc: ltp-list, maknayak, linuxppc-dev, Paul Mackerras, Gerd Hoffmann

[-- Attachment #1: Type: text/plain, Size: 583 bytes --]

Hi Subrata,

On Tue, 7 Apr 2009 12:21:18 +0530 Subrata Modak <tosubrata@gmail.com> wrote:
>
> How about contributing the above test to LTP(http://ltp.sourceforge.net/)
> under GPL ? If you agree, i would soon send you a Patch integrating the same
> to LTP.

I have no problem with that.  However, the test was originally written by
Gerd Hoffmann and is essentially unchanged (i just updated some details),
so I think that is where you should direct your request.

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] powerpc: wire up preadv and pwritev
  2009-04-07  6:51 ` Subrata Modak
  2009-04-07  7:30   ` Stephen Rothwell
@ 2009-04-07  7:52   ` Gerd Hoffmann
  2009-04-07  8:48     ` [LTP] " Subrata Modak
  1 sibling, 1 reply; 5+ messages in thread
From: Gerd Hoffmann @ 2009-04-07  7:52 UTC (permalink / raw)
  To: Subrata Modak
  Cc: Stephen Rothwell, ltp-list, maknayak, linuxppc-dev,
	Paul Mackerras

   Hi,

> How about contributing the above test to LTP(http://ltp.sourceforge.net/)
> under GPL ? If you agree, i would soon send you a Patch integrating the same
> to LTP.

Fine with me.  You probably want to remove the hard-coded syscall 
numbers and pickup them from unistd.h instead though.

cheers,
   Gerd

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] powerpc: wire up preadv and pwritev
  2009-04-07  7:52   ` Gerd Hoffmann
@ 2009-04-07  8:48     ` Subrata Modak
  0 siblings, 0 replies; 5+ messages in thread
From: Subrata Modak @ 2009-04-07  8:48 UTC (permalink / raw)
  To: Gerd Hoffmann, Stephen Rothwell
  Cc: ltp-list, maknayak, linuxppc-dev, Paul Mackerras, Subrata Modak

Thanks Gerd/Stephen,

On Tue, 2009-04-07 at 09:52 +0200, Gerd Hoffmann wrote:
> Hi,
> 
> > How about contributing the above test to LTP(http://ltp.sourceforge.net/)
> > under GPL ? If you agree, i would soon send you a Patch integrating the same
> > to LTP.
> 
> Fine with me.  You probably want to remove the hard-coded syscall 
> numbers and pickup them from unistd.h instead though.

Sure. We will do some necessary changes, and you will shortly hear from
us the Patch to integrate, and, retaining your Copyright on the test
program.

Regards--
Subrata

> 
> cheers,
>    Gerd
> 
> 
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> High Quality Requirements in a Collaborative Environment.
> Download a free trial of Rational Requirements Composer Now!
> http://p.sf.net/sfu/www-ibm-com
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-04-07  8:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-07  3:19 [PATCH] powerpc: wire up preadv and pwritev Stephen Rothwell
2009-04-07  6:51 ` Subrata Modak
2009-04-07  7:30   ` Stephen Rothwell
2009-04-07  7:52   ` Gerd Hoffmann
2009-04-07  8:48     ` [LTP] " Subrata Modak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).