LCOV - code coverage report
Current view: top level - spdk/test/event/event_perf - event_perf.c (source / functions) Hit Total Coverage
Test: Combined Lines: 58 75 77.3 %
Date: 2024-07-10 18:23:29 Functions: 5 6 83.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 29 55 52.7 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2016 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/stdinc.h"
       7                 :            : 
       8                 :            : #include "spdk/env.h"
       9                 :            : #include "spdk/event.h"
      10                 :            : #include "spdk/log.h"
      11                 :            : #include "spdk/string.h"
      12                 :            : 
      13                 :            : static uint64_t g_tsc_rate;
      14                 :            : static uint64_t g_tsc_end;
      15                 :            : 
      16                 :            : static int g_time_in_sec;
      17                 :            : 
      18                 :            : static uint64_t *call_count;
      19                 :            : 
      20                 :            : static bool g_app_stopped = false;
      21                 :            : 
      22                 :            : static void
      23                 :   16375750 : submit_new_event(void *arg1, void *arg2)
      24                 :            : {
      25                 :            :         struct spdk_event *event;
      26                 :            :         static __thread uint32_t next_lcore = UINT32_MAX;
      27                 :            : 
      28         [ +  + ]:   16375750 :         if (spdk_get_ticks() > g_tsc_end) {
      29         [ +  + ]:        336 :                 if (__sync_bool_compare_and_swap(&g_app_stopped, false, true)) {
      30                 :         21 :                         spdk_app_stop(0);
      31                 :            :                 }
      32                 :        336 :                 return;
      33                 :            :         }
      34                 :            : 
      35         [ +  + ]:   16375414 :         if (next_lcore == UINT32_MAX) {
      36                 :         84 :                 next_lcore = spdk_env_get_next_core(spdk_env_get_current_core());
      37         [ +  + ]:         84 :                 if (next_lcore == UINT32_MAX) {
      38                 :         21 :                         next_lcore = spdk_env_get_first_core();
      39                 :            :                 }
      40                 :            :         }
      41                 :            : 
      42                 :   16375414 :         call_count[next_lcore]++;
      43                 :   16375414 :         event = spdk_event_allocate(next_lcore, submit_new_event, NULL, NULL);
      44                 :   16375414 :         spdk_event_call(event);
      45                 :            : }
      46                 :            : 
      47                 :            : static void
      48                 :         84 : event_work_fn(void *arg1, void *arg2)
      49                 :            : {
      50                 :            : 
      51                 :         84 :         submit_new_event(NULL, NULL);
      52                 :         84 :         submit_new_event(NULL, NULL);
      53                 :         84 :         submit_new_event(NULL, NULL);
      54                 :         84 :         submit_new_event(NULL, NULL);
      55                 :         84 : }
      56                 :            : 
      57                 :            : static void
      58                 :         21 : event_perf_start(void *arg1)
      59                 :            : {
      60                 :            :         uint32_t i;
      61                 :            : 
      62                 :         21 :         call_count = calloc(spdk_env_get_last_core() + 1, sizeof(*call_count));
      63         [ -  + ]:         21 :         if (call_count == NULL) {
      64   [ #  #  #  # ]:          0 :                 fprintf(stderr, "call_count allocation failed\n");
      65                 :          0 :                 spdk_app_stop(1);
      66                 :          0 :                 return;
      67                 :            :         }
      68                 :            : 
      69                 :         21 :         g_tsc_rate = spdk_get_ticks_hz();
      70                 :         21 :         g_tsc_end = spdk_get_ticks() + g_time_in_sec * g_tsc_rate;
      71                 :            : 
      72         [ -  + ]:         21 :         printf("Running I/O for %d seconds...", g_time_in_sec);
      73                 :         21 :         fflush(stdout);
      74                 :            : 
      75         [ +  + ]:        105 :         SPDK_ENV_FOREACH_CORE(i) {
      76                 :         84 :                 spdk_event_call(spdk_event_allocate(i, event_work_fn,
      77                 :            :                                                     NULL, NULL));
      78                 :            :         }
      79                 :            : 
      80                 :            : }
      81                 :            : 
      82                 :            : static void
      83                 :          0 : usage(char *program_name)
      84                 :            : {
      85         [ #  # ]:          0 :         printf("%s options\n", program_name);
      86         [ #  # ]:          0 :         printf("\t[-m core mask for distributing I/O submission/completion work\n");
      87         [ #  # ]:          0 :         printf("\t\t(default: 0x1 - use core 0 only)]\n");
      88         [ #  # ]:          0 :         printf("\t[-t time in seconds]\n");
      89                 :          0 : }
      90                 :            : 
      91                 :            : static void
      92                 :         21 : performance_dump(int io_time)
      93                 :            : {
      94                 :            :         uint32_t i;
      95                 :            : 
      96         [ -  + ]:         21 :         if (call_count == NULL) {
      97                 :          0 :                 return;
      98                 :            :         }
      99                 :            : 
     100                 :         21 :         printf("\n");
     101         [ +  + ]:        105 :         SPDK_ENV_FOREACH_CORE(i) {
     102   [ -  +  -  + ]:         84 :                 printf("lcore %2d: %8ju\n", i, call_count[i] / g_time_in_sec);
     103                 :            :         }
     104                 :            : 
     105                 :         21 :         fflush(stdout);
     106                 :         21 :         free(call_count);
     107                 :            : }
     108                 :            : 
     109                 :            : int
     110                 :         21 : main(int argc, char **argv)
     111                 :            : {
     112                 :         21 :         struct spdk_app_opts opts = {};
     113                 :            :         int op;
     114                 :         21 :         int rc = 0;
     115                 :            : 
     116                 :         21 :         spdk_app_opts_init(&opts, sizeof(opts));
     117                 :         21 :         opts.name = "event_perf";
     118                 :         21 :         opts.rpc_addr = NULL;
     119                 :            : 
     120                 :         21 :         g_time_in_sec = 0;
     121                 :            : 
     122   [ +  +  +  +  :         63 :         while ((op = getopt(argc, argv, "m:t:")) != -1) {
                   +  + ]
     123      [ +  +  - ]:         42 :                 switch (op) {
     124                 :         21 :                 case 'm':
     125                 :         21 :                         opts.reactor_mask = optarg;
     126                 :         21 :                         break;
     127                 :         21 :                 case 't':
     128                 :         21 :                         g_time_in_sec = spdk_strtol(optarg, 10);
     129         [ -  + ]:         21 :                         if (g_time_in_sec < 0) {
     130   [ #  #  #  # ]:          0 :                                 fprintf(stderr, "Invalid run time\n");
     131                 :          0 :                                 return g_time_in_sec;
     132                 :            :                         }
     133                 :         21 :                         break;
     134                 :          0 :                 default:
     135                 :          0 :                         usage(argv[0]);
     136                 :          0 :                         exit(1);
     137                 :            :                 }
     138                 :            :         }
     139                 :            : 
     140         [ -  + ]:         21 :         if (!g_time_in_sec) {
     141                 :          0 :                 usage(argv[0]);
     142                 :          0 :                 exit(1);
     143                 :            :         }
     144                 :            : 
     145         [ -  + ]:         21 :         printf("Running I/O for %d seconds...", g_time_in_sec);
     146                 :         21 :         fflush(stdout);
     147                 :            : 
     148                 :         21 :         rc = spdk_app_start(&opts, event_perf_start, NULL);
     149                 :            : 
     150                 :         21 :         spdk_app_fini();
     151                 :         21 :         performance_dump(g_time_in_sec);
     152                 :            : 
     153         [ -  + ]:         21 :         printf("done.\n");
     154                 :         21 :         return rc;
     155                 :            : }

Generated by: LCOV version 1.14