Lines Matching +full:cpu +full:- +full:nr

1 // SPDX-License-Identifier: GPL-2.0-only
11 * There are three threads running per CPU:
13 * 1) one per-CPU thread takes a per-page pthread_mutex in a random
15 * area_src), and increments a per-page counter in the same page,
18 * 2) another per-CPU thread handles the userfaults generated by
22 * 3) one last per-CPU thread transfers the memory in the background
24 * 2). Each cpu thread takes cares of transferring a portion of the
32 * per-CPU threads 1 by triggering userfaults inside
80 /* Whether to test uffd write-protection */
94 int cpu; member
104 * to avoid non alignment faults on non-x86 archs.
110 sizeof(unsigned long long) - 1) & \
112 - 1)))
123 "# 10MiB-~6GiB 999 bounces anonymous test, "
144 uffd_stats[i].cpu = i; in uffd_stats_reset()
261 * MADV_DONTEED won't work. So exercise -EEXIST on a alias in hugetlb_alias_mapping()
263 * this way we'll exercise the -EEXEC at the fs level. in hugetlb_alias_mapping()
284 MAP_ANONYMOUS | MAP_SHARED, -1, 0); in shmem_allocate_area()
346 /* Undo write-protect, do wakeup after that */ in wp_range()
357 unsigned long cpu = (unsigned long) arg; in locking_thread() local
367 seed = (unsigned int) time(NULL) - bounces; in locking_thread()
369 seed += cpu; in locking_thread()
377 page_nr = -bounces; in locking_thread()
379 page_nr += cpu * nr_pages_per_cpu; in locking_thread()
445 page_nr, cpu, area_dst + page_nr * page_size, in locking_thread()
465 if (time(NULL) - start > 1) in locking_thread()
469 time(NULL) - start); in locking_thread()
478 uffd_test_ops->alias_mapping(&uffdio_copy->dst, in retry_copy_page()
479 uffdio_copy->len, in retry_copy_page()
483 if (uffdio_copy->copy != -EEXIST) { in retry_copy_page()
485 uffdio_copy->copy); in retry_copy_page()
490 uffdio_copy->copy); exit(1); in retry_copy_page()
512 if (uffdio_copy.copy != -EEXIST) { in __copy_page()
563 if (msg->event != UFFD_EVENT_PAGEFAULT) { in uffd_handle_page_fault()
564 fprintf(stderr, "unexpected msg event %u\n", msg->event); in uffd_handle_page_fault()
568 if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WP) { in uffd_handle_page_fault()
569 wp_range(uffd, msg->arg.pagefault.address, page_size, false); in uffd_handle_page_fault()
570 stats->wp_faults++; in uffd_handle_page_fault()
574 msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE) { in uffd_handle_page_fault()
579 offset = (char *)(unsigned long)msg->arg.pagefault.address - area_dst; in uffd_handle_page_fault()
580 offset &= ~(page_size-1); in uffd_handle_page_fault()
583 stats->missing_faults++; in uffd_handle_page_fault()
590 unsigned long cpu = stats->cpu; in uffd_poll_thread() local
599 pollfd[1].fd = pipefd[cpu*2]; in uffd_poll_thread()
603 ret = poll(pollfd, 2, -1); in uffd_poll_thread()
641 uffd_reg.range.len = msg.arg.remove.end - in uffd_poll_thread()
678 unsigned long cpu = (unsigned long) arg; in background_thread() local
681 start_nr = cpu * nr_pages_per_cpu; in background_thread()
682 end_nr = (cpu+1) * nr_pages_per_cpu; in background_thread()
690 * If we need to test uffd-wp, set it up now. Then we'll have in background_thread()
692 * can be write-protected for testing in background_thread()
710 unsigned long cpu; in stress() local
716 for (cpu = 0; cpu < nr_cpus; cpu++) { in stress()
717 if (pthread_create(&locking_threads[cpu], &attr, in stress()
718 locking_thread, (void *)cpu)) in stress()
721 if (pthread_create(&uffd_threads[cpu], &attr, in stress()
723 (void *)&uffd_stats[cpu])) in stress()
726 if (pthread_create(&uffd_threads[cpu], &attr, in stress()
728 (void *)&uffd_stats[cpu])) in stress()
732 if (pthread_create(&background_threads[cpu], &attr, in stress()
733 background_thread, (void *)cpu)) in stress()
736 for (cpu = 0; cpu < nr_cpus; cpu++) in stress()
737 if (pthread_join(background_threads[cpu], NULL)) in stress()
745 * area_src (but they're guaranteed to get -EEXIST from in stress()
749 if (uffd_test_ops->release_pages(area_src)) in stress()
754 for (cpu = 0; cpu < nr_cpus; cpu++) in stress()
755 if (pthread_join(locking_threads[cpu], NULL)) in stress()
758 for (cpu = 0; cpu < nr_cpus; cpu++) { in stress()
761 if (write(pipefd[cpu*2+1], &c, 1) != 1) { in stress()
765 if (pthread_join(uffd_threads[cpu], in stress()
766 (void *)&uffd_stats[cpu])) in stress()
769 if (pthread_cancel(uffd_threads[cpu])) in stress()
771 if (pthread_join(uffd_threads[cpu], NULL)) in stress()
817 * For non-cooperative userfaultfd test we fork() a process that will
832 * test robustness use case - we release monitored area, fork a process
839 unsigned long nr; in faulting_process() local
860 lastnr = (unsigned long)-1; in faulting_process()
863 for (nr = 0; nr < split_nr_pages; nr++) { in faulting_process()
865 unsigned long offset = nr * page_size; in faulting_process()
869 if (steps == 1 && nr == lastnr) { in faulting_process()
874 lastnr = nr; in faulting_process()
896 count = *area_count(area_dst, nr); in faulting_process()
897 if (count != count_verify[nr]) { in faulting_process()
899 "nr %lu memory corruption %Lu %Lu\n", in faulting_process()
900 nr, count, in faulting_process()
901 count_verify[nr]); in faulting_process()
907 *area_count(area_dst, nr) = count; in faulting_process()
923 for (; nr < nr_pages; nr++) { in faulting_process()
924 count = *area_count(area_dst, nr); in faulting_process()
925 if (count != count_verify[nr]) { in faulting_process()
927 "nr %lu memory corruption %Lu %Lu\n", in faulting_process()
928 nr, count, in faulting_process()
929 count_verify[nr]); exit(1); in faulting_process()
935 *area_count(area_dst, nr) = count; in faulting_process()
938 if (uffd_test_ops->release_pages(area_dst)) in faulting_process()
941 for (nr = 0; nr < nr_pages; nr++) { in faulting_process()
942 if (my_bcmp(area_dst + nr * page_size, zeropage, page_size)) { in faulting_process()
943 fprintf(stderr, "nr %lu is not zero\n", nr); in faulting_process()
955 uffd_test_ops->alias_mapping(&uffdio_zeropage->range.start, in retry_uffdio_zeropage()
956 uffdio_zeropage->range.len, in retry_uffdio_zeropage()
959 if (uffdio_zeropage->zeropage != -EEXIST) { in retry_uffdio_zeropage()
961 uffdio_zeropage->zeropage); in retry_uffdio_zeropage()
966 uffdio_zeropage->zeropage); exit(1); in retry_uffdio_zeropage()
976 has_zeropage = uffd_test_ops->expected_ioctls & (1 << _UFFDIO_ZEROPAGE); in __uffdio_zeropage()
989 if (uffdio_zeropage.zeropage == -EEXIST) { in __uffdio_zeropage()
990 fprintf(stderr, "UFFDIO_ZEROPAGE -EEXIST\n"); in __uffdio_zeropage()
998 if (uffdio_zeropage.zeropage != -EINVAL) { in __uffdio_zeropage()
1000 "UFFDIO_ZEROPAGE not -EINVAL %Ld\n", in __uffdio_zeropage()
1040 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_zeropage_test()
1055 expected_ioctls = uffd_test_ops->expected_ioctls; in userfaultfd_zeropage_test()
1088 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_events_test()
1107 expected_ioctls = uffd_test_ops->expected_ioctls; in userfaultfd_events_test()
1161 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_sig_test()
1179 expected_ioctls = uffd_test_ops->expected_ioctls; in userfaultfd_sig_test()
1190 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_sig_test()
1232 unsigned long nr; in userfaultfd_stress() local
1234 unsigned long cpu; in userfaultfd_stress() local
1238 uffd_test_ops->allocate_area((void **)&area_src); in userfaultfd_stress()
1241 uffd_test_ops->allocate_area((void **)&area_dst); in userfaultfd_stress()
1254 for (nr = 0; nr < nr_pages; nr++) { in userfaultfd_stress()
1255 *area_mutex(area_src, nr) = (pthread_mutex_t) in userfaultfd_stress()
1257 count_verify[nr] = *area_count(area_src, nr) = 1; in userfaultfd_stress()
1261 * zero, so leave a placeholder below always non-zero in userfaultfd_stress()
1265 *(area_count(area_src, nr) + 1) = 1; in userfaultfd_stress()
1273 for (cpu = 0; cpu < nr_cpus; cpu++) { in userfaultfd_stress()
1274 if (pipe2(&pipefd[cpu*2], O_CLOEXEC | O_NONBLOCK)) { in userfaultfd_stress()
1293 while (bounces--) { in userfaultfd_stress()
1323 expected_ioctls = uffd_test_ops->expected_ioctls; in userfaultfd_stress()
1348 * return -EEXIST). The problem comes at the next in userfaultfd_stress()
1353 * area_src would lead to -EEXIST failure during the in userfaultfd_stress()
1364 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_stress()
1394 for (nr = 0; nr < nr_pages; nr++) { in userfaultfd_stress()
1395 if (*area_count(area_dst, nr) != count_verify[nr]) { in userfaultfd_stress()
1398 *area_count(area_src, nr), in userfaultfd_stress()
1399 count_verify[nr], in userfaultfd_stress()
1400 nr); in userfaultfd_stress()
1428 * Copied from mlock2-tests.c
1456 /* Only enable write-protect test for anonymous test */ in set_test_type()