| 647 | #define ENTRIES (1 << 15) /* How many entries. */ |
| 648 | |
| 649 | static int |
| 650 | fbk_hash_perf_test(void) |
| 651 | { |
| 652 | struct rte_fbk_hash_params params = { |
| 653 | .name = "fbk_hash_test", |
| 654 | .entries = ENTRIES, |
| 655 | .entries_per_bucket = 4, |
| 656 | .socket_id = rte_socket_id(), |
| 657 | }; |
| 658 | struct rte_fbk_hash_table *handle = NULL; |
| 659 | uint32_t *keys = NULL; |
| 660 | unsigned indexes[TEST_SIZE]; |
| 661 | uint64_t lookup_time = 0; |
| 662 | unsigned added = 0; |
| 663 | unsigned value = 0; |
| 664 | uint32_t key; |
| 665 | uint16_t val; |
| 666 | unsigned i, j; |
| 667 | |
| 668 | handle = rte_fbk_hash_create(¶ms); |
| 669 | if (handle == NULL) { |
| 670 | printf("Error creating table\n"); |
| 671 | return -1; |
| 672 | } |
| 673 | |
| 674 | keys = rte_zmalloc(NULL, ENTRIES * sizeof(*keys), 0); |
| 675 | if (keys == NULL) { |
| 676 | printf("fbk hash: memory allocation for key store failed\n"); |
| 677 | return -1; |
| 678 | } |
| 679 | |
| 680 | /* Generate random keys and values. */ |
| 681 | for (i = 0; i < ENTRIES; i++) { |
| 682 | key = (uint32_t)rte_rand(); |
| 683 | key = ((uint64_t)key << 32) | (uint64_t)rte_rand(); |
| 684 | val = (uint16_t)rte_rand(); |
| 685 | |
| 686 | if (rte_fbk_hash_add_key(handle, key, val) == 0) { |
| 687 | keys[added] = key; |
| 688 | added++; |
| 689 | } |
| 690 | if (added > (LOAD_FACTOR * ENTRIES)) |
| 691 | break; |
| 692 | } |
| 693 | |
| 694 | for (i = 0; i < TEST_ITERATIONS; i++) { |
| 695 | uint64_t begin; |
| 696 | uint64_t end; |
| 697 | |
| 698 | /* Generate random indexes into keys[] array. */ |
| 699 | for (j = 0; j < TEST_SIZE; j++) |
| 700 | indexes[j] = rte_rand() % added; |
| 701 | |
| 702 | begin = rte_rdtsc(); |
| 703 | /* Do lookups */ |
| 704 | for (j = 0; j < TEST_SIZE; j++) |
| 705 | value += rte_fbk_hash_lookup(handle, keys[indexes[j]]); |
| 706 |
no test coverage detected