xref: /spdk/lib/ftl/ftl_debug.c (revision 552e21cce6cccbf833ed9109827e08337377d7ce)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) Intel Corporation.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include "spdk_internal/log.h"
35 #include "spdk/ftl.h"
36 #include "ftl_debug.h"
37 
38 #if defined(DEBUG)
39 #if defined(FTL_META_DEBUG)
40 
41 static const char *ftl_band_state_str[] = {
42 	"free",
43 	"prep",
44 	"opening",
45 	"open",
46 	"full",
47 	"closing",
48 	"closed",
49 	"max"
50 };
51 
52 bool
53 ftl_band_validate_md(struct ftl_band *band, const uint64_t *lba_map)
54 {
55 	struct spdk_ftl_dev *dev = band->dev;
56 	struct ftl_md *md = &band->md;
57 	struct ftl_ppa ppa_md, ppa_l2p;
58 	size_t i, size;
59 	bool valid = true;
60 
61 	size = ftl_num_band_lbks(dev);
62 
63 	pthread_spin_lock(&md->lock);
64 	for (i = 0; i < size; ++i) {
65 		if (!spdk_bit_array_get(md->vld_map, i)) {
66 			continue;
67 		}
68 
69 		ppa_md = ftl_band_ppa_from_lbkoff(band, i);
70 		ppa_l2p = ftl_l2p_get(dev, lba_map[i]);
71 
72 		if (ppa_l2p.cached) {
73 			continue;
74 		}
75 
76 		if (ppa_l2p.ppa != ppa_md.ppa) {
77 			valid = false;
78 			break;
79 		}
80 
81 	}
82 
83 	pthread_spin_unlock(&md->lock);
84 
85 	return valid;
86 }
87 
88 void
89 ftl_dev_dump_bands(struct spdk_ftl_dev *dev)
90 {
91 	size_t i, total = 0;
92 
93 	if (!dev->bands) {
94 		return;
95 	}
96 
97 	ftl_debug("Bands validity:\n");
98 	for (i = 0; i < ftl_dev_num_bands(dev); ++i) {
99 		if (dev->bands[i].state == FTL_BAND_STATE_FREE &&
100 		    dev->bands[i].md.wr_cnt == 0) {
101 			continue;
102 		}
103 
104 		if (!dev->bands[i].num_chunks) {
105 			ftl_debug(" Band %3zu: all chunks are offline\n", i + 1);
106 			continue;
107 		}
108 
109 		total += dev->bands[i].md.num_vld;
110 		ftl_debug(" Band %3zu: %8zu / %zu \tnum_chunks: %zu \twr_cnt: %"PRIu64"\tmerit:"
111 			  "%10.3f\tstate: %s\n",
112 			  i + 1, dev->bands[i].md.num_vld,
113 			  ftl_band_user_lbks(&dev->bands[i]),
114 			  dev->bands[i].num_chunks,
115 			  dev->bands[i].md.wr_cnt,
116 			  dev->bands[i].merit,
117 			  ftl_band_state_str[dev->bands[i].state]);
118 	}
119 }
120 
121 #endif /* defined(FTL_META_DEBUG) */
122 
123 #if defined(FTL_DUMP_STATS)
124 
125 void
126 ftl_dev_dump_stats(const struct spdk_ftl_dev *dev)
127 {
128 	size_t i, total = 0;
129 	char uuid[SPDK_UUID_STRING_LEN];
130 	double waf;
131 	const char *limits[] = {
132 		[SPDK_FTL_LIMIT_CRIT]  = "crit",
133 		[SPDK_FTL_LIMIT_HIGH]  = "high",
134 		[SPDK_FTL_LIMIT_LOW]   = "low",
135 		[SPDK_FTL_LIMIT_START] = "start"
136 	};
137 
138 	if (!dev->bands) {
139 		return;
140 	}
141 
142 	/* Count the number of valid LBAs */
143 	for (i = 0; i < ftl_dev_num_bands(dev); ++i) {
144 		total += dev->bands[i].md.num_vld;
145 	}
146 
147 	waf = (double)dev->stats.write_total / (double)dev->stats.write_user;
148 
149 	spdk_uuid_fmt_lower(uuid, sizeof(uuid), &dev->uuid);
150 	ftl_debug("\n");
151 	ftl_debug("device UUID:         %s\n", uuid);
152 	ftl_debug("total valid LBAs:    %zu\n", total);
153 	ftl_debug("total writes:        %"PRIu64"\n", dev->stats.write_total);
154 	ftl_debug("user writes:         %"PRIu64"\n", dev->stats.write_user);
155 	ftl_debug("WAF:                 %.4lf\n", waf);
156 	ftl_debug("limits:\n");
157 	for (i = 0; i < SPDK_FTL_LIMIT_MAX; ++i) {
158 		ftl_debug(" %5s: %"PRIu64"\n", limits[i], dev->stats.limits[i]);
159 	}
160 }
161 
162 #endif /* defined(FTL_DUMP_STATS) */
163 #endif /* defined(DEBUG) */
164