LCOV - code coverage report
Current view: top level - app/test - test_thash_perf.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 1 44 2.3 %
Date: 2024-12-01 18:57:19 Functions: 1 5 20.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 16 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2021 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <stdint.h>
       7                 :            : #include <stdlib.h>
       8                 :            : #include <math.h>
       9                 :            : 
      10                 :            : #include <rte_cycles.h>
      11                 :            : #include <rte_malloc.h>
      12                 :            : #include <rte_random.h>
      13                 :            : #include <rte_thash.h>
      14                 :            : 
      15                 :            : #include "test.h"
      16                 :            : 
      17                 :            : #define ITERATIONS      (1 << 15)
      18                 :            : #define BATCH_SZ        (1 << 10)
      19                 :            : 
      20                 :            : #define IPV4_2_TUPLE_LEN        (8)
      21                 :            : #define IPV4_4_TUPLE_LEN        (12)
      22                 :            : #define IPV6_2_TUPLE_LEN        (32)
      23                 :            : #define IPV6_4_TUPLE_LEN        (36)
      24                 :            : 
      25                 :            : 
      26                 :            : static const uint8_t default_rss_key[] = {
      27                 :            :         0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
      28                 :            :         0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
      29                 :            :         0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
      30                 :            :         0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
      31                 :            :         0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa,
      32                 :            : };
      33                 :            : 
      34                 :            : enum test_rss_type {
      35                 :            :         TEST_SOFTRSS,
      36                 :            :         TEST_SOFTRSS_BE,
      37                 :            :         TEST_RSS_GFNI
      38                 :            : };
      39                 :            : 
      40                 :            : static inline uint64_t
      41                 :          0 : run_rss_calc(uint32_t *tuples[BATCH_SZ], enum test_rss_type type, int len,
      42                 :            :         const void *key)
      43                 :            : {
      44                 :            :         int i, j;
      45                 :            :         uint64_t start_tsc, end_tsc;
      46                 :          0 :         volatile uint32_t hash = 0;
      47                 :            : 
      48                 :            :         start_tsc = rte_rdtsc_precise();
      49         [ #  # ]:          0 :         for (i = 0; i < ITERATIONS; i++) {
      50         [ #  # ]:          0 :                 for (j = 0; j < BATCH_SZ; j++) {
      51         [ #  # ]:          0 :                         if (type == TEST_SOFTRSS)
      52                 :          0 :                                 hash ^= rte_softrss(tuples[j], len /
      53                 :            :                                         sizeof(uint32_t), (const uint8_t *)key);
      54         [ #  # ]:          0 :                         else if (type == TEST_SOFTRSS_BE)
      55                 :          0 :                                 hash ^= rte_softrss_be(tuples[j], len /
      56                 :            :                                         sizeof(uint32_t), (const uint8_t *)key);
      57                 :            :                         else
      58                 :          0 :                                 hash ^= rte_thash_gfni((const uint64_t *)key,
      59                 :          0 :                                         (uint8_t *)tuples[j], len);
      60                 :            :                 }
      61                 :            :         }
      62                 :            :         end_tsc = rte_rdtsc_precise();
      63                 :            : 
      64                 :            :         /* To avoid compiler warnings set hash to used. */
      65                 :          0 :         RTE_SET_USED(hash);
      66                 :            : 
      67                 :          0 :         return end_tsc - start_tsc;
      68                 :            : }
      69                 :            : 
      70                 :            : static inline uint64_t
      71                 :          0 : run_rss_calc_bulk(uint32_t *tuples[BATCH_SZ], int len, const void *key)
      72                 :            : {
      73                 :            :         int i;
      74                 :            :         uint64_t start_tsc, end_tsc;
      75                 :          0 :         uint32_t bulk_hash[BATCH_SZ] = { 0 };
      76                 :            : 
      77                 :            :         start_tsc = rte_rdtsc_precise();
      78         [ #  # ]:          0 :         for (i = 0; i < ITERATIONS; i++)
      79                 :            :                 rte_thash_gfni_bulk((const uint64_t *)key, len,
      80                 :            :                         (uint8_t **)tuples, bulk_hash, BATCH_SZ);
      81                 :            : 
      82                 :            :         end_tsc = rte_rdtsc_precise();
      83                 :            : 
      84                 :          0 :         return end_tsc - start_tsc;
      85                 :            : }
      86                 :            : 
      87                 :            : static void
      88                 :          0 : run_thash_test(unsigned int tuple_len)
      89                 :            : {
      90                 :            :         uint32_t *tuples[BATCH_SZ];
      91                 :            :         unsigned int i, j;
      92                 :          0 :         uint32_t len = RTE_ALIGN_CEIL(tuple_len, sizeof(uint32_t));
      93                 :            :         uint64_t tsc_diff;
      94                 :            : 
      95         [ #  # ]:          0 :         for (i = 0; i < BATCH_SZ; i++) {
      96                 :          0 :                 tuples[i] = rte_zmalloc(NULL, len, 0);
      97         [ #  # ]:          0 :                 for (j = 0; j < len / sizeof(uint32_t); j++)
      98                 :          0 :                         tuples[i][j] = rte_rand();
      99                 :            :         }
     100                 :            : 
     101                 :          0 :         tsc_diff = run_rss_calc(tuples, TEST_SOFTRSS, len, default_rss_key);
     102                 :          0 :         printf("Average rte_softrss() takes \t\t%.1f cycles for key len %d\n",
     103                 :          0 :                 (double)(tsc_diff) / (double)(ITERATIONS * BATCH_SZ), len);
     104                 :            : 
     105                 :          0 :         tsc_diff = run_rss_calc(tuples, TEST_SOFTRSS_BE, len,
     106                 :            :                 default_rss_key);
     107                 :          0 :         printf("Average rte_softrss_be() takes \t\t%.1f cycles for key len %d\n",
     108                 :          0 :                 (double)(tsc_diff) / (double)(ITERATIONS * BATCH_SZ), len);
     109                 :            : 
     110         [ #  # ]:          0 :         if (!rte_thash_gfni_supported())
     111                 :          0 :                 return;
     112                 :            : 
     113                 :            :         uint64_t rss_key_matrixes[RTE_DIM(default_rss_key)];
     114                 :            : 
     115                 :          0 :         rte_thash_complete_matrix(rss_key_matrixes, default_rss_key,
     116                 :            :                 RTE_DIM(default_rss_key));
     117                 :            : 
     118                 :          0 :         tsc_diff = run_rss_calc(tuples, TEST_RSS_GFNI, len, rss_key_matrixes);
     119                 :          0 :         printf("Average rte_thash_gfni takes \t\t%.1f cycles for key len %d\n",
     120                 :          0 :                 (double)(tsc_diff) / (double)(ITERATIONS * BATCH_SZ), len);
     121                 :            : 
     122                 :          0 :         tsc_diff = run_rss_calc_bulk(tuples, len, rss_key_matrixes);
     123                 :          0 :         printf("Average rte_thash_gfni_bulk takes \t%.1f cycles for key len %d\n",
     124                 :          0 :                 (double)(tsc_diff) / (double)(ITERATIONS * BATCH_SZ), len);
     125                 :            : }
     126                 :            : 
     127                 :            : static int
     128                 :          0 : test_thash_perf(void)
     129                 :            : {
     130                 :          0 :         run_thash_test(IPV4_2_TUPLE_LEN);
     131                 :          0 :         run_thash_test(IPV4_4_TUPLE_LEN);
     132                 :          0 :         run_thash_test(IPV6_2_TUPLE_LEN);
     133                 :          0 :         run_thash_test(IPV6_4_TUPLE_LEN);
     134                 :            : 
     135                 :          0 :         return 0;
     136                 :            : }
     137                 :            : 
     138                 :        251 : REGISTER_PERF_TEST(thash_perf_autotest, test_thash_perf);

Generated by: LCOV version 1.14