On Fri, 2008-06-20 at 00:16 +0530, Vijay Kumar wrote:
> Subrata Modak wrote:
> > I would go with you. So, are you resending a renewed patch without any
> > build/run brakes ? Nothing in hurry at all ;-)
> 
> OK, here is the updated patch. The following changes have been made.
> 
>   1. Setting setuid root for move_pages03.
>   2. Checking for NUMA support in top level Makefile.
>   3. Moved NUMA detection script to tools/script. This is where
>      Garrett is moving all the build scripts.
>   4. Checking for required kernel version and architecture.
> 
> Signed-off-by: Vijay Kumar <[EMAIL PROTECTED]>

Thanks for the revised patch. I had an opportunity to test it across
various machines and architectures. Although i have not tested it across
a real NUMA node, but it also has some build/install/run issues with
non-numa machines as well, which also needs to be fixed.

Following are my observations on testing this patch:

1) Building is not done for most of the architectures which does not
have NUMA support. But there is an unwanted failure on an i686 machine
for kernel 2.6.7, which should not happen. Please see the exact nature
of the error below.
2) Install does not create problem when building is not done at all.
3) Running move_pages01,move_pages02 and move_pages03 through
runtests/syscalls and runtest/numa will create problem as the
corresponding testcases will not be found under testcases/bin, as they
are not built in the first place. In such a scenario, even default
ltp/runltp will throw the following error:

initiation_status="pan(): execvp of 'move_pages01' (tag move_pages01)
failed.  errno:2  No such file or directory"
initiation_status="pan(): execvp of 'move_pages02' (tag move_pages02)
failed.  errno:2  No such file or directory"
initiation_status="pan(): execvp of 'move_pages03' (tag move_pages03)
failed.  errno:2  No such file or directory"

The user will not entertain this, rather some message like below can be
displayed instead:
move_pages01 0 CONF : System doesn't support execution of the test
move_pages02 0 CONF : System doesn't support execution of the test
move_pages03 0 CONF : System doesn't support execution of the test

And the above should be done inside runtest/syscalls and runtest/numa,
through shell command checking for testcases/bin/move_pages*. If found,
it should execute the test, else display the above message. The code
inside runtest/syscalls and runtest/numa can be of like:

move_page01 if [ -f move_pages01 ]; then move_pages01; else echo
"move_pages01 0 CONF : System doesn't support execution of the test";
exit 0; fi
move_page02 if [ -f move_pages02 ]; then move_pages02; else echo
"move_pages02 0 CONF : System doesn't support execution of the test";
exit 0; fi
move_page03 if [ -f move_pages03 ]; then move_pages03; else echo
"move_pages03 0 CONF : System doesn't support execution of the test";
exit 0; fi


I would request you to look in to the build failure, as well as fix the
run error when the system does not support NUMA, but move_pages* will be
called from runtest/syscalls and runtest/numa. You can resend me a fresh
patch after incorporating the mentioned points, as well as after getting
review comments from SUZUKI.

