teknoraver

test_string

Jun 15th, 2021 (edited)
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. static __init int memcpy_align_selftest(void)
  2. {
  3.     struct page *page1, *page2;
  4.     char *dst, *src;
  5.     int err = 0;
  6.     int i, j;
  7.     ktime_t j0, j1;
  8.  
  9.     printk("Strings selftest: testing with size: %d\n", PG_SIZE);
  10.  
  11.     page1 = alloc_pages(GFP_KERNEL, MAX_ORDER-1);
  12.     if (!page1)
  13.         return 1;
  14.  
  15.     page2 = alloc_pages(GFP_KERNEL, MAX_ORDER-1);
  16.     if (!page2) {
  17.         err = 1;
  18.         goto free1;
  19.     }
  20.  
  21.     src = page_to_virt(page1);
  22.     dst = page_to_virt(page1);
  23.  
  24.     preempt_disable();
  25.  
  26.     for (i = 0; i < sizeof(void*); i++) {
  27.         for (j = 0; j < sizeof(void*); j++) {
  28.             t0 = ktime_get();
  29.             memcpy(dst + j, src + i, PG_SIZE - max(i, j));
  30.             t1 = ktime_get();
  31.             printk("Strings selftest: memcpy(src+%d, dst+%d): %llu Mb/s\n", i, j, PG_SIZE * (1000000000l / 1048576l) / (t1-t0));
  32.         }
  33.     }
  34.  
  35.     preempt_enable();
  36.  
  37.     put_page(page2);
  38.  
  39. free1:
  40.     put_page(page1);
  41.  
  42.     return err;
  43. }
  44.  
  45. static __init int memset_align_selftest(void)
  46. {
  47.     struct page *page;
  48.     ktime_t t0, t1;
  49.     char *dst;
  50.     int i;
  51.  
  52.     printk("Strings selftest: testing with size: %d\n", PG_SIZE);
  53.  
  54.     page = alloc_pages(GFP_KERNEL, MAX_ORDER-1);
  55.     if (!page)
  56.         return 1;
  57.  
  58.     dst = page_to_virt(page);
  59.  
  60.     preempt_disable();
  61.  
  62.     for (i = 0; i < sizeof(void*); i++) {
  63.         t0 = ktime_get();
  64.         memset(dst + i, 0, PG_SIZE - i);
  65.         t1 = ktime_get();
  66.         printk("Strings selftest: memset(dst+%d): %llu Mb/s\n", i, PG_SIZE * (1000000000l / 1048576l) / (t1-t0));
  67.     }
  68.  
  69.     preempt_enable();
  70.  
  71.     put_page(page);
  72.  
  73.     return 0;
  74. }
  75.  
Add Comment
Please, Sign In to add comment