Motr  M0
fl.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2014-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 #include "be/fl.h"
24 
25 #include "lib/types.h" /* uint64_t */
26 #include "lib/arith.h" /* m0_rnd64 */
27 
28 #include "ut/ut.h" /* M0_UT_ASSERT */
29 
30 #include "be/alloc_internal.h" /* be_alloc_chunk */
31 #include "be/ut/helper.h" /* m0_be_ut_backend */
32 
33 enum {
35  BE_UT_FL_ITER = 0x800,
36  BE_UT_FL_SEG_SIZE = 0x20000,
39 };
40 
42 
43 static uint64_t be_ut_fl_rand(uint64_t max, uint64_t *seed)
44 {
45  return m0_rnd64(seed) % max;
46 }
47 
49 {
51 }
52 
53 void m0_be_ut_fl(void)
54 {
55  static struct m0_be_ut_backend *ut_be = &be_ut_fl_backend;
56  static struct m0_be_ut_seg ut_seg;
57  static struct m0_be_tx tx;
58  struct be_alloc_chunk *chunks;
59  struct m0_be_tx_credit cred;
60  struct m0_be_fl *fl;
61  struct m0_be_seg *seg;
62  uint64_t seed = 0;
63  void *addr;
64  int *chunks_used;
65  int i;
66  int rc;
67  uint64_t index;
68 
69  M0_SET0(ut_be);
70 
73  seg = ut_seg.bus_seg;
74 
76  fl = (struct m0_be_fl *)addr;
77  addr += sizeof *fl;
78  chunks = (struct be_alloc_chunk *)addr;
79 
80  M0_BE_UT_TRANSACT(ut_be, tx, cred,
82  m0_be_fl_create(fl, tx, seg));
83 
84  M0_ALLOC_ARR(chunks_used, BE_UT_FL_CHUNK_NR);
85  M0_ASSERT(chunks_used != NULL);
86 
87  for (i = 0; i < BE_UT_FL_ITER; ++i) {
88  if ((i % BE_UT_FL_OP_PER_TX) == 0) {
89  M0_SET0(&tx);
90  m0_be_ut_tx_init(&tx, ut_be);
91 
92  cred = M0_BE_TX_CREDIT(0, 0);
93  /* XXX don't use the largest possible credit */
94  m0_be_fl_credit(fl, M0_BFL_ADD, &cred);
96  m0_be_tx_prep(&tx, &cred);
97 
98  rc = m0_be_tx_open_sync(&tx);
99  M0_ASSERT_INFO(rc == 0, "rc=%d", rc);
100  }
102  if (chunks_used[index]) {
103  m0_be_fl_del(fl, &tx, &chunks[index]);
104  chunks_used[index] = false;
105  } else {
107  m0_be_fl_add(fl, &tx, &chunks[index]);
108  chunks_used[index] = true;
109  }
110  if (i + 1 == BE_UT_FL_ITER ||
111  ((i + 1) % BE_UT_FL_OP_PER_TX) == 0) {
112  m0_be_tx_close_sync(&tx);
113  m0_be_tx_fini(&tx);
114  }
115  }
116 
117  for (i = 0; i < BE_UT_FL_CHUNK_NR; ++i) {
118  if (chunks_used[i]) {
119  M0_BE_UT_TRANSACT(ut_be, tx, cred,
121  m0_be_fl_del(fl, tx, &chunks[i]));
122  }
123  }
124 
125  m0_free(chunks_used);
126 
127  M0_BE_UT_TRANSACT(ut_be, tx, cred,
129  m0_be_fl_destroy(fl, tx));
130 
133 }
134 
135 /*
136  * Local variables:
137  * c-indentation-style: "K&R"
138  * c-basic-offset: 8
139  * tab-width: 8
140  * fill-column: 80
141  * scroll-step: 1
142  * End:
143  */
144 /*
145  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
146  */
Definition: fl.h:54
void * bs_addr
Definition: seg.h:71
void m0_be_ut_seg_fini(struct m0_be_ut_seg *ut_seg)
Definition: stubs.c:267
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
M0_INTERNAL void m0_be_fl_destroy(struct m0_be_fl *fl, struct m0_be_tx *tx)
Definition: fl.c:120
static m0_bcount_t be_ut_fl_rand_size(uint64_t *seed)
Definition: fl.c:48
#define NULL
Definition: misc.h:38
m0_bcount_t bac_size
struct m0_be_seg * bus_seg
Definition: helper.h:119
M0_INTERNAL void m0_be_tx_fini(struct m0_be_tx *tx)
Definition: stubs.c:163
M0_INTERNAL void m0_be_tx_prep(struct m0_be_tx *tx, const struct m0_be_tx_credit *credit)
Definition: stubs.c:175
struct m0_be_ut_seg ut_seg
Definition: ad.c:73
void m0_be_ut_seg_init(struct m0_be_ut_seg *ut_seg, struct m0_be_ut_backend *ut_be, m0_bcount_t size)
Definition: stubs.c:256
uint64_t m0_bcount_t
Definition: types.h:77
#define M0_SET0(obj)
Definition: misc.h:64
Definition: fl.h:67
M0_INTERNAL void m0_be_fl_create(struct m0_be_fl *fl, struct m0_be_tx *tx, struct m0_be_seg *seg)
Definition: fl.c:110
#define M0_BE_TX_CREDIT(nr, size)
Definition: tx_credit.h:94
static char * addr
Definition: node_k.c:37
M0_INTERNAL m0_bcount_t m0_be_seg_reserved(const struct m0_be_seg *seg)
Definition: seg.c:430
int i
Definition: dir.c:1033
struct m0_be_ut_backend ut_be
Definition: ad.c:72
M0_INTERNAL void m0_be_fl_credit(struct m0_be_fl *fl, enum m0_be_fl_op fl_op, struct m0_be_tx_credit *accum)
Definition: fl.c:218
Definition: fl.h:41
#define M0_ASSERT(cond)
Allocator chunk.
M0_INTERNAL void m0_be_tx_credit_mul(struct m0_be_tx_credit *c, m0_bcount_t k)
Definition: tx_credit.c:73
static long long max(long long a, long long b)
Definition: crate.c:196
M0_INTERNAL int m0_be_tx_open_sync(struct m0_be_tx *tx)
Definition: stubs.c:199
void m0_be_ut_backend_init(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:238
Definition: xcode.h:73
static struct m0_be_ut_backend be_ut_fl_backend
Definition: fl.c:41
Definition: seg.h:66
void m0_be_ut_fl(void)
Definition: fl.c:53
Definition: fl.h:53
M0_INTERNAL uint64_t m0_rnd64(uint64_t *seed)
Definition: misc.c:100
#define M0_BE_UT_TRANSACT(__ut_be, __tx, __cred, __credit_func, __action_func)
Definition: helper.h:159
M0_INTERNAL void m0_be_fl_add(struct m0_be_fl *fl, struct m0_be_tx *tx, struct be_alloc_chunk *chunk)
Definition: fl.c:151
void m0_be_ut_tx_init(struct m0_be_tx *tx, struct m0_be_ut_backend *ut_be)
Definition: stubs.c:286
void m0_be_ut_backend_fini(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:242
static struct m0_be_seg * seg
Definition: btree.c:40
#define M0_ASSERT_INFO(cond, fmt,...)
M0_INTERNAL void m0_be_fl_del(struct m0_be_fl *fl, struct m0_be_tx *tx, struct be_alloc_chunk *chunk)
Definition: fl.c:165
void m0_free(void *data)
Definition: memory.c:146
static uint64_t be_ut_fl_rand(uint64_t max, uint64_t *seed)
Definition: fl.c:43
int32_t rc
Definition: trigger_fop.h:47
M0_INTERNAL void m0_be_tx_close_sync(struct m0_be_tx *tx)
Definition: stubs.c:205
Definition: tx.h:280