int main(int argc, char **argv) { char *msg; msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); #if HAVE_NUMA_MOVE_PAGES unsigned int i; int lc; unsigned int from_node; unsigned int to_node; int ret; ret = get_allowed_nodes(NH_MEMS, 1, &from_node); if (ret < 0) tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret); /* 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]; /* 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; to_node = numa_max_node() + 1; 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 == -1 && errno == ENODEV) tst_resm(TPASS, "move_pages failed with " "ENODEV as expected"); else tst_resm(TFAIL, "move pages did not fail " "with ENODEV"); free_pages(pages, TEST_PAGES); } #else tst_resm(TCONF, "move_pages support not found."); #endif cleanup(); tst_exit(); }
int map_addr2nodedst(pid_t pid, void **addr_arr, int *lat_arr, int addr_num, map_nodedst_t *nodedst_arr, int nnodes, int *naccess_total) { int *status_arr, i, nid; if ((status_arr = zalloc(sizeof (int) * addr_num)) == NULL) { return (-1); } if (numa_move_pages(pid, addr_num, addr_arr, NULL, status_arr, 0) != 0) { free(status_arr); return (-1); } *naccess_total = 0; for (i = 0; i < addr_num; i++) { nid = status_arr[i]; if ((nid >= 0) && (nid < nnodes)) { nodedst_arr[nid].naccess++; nodedst_arr[nid].total_lat += lat_arr[i]; *naccess_total += 1; } } free(status_arr); return (0); }
int map_map2numa(struct _track_proc *proc, map_entry_t *map_entry) { void *addr_arr[NUMA_MOVE_NPAGES]; unsigned int npages_total, npages_tomove, npages_moved = 0; int node_arr[NUMA_MOVE_NPAGES], i; numa_entry_t *last_entry = NULL; numa_map_fini(map_entry); npages_total = (map_entry->end_addr - map_entry->start_addr) / g_pagesize; while (npages_moved < npages_total) { npages_tomove = MIN(NUMA_MOVE_NPAGES, npages_total - npages_moved); for (i = 0; i < npages_tomove; i++) { addr_arr[i] = (void *)(map_entry->start_addr + (i + npages_moved) * g_pagesize); } memset(node_arr, 0, sizeof (node_arr)); if (numa_move_pages(proc->pid, npages_tomove, addr_arr, NULL, node_arr, 0) != 0) { return (-1); } if ((last_entry = numa_map_update(&map_entry->numa_map, addr_arr, node_arr, npages_tomove, last_entry)) == NULL) { return (-1); } npages_moved += npages_tomove; } return (0); }
int main(int argc, char **argv) { 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(); #if HAVE_NUMA_MOVE_PAGES unsigned int i; int lc; /* loop counter */ unsigned int from_node = 0; unsigned int to_node = 1; /* 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, ULONG_MAX, pages, nodes, status, MPOL_MF_MOVE); TEST_ERRNO = errno; if (ret == -1 && errno == E2BIG) tst_resm(TPASS, "move_pages failed with " "E2BIG as expected"); else tst_resm(TFAIL, "move pages did not fail " "with E2BIG"); free_pages(pages, TEST_PAGES); } #else tst_resm(TCONF, "move_pages support not found."); #endif cleanup(); /* NOT REACHED */ return 0; }
int main(int argc, char **argv) { tst_parse_opts(argc, argv, NULL, NULL); setup(); #if HAVE_NUMA_MOVE_PAGES unsigned int i; int lc; unsigned int from_node; unsigned int to_node; int ret; ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node); if (ret < 0) tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret); /* 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]; /* 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); if (ret != 0) { tst_resm(TFAIL|TERRNO, "move_pages failed"); free_pages(pages, TEST_PAGES); continue; } for (i = 0; i < TEST_PAGES; i++) *((char *)pages[i]) = 0xAA; verify_pages_on_node(pages, status, TEST_PAGES, to_node); free_pages(pages, TEST_PAGES); } #else tst_resm(TCONF, "move_pages support not found."); #endif cleanup(); tst_exit(); }
void migrate_show() { rbtree_print(migrate_tree, fill_page_to_migrate); pages_array.status = malloc(sizeof(*pages_array.status)*pages_array.count); int ret = numa_move_pages(pid, pages_array.count, pages_array.pages, pages_array.nodes, pages_array.status, MPOL_MF_MOVE_ALL); printf("#%d pages migrated (result = %d %s)\n", pages_array.count, ret, move_pages_to_error_code(ret)); int i; for(i = 0; i < pages_array.count; i++) { printf("#%lx %d %d %s\n", (long unsigned)pages_array.pages[i], pages_array.nodes[i], pages_array.status[i], status_to_error(pages_array.status[i])); } }
int main(int argc, char **argv) { char *msg; msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); #if HAVE_NUMA_MOVE_PAGES int lc; /* 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); if (ret != 0) { tst_resm(TFAIL|TERRNO, "move_pages failed"); free_pages(pages, TEST_PAGES); continue; } verify_pages_linear(pages, status, TEST_PAGES); free_pages(pages, TEST_PAGES); } #else tst_resm(TCONF, "move_pages support not found."); #endif cleanup(); tst_exit(); }
int main(int argc, char **argv) { char *msg; msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); #if HAVE_NUMA_MOVE_PAGES unsigned int i; int lc; unsigned int from_node; int ret; ret = get_allowed_nodes(NH_MEMS, 1, &from_node); if (ret < 0) tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret); /* 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]; /* 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] = from_node; ret = numa_move_pages(0, TEST_PAGES, pages, nodes, status, MPOL_MF_MOVE); TEST_ERRNO = errno; /* * commit e78bbfa8262424417a29349a8064a535053912b9 * Author: Brice Goglin <*****@*****.**> * Date: Sat Oct 18 20:27:15 2008 -0700 * mm: stop returning -ENOENT from sys_move_pages() if nothing got migrated */ if ((tst_kvercmp(2, 6, 28)) >= 0) { if (ret == 0) tst_resm(TPASS, "move_pages succeeded"); else tst_resm(TFAIL | TERRNO, "move_pages"); } else { if (ret == -1 && errno == ENOENT) tst_resm(TPASS, "move_pages failed with " "ENOENT as expected"); else tst_resm(TFAIL | TERRNO, "move_pages"); } free_pages(pages, TEST_PAGES); } #else tst_resm(TCONF, "move_pages support not found."); #endif cleanup(); tst_exit(); }
int main(int argc, char **argv) { const char *msg; msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); #if HAVE_NUMA_MOVE_PAGES unsigned int i; int lc; unsigned int from_node; unsigned int to_node; int ret; ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node); if (ret < 0) tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret); /* check for looping state if -i option is given */ for (lc = 0; TEST_LOOPING(lc); lc++) { void *pages[N_TEST_PAGES] = { 0 }; int nodes[N_TEST_PAGES]; int status[N_TEST_PAGES]; pid_t cpid; sem_t *sem; /* reset tst_count in case we are looping */ tst_count = 0; ret = alloc_shared_pages_on_node(pages + SHARED_PAGE, N_SHARED_PAGES, from_node); if (ret == -1) continue; ret = alloc_pages_on_node(pages + UNSHARED_PAGE, N_UNSHARED_PAGES, from_node); if (ret == -1) goto err_free_shared; for (i = 0; i < N_TEST_PAGES; i++) { nodes[i] = to_node; } sem = alloc_sem(MAX_SEMS); if (sem == NULL) { goto err_free_unshared; } /* * 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_sem; } else if (cpid == 0) { child(pages, sem); } /* Wait for child to setup and signal. */ if (sem_wait(&sem[SEM_CHILD_SETUP]) == -1) tst_resm(TWARN | TERRNO, "error wait semaphore"); ret = numa_move_pages(0, N_TEST_PAGES, pages, nodes, status, MPOL_MF_MOVE); if (ret == -1) { tst_resm(TFAIL | TERRNO, "move_pages unexpectedly failed"); goto err_kill_child; } if (status[SHARED_PAGE] == -EACCES) tst_resm(TPASS, "status[%d] set to expected -EACCES", SHARED_PAGE); else tst_resm(TFAIL, "status[%d] is %d", SHARED_PAGE, status[SHARED_PAGE]); err_kill_child: /* Test done. Ask child to terminate. */ if (sem_post(&sem[SEM_PARENT_TEST]) == -1) tst_resm(TWARN | TERRNO, "error post semaphore"); /* Read the status, no zombies! */ wait(NULL); err_free_sem: free_sem(sem, MAX_SEMS); err_free_unshared: free_pages(pages + UNSHARED_PAGE, N_UNSHARED_PAGES); err_free_shared: free_shared_pages(pages + SHARED_PAGE, N_SHARED_PAGES); } #else tst_resm(TCONF, "move_pages support not found."); #endif cleanup(); tst_exit(); }
int main(int argc, char **argv) { char *msg; /* message returned from parse_opts */ /* parse standard options */ msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } setup(); #if HAVE_NUMA_MOVE_PAGES unsigned int i; int lc; /* loop counter */ unsigned int from_node; unsigned int to_node; int ret; ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node); if (ret < 0) tst_brkm(TBROK|TERRNO, cleanup, "get_allowed_nodes: %d", ret); /* 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]; pid_t cpid; sem_t *sem; /* 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; } sem = alloc_sem(MAX_SEMS); if (sem == NULL) { goto err_free_pages; } /* * 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: %s", strerror(errno)); goto err_free_sem; } else if (cpid == 0) { child(pages, sem); } /* Wait for child to setup and signal. */ if (sem_wait(&sem[SEM_CHILD_SETUP]) == -1) tst_resm(TWARN, "error wait semaphore: %s", strerror(errno)); ret = numa_move_pages(0, TEST_PAGES, pages, nodes, status, MPOL_MF_MOVE_ALL); TEST_ERRNO = errno; if (ret == -1 && errno == EPERM) tst_resm(TPASS, "move_pages failed with " "EPERM as expected"); else tst_resm(TFAIL, "move_pages did not fail " "with EPERM"); /* Test done. Ask child to terminate. */ if (sem_post(&sem[SEM_PARENT_TEST]) == -1) tst_resm(TWARN, "error post semaphore: %s", strerror(errno)); /* Read the status, no zombies! */ wait(NULL); err_free_sem: free_sem(sem, MAX_SEMS); err_free_pages: free_shared_pages(pages, TEST_PAGES); } #else tst_resm(TCONF, "move_pages support not found."); #endif cleanup(); tst_exit(); }
int main(int argc, char **argv) { tst_parse_opts(argc, argv, NULL, NULL); setup(); #if HAVE_NUMA_MOVE_PAGES unsigned int i; int lc; unsigned int from_node; unsigned int to_node; int ret, exp_status; if ((tst_kvercmp(4, 3, 0)) >= 0) exp_status = -EFAULT; else exp_status = -ENOENT; ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node); if (ret < 0) tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret); /* 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]; unsigned long onepage = get_page_size(); /* reset tst_count in case we are looping */ tst_count = 0; ret = alloc_pages_on_node(pages, TOUCHED_PAGES, from_node); if (ret == -1) continue; /* Allocate page and do not touch it. */ pages[UNTOUCHED_PAGE] = numa_alloc_onnode(onepage, from_node); if (pages[UNTOUCHED_PAGE] == NULL) { tst_resm(TBROK, "failed allocating page on node %d", from_node); goto err_free_pages; } for (i = 0; i < TEST_PAGES; i++) nodes[i] = to_node; ret = numa_move_pages(0, TEST_PAGES, pages, nodes, status, MPOL_MF_MOVE); if (ret == -1) { tst_resm(TFAIL | TERRNO, "move_pages unexpectedly failed"); goto err_free_pages; } if (status[UNTOUCHED_PAGE] == exp_status) { tst_resm(TPASS, "status[%d] has expected value", UNTOUCHED_PAGE); } else { tst_resm(TFAIL, "status[%d] is %s, expected %s", UNTOUCHED_PAGE, tst_strerrno(-status[UNTOUCHED_PAGE]), tst_strerrno(-exp_status)); } err_free_pages: /* This is capable of freeing both the touched and * untouched pages. */ free_pages(pages, TEST_PAGES); } #else tst_resm(TCONF, "move_pages support not found."); #endif cleanup(); tst_exit(); }
int main(int argc, char **argv) { char *msg; /* message returned from parse_opts */ /* parse standard options */ msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); #if HAVE_NUMA_MOVE_PAGES unsigned int i; int lc; /* loop counter */ unsigned int from_node; unsigned int to_node; int ret; ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node); if (ret < 0) tst_brkm(TBROK|TERRNO, cleanup, "get_allowed_nodes: %d", ret); /* 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]; /* 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; } for (i = 0; i < TEST_PAGES; i++) *((char *)pages[i]) = 0xAA; verify_pages_on_node(pages, status, TEST_PAGES, to_node); free_pages(pages, TEST_PAGES); } #else tst_resm(TCONF, "move_pages support not found."); #endif cleanup(); tst_exit(); }
int main(int argc, char **argv) { tst_parse_opts(argc, argv, NULL, NULL); setup(); #ifdef HAVE_NUMA_V2 unsigned int i; int lc; unsigned int from_node; unsigned int to_node; int ret; ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node); if (ret < 0) tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret); /* 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]; pid_t cpid; sem_t *sem; /* 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; } sem = alloc_sem(MAX_SEMS); if (sem == NULL) { goto err_free_pages; } /* * Fork a child process so that the shared pages are * now really shared between two processes. */ cpid = fork(); if (cpid == -1) { tst_resm(TBROK | TERRNO, "forking child failed"); goto err_free_sem; } else if (cpid == 0) { child(pages, sem); } /* Wait for child to setup and signal. */ if (sem_wait(&sem[SEM_CHILD_SETUP]) == -1) tst_resm(TWARN | TERRNO, "error wait semaphore"); ret = numa_move_pages(0, TEST_PAGES, pages, nodes, status, MPOL_MF_MOVE_ALL); if (ret < 0) { tst_resm(TFAIL|TERRNO, "move_pages failed"); goto err_kill_child; } else if (ret > 0) { tst_resm(TINFO, "move_pages() returned %d\n", ret); } verify_pages_on_node(pages, status, TEST_PAGES, to_node); err_kill_child: /* Test done. Ask child to terminate. */ if (sem_post(&sem[SEM_PARENT_TEST]) == -1) tst_resm(TWARN | TERRNO, "error post semaphore"); /* Read the status, no zombies! */ wait(NULL); err_free_sem: free_sem(sem, MAX_SEMS); err_free_pages: free_shared_pages(pages, TEST_PAGES); } #else tst_resm(TCONF, NUMA_ERROR_MSG); #endif cleanup(); tst_exit(); }
int main(int argc, char **argv) { char *msg; /* message returned from parse_opts */ /* parse standard options */ msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); #if HAVE_NUMA_MOVE_PAGES unsigned int i; int lc; /* loop counter */ unsigned int from_node; unsigned int to_node; int ret; ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node); if (ret < 0) tst_brkm(TBROK|TERRNO, cleanup, "get_allowed_nodes: %d", ret); /* 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]; unsigned long onepage = get_page_size(); /* reset Tst_count in case we are looping */ Tst_count = 0; ret = alloc_pages_on_node(pages, TOUCHED_PAGES, from_node); if (ret == -1) continue; /* Allocate page and do not touch it. */ pages[UNTOUCHED_PAGE] = numa_alloc_onnode(onepage, from_node); if (pages[UNTOUCHED_PAGE] == NULL) { tst_resm(TBROK, "failed allocating page on node %d", from_node); goto err_free_pages; } 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 == -1) { tst_resm(TFAIL | TERRNO, "move_pages unexpectedly failed"); goto err_free_pages; } if (status[UNTOUCHED_PAGE] == -ENOENT) tst_resm(TPASS, "status[%d] set to expected -ENOENT", UNTOUCHED_PAGE); else tst_resm(TFAIL, "status[%d] is %d", UNTOUCHED_PAGE, status[UNTOUCHED_PAGE]); err_free_pages: /* This is capable of freeing both the touched and * untouched pages. */ free_pages(pages, TEST_PAGES); } #else tst_resm(TCONF, "move_pages support not found."); #endif cleanup(); tst_exit(); }