• Home
  • Raw
  • Download

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
81 /* Whether to test uffd write-protection */
95 int cpu; member
105 * to avoid non alignment faults on non-x86 archs.
111 sizeof(unsigned long long) - 1) & \
113 - 1)))
124 "# 10MiB-~6GiB 999 bounces anonymous test, "
145 uffd_stats[i].cpu = i; in uffd_stats_reset()
185 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); in anon_allocate_area()
264 * MADV_DONTEED won't work. So exercise -EEXIST on a alias in hugetlb_alias_mapping()
266 * this way we'll exercise the -EEXEC at the fs level. in hugetlb_alias_mapping()
287 MAP_ANONYMOUS | MAP_SHARED, -1, 0); in shmem_allocate_area()
349 /* Undo write-protect, do wakeup after that */ in wp_range()
360 unsigned long cpu = (unsigned long) arg; in locking_thread() local
370 seed = (unsigned int) time(NULL) - bounces; in locking_thread()
372 seed += cpu; in locking_thread()
380 page_nr = -bounces; in locking_thread()
382 page_nr += cpu * nr_pages_per_cpu; in locking_thread()
448 page_nr, cpu, area_dst + page_nr * page_size, in locking_thread()
468 if (time(NULL) - start > 1) in locking_thread()
472 time(NULL) - start); in locking_thread()
481 uffd_test_ops->alias_mapping(&uffdio_copy->dst, in retry_copy_page()
482 uffdio_copy->len, in retry_copy_page()
486 if (uffdio_copy->copy != -EEXIST) { in retry_copy_page()
488 uffdio_copy->copy); in retry_copy_page()
493 uffdio_copy->copy); exit(1); in retry_copy_page()
515 if (uffdio_copy.copy != -EEXIST) { in __copy_page()
566 if (msg->event != UFFD_EVENT_PAGEFAULT) { in uffd_handle_page_fault()
567 fprintf(stderr, "unexpected msg event %u\n", msg->event); in uffd_handle_page_fault()
571 if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WP) { in uffd_handle_page_fault()
572 wp_range(uffd, msg->arg.pagefault.address, page_size, false); in uffd_handle_page_fault()
573 stats->wp_faults++; in uffd_handle_page_fault()
577 msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE) { in uffd_handle_page_fault()
582 offset = (char *)(unsigned long)msg->arg.pagefault.address - area_dst; in uffd_handle_page_fault()
583 offset &= ~(page_size-1); in uffd_handle_page_fault()
586 stats->missing_faults++; in uffd_handle_page_fault()
593 unsigned long cpu = stats->cpu; in uffd_poll_thread() local
602 pollfd[1].fd = pipefd[cpu*2]; in uffd_poll_thread()
606 ret = poll(pollfd, 2, -1); in uffd_poll_thread()
644 uffd_reg.range.len = msg.arg.remove.end - in uffd_poll_thread()
681 unsigned long cpu = (unsigned long) arg; in background_thread() local
684 start_nr = cpu * nr_pages_per_cpu; in background_thread()
685 end_nr = (cpu+1) * nr_pages_per_cpu; in background_thread()
693 * If we need to test uffd-wp, set it up now. Then we'll have in background_thread()
695 * can be write-protected for testing in background_thread()
713 unsigned long cpu; in stress() local
719 for (cpu = 0; cpu < nr_cpus; cpu++) { in stress()
720 if (pthread_create(&locking_threads[cpu], &attr, in stress()
721 locking_thread, (void *)cpu)) in stress()
724 if (pthread_create(&uffd_threads[cpu], &attr, in stress()
726 (void *)&uffd_stats[cpu])) in stress()
729 if (pthread_create(&uffd_threads[cpu], &attr, in stress()
731 (void *)&uffd_stats[cpu])) in stress()
735 if (pthread_create(&background_threads[cpu], &attr, in stress()
736 background_thread, (void *)cpu)) in stress()
739 for (cpu = 0; cpu < nr_cpus; cpu++) in stress()
740 if (pthread_join(background_threads[cpu], NULL)) in stress()
748 * area_src (but they're guaranteed to get -EEXIST from in stress()
752 if (uffd_test_ops->release_pages(area_src)) in stress()
757 for (cpu = 0; cpu < nr_cpus; cpu++) in stress()
758 if (pthread_join(locking_threads[cpu], NULL)) in stress()
761 for (cpu = 0; cpu < nr_cpus; cpu++) { in stress()
764 if (write(pipefd[cpu*2+1], &c, 1) != 1) { in stress()
768 if (pthread_join(uffd_threads[cpu], in stress()
769 (void *)&uffd_stats[cpu])) in stress()
772 if (pthread_cancel(uffd_threads[cpu])) in stress()
774 if (pthread_join(uffd_threads[cpu], NULL)) in stress()
820 * For non-cooperative userfaultfd test we fork() a process that will
835 * test robustness use case - we release monitored area, fork a process
842 unsigned long nr; in faulting_process() local
863 lastnr = (unsigned long)-1; in faulting_process()
866 for (nr = 0; nr < split_nr_pages; nr++) { in faulting_process()
868 unsigned long offset = nr * page_size; in faulting_process()
872 if (steps == 1 && nr == lastnr) { in faulting_process()
877 lastnr = nr; in faulting_process()
899 count = *area_count(area_dst, nr); in faulting_process()
900 if (count != count_verify[nr]) { in faulting_process()
902 "nr %lu memory corruption %Lu %Lu\n", in faulting_process()
903 nr, count, in faulting_process()
904 count_verify[nr]); in faulting_process()
910 *area_count(area_dst, nr) = count; in faulting_process()
926 for (; nr < nr_pages; nr++) { in faulting_process()
927 count = *area_count(area_dst, nr); in faulting_process()
928 if (count != count_verify[nr]) { in faulting_process()
930 "nr %lu memory corruption %Lu %Lu\n", in faulting_process()
931 nr, count, in faulting_process()
932 count_verify[nr]); exit(1); in faulting_process()
938 *area_count(area_dst, nr) = count; in faulting_process()
941 if (uffd_test_ops->release_pages(area_dst)) in faulting_process()
944 for (nr = 0; nr < nr_pages; nr++) { in faulting_process()
945 if (my_bcmp(area_dst + nr * page_size, zeropage, page_size)) { in faulting_process()
946 fprintf(stderr, "nr %lu is not zero\n", nr); in faulting_process()
958 uffd_test_ops->alias_mapping(&uffdio_zeropage->range.start, in retry_uffdio_zeropage()
959 uffdio_zeropage->range.len, in retry_uffdio_zeropage()
962 if (uffdio_zeropage->zeropage != -EEXIST) { in retry_uffdio_zeropage()
964 uffdio_zeropage->zeropage); in retry_uffdio_zeropage()
969 uffdio_zeropage->zeropage); exit(1); in retry_uffdio_zeropage()
979 has_zeropage = uffd_test_ops->expected_ioctls & (1 << _UFFDIO_ZEROPAGE); in __uffdio_zeropage()
992 if (uffdio_zeropage.zeropage == -EEXIST) { in __uffdio_zeropage()
993 fprintf(stderr, "UFFDIO_ZEROPAGE -EEXIST\n"); in __uffdio_zeropage()
1001 if (uffdio_zeropage.zeropage != -EINVAL) { in __uffdio_zeropage()
1003 "UFFDIO_ZEROPAGE not -EINVAL %Ld\n", in __uffdio_zeropage()
1043 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_zeropage_test()
1058 expected_ioctls = uffd_test_ops->expected_ioctls; in userfaultfd_zeropage_test()
1091 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_events_test()
1110 expected_ioctls = uffd_test_ops->expected_ioctls; in userfaultfd_events_test()
1164 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_sig_test()
1182 expected_ioctls = uffd_test_ops->expected_ioctls; in userfaultfd_sig_test()
1193 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_sig_test()
1235 unsigned long nr; in userfaultfd_stress() local
1237 unsigned long cpu; in userfaultfd_stress() local
1241 uffd_test_ops->allocate_area((void **)&area_src); in userfaultfd_stress()
1244 uffd_test_ops->allocate_area((void **)&area_dst); in userfaultfd_stress()
1257 for (nr = 0; nr < nr_pages; nr++) { in userfaultfd_stress()
1258 *area_mutex(area_src, nr) = (pthread_mutex_t) in userfaultfd_stress()
1260 count_verify[nr] = *area_count(area_src, nr) = 1; in userfaultfd_stress()
1264 * zero, so leave a placeholder below always non-zero in userfaultfd_stress()
1268 *(area_count(area_src, nr) + 1) = 1; in userfaultfd_stress()
1276 for (cpu = 0; cpu < nr_cpus; cpu++) { in userfaultfd_stress()
1277 if (pipe2(&pipefd[cpu*2], O_CLOEXEC | O_NONBLOCK)) { in userfaultfd_stress()
1296 while (bounces--) { in userfaultfd_stress()
1326 expected_ioctls = uffd_test_ops->expected_ioctls; in userfaultfd_stress()
1351 * return -EEXIST). The problem comes at the next in userfaultfd_stress()
1356 * area_src would lead to -EEXIST failure during the in userfaultfd_stress()
1367 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_stress()
1397 for (nr = 0; nr < nr_pages; nr++) { in userfaultfd_stress()
1398 if (*area_count(area_dst, nr) != count_verify[nr]) { in userfaultfd_stress()
1401 *area_count(area_src, nr), in userfaultfd_stress()
1402 count_verify[nr], in userfaultfd_stress()
1403 nr); in userfaultfd_stress()
1431 * Copied from mlock2-tests.c
1459 /* Only enable write-protect test for anonymous test */ in set_test_type()