Index: user/ngie/more-tests/tests/sys/aio/lio_kqueue.c =================================================================== --- user/ngie/more-tests/tests/sys/aio/lio_kqueue.c (revision 282079) +++ user/ngie/more-tests/tests/sys/aio/lio_kqueue.c (nonexistent) @@ -1,245 +0,0 @@ -/*- - * Copyright (C) 2005 IronPort Systems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * $FreeBSD$ - */ - -/* - * Note: it is a good idea to run this against a physical drive to - * exercise the physio fast path (ie. lio_kqueue /dev/) - * This will ensure op's counting is correct. It is currently broken. - * - * Also note that LIO & kqueue is not implemented in FreeBSD yet, LIO - * is also broken with respect to op's and some paths. - * - * A patch to make this work is at: - * http://www.ambrisko.com/doug/listio_kqueue/listio_kqueue.patch - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define PATH_TEMPLATE "/tmp/aio.XXXXXXXXXX" - -#define LIO_MAX 5 -#define MAX LIO_MAX * 16 -#define MAX_RUNS 300 - -int -main(int argc, char *argv[]){ - int fd; - struct aiocb *iocb[MAX]; - struct aiocb **lio[LIO_MAX], **lio_element, **kq_lio; - int i, result, run, error, j, k; - char buffer[32768]; - int kq = kqueue(); - struct kevent ke, kq_returned; - struct timespec ts; - struct sigevent sig; - time_t time1, time2; - char *file, pathname[sizeof(PATH_TEMPLATE)-1]; - int tmp_file = 0, failed = 0; - - if (kq < 0) { - perror("No kqeueue\n"); - exit(1); - } - - if (argc == 1) { - strcpy(pathname, PATH_TEMPLATE); - fd = mkstemp(pathname); - file = pathname; - tmp_file = 1; - } else { - file = argv[1]; - fd = open(file, O_RDWR|O_CREAT, 0666); - } - if (fd < 0){ - fprintf(stderr, "Can't open %s\n", argv[1]); - perror(""); - exit(1); - } - -#ifdef DEBUG - printf("Hello kq %d fd %d\n", kq, fd); -#endif - - for (run = 0; run < MAX_RUNS; run++){ -#ifdef DEBUG - printf("Run %d\n", run); -#endif - for (j = 0; j < LIO_MAX; j++) { - lio[j] = (struct aiocb **) - malloc(sizeof(struct aiocb *) * MAX/LIO_MAX); - for(i = 0; i < MAX / LIO_MAX; i++) { - k = (MAX / LIO_MAX * j) + i; - lio_element = lio[j]; - lio[j][i] = iocb[k] = (struct aiocb *) - malloc(sizeof(struct aiocb)); - bzero(iocb[k], sizeof(struct aiocb)); - iocb[k]->aio_nbytes = sizeof(buffer); - iocb[k]->aio_buf = buffer; - iocb[k]->aio_fildes = fd; - iocb[k]->aio_offset - = iocb[k]->aio_nbytes * k * (run + 1); - -#ifdef DEBUG - printf("hello iocb[k] %d\n", - iocb[k]->aio_offset); -#endif - iocb[k]->aio_lio_opcode = LIO_WRITE; - } - sig.sigev_notify_kqueue = kq; - sig.sigev_value.sival_ptr = lio[j]; - sig.sigev_notify = SIGEV_KEVENT; - time(&time1); - result = lio_listio(LIO_NOWAIT, lio[j], - MAX / LIO_MAX, &sig); - error = errno; - time(&time2); -#ifdef DEBUG - printf("Time %d %d %d result -> %d\n", - time1, time2, time2-time1, result); -#endif - if (result != 0) { - errno = error; - perror("list_listio"); - printf("FAIL: Result %d iteration %d\n",result, j); - exit(1); - } -#ifdef DEBUG - printf("write %d is at %p\n", j, lio[j]); -#endif - } - - for(i = 0; i < LIO_MAX; i++) { - for(j = LIO_MAX - 1; j >=0; j--) { - if (lio[j]) - break; - } - - for(;;) { - bzero(&ke, sizeof(ke)); - bzero(&kq_returned, sizeof(ke)); - ts.tv_sec = 0; - ts.tv_nsec = 1; -#ifdef DEBUG - printf("FOO lio %d -> %p\n", j, lio[j]); -#endif - EV_SET(&ke, (uintptr_t)lio[j], - EVFILT_LIO, EV_ONESHOT, 0, 0, iocb[j]); - result = kevent(kq, NULL, 0, - &kq_returned, 1, &ts); - error = errno; - if (result < 0) { - perror("kevent error: "); - } - kq_lio = kq_returned.udata; -#ifdef DEBUG - printf("kevent %d %d errno %d return.ident %p " - "return.data %p return.udata %p %p\n", - i, result, error, - kq_returned.ident, kq_returned.data, - kq_returned.udata, - lio[j]); -#endif - - if(kq_lio) - break; -#ifdef DEBUG - printf("Try again\n"); -#endif - } - -#ifdef DEBUG - printf("lio %p\n", lio); -#endif - - for (j = 0; j < LIO_MAX; j++) { - if (lio[j] == kq_lio) { - break; - } - } - if (j == LIO_MAX) { - printf("FAIL:\n"); - exit(1); - } - -#ifdef DEBUG - printf("Error Result for %d is %d\n", j, result); -#endif - if (result < 0) { - printf("FAIL: run %d, operation %d result %d \n", run, LIO_MAX - i -1, result); - failed = 1; - } else { - printf("PASS: run %d, operation %d result %d \n", run, LIO_MAX - i -1, result); - } - for(k = 0; k < MAX / LIO_MAX; k++){ - result = aio_return(kq_lio[k]); -#ifdef DEBUG - printf("Return Resulto for %d %d is %d\n", j, k, result); -#endif - if (result != sizeof(buffer)) { - printf("FAIL: run %d, operation %d sub-opt %d result %d (errno=%d) should be %zu\n", - run, LIO_MAX - i -1, k, result, errno, sizeof(buffer)); - } else { - printf("PASS: run %d, operation %d sub-opt %d result %d\n", - run, LIO_MAX - i -1, k, result); - } - } -#ifdef DEBUG - printf("\n"); -#endif - - for(k = 0; k < MAX / LIO_MAX; k++) { - free(lio[j][k]); - } - free(lio[j]); - lio[j] = NULL; - } - } -#ifdef DEBUG - printf("Done\n"); -#endif - - if (tmp_file) { - unlink(pathname); - } - - if (failed) { - printf("FAIL: Atleast one\n"); - exit(1); - } else { - printf("PASS: All\n"); - exit(0); - } -} Property changes on: user/ngie/more-tests/tests/sys/aio/lio_kqueue.c ___________________________________________________________________ Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Index: user/ngie/more-tests/tests/sys/aio/aio_kqueue.c =================================================================== --- user/ngie/more-tests/tests/sys/aio/aio_kqueue.c (revision 282079) +++ user/ngie/more-tests/tests/sys/aio/aio_kqueue.c (nonexistent) @@ -1,207 +0,0 @@ -/*- - * Copyright (C) 2005 IronPort Systems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * $FreeBSD$ - */ - -/* - * Prerequisities: - * - AIO support must be compiled into the kernel (see sys//NOTES for - * more details). - * - * Note: it is a good idea to run this against a physical drive to - * exercise the physio fast path (ie. aio_kqueue /dev/) - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define PATH_TEMPLATE "/tmp/aio.XXXXXXXXXX" - -#define MAX 128 -#define MAX_RUNS 300 -/* #define DEBUG */ - -int -main (int argc, char *argv[]) -{ - int fd; - struct aiocb *iocb[MAX], *kq_iocb; - int i, result, run, error, j; - char buffer[32768]; - int kq = kqueue(); - struct kevent ke, kq_returned; - struct timespec ts; - int cancel, pending, tmp_file = 0, failed = 0; - char *file, pathname[sizeof(PATH_TEMPLATE)+1]; - - if (kq < 0) { - perror("No kqeueue\n"); - exit(1); - } - - if (argc == 1) { - strcpy(pathname, PATH_TEMPLATE); - fd = mkstemp(pathname); - file = pathname; - tmp_file = 1; - } else { - file = argv[1]; - fd = open(file, O_RDWR|O_CREAT, 0666); - } - if (fd == -1) - err(1, "Can't open %s\n", file); - - for (run = 0; run < MAX_RUNS; run++){ -#ifdef DEBUG - printf("Run %d\n", run); -#endif - for (i = 0; i < MAX; i++) { - iocb[i] = (struct aiocb *)calloc(1, - sizeof(struct aiocb)); - if (iocb[i] == NULL) - err(1, "calloc"); - } - - pending = 0; - for (i = 0; i < MAX; i++) { - pending++; - iocb[i]->aio_nbytes = sizeof(buffer); - iocb[i]->aio_buf = buffer; - iocb[i]->aio_fildes = fd; - iocb[i]->aio_offset = iocb[i]->aio_nbytes * i * run; - - iocb[i]->aio_sigevent.sigev_notify_kqueue = kq; - iocb[i]->aio_sigevent.sigev_value.sival_ptr = iocb[i]; - iocb[i]->aio_sigevent.sigev_notify = SIGEV_KEVENT; - - result = aio_write(iocb[i]); - if (result != 0) { - perror("aio_write"); - printf("Result %d iteration %d\n", result, i); - exit(1); - } -#ifdef DEBUG - printf("WRITE %d is at %p\n", i, iocb[i]); -#endif - result = rand(); - if (result < RAND_MAX/32) { - if (result > RAND_MAX/64) { - result = aio_cancel(fd, iocb[i]); -#ifdef DEBUG - printf("Cancel %d %p result %d\n", i, iocb[i], result); -#endif - if (result == AIO_CANCELED) { - aio_return(iocb[i]); - iocb[i] = NULL; - pending--; - } - } - } - } - cancel = MAX - pending; - - i = 0; - while (pending) { - - for (;;) { - - bzero(&ke, sizeof(ke)); - bzero(&kq_returned, sizeof(ke)); - ts.tv_sec = 0; - ts.tv_nsec = 1; - result = kevent(kq, NULL, 0, - &kq_returned, 1, &ts); - error = errno; - if (result < 0) - perror("kevent error: "); - kq_iocb = kq_returned.udata; -#ifdef DEBUG - printf("kevent %d %d errno %d return.ident %p " - "return.data %p return.udata %p %p\n", - i, result, error, - kq_returned.ident, kq_returned.data, - kq_returned.udata, - kq_iocb); -#endif - - if (kq_iocb) - break; -#ifdef DEBUG - printf("Try again left %d out of %d %d\n", - pending, MAX, cancel); -#endif - } - - for (j = 0; j < MAX && iocb[j] != kq_iocb; - j++) ; -#ifdef DEBUG - printf("kq_iocb %p\n", kq_iocb); - - printf("Error Result for %d is %d pending %d\n", - j, result, pending); -#endif - result = aio_return(kq_iocb); -#ifdef DEBUG - printf("Return Result for %d is %d\n\n", j, result); -#endif - if (result != sizeof(buffer)) { - printf("FAIL: run %d, operation %d, result %d " - " (errno=%d) should be %zu\n", run, pending, - result, errno, sizeof(buffer)); - failed++; - } else - printf("PASS: run %d, left %d\n", run, - pending - 1); - - free(kq_iocb); - iocb[j] = NULL; - pending--; - i++; - } - - for (i = 0; i < MAX; i++) - free(iocb[i]); - - } - - if (tmp_file) - unlink(pathname); - - if (failed != 0) - printf("FAIL: %d tests failed\n", failed); - else - printf("PASS: All tests passed\n"); - - exit (failed == 0 ? 0 : 1); -} Property changes on: user/ngie/more-tests/tests/sys/aio/aio_kqueue.c ___________________________________________________________________ Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Index: user/ngie/more-tests/tests/sys/aio/aio_kqueue_test.c =================================================================== --- user/ngie/more-tests/tests/sys/aio/aio_kqueue_test.c (nonexistent) +++ user/ngie/more-tests/tests/sys/aio/aio_kqueue_test.c (revision 282080) @@ -0,0 +1,207 @@ +/*- + * Copyright (C) 2005 IronPort Systems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +/* + * Prerequisities: + * - AIO support must be compiled into the kernel (see sys//NOTES for + * more details). + * + * Note: it is a good idea to run this against a physical drive to + * exercise the physio fast path (ie. aio_kqueue /dev/) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PATH_TEMPLATE "/tmp/aio.XXXXXXXXXX" + +#define MAX 128 +#define MAX_RUNS 300 +/* #define DEBUG */ + +int +main (int argc, char *argv[]) +{ + int fd; + struct aiocb *iocb[MAX], *kq_iocb; + int i, result, run, error, j; + char buffer[32768]; + int kq = kqueue(); + struct kevent ke, kq_returned; + struct timespec ts; + int cancel, pending, tmp_file = 0, failed = 0; + char *file, pathname[sizeof(PATH_TEMPLATE)+1]; + + if (kq < 0) { + perror("No kqeueue\n"); + exit(1); + } + + if (argc == 1) { + strcpy(pathname, PATH_TEMPLATE); + fd = mkstemp(pathname); + file = pathname; + tmp_file = 1; + } else { + file = argv[1]; + fd = open(file, O_RDWR|O_CREAT, 0666); + } + if (fd == -1) + err(1, "Can't open %s\n", file); + + for (run = 0; run < MAX_RUNS; run++){ +#ifdef DEBUG + printf("Run %d\n", run); +#endif + for (i = 0; i < MAX; i++) { + iocb[i] = (struct aiocb *)calloc(1, + sizeof(struct aiocb)); + if (iocb[i] == NULL) + err(1, "calloc"); + } + + pending = 0; + for (i = 0; i < MAX; i++) { + pending++; + iocb[i]->aio_nbytes = sizeof(buffer); + iocb[i]->aio_buf = buffer; + iocb[i]->aio_fildes = fd; + iocb[i]->aio_offset = iocb[i]->aio_nbytes * i * run; + + iocb[i]->aio_sigevent.sigev_notify_kqueue = kq; + iocb[i]->aio_sigevent.sigev_value.sival_ptr = iocb[i]; + iocb[i]->aio_sigevent.sigev_notify = SIGEV_KEVENT; + + result = aio_write(iocb[i]); + if (result != 0) { + perror("aio_write"); + printf("Result %d iteration %d\n", result, i); + exit(1); + } +#ifdef DEBUG + printf("WRITE %d is at %p\n", i, iocb[i]); +#endif + result = rand(); + if (result < RAND_MAX/32) { + if (result > RAND_MAX/64) { + result = aio_cancel(fd, iocb[i]); +#ifdef DEBUG + printf("Cancel %d %p result %d\n", i, iocb[i], result); +#endif + if (result == AIO_CANCELED) { + aio_return(iocb[i]); + iocb[i] = NULL; + pending--; + } + } + } + } + cancel = MAX - pending; + + i = 0; + while (pending) { + + for (;;) { + + bzero(&ke, sizeof(ke)); + bzero(&kq_returned, sizeof(ke)); + ts.tv_sec = 0; + ts.tv_nsec = 1; + result = kevent(kq, NULL, 0, + &kq_returned, 1, &ts); + error = errno; + if (result < 0) + perror("kevent error: "); + kq_iocb = kq_returned.udata; +#ifdef DEBUG + printf("kevent %d %d errno %d return.ident %p " + "return.data %p return.udata %p %p\n", + i, result, error, + kq_returned.ident, kq_returned.data, + kq_returned.udata, + kq_iocb); +#endif + + if (kq_iocb) + break; +#ifdef DEBUG + printf("Try again left %d out of %d %d\n", + pending, MAX, cancel); +#endif + } + + for (j = 0; j < MAX && iocb[j] != kq_iocb; + j++) ; +#ifdef DEBUG + printf("kq_iocb %p\n", kq_iocb); + + printf("Error Result for %d is %d pending %d\n", + j, result, pending); +#endif + result = aio_return(kq_iocb); +#ifdef DEBUG + printf("Return Result for %d is %d\n\n", j, result); +#endif + if (result != sizeof(buffer)) { + printf("FAIL: run %d, operation %d, result %d " + " (errno=%d) should be %zu\n", run, pending, + result, errno, sizeof(buffer)); + failed++; + } else + printf("PASS: run %d, left %d\n", run, + pending - 1); + + free(kq_iocb); + iocb[j] = NULL; + pending--; + i++; + } + + for (i = 0; i < MAX; i++) + free(iocb[i]); + + } + + if (tmp_file) + unlink(pathname); + + if (failed != 0) + printf("FAIL: %d tests failed\n", failed); + else + printf("PASS: All tests passed\n"); + + exit (failed == 0 ? 0 : 1); +} Property changes on: user/ngie/more-tests/tests/sys/aio/aio_kqueue_test.c ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mergeinfo ## -0,0 +0,19 ## Merged /projects/pf/head/tests/sys/aio/aio_kqueue_test.c:r263908 Merged /projects/elftoolchain/tests/sys/aio/aio_kqueue_test.c:r260687-261245 Merged /projects/multi-fibv6/head/tests/sys/aio/aio_kqueue_test.c:r230929-231848 Merged /projects/building-blocks/tests/sys/aio/aio_kqueue_test.c:r275142-275143,275198,275297,275306-275307,275309,275311,275556,275558,275600,277445,277670,277673 Merged /projects/ipfw/tests/sys/aio/aio_kqueue_test.c:r267383-272837 Merged /vendor/resolver/dist/tests/sys/aio/aio_kqueue_test.c:r1540-186085 Merged /projects/clang350-import/tests/sys/aio/aio_kqueue_test.c:r274961-275126,275128-275133,275135-276476 Merged /projects/release-arm64/tests/sys/aio/aio_kqueue_test.c:r281786,281788,281792 Merged /projects/clang360-import/tests/sys/aio/aio_kqueue_test.c:r277327-280030 Merged /projects/quota64/tests/sys/aio/aio_kqueue_test.c:r184125-207707 Merged /projects/release-embedded/tests/sys/aio/aio_kqueue_test.c:r262314,262504,262510-262511,262580,262660,262662,262700,262713,262774,262786-262788,262790-262792,262798,262802,262808 Merged /projects/elftoolchain-update-r3130/tests/sys/aio/aio_kqueue_test.c:r276164,276167,276170-276172 Merged /projects/largeSMP/tests/sys/aio/aio_kqueue_test.c:r221273-222812,222815-223757 Merged /projects/random_number_generator/tests/sys/aio/aio_kqueue_test.c:r254613-256243 Merged /projects/head_mfi/tests/sys/aio/aio_kqueue_test.c:r233621 Merged /projects/zfsd/head/tests/sys/aio/aio_kqueue_test.c:r266519,269993 Merged /projects/lldb-r201577/tests/sys/aio/aio_kqueue_test.c:r262185-262527 Merged /projects/clang-sparc64/tests/sys/aio/aio_kqueue_test.c:r262258-262612 Merged /user/ngie/more-tests/tests/sys/aio/aio_kqueue_test.c:r281427-281428,281430,281432,281450,281460,281464-281465,281485,281489-281491,281515,281519,281589,281593-281597,281619 Index: user/ngie/more-tests/tests/sys/aio/lio_kqueue_test.c =================================================================== --- user/ngie/more-tests/tests/sys/aio/lio_kqueue_test.c (nonexistent) +++ user/ngie/more-tests/tests/sys/aio/lio_kqueue_test.c (revision 282080) @@ -0,0 +1,245 @@ +/*- + * Copyright (C) 2005 IronPort Systems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +/* + * Note: it is a good idea to run this against a physical drive to + * exercise the physio fast path (ie. lio_kqueue /dev/) + * This will ensure op's counting is correct. It is currently broken. + * + * Also note that LIO & kqueue is not implemented in FreeBSD yet, LIO + * is also broken with respect to op's and some paths. + * + * A patch to make this work is at: + * http://www.ambrisko.com/doug/listio_kqueue/listio_kqueue.patch + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PATH_TEMPLATE "/tmp/aio.XXXXXXXXXX" + +#define LIO_MAX 5 +#define MAX LIO_MAX * 16 +#define MAX_RUNS 300 + +int +main(int argc, char *argv[]){ + int fd; + struct aiocb *iocb[MAX]; + struct aiocb **lio[LIO_MAX], **lio_element, **kq_lio; + int i, result, run, error, j, k; + char buffer[32768]; + int kq = kqueue(); + struct kevent ke, kq_returned; + struct timespec ts; + struct sigevent sig; + time_t time1, time2; + char *file, pathname[sizeof(PATH_TEMPLATE)-1]; + int tmp_file = 0, failed = 0; + + if (kq < 0) { + perror("No kqeueue\n"); + exit(1); + } + + if (argc == 1) { + strcpy(pathname, PATH_TEMPLATE); + fd = mkstemp(pathname); + file = pathname; + tmp_file = 1; + } else { + file = argv[1]; + fd = open(file, O_RDWR|O_CREAT, 0666); + } + if (fd < 0){ + fprintf(stderr, "Can't open %s\n", argv[1]); + perror(""); + exit(1); + } + +#ifdef DEBUG + printf("Hello kq %d fd %d\n", kq, fd); +#endif + + for (run = 0; run < MAX_RUNS; run++){ +#ifdef DEBUG + printf("Run %d\n", run); +#endif + for (j = 0; j < LIO_MAX; j++) { + lio[j] = (struct aiocb **) + malloc(sizeof(struct aiocb *) * MAX/LIO_MAX); + for(i = 0; i < MAX / LIO_MAX; i++) { + k = (MAX / LIO_MAX * j) + i; + lio_element = lio[j]; + lio[j][i] = iocb[k] = (struct aiocb *) + malloc(sizeof(struct aiocb)); + bzero(iocb[k], sizeof(struct aiocb)); + iocb[k]->aio_nbytes = sizeof(buffer); + iocb[k]->aio_buf = buffer; + iocb[k]->aio_fildes = fd; + iocb[k]->aio_offset + = iocb[k]->aio_nbytes * k * (run + 1); + +#ifdef DEBUG + printf("hello iocb[k] %d\n", + iocb[k]->aio_offset); +#endif + iocb[k]->aio_lio_opcode = LIO_WRITE; + } + sig.sigev_notify_kqueue = kq; + sig.sigev_value.sival_ptr = lio[j]; + sig.sigev_notify = SIGEV_KEVENT; + time(&time1); + result = lio_listio(LIO_NOWAIT, lio[j], + MAX / LIO_MAX, &sig); + error = errno; + time(&time2); +#ifdef DEBUG + printf("Time %d %d %d result -> %d\n", + time1, time2, time2-time1, result); +#endif + if (result != 0) { + errno = error; + perror("list_listio"); + printf("FAIL: Result %d iteration %d\n",result, j); + exit(1); + } +#ifdef DEBUG + printf("write %d is at %p\n", j, lio[j]); +#endif + } + + for(i = 0; i < LIO_MAX; i++) { + for(j = LIO_MAX - 1; j >=0; j--) { + if (lio[j]) + break; + } + + for(;;) { + bzero(&ke, sizeof(ke)); + bzero(&kq_returned, sizeof(ke)); + ts.tv_sec = 0; + ts.tv_nsec = 1; +#ifdef DEBUG + printf("FOO lio %d -> %p\n", j, lio[j]); +#endif + EV_SET(&ke, (uintptr_t)lio[j], + EVFILT_LIO, EV_ONESHOT, 0, 0, iocb[j]); + result = kevent(kq, NULL, 0, + &kq_returned, 1, &ts); + error = errno; + if (result < 0) { + perror("kevent error: "); + } + kq_lio = kq_returned.udata; +#ifdef DEBUG + printf("kevent %d %d errno %d return.ident %p " + "return.data %p return.udata %p %p\n", + i, result, error, + kq_returned.ident, kq_returned.data, + kq_returned.udata, + lio[j]); +#endif + + if(kq_lio) + break; +#ifdef DEBUG + printf("Try again\n"); +#endif + } + +#ifdef DEBUG + printf("lio %p\n", lio); +#endif + + for (j = 0; j < LIO_MAX; j++) { + if (lio[j] == kq_lio) { + break; + } + } + if (j == LIO_MAX) { + printf("FAIL:\n"); + exit(1); + } + +#ifdef DEBUG + printf("Error Result for %d is %d\n", j, result); +#endif + if (result < 0) { + printf("FAIL: run %d, operation %d result %d \n", run, LIO_MAX - i -1, result); + failed = 1; + } else { + printf("PASS: run %d, operation %d result %d \n", run, LIO_MAX - i -1, result); + } + for(k = 0; k < MAX / LIO_MAX; k++){ + result = aio_return(kq_lio[k]); +#ifdef DEBUG + printf("Return Resulto for %d %d is %d\n", j, k, result); +#endif + if (result != sizeof(buffer)) { + printf("FAIL: run %d, operation %d sub-opt %d result %d (errno=%d) should be %zu\n", + run, LIO_MAX - i -1, k, result, errno, sizeof(buffer)); + } else { + printf("PASS: run %d, operation %d sub-opt %d result %d\n", + run, LIO_MAX - i -1, k, result); + } + } +#ifdef DEBUG + printf("\n"); +#endif + + for(k = 0; k < MAX / LIO_MAX; k++) { + free(lio[j][k]); + } + free(lio[j]); + lio[j] = NULL; + } + } +#ifdef DEBUG + printf("Done\n"); +#endif + + if (tmp_file) { + unlink(pathname); + } + + if (failed) { + printf("FAIL: Atleast one\n"); + exit(1); + } else { + printf("PASS: All\n"); + exit(0); + } +} Property changes on: user/ngie/more-tests/tests/sys/aio/lio_kqueue_test.c ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mergeinfo ## -0,0 +0,19 ## Merged /projects/elftoolchain/tests/sys/aio/lio_kqueue_test.c:r260687-261245 Merged /projects/multi-fibv6/head/tests/sys/aio/lio_kqueue_test.c:r230929-231848 Merged /projects/ipfw/tests/sys/aio/lio_kqueue_test.c:r267383-272837 Merged /projects/clang-sparc64/tests/sys/aio/lio_kqueue_test.c:r262258-262612 Merged /user/ngie/more-tests/tests/sys/aio/lio_kqueue_test.c:r281427-281428,281430,281432,281450,281460,281464-281465,281485,281489-281491,281515,281519,281589,281593-281597,281619 Merged /projects/pf/head/tests/sys/aio/lio_kqueue_test.c:r263908 Merged /projects/building-blocks/tests/sys/aio/lio_kqueue_test.c:r275142-275143,275198,275297,275306-275307,275309,275311,275556,275558,275600,277445,277670,277673 Merged /projects/release-embedded/tests/sys/aio/lio_kqueue_test.c:r262314,262504,262510-262511,262580,262660,262662,262700,262713,262774,262786-262788,262790-262792,262798,262802,262808 Merged /projects/largeSMP/tests/sys/aio/lio_kqueue_test.c:r221273-222812,222815-223757 Merged /projects/release-arm64/tests/sys/aio/lio_kqueue_test.c:r281786,281788,281792 Merged /projects/head_mfi/tests/sys/aio/lio_kqueue_test.c:r233621 Merged /projects/elftoolchain-update-r3130/tests/sys/aio/lio_kqueue_test.c:r276164,276167,276170-276172 Merged /vendor/resolver/dist/tests/sys/aio/lio_kqueue_test.c:r1540-186085 Merged /projects/clang350-import/tests/sys/aio/lio_kqueue_test.c:r274961-275126,275128-275133,275135-276476 Merged /projects/clang360-import/tests/sys/aio/lio_kqueue_test.c:r277327-280030 Merged /projects/quota64/tests/sys/aio/lio_kqueue_test.c:r184125-207707 Merged /projects/lldb-r201577/tests/sys/aio/lio_kqueue_test.c:r262185-262527 Merged /projects/random_number_generator/tests/sys/aio/lio_kqueue_test.c:r254613-256243 Merged /projects/zfsd/head/tests/sys/aio/lio_kqueue_test.c:r266519,269993