LCOV - code coverage report
Current view: top level - spdk/examples/interrupt_tgt - interrupt_tgt.c (source / functions) Hit Total Coverage
Test: Combined Lines: 34 53 64.2 %
Date: 2024-07-11 19:06:16 Functions: 6 7 85.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 25 48.0 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2020 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/stdinc.h"
       7                 :            : #include "spdk/conf.h"
       8                 :            : #include "spdk/event.h"
       9                 :            : #include "spdk/vhost.h"
      10                 :            : #include "spdk/json.h"
      11                 :            : #include "spdk/jsonrpc.h"
      12                 :            : #include "spdk/rpc.h"
      13                 :            : #include "spdk/env.h"
      14                 :            : 
      15                 :            : #include "spdk_internal/event.h"
      16                 :            : 
      17                 :            : struct rpc_reactor_set_interrupt_mode {
      18                 :            :         int32_t lcore;
      19                 :            :         bool disable_interrupt;
      20                 :            : };
      21                 :            : 
      22                 :            : static const struct spdk_json_object_decoder rpc_reactor_set_interrupt_mode_decoders[] = {
      23                 :            :         {"lcore", offsetof(struct rpc_reactor_set_interrupt_mode, lcore), spdk_json_decode_int32},
      24                 :            :         {"disable_interrupt", offsetof(struct rpc_reactor_set_interrupt_mode, disable_interrupt), spdk_json_decode_bool},
      25                 :            : };
      26                 :            : 
      27                 :            : static void
      28                 :         40 : rpc_reactor_set_interrupt_mode_cb(void *cb_arg)
      29                 :            : {
      30                 :         40 :         struct spdk_jsonrpc_request *request = cb_arg;
      31                 :            : 
      32                 :         40 :         SPDK_NOTICELOG("complete reactor switch\n");
      33                 :            : 
      34                 :         40 :         spdk_jsonrpc_send_bool_response(request, true);
      35                 :         40 : }
      36                 :            : 
      37                 :            : static void
      38                 :         40 : rpc_reactor_set_interrupt_mode(struct spdk_jsonrpc_request *request,
      39                 :            :                                const struct spdk_json_val *params)
      40                 :            : {
      41                 :         40 :         struct rpc_reactor_set_interrupt_mode req = {};
      42                 :            :         int rc;
      43                 :            : 
      44         [ -  + ]:         40 :         if (spdk_json_decode_object(params, rpc_reactor_set_interrupt_mode_decoders,
      45                 :            :                                     SPDK_COUNTOF(rpc_reactor_set_interrupt_mode_decoders),
      46                 :            :                                     &req)) {
      47                 :          0 :                 SPDK_ERRLOG("spdk_json_decode_object failed\n");
      48                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
      49                 :            :                                                  "spdk_json_decode_object failed");
      50                 :          8 :                 return;
      51                 :            :         }
      52                 :            : 
      53         [ -  + ]:         40 :         if (!spdk_interrupt_mode_is_enabled()) {
      54                 :          0 :                 SPDK_ERRLOG("Interrupt mode is not set when staring the application\n");
      55                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
      56                 :            :                                                  "spdk_json_decode_object failed");
      57                 :          0 :                 return;
      58                 :            :         }
      59                 :            : 
      60                 :            : 
      61   [ +  +  +  + ]:         40 :         SPDK_NOTICELOG("RPC Start to %s interrupt mode on reactor %d.\n",
      62                 :            :                        req.disable_interrupt ? "disable" : "enable", req.lcore);
      63         [ +  - ]:         40 :         if (req.lcore >= (int64_t)spdk_env_get_first_core() &&
      64         [ +  - ]:         40 :             req.lcore <= (int64_t)spdk_env_get_last_core()) {
      65         [ -  + ]:         40 :                 rc = spdk_reactor_set_interrupt_mode(req.lcore, !req.disable_interrupt,
      66                 :         40 :                                                      rpc_reactor_set_interrupt_mode_cb, request);
      67         [ -  + ]:         40 :                 if (rc) {
      68                 :          0 :                         goto err;
      69                 :            :                 }
      70                 :            :         } else {
      71                 :          0 :                 goto err;
      72                 :            :         }
      73                 :            : 
      74                 :         40 :         return;
      75                 :            : 
      76                 :          0 : err:
      77                 :          0 :         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
      78                 :            :                                          "Invalid parameters");
      79                 :            : }
      80                 :         15 : /* private */ SPDK_RPC_REGISTER("reactor_set_interrupt_mode", rpc_reactor_set_interrupt_mode,
      81                 :            :                                 SPDK_RPC_RUNTIME)
      82                 :            : 
      83                 :            : static void
      84                 :          0 : interrupt_tgt_usage(void)
      85                 :            : {
      86         [ #  # ]:          0 :         printf(" -E                        Set interrupt mode\n");
      87         [ #  # ]:          0 :         printf(" -S <path>                 directory where to create vhost sockets (default: pwd)\n");
      88                 :          0 : }
      89                 :            : 
      90                 :            : static int
      91                 :         15 : interrupt_tgt_parse_arg(int ch, char *arg)
      92                 :            : {
      93      [ -  +  - ]:         15 :         switch (ch) {
      94                 :          0 :         case 'S':
      95                 :          0 :                 spdk_vhost_set_socket_path(arg);
      96                 :          0 :                 break;
      97                 :         15 :         case 'E':
      98                 :         15 :                 spdk_interrupt_mode_enable();
      99                 :         15 :                 break;
     100                 :          0 :         default:
     101                 :          0 :                 return -EINVAL;
     102                 :            :         }
     103                 :         15 :         return 0;
     104                 :            : }
     105                 :            : 
     106                 :            : static void
     107                 :         15 : interrupt_tgt_started(void *arg1)
     108                 :            : {
     109                 :         15 : }
     110                 :            : 
     111                 :            : int
     112                 :         15 : main(int argc, char *argv[])
     113                 :            : {
     114                 :         15 :         struct spdk_app_opts opts = {};
     115                 :            :         int rc;
     116                 :            : 
     117                 :         15 :         spdk_app_opts_init(&opts, sizeof(opts));
     118                 :         15 :         opts.name = "interrupt_tgt";
     119                 :            : 
     120         [ -  + ]:         15 :         if ((rc = spdk_app_parse_args(argc, argv, &opts, "S:E", NULL,
     121                 :            :                                       interrupt_tgt_parse_arg, interrupt_tgt_usage)) !=
     122                 :            :             SPDK_APP_PARSE_ARGS_SUCCESS) {
     123                 :          0 :                 exit(rc);
     124                 :            :         }
     125                 :            : 
     126                 :            :         /* Blocks until the application is exiting */
     127                 :         15 :         rc = spdk_app_start(&opts, interrupt_tgt_started, NULL);
     128                 :            : 
     129                 :         15 :         spdk_app_fini();
     130                 :            : 
     131                 :         15 :         return rc;
     132                 :            : }

Generated by: LCOV version 1.14