LCOV - code coverage report
Current view: top level - app/test - test_cksum_perf.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 1 30 3.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 22 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2022 Ericsson AB
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : 
       7                 :            : #include <rte_common.h>
       8                 :            : #include <rte_cycles.h>
       9                 :            : #include <rte_ip.h>
      10                 :            : #include <rte_malloc.h>
      11                 :            : #include <rte_random.h>
      12                 :            : 
      13                 :            : #include "test.h"
      14                 :            : 
      15                 :            : #define NUM_BLOCKS 10
      16                 :            : #define ITERATIONS 1000000
      17                 :            : 
      18                 :            : static const size_t data_sizes[] = { 20, 21, 100, 101, 1500, 1501 };
      19                 :            : 
      20                 :            : static __rte_noinline uint16_t
      21                 :          0 : do_rte_raw_cksum(const void *buf, size_t len)
      22                 :            : {
      23                 :          0 :         return rte_raw_cksum(buf, len);
      24                 :            : }
      25                 :            : 
      26                 :            : static void
      27                 :            : init_block(char *buf, size_t len)
      28                 :            : {
      29                 :            :         size_t i;
      30                 :            : 
      31         [ #  # ]:          0 :         for (i = 0; i < len; i++)
      32                 :          0 :                 buf[i] = (char)rte_rand();
      33                 :            : }
      34                 :            : 
      35                 :            : static int
      36                 :          0 : test_cksum_perf_size_alignment(size_t block_size, bool aligned)
      37                 :            : {
      38                 :            :         char *data[NUM_BLOCKS];
      39                 :            :         char *blocks[NUM_BLOCKS];
      40                 :            :         unsigned int i;
      41                 :            :         uint64_t start;
      42                 :            :         uint64_t end;
      43                 :            :         /* Floating point to handle low (pseudo-)TSC frequencies */
      44                 :            :         double block_latency;
      45                 :            :         double byte_latency;
      46                 :          0 :         volatile __rte_unused uint64_t sum = 0;
      47                 :            : 
      48         [ #  # ]:          0 :         for (i = 0; i < NUM_BLOCKS; i++) {
      49                 :          0 :                 data[i] = rte_malloc(NULL, block_size + 1, 0);
      50                 :            : 
      51         [ #  # ]:          0 :                 if (data[i] == NULL) {
      52                 :            :                         printf("Failed to allocate memory for block\n");
      53                 :          0 :                         return TEST_FAILED;
      54                 :            :                 }
      55                 :            : 
      56                 :            :                 init_block(data[i], block_size + 1);
      57                 :            : 
      58         [ #  # ]:          0 :                 blocks[i] = aligned ? data[i] : data[i] + 1;
      59                 :            :         }
      60                 :            : 
      61                 :            :         start = rte_rdtsc();
      62                 :            : 
      63         [ #  # ]:          0 :         for (i = 0; i < ITERATIONS; i++) {
      64                 :            :                 unsigned int j;
      65         [ #  # ]:          0 :                 for (j = 0; j < NUM_BLOCKS; j++)
      66                 :          0 :                         sum += do_rte_raw_cksum(blocks[j], block_size);
      67                 :            :         }
      68                 :            : 
      69                 :            :         end = rte_rdtsc();
      70                 :            : 
      71                 :          0 :         block_latency = (end - start) / (double)(ITERATIONS * NUM_BLOCKS);
      72                 :          0 :         byte_latency = block_latency / block_size;
      73                 :            : 
      74         [ #  # ]:          0 :         printf("%-9s %10zd %19.1f %16.2f\n", aligned ? "Aligned" : "Unaligned",
      75                 :            :                block_size, block_latency, byte_latency);
      76                 :            : 
      77         [ #  # ]:          0 :         for (i = 0; i < NUM_BLOCKS; i++)
      78                 :          0 :                 rte_free(data[i]);
      79                 :            : 
      80                 :            :         return TEST_SUCCESS;
      81                 :            : }
      82                 :            : 
      83                 :            : static int
      84                 :          0 : test_cksum_perf_size(size_t block_size)
      85                 :            : {
      86                 :            :         int rc;
      87                 :            : 
      88                 :          0 :         rc = test_cksum_perf_size_alignment(block_size, true);
      89         [ #  # ]:          0 :         if (rc != TEST_SUCCESS)
      90                 :            :                 return rc;
      91                 :            : 
      92                 :          0 :         rc = test_cksum_perf_size_alignment(block_size, false);
      93                 :            : 
      94                 :          0 :         return rc;
      95                 :            : }
      96                 :            : 
      97                 :            : static int
      98                 :          0 : test_cksum_perf(void)
      99                 :            : {
     100                 :            :         uint16_t i;
     101                 :            : 
     102                 :            :         printf("### rte_raw_cksum() performance ###\n");
     103                 :            :         printf("Alignment  Block size    TSC cycles/block  TSC cycles/byte\n");
     104                 :            : 
     105         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(data_sizes); i++) {
     106                 :            :                 int rc;
     107                 :            : 
     108                 :          0 :                 rc = test_cksum_perf_size(data_sizes[i]);
     109         [ #  # ]:          0 :                 if (rc != TEST_SUCCESS)
     110                 :          0 :                         return rc;
     111                 :            :         }
     112                 :            : 
     113                 :            :         return TEST_SUCCESS;
     114                 :            : }
     115                 :            : 
     116                 :        251 : REGISTER_PERF_TEST(cksum_perf_autotest, test_cksum_perf);

Generated by: LCOV version 1.14