Following are results as obtained on various machines/architectures:
=====================================================================
=====================================================================
1) Linux 2.6.23.13 #1 SMP Wed Jan 9 18:14:28 PST 2008 ia64 GNU/Linux 
[move_pages: No build, No Install, Run will give following failures,
initiation_status="pan(4640): execvp of 'move_pages01' (tag
move_pages01) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages02' (tag
move_pages02) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages03' (tag
move_pages03) failed.  errno:2  No such file or directory"
]
=====================================================================
2) Linux 2.6.16.21-0.8-default #1 SMP Mon Jul 3 18:25:39 UTC 2006 ia64
ia64 ia64 GNU/Linux
[move_pages: No build, No Install, Run will give following failures,
initiation_status="pan(4640): execvp of 'move_pages01' (tag
move_pages01) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages02' (tag
move_pages02) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages03' (tag
move_pages03) failed.  errno:2  No such file or directory"
]
=====================================================================
3) Linux 2.6.9-70.EL #1 Fri May 2 13:00:36 EDT 2008 x86_64 x86_64 x86_64
GNU/Linux
[move_pages: No build, No Install, Run will give following failures,
initiation_status="pan(4640): execvp of 'move_pages01' (tag
move_pages01) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages02' (tag
move_pages02) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages03' (tag
move_pages03) failed.  errno:2  No such file or directory"
]
=====================================================================
4) Linux 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:15 EDT 2008 x86_64 x86_64
x86_64 GNU/Linux 
[move_pages: No build, No Install, Run will give following failures,
initiation_status="pan(4640): execvp of 'move_pages01' (tag
move_pages01) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages02' (tag
move_pages02) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages03' (tag
move_pages03) failed.  errno:2  No such file or directory"
]
=====================================================================
5) Linux 2.6.15-23-server #1 SMP Tue May 23 15:10:35 UTC 2006 i686
GNU/Linux
[move_pages: No build, No Install, Run will give following failures,
initiation_status="pan(4640): execvp of 'move_pages01' (tag
move_pages01) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages02' (tag
move_pages02) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages03' (tag
move_pages03) failed.  errno:2  No such file or directory"
]
=====================================================================
6) Linux 2.6.7 #1 SMP Tue Aug 10 15:35:24 PDT 2004 i686 GNU/Linux  
[move_pages: Build Failure,
make[4]: Entering directory
`/root/subrata/ltp/ltp/testcases/kernel/syscalls/move_pages'
cc -Wall  -I../../include -g -Wall -I../../../../include -Wall   -c -o
move_pages_support.o move_pages_support.c
move_pages_support.c:2:29: linux/mempolicy.h: No such file or directory
make[4]: *** [move_pages_support.o] Error 1
]
=====================================================================
7) Linux 2.6.9-42.EL #1 SMP Wed Jul 12 23:22:51 EDT 2006 ppc64 ppc64
ppc64 GNU/Linux
[move_pages: No build, No Install, Run will give following failures,
initiation_status="pan(4640): execvp of 'move_pages01' (tag
move_pages01) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages02' (tag
move_pages02) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages03' (tag
move_pages03) failed.  errno:2  No such file or directory"
]
=====================================================================
8) Linux 2.6.18-92.el5 #1 SMP Tue Apr 29 13:21:29 EDT 2008 ppc64 ppc64
ppc64 GNU/Linux
[move_pages: No build, No Install, Run will give following failures,
initiation_status="pan(4640): execvp of 'move_pages01' (tag
move_pages01) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages02' (tag
move_pages02) failed.  errno:2  No such file or directory"
initiation_status="pan(4640): execvp of 'move_pages03' (tag
move_pages03) failed.  errno:2  No such file or directory"
]
=====================================================================
=====================================================================

Regards--
Subrata

> 
> Index: ltp-stripped/testcases/kernel/syscalls/move_pages/Makefile
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ ltp-stripped/testcases/kernel/syscalls/move_pages/Makefile        
> 2008-06-19 22:51:32.000000000 +0530
> @@ -0,0 +1,42 @@
> +#
> +#  Copyright (c) International Business Machines  Corp., 2001
> +#
> +#  This program is free software;  you can redistribute it and/or modify
> +#  it under the terms of the GNU General Public License as published by
> +#  the Free Software Foundation; either version 2 of the License, or
> +#  (at your option) any later version.
> +#
> +#  This program is distributed in the hope that it will be useful,
> +#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
> +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> +#  the GNU General Public License for more details.
> +#
> +#  You should have received a copy of the GNU General Public License
> +#  along with this program;  if not, write to the Free Software
> +#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> +#
> +
> +CFLAGS += -I../../../../include -Wall
> +LDLIBS += -L../../../../lib -lltp -lnuma
> +
> +ifeq ($(HAS_NUMA),yes)
> +SRCS    = $(wildcard *.c)
> +TARGETS = $(patsubst %.c, %, $(wildcard *[0-9].c))
> +endif
> +
> +all: $(TARGETS)
> +
> +move_pages_support.o: move_pages_support.h move_pages_support.c
> +
> +$(TARGETS): move_pages_support.o
> +
> +install: move_page03.mode
> +     @set -e; for i in $(TARGETS); do ln -f $$i ../../../bin/$$i ; done
> +
> +clean:
> +     rm -f $(TARGETS)
> +
> +move_page03.mode:
> +     @/bin/sh ./move_pages03.mode.sh
> +
> +.PHONY: move_pages03.mode
> \ No newline at end of file
> Index: ltp-stripped/testcases/kernel/syscalls/move_pages/move_pages01.c
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ ltp-stripped/testcases/kernel/syscalls/move_pages/move_pages01.c  
> 2008-06-19 23:33:26.000000000 +0530
> @@ -0,0 +1,147 @@
> +/*
> + *
> + *   Copyright (c) International Business Machines  Corp., 2001
> + *
> + *   This program is free software;  you can redistribute it and/or modify
> + *   it under the terms of the GNU General Public License as published by
> + *   the Free Software Foundation; either version 2 of the License, or
> + *   (at your option) any later version.
> + *
> + *   This program is distributed in the hope that it will be useful,
> + *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
> + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> + *   the GNU General Public License for more details.
> + *
> + *   You should have received a copy of the GNU General Public License
> + *   along with this program;  if not, write to the Free Software
> + *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + */
> +
> +/*
> + * NAME
> + *   move_pages01.c
> + *
> + * DESCRIPTION
> + *      Test retrieval of NUMA node
> + *
> + * ALGORITHM
> + *      1. Allocate pages in NUMA nodes A and B.
> + *      2. Use move_pages() to retrieve the NUMA node of the pages.
> + *      3. Check if the NUMA nodes reported are correct.
> + *
> + * USAGE:  <for command-line>
> + *      move_pages01 [-c n] [-i n] [-I x] [-P x] [-t]
> + *      where,  -c n : Run n copies concurrently.
> + *              -i n : Execute test n times.
> + *              -I x : Execute test for x seconds.
> + *              -P x : Pause for x seconds between iterations.
> + *              -t   : Turn on syscall timing.
> + *
> + * History
> + *   05/2008 Vijay Kumar
> + *           Initial Version.
> + *
> + * Restrictions
> + *   None
> + */
> +
> +#include <sys/signal.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <errno.h>
> +#include <numa.h>
> +
> +#include <test.h>
> +#include <usctest.h>
> +
> +#include "move_pages_support.h"
> +
> +#define TEST_PAGES 2
> +#define TEST_NODES TEST_PAGES
> +
> +void setup(void);
> +void cleanup(void);
> +
> +char *TCID = "move_pages01";
> +int TST_TOTAL = 1;
> +extern int Tst_count;
> +
> +int main(int argc, char **argv)
> +{
> +     int lc;                         /* loop counter */
> +     char *msg;                      /* message returned from parse_opts */
> +
> +     /* parse standard options */
> +     msg = parse_opts(argc, argv, (option_t *) NULL, NULL);
> +     if (msg != NULL) {
> +             tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +             tst_exit();
> +             /* NOTREACHED */
> +     }
> +
> +     setup();
> +
> +     /* check for looping state if -i option is given */
> +     for (lc = 0; TEST_LOOPING(lc); lc++) {
> +             void *pages[TEST_PAGES] = { 0 };
> +             int status[TEST_PAGES];
> +             int ret;
> +
> +             /* reset Tst_count in case we are looping */
> +             Tst_count = 0;
> +
> +             ret = alloc_pages_linear(pages, TEST_PAGES);
> +             if (ret == -1)
> +                     continue;
> +
> +             ret = numa_move_pages(0, TEST_PAGES, pages, NULL, status, 0);
> +             TEST_ERRNO = errno;
> +             if (ret != 0) {
> +                     tst_resm(TFAIL, "retrieving NUMA nodes failed");
> +                     free_pages(pages, TEST_PAGES);
> +                     continue;
> +             }
> +
> +             verify_pages_linear(status, TEST_PAGES);
> +
> +             free_pages(pages, TEST_PAGES);
> +     }
> +
> +     cleanup();
> +     /* NOT REACHED */
> +
> +     return 0;
> +}
> +
> +/*
> + * setup() - performs all ONE TIME setup for this test
> + */
> +void
> +setup(void)
> +{
> +     /* capture signals */
> +     tst_sig(NOFORK, DEF_HANDLER, cleanup);
> +
> +     check_config(TEST_NODES);
> +     /* Pause if that option was specified
> +      * TEST_PAUSE contains the code to fork the test with the -c option.
> +      */
> +     TEST_PAUSE;
> +}
> +
> +/*
> + * cleanup() - performs all ONE TIME cleanup for this test
> + */
> +void
> +cleanup(void)
> +{
> +     /*
> +      * print timing stats if that option was specified.
> +      * print errno log if that option was specified.
> +      */
> +     TEST_CLEANUP;
> +
> +     /* exit with return code appropriate for results */
> +     tst_exit();
> +     /*NOTREACHED*/
> +}
> Index: ltp-stripped/testcases/kernel/syscalls/move_pages/move_pages02.c
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ ltp-stripped/testcases/kernel/syscalls/move_pages/move_pages02.c  
> 2008-06-19 23:33:40.000000000 +0530
> @@ -0,0 +1,157 @@
> +/*
> + *
> + *   Copyright (c) International Business Machines  Corp., 2001
> + *
> + *   This program is free software;  you can redistribute it and/or modify
> + *   it under the terms of the GNU General Public License as published by
> + *   the Free Software Foundation; either version 2 of the License, or
> + *   (at your option) any later version.
> + *
> + *   This program is distributed in the hope that it will be useful,
> + *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
> + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> + *   the GNU General Public License for more details.
> + *
> + *   You should have received a copy of the GNU General Public License
> + *   along with this program;  if not, write to the Free Software
> + *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + */
> +
> +/*
> + * NAME
> + *   move_pages02.c
> + *
> + * DESCRIPTION
> + *      Test movement of pages mapped by a process.
> + *
> + * ALGORITHM
> + *      1. Allocate pages in NUMA node A.
> + *      2. Use move_pages() to move the pages to NUMA node B.
> + *      3. Retrieve the NUMA nodes of the moved pages.
> + *      4. Check if all pages are in node B.
> + *
> + * USAGE:  <for command-line>
> + *      move_pages02 [-c n] [-i n] [-I x] [-P x] [-t]
> + *      where,  -c n : Run n copies concurrently.
> + *              -i n : Execute test n times.
> + *              -I x : Execute test for x seconds.
> + *              -P x : Pause for x seconds between iterations.
> + *              -t   : Turn on syscall timing.
> + *
> + * History
> + *   05/2008 Vijay Kumar
> + *           Initial Version.
> + *
> + * Restrictions
> + *   None
> + */
> +
> +#include <sys/signal.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <linux/mempolicy.h>
> +#include <errno.h>
> +#include <numa.h>
> +
> +#include <test.h>
> +#include <usctest.h>
> +
> +#include "move_pages_support.h"
> +
> +#define TEST_PAGES 2
> +#define TEST_NODES 2
> +
> +void setup(void);
> +void cleanup(void);
> +
> +char *TCID = "move_pages02";
> +int TST_TOTAL = 1;
> +extern int Tst_count;
> +
> +int main(int argc, char **argv)
> +{
> +     unsigned int i;
> +     int lc;                         /* loop counter */
> +     char *msg;                      /* message returned from parse_opts */
> +     unsigned int from_node = 0;
> +     unsigned int to_node = 1;
> +
> +     /* parse standard options */
> +     msg = parse_opts(argc, argv, (option_t *) NULL, NULL);
> +     if (msg != NULL) {
> +             tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +             tst_exit();
> +             /* NOTREACHED */
> +     }
> +
> +     setup();
> +
> +     /* check for looping state if -i option is given */
> +     for (lc = 0; TEST_LOOPING(lc); lc++) {
> +             void *pages[TEST_PAGES] = { 0 };
> +             int nodes[TEST_PAGES];
> +             int status[TEST_PAGES];
> +             int ret;
> +
> +             /* reset Tst_count in case we are looping */
> +             Tst_count = 0;
> +
> +             ret = alloc_pages_on_node(pages, TEST_PAGES, from_node);
> +             if (ret == -1)
> +                     continue;
> +
> +             for (i = 0; i < TEST_PAGES; i++)
> +                     nodes[i] = to_node;
> +
> +             ret = numa_move_pages(0, TEST_PAGES, pages, nodes, status, 
> MPOL_MF_MOVE);
> +             TEST_ERRNO = errno;
> +             if (ret != 0) {
> +                     tst_resm(TFAIL, "retrieving NUMA nodes failed");
> +                     free_pages(pages, TEST_PAGES);
> +                     continue;
> +             }
> +
> +             verify_pages_on_node(status, TEST_PAGES, to_node);
> +
> +             free_pages(pages, TEST_PAGES);
> +     }
> +
> +     cleanup();
> +     /* NOT REACHED */
> +
> +     return 0;
> +}
> +
> +/*
> + * setup() - performs all ONE TIME setup for this test
> + */
> +void
> +setup(void)
> +{
> +     /* capture signals */
> +     tst_sig(NOFORK, DEF_HANDLER, cleanup);
> +
> +     check_config(TEST_NODES);
> +
> +     /* Pause if that option was specified
> +      * TEST_PAUSE contains the code to fork the test with the -c option.
> +      */
> +     TEST_PAUSE;
> +}
> +
> +/*
> + * cleanup() - performs all ONE TIME cleanup for this test at completion
> + */
> +void
> +cleanup(void)
> +{
> +     /*
> +      * print timing stats if that option was specified.
> +      * print errno log if that option was specified.
> +      */
> +     TEST_CLEANUP;
> +
> +     /* exit with return code appropriate for results */
> +     tst_exit();
> +     /*NOTREACHED*/
> +}
> Index: ltp-stripped/testcases/kernel/syscalls/move_pages/move_pages03.c
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ ltp-stripped/testcases/kernel/syscalls/move_pages/move_pages03.c  
> 2008-06-19 23:33:54.000000000 +0530
> @@ -0,0 +1,209 @@
> +/*
> + *
> + *   Copyright (c) International Business Machines  Corp., 2001
> + *
> + *   This program is free software;  you can redistribute it and/or modify
> + *   it under the terms of the GNU General Public License as published by
> + *   the Free Software Foundation; either version 2 of the License, or
> + *   (at your option) any later version.
> + *
> + *   This program is distributed in the hope that it will be useful,
> + *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
> + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> + *   the GNU General Public License for more details.
> + *
> + *   You should have received a copy of the GNU General Public License
> + *   along with this program;  if not, write to the Free Software
> + *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + */
> +
> +/*
> + * NAME
> + *   move_pages03.c
> + *
> + * DESCRIPTION
> + *      Test movement of pages mapped by a process.
> + *
> + * ALGORITHM
> + *      1. Start the test case program as root.
> + *      2. Allocate a shared memory in NUMA node A.
> + *      3. Fork another process.
> + *      4. Use move_pages() to move the pages to NUMA node B, with the
> + *         MPOL_MF_MOVE_ALL.
> + *      5. Check if all pages are in node B.
> + *
> + * USAGE:  <for command-line>
> + *      move_pages03 [-c n] [-i n] [-I x] [-P x] [-t]
> + *      where,  -c n : Run n copies concurrently.
> + *              -i n : Execute test n times.
> + *              -I x : Execute test for x seconds.
> + *              -P x : Pause for x seconds between iterations.
> + *              -t   : Turn on syscall timing.
> + *
> + * History
> + *   05/2008 Vijay Kumar
> + *           Initial Version.
> + *
> + * Restrictions
> + *   None
> + */
> +
> +#include <linux/mempolicy.h>
> +
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <unistd.h>
> +#include <signal.h>
> +#include <errno.h>
> +#include <numa.h>
> +
> +#include <test.h>
> +#include <usctest.h>
> +
> +#include "move_pages_support.h"
> +
> +#define TEST_PAGES 2
> +#define TEST_NODES 2
> +
> +void setup(void);
> +void cleanup(void);
> +
> +char *TCID = "move_pages03";
> +int TST_TOTAL = 1;
> +extern int Tst_count;
> +
> +typedef void (*sighandler_t)(int);
> +
> +/*
> + * child() - touches shared pages, and waits for signal from parent.
> + * @pages: shared pages allocated in parent
> + */
> +void child(void **pages)
> +{
> +     sighandler_t sigret;
> +     int i;
> +
> +     for (i = 0; i < TEST_PAGES; i++) {
> +             char *page;
> +
> +             page = pages[i];
> +             page[0] = 0xAA;
> +     }
> +
> +     /* Remove the parent's SIGTERM handler if any. */
> +     sigret = signal(SIGTERM, SIG_DFL);
> +     if (sigret == SIG_ERR)
> +             tst_resm(TBROK, "resetting SIGTERM handler failed");
> +
> +     /* Wait for SIGTERM. */
> +     pause();
> +
> +     exit(0);
> +}
> +
> +int main(int argc, char **argv)
> +{
> +     unsigned int i;
> +     int lc;                         /* loop counter */
> +     char *msg;                      /* message returned from parse_opts */
> +     unsigned int from_node = 0;
> +     unsigned int to_node = 1;
> +
> +     /* parse standard options */
> +     msg = parse_opts(argc, argv, (option_t *) NULL, NULL);
> +     if (msg != NULL) {
> +             tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +             tst_exit();
> +             /* NOTREACHED */
> +     }
> +
> +     setup();
> +
> +     /* check for looping state if -i option is given */
> +     for (lc = 0; TEST_LOOPING(lc); lc++) {
> +             void *pages[TEST_PAGES] = { 0 };
> +             int nodes[TEST_PAGES];
> +             int status[TEST_PAGES];
> +             int ret;
> +             pid_t cpid;
> +
> +             /* reset Tst_count in case we are looping */
> +             Tst_count = 0;
> +
> +             ret = alloc_shared_pages_on_node(pages, TEST_PAGES,
> +                                              from_node);
> +             if (ret == -1)
> +                     continue;
> +
> +
> +             for (i = 0; i < TEST_PAGES; i++) {
> +                     nodes[i] = to_node;
> +             }
> +
> +             /*
> +              * Fork a child process so that the shared pages are
> +              * now really shared between two processes.
> +              */
> +             cpid = fork();
> +             if (cpid == -1) {
> +                     tst_resm(TBROK, "forking child failed");
> +                     goto err_free_pages;
> +             } else if (cpid == 0) {
> +                     child(pages);
> +             }
> +
> +             ret = numa_move_pages(0, TEST_PAGES, pages, nodes,
> +                                   status, MPOL_MF_MOVE_ALL);
> +             TEST_ERRNO = errno;
> +             if (ret != 0) {
> +                     tst_resm(TFAIL, "retrieving NUMA nodes failed");
> +                     goto err_kill_child;
> +             }
> +
> +             verify_pages_on_node(status, TEST_PAGES, to_node);
> +
> +     err_kill_child:
> +             kill(cpid, SIGCHLD);
> +     err_free_pages:
> +             free_shared_pages(pages, TEST_PAGES);
> +     }
> +
> +     cleanup();
> +     /* NOT REACHED */
> +
> +     return 0;
> +}
> +
> +/*
> + * setup() - performs all ONE TIME setup for this test
> + */
> +void
> +setup(void)
> +{
> +     /* capture signals */
> +     tst_sig(FORK, DEF_HANDLER, cleanup);
> +
> +     check_config(TEST_NODES);
> +
> +     /* Pause if that option was specified
> +      * TEST_PAUSE contains the code to fork the test with the -c option.
> +      */
> +     TEST_PAUSE;
> +}
> +
> +/*
> + * cleanup() - performs all ONE TIME cleanup for this test at completion
> + */
> +void
> +cleanup(void)
> +{
> +     /*
> +      * print timing stats if that option was specified.
> +      * print errno log if that option was specified.
> +      */
> +     TEST_CLEANUP;
> +
> +     /* exit with return code appropriate for results */
> +     tst_exit();
> +     /*NOTREACHED*/
> +}
> Index: ltp-stripped/testcases/kernel/syscalls/move_pages/move_pages_support.c
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ ltp-stripped/testcases/kernel/syscalls/move_pages/move_pages_support.c    
> 2008-06-19 23:37:58.000000000 +0530
> @@ -0,0 +1,295 @@
> +#include <sys/mman.h>
> +#include <linux/mempolicy.h>
> +#include <syscall.h>
> +#include <unistd.h>
> +#include <numa.h>
> +
> +#include <test.h>
> +#include <usctest.h>
> +#include <linux_syscall_numbers.h>
> +
> +#ifndef __NR_move_pages
> +     int arch_support = 0;
> +#else
> +     int arch_support = 1;
> +#endif
> +
> +long
> +get_page_size()
> +{
> +     return sysconf(_SC_PAGESIZE);
> +}
> +
> +/*
> + * free_pages() - free an array of pages
> + * @pages: array of page pointers to be freed
> + * @num: no. of pages in the array
> + */
> +void
> +free_pages(void **pages, unsigned int num)
> +{
> +     int i;
> +     size_t onepage = get_page_size();
> +
> +     for (i = 0; i < num; i++) {
> +             if (pages[i] != NULL) {
> +                     numa_free(pages[i], onepage);
> +             }
> +     }
> +}
> +
> +/*
> + * alloc_pages_on_node() - allocate pages on specified NUMA nodes
> + * @pages: array in which the page pointers will be stored
> + * @num: no. of pages to allocate
> + * @nodes: array of NUMA nodes
> + *
> + * A page will be allocated in each node specified by @nodes, and the
> + * page pointers will be stored in @pages array.
> + *
> + * RETURNS:
> + * 0 on success, -1 on allocation failure.
> + */
> +int
> +alloc_pages_on_nodes(void **pages, unsigned int num, int *nodes)
> +{
> +     int i;
> +     size_t onepage = get_page_size();
> +
> +     for (i = 0; i < num; i++) {
> +             pages[i] = NULL;
> +     }
> +
> +     for (i = 0; i < num; i++) {
> +             char *page;
> +
> +             pages[i] = numa_alloc_onnode(onepage, nodes[i]);
> +             if (pages[i] == NULL) {
> +                     tst_resm(TBROK, "allocation of page on node "
> +                              "%d failed", nodes[i]);
> +                     break;
> +             }
> +
> +             /* Touch the page, to force allocation. */
> +             page = pages[i];
> +             page[0] = i;
> +     }
> +
> +     if (i == num)
> +             return 0;
> +
> +     free_pages(pages, num);
> +
> +     return -1;
> +}
> +
> +/*
> + * alloc_pages_linear() - allocate pages in each NUMA node
> + * @pages: array in which the page pointers will be stored
> + * @num: no. of pages to allocate
> + *
> + * Pages will be allocated one from each NUMA node, in an interleaved
> + * fashion.
> + *
> + * RETURNS:
> + * 0 on success, -1 on allocation failure.
> + */
> +int
> +alloc_pages_linear(void **pages, unsigned int num)
> +{
> +     unsigned int i;
> +     unsigned int n;
> +     int nodes[num];
> +
> +     n = 0;
> +     for (i = 0; i < num; i++) {
> +             nodes[i] = n;
> +
> +             n++;
> +             if (n > numa_max_node())
> +                     n = 0;
> +     }
> +
> +     return alloc_pages_on_nodes(pages, num, nodes);
> +}
> +
> +/*
> + * alloc_pages_on_node() - allocate pages on specified NUMA node
> + * @pages: array in which the page pointers will be stored
> + * @num: no. of pages to allocate
> + * @node: NUMA node from which to allocate pages
> + *
> + * Pages will be allocated from the NUMA node @node, and the page
> + * pointers will be stored in the @pages array.
> + *
> + * RETURNS:
> + * 0 on success, -1 on allocation failure.
> + */
> +int
> +alloc_pages_on_node(void **pages, unsigned int num, int node)
> +{
> +     unsigned int i;
> +     int nodes[num];
> +
> +     for (i = 0; i < num; i++)
> +             nodes[i] = node;
> +
> +     return alloc_pages_on_nodes(pages, num, nodes);
> +}
> +
> +/*
> + * verify_pages_on_nodes() - verify pages are in specified nodes
> + * @status: the NUMA node of each page
> + * @num: the no. of pages
> + * @nodes: the expected NUMA nodes
> + */
> +void
> +verify_pages_on_nodes(int *status, unsigned int num, int *nodes)
> +{
> +     unsigned int i;
> +
> +     for (i = 0; i < num; i++) {
> +             if (status[i] != nodes[i]) {
> +                     tst_resm(TFAIL, "page %d on node %d, "
> +                              "expected on node %d", i,
> +                              status[i], nodes[i]);
> +                     return;
> +             }
> +     }
> +
> +     tst_resm(TPASS, "pages are present in expected nodes");
> +}
> +
> +/*
> + * verify_pages_linear() - verify pages are interleaved
> + * @status: the NUMA node of each page
> + * @num: the no. of pages
> + */
> +void
> +verify_pages_linear(int *status, unsigned int num)
> +{
> +     unsigned int i;
> +     unsigned int n;
> +     int nodes[num];
> +
> +     n = 0;
> +     for (i = 0; i < num; i++) {
> +             nodes[i] = i;
> +
> +             n++;
> +             if (n > numa_max_node())
> +                     n = 0;
> +     }
> +
> +     verify_pages_on_nodes(status, num, nodes);
> +}
> +
> +/*
> + * verify_pages_on_node() - verify pages are in specified node
> + * @status: the NUMA node of each page
> + * @num: the no. of pages
> + * @node: the expected NUMA node
> + */
> +void
> +verify_pages_on_node(int *status, unsigned int num, int node)
> +{
> +     unsigned int i;
> +     int nodes[num];
> +
> +     for (i = 0; i < num; i++) {
> +             nodes[i] = node;
> +     }
> +
> +     verify_pages_on_nodes(status, num, nodes);
> +}
> +
> +/*
> + * alloc_shared_pages_on_node() - allocate shared pages on a NUMA node
> + * @pages: array to store the allocated pages
> + * @num: the no. of pages to allocate
> + * @node: the node in which the pages should be allocated
> + *
> + * RETURNS:
> + * 0 on success, -1 on allocation failure
> + */
> +int
> +alloc_shared_pages_on_node(void **pages, unsigned int num,
> +                        int node)
> +{
> +     char *shared;
> +     unsigned int i;
> +     int nodes[num];
> +     size_t total_size = num * get_page_size();
> +
> +     shared = mmap(NULL, total_size,
> +                   PROT_READ | PROT_WRITE,
> +                   MAP_SHARED | MAP_ANONYMOUS, 0, 0);
> +     if (shared == MAP_FAILED) {
> +             tst_resm(TBROK, "allocation of shared pages failed");
> +             return -1;
> +     }
> +
> +     numa_tonode_memory(shared, total_size, node);
> +
> +     for (i = 0; i < num; i++) {
> +             char *page;
> +
> +             pages[i] = shared;
> +             shared += get_page_size();
> +
> +             nodes[i] = node;
> +
> +             /* Touch the page to force allocation */
> +             page = pages[i];
> +             page[0] = i;
> +     }
> +
> +     return 0;
> +}
> +
> +/*
> + * free_shared_pages() - free shared pages
> + * @pages: array of pages to be freed
> + * @num: the no. of pages to free
> + */
> +void
> +free_shared_pages(void **pages, unsigned int num)
> +{
> +     int ret;
> +
> +     ret = munmap(pages[0], num * get_page_size());
> +     if (ret == -1)
> +             tst_resm(TWARN, "unmapping of shared pages failed");
> +}
> +
> +/*
> + * check_config() - check for required configuration
> + * @min_nodes: the minimum required NUMA nodes
> + *
> + * Checks if numa support is availabe, kernel is >= 2.6.18, arch is
> + * one of the supported architectures.
> + */
> +void
> +check_config(unsigned int min_nodes)
> +{
> +     if (numa_available() < 0) {
> +             tst_resm(TCONF, "NUMA support is not available");
> +             tst_exit();
> +     }
> +
> +     if (numa_max_node() < (min_nodes - 1)) {
> +             tst_resm(TCONF, "atleast 2 NUMA nodes are required");
> +             tst_exit();
> +     }
> +
> +     if (tst_kvercmp(2, 6, 18) < 0) {
> +             tst_resm(TCONF, "2.6.18 or greater kernel required");
> +             tst_exit();
> +     }
> +
> +     if (arch_support == 0) {
> +             tst_resm(TCONF, "this arch does not support move_pages");
> +             tst_exit();
> +     }
> +}
> +
> Index: ltp-stripped/testcases/kernel/syscalls/move_pages/move_pages_support.h
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ ltp-stripped/testcases/kernel/syscalls/move_pages/move_pages_support.h    
> 2008-06-19 23:35:06.000000000 +0530
> @@ -0,0 +1,17 @@
> +long get_page_size();
> +
> +void free_pages(void **pages, unsigned int num);
> +
> +int alloc_pages_on_nodes(void **pages, unsigned int num, unsigned int 
> *nodes);
> +int alloc_pages_linear(void **pages, unsigned int num);
> +int alloc_pages_on_node(void **pages, unsigned int num, unsigned int node);
> +
> +void verify_pages_on_nodes(int *status, unsigned int num, unsigned int 
> *nodes);
> +void verify_pages_linear(int *status, unsigned int num);
> +void verify_pages_on_node(int *status, unsigned int num, unsigned int node);
> +
> +int alloc_shared_pages_on_node(void **pages, unsigned int num,
> +                            unsigned int node);
> +void free_shared_pages(void **pages, unsigned int num);
> +
> +void check_config(unsigned int min_nodes);
> Index: ltp-stripped/runtest/numa
> ===================================================================
> --- ltp-stripped.orig/runtest/numa    2008-06-19 22:51:28.000000000 +0530
> +++ ltp-stripped/runtest/numa 2008-06-19 22:51:32.000000000 +0530
> @@ -1 +1,4 @@
>  Numa-testcases numa01.sh
> +move_pages01 move_pages01
> +move_pages02 move_pages02
> +move_pages03 move_pages03
> Index: ltp-stripped/runtest/syscalls
> ===================================================================
> --- ltp-stripped.orig/runtest/syscalls        2008-06-19 22:51:28.000000000 
> +0530
> +++ ltp-stripped/runtest/syscalls     2008-06-19 22:51:32.000000000 +0530
> @@ -445,6 +445,10 @@
>  #mount03 mount03 -D /dev/...
>  #mount04 mount04 -D /dev/...
> 
> +move_pages01 move_pages01
> +move_pages02 move_pages02
> +move_pages03 move_pages03
> +
>  mprotect01 mprotect01
>  mprotect02 mprotect02
>  mprotect03 mprotect03
> Index: ltp-stripped/Makefile
> ===================================================================
> --- ltp-stripped.orig/Makefile        2008-06-19 22:51:28.000000000 +0530
> +++ ltp-stripped/Makefile     2008-06-19 22:51:32.000000000 +0530
> @@ -37,8 +37,10 @@
>  RANLIB=$(CROSS_COMPILER)ranlib
>  endif
> 
> +HAS_NUMA=$(shell sh tools/scripts/numa_test.sh)
> +
>  export CFLAGS += -Wall $(CROSS_CFLAGS)
> -export CC AR RANLIB LDFLAGS
> +export CC AR RANLIB LDFLAGS HAS_NUMA
> 
>  -include config.mk
> 
> Index: ltp-stripped/testcases/kernel/numa/Makefile
> ===================================================================
> --- ltp-stripped.orig/testcases/kernel/numa/Makefile  2008-06-19 
> 22:51:28.000000000 +0530
> +++ ltp-stripped/testcases/kernel/numa/Makefile       2008-06-19 
> 22:51:32.000000000 +0530
> @@ -20,7 +20,7 @@
> 
>  LDLIBS += -L../../../lib -lltp 
> 
> -ifeq ($(shell sh test.sh),yes)    #its a numa machine
> +ifeq ($(HAS_NUMA),yes)    #its a numa machine
>  LDLIBS += -L../../../lib  -lnuma
>  SRCS    = $(wildcard *.c)
>  TARGETS = $(patsubst %.c,%,$(SRCS))
> Index: ltp-stripped/testcases/kernel/numa/test.sh
> ===================================================================
> --- ltp-stripped.orig/testcases/kernel/numa/test.sh   2008-06-19 
> 22:51:28.000000000 +0530
> +++ /dev/null 1970-01-01 00:00:00.000000000 +0000
> @@ -1,53 +0,0 @@
> -################################################################################
> -##                                                                           
>  ##
> -## Copyright (c) International Business Machines  Corp., 2007                
>  ##
> -##                                                                           
>  ##
> -## This program is free software;  you can redistribute it and#or modify     
>  ##
> -## it under the terms of the GNU General Public License as published by      
>  ##
> -## the Free Software Foundation; either version 2 of the License, or         
>  ##
> -## (at your option) any later version.                                       
>  ##
> -##                                                                           
>  ##
> -## This program is distributed in the hope that it will be useful, but       
>  ##
> -## WITHOUT ANY WARRANTY; without even the implied warranty of 
> MERCHANTABILITY ##
> -## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License  
>  ##
> -## for more details.                                                         
>  ##
> -##                                                                           
>  ##
> -## You should have received a copy of the GNU General Public License         
>  ##
> -## along with this program;  if not, write to the Free Software              
>  ##
> -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   
>  ##
> -##                                                                           
>  ##
> -################################################################################
> -#   
> -# Author         Pradeep Kumar Surisetty, [EMAIL PROTECTED]
> -#   
> -# History        Nov 27 2007 -created- pradeep kumar surisetty
> -#! /bin/sh
> -#
> -# File :         test.sh
> -
> -
> -#!/bin/sh
> -x=0
> -chk_ifexist()
> -{
> -if [ ! -d /sys/devices/system/node ]
> -then
> -x=0
> -else
> -x=$(ls /sys/devices/system/node | wc -l)
> -fi
> -if [ $x -gt 1 ]
> -then
> -     if [ ! -f /usr/include/numa.h ]
> -     then
> -             echo no;
> -     else
> -             echo yes;
> -     fi      
> -else
> -        echo no;     #numa is not present
> -
> -fi
> -}
> -chk_ifexist
> -
> Index: ltp-stripped/testcases/kernel/syscalls/move_pages/move_pages03.mode.sh
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ ltp-stripped/testcases/kernel/syscalls/move_pages/move_pages03.mode.sh    
> 2008-06-20 00:00:50.000000000 +0530
> @@ -0,0 +1,16 @@
> +#!/bin/sh
> +
> +failed() {
> +     echo ""
> +     echo "             ************** WARNING **************"
> +     echo "    Cannot change permission or ownership of \"move_pages03\"."
> +     echo "                   Test move_pages03 will fail"
> +     echo "                   Run "make install" as root."
> +     echo "             *************************************"
> +     sleep 2
> +}
> +
> +chown root move_pages03 || failed
> +chmod 04755 move_pages03 || failed
> +
> +exit 0
> Index: ltp-stripped/tools/scripts/numa_test.sh
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ ltp-stripped/tools/scripts/numa_test.sh   2008-06-19 22:51:32.000000000 
> +0530
> @@ -0,0 +1,53 @@
> +#############################################################################
> +##
> +## Copyright (c) International Business Machines  Corp., 2007
> +##
> +## This program is free software;  you can redistribute it and#or modify
> +## it under the terms of the GNU General Public License as published by
> +## the Free Software Foundation; either version 2 of the License, or
> +## (at your option) any later version.
> +##
> +## This program is distributed in the hope that it will be useful, but
> +## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
> +## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
> +## for more details.
> +##
> +## You should have received a copy of the GNU General Public License
> +## along with this program;  if not, write to the Free Software
> +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> +##
> +#############################################################################
> +#
> +# Author         Pradeep Kumar Surisetty, [EMAIL PROTECTED]
> +#
> +# History        Nov 27 2007 -created- pradeep kumar surisetty
> +#! /bin/sh
> +#
> +# File :         numa_test.sh
> +
> +
> +#!/bin/sh
> +x=0
> +chk_ifexist()
> +{
> +if [ ! -d /sys/devices/system/node ]
> +then
> +x=0
> +else
> +x=$(ls /sys/devices/system/node | wc -l)
> +fi
> +if [ $x -gt 1 ]
> +then
> +     if [ ! -f /usr/include/numa.h ]
> +     then
> +             echo no;
> +     else
> +             echo yes;
> +     fi
> +else
> +        echo no;     #numa is not present
> +
> +fi
> +}
> +chk_ifexist
> +
> 


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to