]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
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 | #ifndef FTL_RWB_H | |
35 | #define FTL_RWB_H | |
36 | ||
37 | #include "spdk/stdinc.h" | |
38 | #include "spdk/queue.h" | |
39 | ||
40 | #include "ftl_io.h" | |
41 | #include "ftl_ppa.h" | |
42 | #include "ftl_trace.h" | |
43 | ||
44 | struct ftl_rwb; | |
45 | struct spdk_ftl_conf; | |
46 | struct ftl_rwb_batch; | |
47 | ||
48 | enum ftl_rwb_entry_type { | |
49 | FTL_RWB_TYPE_INTERNAL, | |
50 | FTL_RWB_TYPE_USER, | |
51 | FTL_RWB_TYPE_MAX | |
52 | }; | |
53 | ||
54 | /* Write buffer entry */ | |
55 | struct ftl_rwb_entry { | |
56 | /* Owner rwb */ | |
57 | struct ftl_rwb *rwb; | |
58 | ||
59 | /* Batch containing the entry */ | |
60 | struct ftl_rwb_batch *batch; | |
61 | ||
62 | /* Logical address */ | |
63 | uint64_t lba; | |
64 | ||
65 | /* Physical address */ | |
66 | struct ftl_ppa ppa; | |
67 | ||
68 | /* Position within the rwb's buffer */ | |
69 | unsigned int pos; | |
70 | ||
71 | /* Data pointer */ | |
72 | void *data; | |
73 | ||
74 | /* Metadata pointer */ | |
75 | void *md; | |
76 | ||
77 | /* Data/state lock */ | |
78 | pthread_spinlock_t lock; | |
79 | ||
80 | /* Flags */ | |
81 | unsigned int flags; | |
82 | ||
83 | /* Indicates whether the entry is part of cache and is assigned a PPA */ | |
84 | bool valid; | |
85 | ||
86 | /* Trace group id */ | |
87 | uint64_t trace; | |
88 | ||
89 | /* Batch list entry */ | |
90 | LIST_ENTRY(ftl_rwb_entry) list_entry; | |
91 | }; | |
92 | ||
93 | struct ftl_rwb *ftl_rwb_init(const struct spdk_ftl_conf *conf, size_t xfer_size, | |
94 | size_t md_size, size_t num_punits); | |
95 | size_t ftl_rwb_get_active_batches(const struct ftl_rwb *rwb); | |
96 | void ftl_rwb_free(struct ftl_rwb *rwb); | |
97 | void ftl_rwb_batch_release(struct ftl_rwb_batch *batch); | |
98 | void ftl_rwb_push(struct ftl_rwb_entry *entry); | |
99 | size_t ftl_rwb_entry_cnt(const struct ftl_rwb *rwb); | |
100 | void ftl_rwb_set_limits(struct ftl_rwb *rwb, const size_t limit[FTL_RWB_TYPE_MAX]); | |
101 | void ftl_rwb_get_limits(struct ftl_rwb *rwb, size_t limit[FTL_RWB_TYPE_MAX]); | |
102 | size_t ftl_rwb_num_acquired(struct ftl_rwb *rwb, enum ftl_rwb_entry_type type); | |
103 | size_t ftl_rwb_num_batches(const struct ftl_rwb *rwb); | |
104 | size_t ftl_rwb_size(const struct ftl_rwb *rwb); | |
105 | struct ftl_rwb_entry *ftl_rwb_acquire(struct ftl_rwb *rwb, enum ftl_rwb_entry_type type); | |
106 | struct ftl_rwb_batch *ftl_rwb_pop(struct ftl_rwb *rwb); | |
107 | struct ftl_rwb_batch *ftl_rwb_first_batch(struct ftl_rwb *rwb); | |
108 | struct ftl_rwb_batch *ftl_rwb_next_batch(struct ftl_rwb_batch *batch); | |
109 | int ftl_rwb_batch_empty(struct ftl_rwb_batch *batch); | |
110 | struct ftl_rwb_entry *ftl_rwb_entry_from_offset(struct ftl_rwb *rwb, size_t offset); | |
111 | size_t ftl_rwb_batch_get_offset(const struct ftl_rwb_batch *batch); | |
112 | void ftl_rwb_batch_revert(struct ftl_rwb_batch *batch); | |
113 | struct ftl_rwb_entry *ftl_rwb_batch_first_entry(struct ftl_rwb_batch *batch); | |
114 | void *ftl_rwb_batch_get_data(struct ftl_rwb_batch *batch); | |
115 | void *ftl_rwb_batch_get_md(struct ftl_rwb_batch *batch); | |
116 | void ftl_rwb_disable_interleaving(struct ftl_rwb *rwb); | |
117 | ||
118 | static inline void | |
119 | _ftl_rwb_entry_set_valid(struct ftl_rwb_entry *entry, bool valid) | |
120 | { | |
121 | __atomic_store_n(&entry->valid, valid, __ATOMIC_SEQ_CST); | |
122 | } | |
123 | ||
124 | static inline void | |
125 | ftl_rwb_entry_set_valid(struct ftl_rwb_entry *entry) | |
126 | { | |
127 | _ftl_rwb_entry_set_valid(entry, true); | |
128 | } | |
129 | ||
130 | static inline void | |
131 | ftl_rwb_entry_invalidate(struct ftl_rwb_entry *entry) | |
132 | { | |
133 | _ftl_rwb_entry_set_valid(entry, false); | |
134 | } | |
135 | ||
136 | static inline int | |
137 | ftl_rwb_entry_valid(struct ftl_rwb_entry *entry) | |
138 | { | |
139 | return __atomic_load_n(&entry->valid, __ATOMIC_SEQ_CST); | |
140 | } | |
141 | ||
142 | static inline enum ftl_rwb_entry_type | |
143 | ftl_rwb_type_from_flags(int flags) { | |
144 | return (flags & FTL_IO_INTERNAL) ? FTL_RWB_TYPE_INTERNAL : FTL_RWB_TYPE_USER; | |
145 | } | |
146 | ||
147 | static inline enum ftl_rwb_entry_type | |
148 | ftl_rwb_entry_type(const struct ftl_rwb_entry *entry) { | |
149 | return ftl_rwb_type_from_flags(entry->flags); | |
150 | } | |
151 | ||
152 | static inline int | |
153 | ftl_rwb_entry_internal(const struct ftl_rwb_entry *entry) | |
154 | { | |
155 | return ftl_rwb_entry_type(entry) == FTL_RWB_TYPE_INTERNAL; | |
156 | } | |
157 | ||
158 | #define ftl_rwb_foreach(entry, batch) \ | |
159 | for (entry = ftl_rwb_batch_first_entry(batch); \ | |
160 | entry; entry = LIST_NEXT(entry, list_entry)) | |
161 | ||
162 | #define ftl_rwb_foreach_batch(batch, rwb) \ | |
163 | for (batch = ftl_rwb_first_batch(rwb); batch; \ | |
164 | batch = ftl_rwb_next_batch(batch)) | |
165 | ||
166 | #endif /* FTL_RWB_H */ |