1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * Copyright (c) 2008 Vijay Kumar B. <vijaykumar@bravegnu.org> 3f08c3bdfSopenharmony_ci * 4f08c3bdfSopenharmony_ci * Based on testcases/kernel/syscalls/waitpid/waitpid01.c 5f08c3bdfSopenharmony_ci * Original copyright message: 6f08c3bdfSopenharmony_ci * 7f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 8f08c3bdfSopenharmony_ci * 9f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify 10f08c3bdfSopenharmony_ci * it under the terms of the GNU General Public License as published by 11f08c3bdfSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or 12f08c3bdfSopenharmony_ci * (at your option) any later version. 13f08c3bdfSopenharmony_ci * 14f08c3bdfSopenharmony_ci * This program is distributed in the hope that it will be useful, 15f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 16f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 17f08c3bdfSopenharmony_ci * the GNU General Public License for more details. 18f08c3bdfSopenharmony_ci * 19f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License 20f08c3bdfSopenharmony_ci * along with this program; if not, write to the Free Software 21f08c3bdfSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22f08c3bdfSopenharmony_ci */ 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_ci/* 25f08c3bdfSopenharmony_ci * NAME 26f08c3bdfSopenharmony_ci * move_pages02.c 27f08c3bdfSopenharmony_ci * 28f08c3bdfSopenharmony_ci * DESCRIPTION 29f08c3bdfSopenharmony_ci * Test movement of pages mapped by a process. 30f08c3bdfSopenharmony_ci * 31f08c3bdfSopenharmony_ci * ALGORITHM 32f08c3bdfSopenharmony_ci * 1. Allocate pages in NUMA node A. 33f08c3bdfSopenharmony_ci * 2. Use move_pages() to move the pages to NUMA node B. 34f08c3bdfSopenharmony_ci * 3. Retrieve the NUMA nodes of the moved pages. 35f08c3bdfSopenharmony_ci * 4. Check if all pages are in node B. 36f08c3bdfSopenharmony_ci * 37f08c3bdfSopenharmony_ci * USAGE: <for command-line> 38f08c3bdfSopenharmony_ci * move_pages02 [-c n] [-i n] [-I x] [-P x] [-t] 39f08c3bdfSopenharmony_ci * where, -c n : Run n copies concurrently. 40f08c3bdfSopenharmony_ci * -i n : Execute test n times. 41f08c3bdfSopenharmony_ci * -I x : Execute test for x seconds. 42f08c3bdfSopenharmony_ci * -P x : Pause for x seconds between iterations. 43f08c3bdfSopenharmony_ci * -t : Turn on syscall timing. 44f08c3bdfSopenharmony_ci * 45f08c3bdfSopenharmony_ci * History 46f08c3bdfSopenharmony_ci * 05/2008 Vijay Kumar 47f08c3bdfSopenharmony_ci * Initial Version. 48f08c3bdfSopenharmony_ci * 49f08c3bdfSopenharmony_ci * Restrictions 50f08c3bdfSopenharmony_ci * None 51f08c3bdfSopenharmony_ci */ 52f08c3bdfSopenharmony_ci 53f08c3bdfSopenharmony_ci#include <sys/signal.h> 54f08c3bdfSopenharmony_ci#include <sys/types.h> 55f08c3bdfSopenharmony_ci#include <sys/wait.h> 56f08c3bdfSopenharmony_ci#include <errno.h> 57f08c3bdfSopenharmony_ci#include "test.h" 58f08c3bdfSopenharmony_ci#include "move_pages_support.h" 59f08c3bdfSopenharmony_ci 60f08c3bdfSopenharmony_ci#define TEST_PAGES 2 61f08c3bdfSopenharmony_ci#define TEST_NODES 2 62f08c3bdfSopenharmony_ci 63f08c3bdfSopenharmony_civoid setup(void); 64f08c3bdfSopenharmony_civoid cleanup(void); 65f08c3bdfSopenharmony_ci 66f08c3bdfSopenharmony_cichar *TCID = "move_pages02"; 67f08c3bdfSopenharmony_ciint TST_TOTAL = 1; 68f08c3bdfSopenharmony_ci 69f08c3bdfSopenharmony_ciint main(int argc, char **argv) 70f08c3bdfSopenharmony_ci{ 71f08c3bdfSopenharmony_ci 72f08c3bdfSopenharmony_ci tst_parse_opts(argc, argv, NULL, NULL); 73f08c3bdfSopenharmony_ci 74f08c3bdfSopenharmony_ci setup(); 75f08c3bdfSopenharmony_ci 76f08c3bdfSopenharmony_ci#ifdef HAVE_NUMA_V2 77f08c3bdfSopenharmony_ci unsigned int i; 78f08c3bdfSopenharmony_ci int lc; 79f08c3bdfSopenharmony_ci unsigned int from_node; 80f08c3bdfSopenharmony_ci unsigned int to_node; 81f08c3bdfSopenharmony_ci int ret; 82f08c3bdfSopenharmony_ci 83f08c3bdfSopenharmony_ci ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node); 84f08c3bdfSopenharmony_ci if (ret < 0) 85f08c3bdfSopenharmony_ci tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret); 86f08c3bdfSopenharmony_ci 87f08c3bdfSopenharmony_ci /* check for looping state if -i option is given */ 88f08c3bdfSopenharmony_ci for (lc = 0; TEST_LOOPING(lc); lc++) { 89f08c3bdfSopenharmony_ci void *pages[TEST_PAGES] = { 0 }; 90f08c3bdfSopenharmony_ci int nodes[TEST_PAGES]; 91f08c3bdfSopenharmony_ci int status[TEST_PAGES]; 92f08c3bdfSopenharmony_ci 93f08c3bdfSopenharmony_ci /* reset tst_count in case we are looping */ 94f08c3bdfSopenharmony_ci tst_count = 0; 95f08c3bdfSopenharmony_ci 96f08c3bdfSopenharmony_ci ret = alloc_pages_on_node(pages, TEST_PAGES, from_node); 97f08c3bdfSopenharmony_ci if (ret == -1) 98f08c3bdfSopenharmony_ci continue; 99f08c3bdfSopenharmony_ci 100f08c3bdfSopenharmony_ci for (i = 0; i < TEST_PAGES; i++) 101f08c3bdfSopenharmony_ci nodes[i] = to_node; 102f08c3bdfSopenharmony_ci 103f08c3bdfSopenharmony_ci ret = 104f08c3bdfSopenharmony_ci numa_move_pages(0, TEST_PAGES, pages, nodes, status, 105f08c3bdfSopenharmony_ci MPOL_MF_MOVE); 106f08c3bdfSopenharmony_ci if (ret < 0) { 107f08c3bdfSopenharmony_ci tst_resm(TFAIL|TERRNO, "move_pages failed"); 108f08c3bdfSopenharmony_ci free_pages(pages, TEST_PAGES); 109f08c3bdfSopenharmony_ci continue; 110f08c3bdfSopenharmony_ci } else if (ret > 0) { 111f08c3bdfSopenharmony_ci tst_resm(TINFO, "move_pages() returned %d", ret); 112f08c3bdfSopenharmony_ci } 113f08c3bdfSopenharmony_ci 114f08c3bdfSopenharmony_ci for (i = 0; i < TEST_PAGES; i++) 115f08c3bdfSopenharmony_ci *((char *)pages[i]) = 0xAA; 116f08c3bdfSopenharmony_ci 117f08c3bdfSopenharmony_ci verify_pages_on_node(pages, status, TEST_PAGES, to_node); 118f08c3bdfSopenharmony_ci 119f08c3bdfSopenharmony_ci free_pages(pages, TEST_PAGES); 120f08c3bdfSopenharmony_ci } 121f08c3bdfSopenharmony_ci#else 122f08c3bdfSopenharmony_ci tst_resm(TCONF, NUMA_ERROR_MSG); 123f08c3bdfSopenharmony_ci#endif 124f08c3bdfSopenharmony_ci 125f08c3bdfSopenharmony_ci cleanup(); 126f08c3bdfSopenharmony_ci tst_exit(); 127f08c3bdfSopenharmony_ci 128f08c3bdfSopenharmony_ci} 129f08c3bdfSopenharmony_ci 130f08c3bdfSopenharmony_ci/* 131f08c3bdfSopenharmony_ci * setup() - performs all ONE TIME setup for this test 132f08c3bdfSopenharmony_ci */ 133f08c3bdfSopenharmony_civoid setup(void) 134f08c3bdfSopenharmony_ci{ 135f08c3bdfSopenharmony_ci 136f08c3bdfSopenharmony_ci tst_sig(NOFORK, DEF_HANDLER, cleanup); 137f08c3bdfSopenharmony_ci 138f08c3bdfSopenharmony_ci check_config(TEST_NODES); 139f08c3bdfSopenharmony_ci 140f08c3bdfSopenharmony_ci /* Pause if that option was specified 141f08c3bdfSopenharmony_ci * TEST_PAUSE contains the code to fork the test with the -c option. 142f08c3bdfSopenharmony_ci */ 143f08c3bdfSopenharmony_ci TEST_PAUSE; 144f08c3bdfSopenharmony_ci} 145f08c3bdfSopenharmony_ci 146f08c3bdfSopenharmony_ci/* 147f08c3bdfSopenharmony_ci * cleanup() - performs all ONE TIME cleanup for this test at completion 148f08c3bdfSopenharmony_ci */ 149f08c3bdfSopenharmony_civoid cleanup(void) 150f08c3bdfSopenharmony_ci{ 151f08c3bdfSopenharmony_ci 152f08c3bdfSopenharmony_ci} 153