LCOV - code coverage report
Current view: top level - lib/ftl - ftl_trace.c (source / functions) Hit Total Coverage
Test: ut_cov_unit.info Lines: 0 125 0.0 %
Date: 2024-12-09 07:19:12 Functions: 0 10 0.0 %

          Line data    Source code
       1             : /*   SPDX-License-Identifier: BSD-3-Clause
       2             :  *   Copyright (C) 2018 Intel Corporation.
       3             :  *   All rights reserved.
       4             :  */
       5             : 
       6             : #include "spdk/trace.h"
       7             : #include "spdk_internal/trace_defs.h"
       8             : 
       9             : #include "ftl_core.h"
      10             : #include "ftl_trace.h"
      11             : #include "ftl_io.h"
      12             : #include "ftl_band.h"
      13             : 
      14             : #if defined(DEBUG)
      15             : 
      16             : enum ftl_trace_source {
      17             :         FTL_TRACE_SOURCE_INTERNAL,
      18             :         FTL_TRACE_SOURCE_USER,
      19             :         FTL_TRACE_SOURCE_MAX,
      20             : };
      21             : 
      22             : #define FTL_TPOINT_ID(id, src) SPDK_TPOINT_ID(TRACE_GROUP_FTL, (((id) << 1) | (!!(src))))
      23             : 
      24             : #define FTL_TRACE_BAND_RELOC(src)               FTL_TPOINT_ID(0, src)
      25             : #define FTL_TRACE_BAND_WRITE(src)               FTL_TPOINT_ID(1, src)
      26             : #define FTL_TRACE_LIMITS(src)                   FTL_TPOINT_ID(2, src)
      27             : #define FTL_TRACE_WBUF_POP(src)                 FTL_TPOINT_ID(3, src)
      28             : 
      29             : #define FTL_TRACE_READ_SCHEDULE(src)            FTL_TPOINT_ID(4, src)
      30             : #define FTL_TRACE_READ_SUBMISSION(src)          FTL_TPOINT_ID(5, src)
      31             : #define FTL_TRACE_READ_COMPLETION_INVALID(src)  FTL_TPOINT_ID(6, src)
      32             : #define FTL_TRACE_READ_COMPLETION_CACHE(src)    FTL_TPOINT_ID(7, src)
      33             : #define FTL_TRACE_READ_COMPLETION_DISK(src)     FTL_TPOINT_ID(8, src)
      34             : 
      35             : #define FTL_TRACE_MD_READ_SCHEDULE(src)         FTL_TPOINT_ID(9,  src)
      36             : #define FTL_TRACE_MD_READ_SUBMISSION(src)       FTL_TPOINT_ID(10, src)
      37             : #define FTL_TRACE_MD_READ_COMPLETION(src)       FTL_TPOINT_ID(11, src)
      38             : 
      39             : #define FTL_TRACE_WRITE_SCHEDULE(src)           FTL_TPOINT_ID(12, src)
      40             : #define FTL_TRACE_WRITE_WBUF_FILL(src)          FTL_TPOINT_ID(13, src)
      41             : #define FTL_TRACE_WRITE_SUBMISSION(src)         FTL_TPOINT_ID(14, src)
      42             : #define FTL_TRACE_WRITE_COMPLETION(src)         FTL_TPOINT_ID(15, src)
      43             : 
      44             : #define FTL_TRACE_MD_WRITE_SCHEDULE(src)        FTL_TPOINT_ID(16, src)
      45             : #define FTL_TRACE_MD_WRITE_SUBMISSION(src)      FTL_TPOINT_ID(17, src)
      46             : #define FTL_TRACE_MD_WRITE_COMPLETION(src)      FTL_TPOINT_ID(18, src)
      47             : 
      48             : #define FTL_TRACE_TRIM_SCHEDULE(src)            FTL_TPOINT_ID(19, src)
      49             : #define FTL_TRACE_TRIM_SUBMISSION(src)          FTL_TPOINT_ID(20, src)
      50             : #define FTL_TRACE_TRIM_COMPLETION(src)          FTL_TPOINT_ID(21, src)
      51             : 
      52             : static void
      53           0 : ftl_trace(void)
      54             : {
      55           0 :         const char source[] = { 'i', 'u' };
      56             :         char descbuf[128];
      57             :         int i;
      58             : 
      59           0 :         spdk_trace_register_owner_type(OWNER_TYPE_FTL, 'f');
      60             : 
      61           0 :         for (i = 0; i < FTL_TRACE_SOURCE_MAX; ++i) {
      62           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "band_reloc");
      63           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_BAND_RELOC(i), OWNER_TYPE_FTL, OBJECT_NONE, 0, 0,
      64             :                                                 "band: ");
      65           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "band_write");
      66           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_BAND_WRITE(i), OWNER_TYPE_FTL, OBJECT_NONE, 0, 0,
      67             :                                                 "band: ");
      68           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "limits");
      69           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_LIMITS(i), OWNER_TYPE_FTL, OBJECT_NONE, 0, 0,
      70             :                                                 "limits: ");
      71           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "rwb_pop");
      72           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_WBUF_POP(i), OWNER_TYPE_FTL, OBJECT_NONE, 0, 0,
      73             :                                                 "lba: ");
      74             : 
      75           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "md_read_sched");
      76           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_MD_READ_SCHEDULE(i), OWNER_TYPE_FTL,
      77             :                                                 OBJECT_NONE, 0, 0, "addr: ");
      78           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "md_read_submit");
      79           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_MD_READ_SUBMISSION(i), OWNER_TYPE_FTL,
      80             :                                                 OBJECT_NONE, 0, 0, "addr: ");
      81           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "md_read_cmpl");
      82           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_MD_READ_COMPLETION(i), OWNER_TYPE_FTL,
      83             :                                                 OBJECT_NONE, 0, 0, "lba: ");
      84             : 
      85           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "md_write_sched");
      86           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_MD_WRITE_SCHEDULE(i), OWNER_TYPE_FTL,
      87             :                                                 OBJECT_NONE, 0, 0, "addr: ");
      88           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "md_write_submit");
      89           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_MD_WRITE_SUBMISSION(i), OWNER_TYPE_FTL,
      90             :                                                 OBJECT_NONE, 0, 0, "addr: ");
      91           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "md_write_cmpl");
      92           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_MD_WRITE_COMPLETION(i), OWNER_TYPE_FTL,
      93             :                                                 OBJECT_NONE, 0, 0, "lba: ");
      94             : 
      95           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "read_sched");
      96           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_READ_SCHEDULE(i), OWNER_TYPE_FTL,
      97             :                                                 OBJECT_NONE, 0, 0, "lba: ");
      98           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "read_submit");
      99           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_READ_SUBMISSION(i), OWNER_TYPE_FTL,
     100             :                                                 OBJECT_NONE, 0, 0, "addr: ");
     101           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "read_cmpl_invld");
     102           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_READ_COMPLETION_INVALID(i), OWNER_TYPE_FTL,
     103             :                                                 OBJECT_NONE, 0, 0, "lba: ");
     104           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "read_cmpl_cache");
     105           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_READ_COMPLETION_CACHE(i), OWNER_TYPE_FTL,
     106             :                                                 OBJECT_NONE, 0, 0, "lba: ");
     107           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "read_cmpl_ssd");
     108           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_READ_COMPLETION_DISK(i), OWNER_TYPE_FTL,
     109             :                                                 OBJECT_NONE, 0, 0, "lba: ");
     110             : 
     111           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "write_sched");
     112           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_WRITE_SCHEDULE(i), OWNER_TYPE_FTL,
     113             :                                                 OBJECT_NONE, 0, 0, "lba: ");
     114           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "rwb_fill");
     115           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_WRITE_WBUF_FILL(i), OWNER_TYPE_FTL,
     116             :                                                 OBJECT_NONE, 0, 0, "lba: ");
     117           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "write_submit");
     118           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_WRITE_SUBMISSION(i), OWNER_TYPE_FTL,
     119             :                                                 OBJECT_NONE, 0, 0, "addr: ");
     120           0 :                 snprintf(descbuf, sizeof(descbuf), "%c %s", source[i], "write_cmpl");
     121           0 :                 spdk_trace_register_description(descbuf, FTL_TRACE_WRITE_COMPLETION(i), OWNER_TYPE_FTL,
     122             :                                                 OBJECT_NONE, 0, 0, "lba: ");
     123             :         }
     124           0 : }
     125           0 : SPDK_TRACE_REGISTER_FN(ftl_trace, "ftl", TRACE_GROUP_FTL)
     126             : 
     127             : static uint64_t
     128           0 : ftl_trace_next_id(struct ftl_trace *trace)
     129             : {
     130           0 :         assert(trace->id != FTL_TRACE_INVALID_ID);
     131           0 :         return __atomic_fetch_add(&trace->id, 1, __ATOMIC_SEQ_CST);
     132             : }
     133             : 
     134             : void
     135           0 : ftl_trace_reloc_band(struct spdk_ftl_dev *dev, const struct ftl_band *band)
     136             : {
     137           0 :         struct ftl_trace *trace = &dev->trace;
     138             : 
     139           0 :         spdk_trace_record(FTL_TRACE_BAND_RELOC(FTL_TRACE_SOURCE_INTERNAL), ftl_trace_next_id(trace), 0,
     140             :                           band->p2l_map.num_valid, band->id);
     141           0 : }
     142             : 
     143             : void
     144           0 : ftl_trace_write_band(struct spdk_ftl_dev *dev, const struct ftl_band *band)
     145             : {
     146           0 :         struct ftl_trace *trace = &dev->trace;
     147             : 
     148           0 :         spdk_trace_record(FTL_TRACE_BAND_WRITE(FTL_TRACE_SOURCE_INTERNAL), ftl_trace_next_id(trace), 0, 0,
     149             :                           band->id);
     150           0 : }
     151             : 
     152             : void
     153           0 : ftl_trace_lba_io_init(struct spdk_ftl_dev *dev, const struct ftl_io *io)
     154             : {
     155           0 :         uint16_t tpoint_id = 0, source;
     156             : 
     157           0 :         assert(io->trace != FTL_TRACE_INVALID_ID);
     158           0 :         source = FTL_TRACE_SOURCE_USER;
     159             : 
     160           0 :         switch (io->type) {
     161           0 :         case FTL_IO_READ:
     162           0 :                 tpoint_id = FTL_TRACE_READ_SCHEDULE(source);
     163           0 :                 break;
     164           0 :         case FTL_IO_WRITE:
     165           0 :                 tpoint_id = FTL_TRACE_WRITE_SCHEDULE(source);
     166           0 :                 break;
     167           0 :         case FTL_IO_TRIM:
     168           0 :                 tpoint_id = FTL_TRACE_TRIM_SCHEDULE(source);
     169           0 :                 break;
     170           0 :         default:
     171           0 :                 assert(0);
     172             :         }
     173             : 
     174           0 :         spdk_trace_record(tpoint_id, io->trace, io->num_blocks, 0, ftl_io_get_lba(io, 0));
     175           0 : }
     176             : 
     177             : void
     178           0 : ftl_trace_completion(struct spdk_ftl_dev *dev, const struct ftl_io *io,
     179             :                      enum ftl_trace_completion completion)
     180             : {
     181           0 :         uint16_t tpoint_id = 0, source;
     182             : 
     183           0 :         assert(io->trace != FTL_TRACE_INVALID_ID);
     184           0 :         source = FTL_TRACE_SOURCE_USER;
     185             : 
     186           0 :         switch (io->type) {
     187           0 :         case FTL_IO_READ:
     188           0 :                 switch (completion) {
     189           0 :                 case FTL_TRACE_COMPLETION_INVALID:
     190           0 :                         tpoint_id = FTL_TRACE_READ_COMPLETION_INVALID(source);
     191           0 :                         break;
     192           0 :                 case FTL_TRACE_COMPLETION_CACHE:
     193           0 :                         tpoint_id = FTL_TRACE_READ_COMPLETION_CACHE(source);
     194           0 :                         break;
     195           0 :                 case FTL_TRACE_COMPLETION_DISK:
     196           0 :                         tpoint_id = FTL_TRACE_READ_COMPLETION_DISK(source);
     197           0 :                         break;
     198             :                 }
     199           0 :                 break;
     200           0 :         case FTL_IO_WRITE:
     201           0 :                 tpoint_id = FTL_TRACE_WRITE_COMPLETION(source);
     202           0 :                 break;
     203           0 :         case FTL_IO_TRIM:
     204           0 :                 tpoint_id = FTL_TRACE_TRIM_COMPLETION(source);
     205           0 :                 break;
     206           0 :         default:
     207           0 :                 assert(0);
     208             :         }
     209             : 
     210           0 :         spdk_trace_record(tpoint_id, io->trace, 0, 0, ftl_io_get_lba(io, io->pos - 1));
     211           0 : }
     212             : 
     213             : void
     214           0 : ftl_trace_submission(struct spdk_ftl_dev *dev, const struct ftl_io *io, ftl_addr addr,
     215             :                      size_t addr_cnt)
     216             : {
     217           0 :         uint16_t tpoint_id = 0, source;
     218             : 
     219           0 :         assert(io->trace != FTL_TRACE_INVALID_ID);
     220           0 :         source = FTL_TRACE_SOURCE_USER;
     221             : 
     222           0 :         switch (io->type) {
     223           0 :         case FTL_IO_READ:
     224           0 :                 tpoint_id = FTL_TRACE_READ_SUBMISSION(source);
     225           0 :                 break;
     226           0 :         case FTL_IO_WRITE:
     227           0 :                 tpoint_id = FTL_TRACE_WRITE_SUBMISSION(source);
     228           0 :                 break;
     229           0 :         case FTL_IO_TRIM:
     230           0 :                 tpoint_id = FTL_TRACE_TRIM_SUBMISSION(source);
     231           0 :                 break;
     232           0 :         default:
     233           0 :                 assert(0);
     234             :         }
     235             : 
     236           0 :         spdk_trace_record(tpoint_id, io->trace, addr_cnt, 0, addr);
     237           0 : }
     238             : 
     239             : void
     240           0 : ftl_trace_limits(struct spdk_ftl_dev *dev, int limit, size_t num_free)
     241             : {
     242           0 :         struct ftl_trace *trace = &dev->trace;
     243             : 
     244           0 :         spdk_trace_record(FTL_TRACE_LIMITS(FTL_TRACE_SOURCE_INTERNAL), ftl_trace_next_id(trace), num_free,
     245             :                           limit, 0);
     246           0 : }
     247             : 
     248             : uint64_t
     249           0 : ftl_trace_alloc_id(struct spdk_ftl_dev *dev)
     250             : {
     251           0 :         struct ftl_trace *trace = &dev->trace;
     252             : 
     253           0 :         return ftl_trace_next_id(trace);
     254             : }
     255             : 
     256             : #endif /* defined(DEBUG) */

Generated by: LCOV version 1.15