Motr  M0
pd.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2015-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 
30 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_UT
31 #include "lib/trace.h"
32 
33 #include "be/pd.h"
34 
35 #include "lib/memory.h" /* M0_ALLOC_PTR */
36 #include "lib/ext.h" /* m0_ext */
37 #include "lib/types.h" /* bool */
38 #include "lib/atomic.h" /* m0_atomic64 */
39 
40 #include "be/op.h" /* M0_BE_OP_SYNC */
41 
42 #include "ut/ut.h" /* M0_UT_ASSERT */
43 #include "ut/stob.h" /* m0_ut_stob_linux_get */
44 #include "ut/threads.h" /* M0_UT_THREADS_DEFINE */
45 
46 enum {
52 };
53 
55  bool bput_read;
59  struct m0_be_pd *bput_pd;
61  struct m0_stob *bput_stob;
62 };
63 
64 static void be_ut_pd_usecase_thread(void *param)
65 {
67  struct m0_be_pd_io **pdio;
68  struct m0_be_op *op;
69  struct m0_be_pd *pd = test->bput_pd;
70  struct m0_be_io *bio;
72  m0_bindex_t pos;
73  char *mem;
74  int iter;
75  int i;
76  int j;
77 
78  M0_ALLOC_ARR(pdio, test->bput_pd_io_nr);
79  M0_UT_ASSERT(pdio != NULL);
80  M0_ALLOC_ARR(op, test->bput_pd_io_nr);
81  M0_UT_ASSERT(op != NULL);
82  M0_ALLOC_ARR(mem, test->bput_pd_io_nr * test->bput_pd_reg_nr * 2);
83  for (iter = 0; iter < test->bput_iter_nr; ++iter) {
84  for (i = 0; i < test->bput_pd_io_nr; ++i) {
85  M0_SET0(&op[i]);
86  m0_be_op_init(&op[i]);
87  M0_BE_OP_SYNC(op1, m0_be_pd_io_get(pd, &pdio[i], &op1));
88  }
89  for (i = 0; i < test->bput_pd_io_nr; ++i) {
90  bio = m0_be_pd_io_be_io(pdio[i]);
91  for (j = 0; j < test->bput_pd_reg_nr; ++j) {
92  offset = (i * test->bput_pd_reg_nr + j) * 2;
93  m0_be_io_add(bio, test->bput_stob,
94  &mem[offset], offset, 1);
95  }
96  m0_be_io_configure(bio, test->bput_read ?
98  if (!test->bput_read) {
99  pos = m0_atomic64_add_return(test->bput_pos,
100  1) - 1;
101  }
102  m0_be_pd_io_add(pd, pdio[i], test->bput_read ?
103  NULL : &M0_EXT(pos, pos + 1), &op[i]);
104  }
105  for (i = 0; i < test->bput_pd_io_nr; ++i)
106  m0_be_op_wait(&op[i]);
107  for (i = 0; i < test->bput_pd_io_nr; ++i) {
108  m0_be_pd_io_put(pd, pdio[i]);
109  m0_be_op_fini(&op[i]);
110  }
111  }
112  m0_free(mem);
113  m0_free(op);
114  m0_free(pdio);
115 }
116 
118 
120 {
121  struct m0_be_pd_cfg pd_cfg = {
122  .bpdc_sched = {
124  },
125  .bpdc_seg_io_nr = BE_UT_PD_USECASE_PD_IO_NR * 2 *
127  .bpdc_seg_io_pending_max = 0,
128  .bpdc_io_credit = {
129  .bic_reg_nr = BE_UT_PD_USECASE_REG_NR,
130  .bic_reg_size = BE_UT_PD_USECASE_REG_NR,
131  .bic_part_nr = 1,
132  },
133  };
135  struct m0_atomic64 pos;
136  struct m0_be_pd *pd;
137  struct m0_stob *stob;
138  uint32_t i;
139  int rc;
140 
142  M0_ALLOC_PTR(pd);
143  M0_UT_ASSERT(pd != NULL);
145  M0_UT_ASSERT(tests != NULL);
146  for (i = 0; i < BE_UT_PD_USECASE_THREAD_NR * 2; ++i) {
147  tests[i] = (struct be_ut_pd_usecase_test){
148  .bput_read = (i % 2) == 0,
152  .bput_pd = pd,
153  .bput_pos = &pos,
154  .bput_stob = stob,
155  };
156  }
157  rc = m0_be_pd_init(pd, &pd_cfg);
158  M0_UT_ASSERT(rc == 0);
160 
161  M0_UT_THREADS_START(be_ut_pd_usecase, BE_UT_PD_USECASE_THREAD_NR * 2,
162  tests);
163  M0_UT_THREADS_STOP(be_ut_pd_usecase);
164 
165  m0_be_pd_fini(pd);
166  m0_free(tests);
167  m0_free(pd);
168  m0_ut_stob_put(stob, true);
169 }
170 
171 
172 #undef M0_TRACE_SUBSYSTEM
173 
176 /*
177  * Local variables:
178  * c-indentation-style: "K&R"
179  * c-basic-offset: 8
180  * tab-width: 8
181  * fill-column: 80
182  * scroll-step: 1
183  * End:
184  */
185 /*
186  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
187  */
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
m0_bcount_t bisc_pos_start
Definition: io_sched.h:44
bool bput_read
Definition: pd.c:55
M0_INTERNAL int m0_be_pd_init(struct m0_be_pd *pd, struct m0_be_pd_cfg *pd_cfg)
Definition: pd.c:86
#define NULL
Definition: misc.h:38
Definition: io.h:230
static char * tests
Definition: st_kmain.c:52
#define M0_BE_OP_SYNC(op_obj, action)
Definition: op.h:190
M0_INTERNAL void m0_be_pd_io_get(struct m0_be_pd *pd, struct m0_be_pd_io **pdio, struct m0_be_op *op)
Definition: pd.c:169
uint64_t m0_bindex_t
Definition: types.h:80
M0_INTERNAL struct m0_be_io * m0_be_pd_io_be_io(struct m0_be_pd_io *pdio)
Definition: pd.c:185
#define M0_SET0(obj)
Definition: misc.h:64
#define M0_EXT(start, end)
Definition: ext.h:55
void m0_be_ut_pd_usecase(void)
Definition: pd.c:119
struct m0_stob * bput_stob
Definition: pd.c:61
op
Definition: libdemo.c:64
M0_INTERNAL void m0_be_io_configure(struct m0_be_io *bio, enum m0_stob_io_opcode opcode)
Definition: io.c:516
int bput_iter_nr
Definition: pd.c:56
int i
Definition: dir.c:1033
M0_INTERNAL struct m0_stob * m0_ut_stob_linux_get(void)
Definition: stob.c:169
M0_INTERNAL void m0_be_pd_io_add(struct m0_be_pd *pd, struct m0_be_pd_io *pdio, struct m0_ext *ext, struct m0_be_op *op)
Definition: pd.c:149
Definition: stob.h:163
static struct m0_stob * stob
Definition: storage.c:39
struct m0_be_io_sched_cfg bpdc_sched
Definition: pd.h:58
static void be_ut_pd_usecase_thread(void *param)
Definition: pd.c:64
static m0_bindex_t offset
Definition: dump.c:173
M0_INTERNAL void m0_ut_stob_put(struct m0_stob *stob, bool destroy)
Definition: stob.c:185
struct m0_atomic64 * bput_pos
Definition: pd.c:60
struct m0_be_pd * bput_pd
Definition: pd.c:59
M0_UT_THREADS_DEFINE(be_ut_pd_usecase, &be_ut_pd_usecase_thread)
M0_INTERNAL void m0_be_pd_io_put(struct m0_be_pd *pd, struct m0_be_pd_io *pdio)
Definition: pd.c:176
int bput_pd_io_nr
Definition: pd.c:57
M0_INTERNAL void m0_be_pd_fini(struct m0_be_pd *pd)
Definition: pd.c:127
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
Definition: list.c:42
Definition: pd.h:64
M0_INTERNAL void m0_be_op_fini(struct m0_be_op *op)
Definition: stubs.c:92
#define M0_UT_THREADS_STOP(name)
Definition: threads.h:55
Definition: io.h:87
#define M0_UT_THREADS_START(name, thread_nr, param_array)
Definition: threads.h:51
Definition: io.h:229
Definition: pd.c:49
Definition: op.h:74
M0_INTERNAL void m0_be_op_init(struct m0_be_op *op)
Definition: stubs.c:87
void m0_free(void *data)
Definition: memory.c:146
M0_INTERNAL void m0_be_io_add(struct m0_be_io *bio, struct m0_stob *stob, void *ptr_user, m0_bindex_t offset_stob, m0_bcount_t size)
Definition: io.c:280
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
static int64_t m0_atomic64_add_return(struct m0_atomic64 *a, int64_t d)
M0_INTERNAL void m0_be_op_wait(struct m0_be_op *op)
Definition: stubs.c:96
static void m0_atomic64_set(struct m0_atomic64 *a, int64_t num)
int bput_pd_reg_nr
Definition: pd.c:58