Motr  M0
chs_test.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 
22 #include <stdio.h>
23 #include <math.h> /* sqrt */
24 
25 #include "motr/init.h"
26 
27 #include "desim/sim.h"
28 #include "desim/storage.h"
29 #include "desim/chs.h"
30 #include "desim/net.h"
31 #include "desim/client.h"
32 #include "desim/elevator.h"
33 
39 #if 0
40 /*
41  * Seagate Cheetah 15K.7 SAS ST3450857SS
42  *
43  * http://www.seagate.com/staticfiles/support/disc/manuals/enterprise/cheetah/15K.7/100516226a.pdf
44  *
45  * Heads: 3*2
46  * Cylinders: 107500
47  * Sectors per track: 680--2040 (680 + (i << 7)/10000)
48  * Rotational speed: 250 revolutions/sec
49  *
50  * Avg rotational latency: 2ms
51  *
52  * Seek: read write
53  * average: 3.4 3.9
54  * track-to-track: 0.2 0.44
55  * full stroke: 6.6 7.4
56  */
57 static struct chs_conf cheetah = {
58  .cc_storage = {
59  .sc_sector_size = 512,
60  },
61  .cc_heads = 3*2,
62  .cc_cylinders = 107500,
63  .cc_track_skew = 0,
64  .cc_cylinder_skew = 0,
65  .cc_sectors_min = 680,
66  .cc_sectors_max = 2040,
67 
68  .cc_seek_avg = 3400000,
69  .cc_seek_track_to_track = 200000,
70  .cc_seek_full_stroke = 6600000,
71  .cc_write_settle = 220000,
72  .cc_head_switch = 0, /* unknown */
73  .cc_command_latency = 0, /* unknown */
74 
75  .cc_rps = 250
76 };
77 #endif
78 
79 static struct chs_conf ST31000640SS = { /* Barracuda ES.2 */
80  .cc_storage = {
81  .sc_sector_size = 512,
82  },
83  .cc_heads = 4*2, /* sginfo */
84  .cc_cylinders = 153352, /* sginfo */
85  .cc_track_skew = 160, /* sginfo */
86  .cc_cylinder_skew = 76, /* sginfo */
87  .cc_sectors_min = 1220, /* sginfo */
88  .cc_sectors_max = 1800, /* guess */
89  .cc_cyl_in_zone = 48080, /* sginfo */
90 
91  .cc_seek_avg = 8500000, /* data sheet */
92  .cc_seek_track_to_track = 800000, /* data sheet */
93  .cc_seek_full_stroke = 16000000, /* guess */
94  .cc_write_settle = 500000, /* guess */
95  .cc_head_switch = 500000, /* guess */
96  .cc_command_latency = 0, /* unknown */
97 
98  .cc_rps = 7200/60
99 };
100 
101 static struct chs_dev disc;
102 static struct elevator el;
103 
104 static struct sim_thread seek_thr;
105 
106 static double seekto(struct sim *s, int64_t sector, int sectors)
107 {
108  sim_time_t now;
109 
110  now = s->ss_bolt;
111  elevator_io(&el, SRT_READ, sector, sectors);
112  return (s->ss_bolt - now)/1000;
113 }
114 
115 enum {
116  LBA_D = 10,
117  ROUNDS = 10,
118  TRACK_D = 8,
119  TRACK_S = 2500
120 };
121 
122 static void seek_test_thread(struct sim *s, struct sim_thread *t, void *arg)
123 {
124  int64_t in_num_sect = -1;
125  int i;
126  int j;
127  int k;
128  int round;
129  int sectors;
130  int64_t sector;
131  double latency;
132  double seeklat[LBA_D][LBA_D] = {};
133  double seeksqr[LBA_D][LBA_D] = {};
134 
135 
136  in_num_sect = 1953525168;
137 
138  /*
139  * repeated read.
140  */
141  for (i = 0; i < LBA_D; ++i) {
142  sector = in_num_sect * i / LBA_D;
143  for (sectors = 1; sectors <= (1 << 16); sectors *= 2) {
144  double avg;
145  double sqr;
146 
147  seekto(s, sector, sectors);
148  for (avg = sqr = 0.0, round = 0; round < ROUNDS; ++round) {
149  latency = seekto(s, sector, sectors);
150  avg += latency;
151  sqr += latency*latency;
152  }
153  avg /= ROUNDS;
154  printf("reading %4i sectors at %i/%i: %6.0f (%6.0f)\n",
155  sectors, i, LBA_D, avg,
156  sqrt(sqr/ROUNDS - avg*avg));
157  }
158  }
159 
160  /*
161  * seeks
162  */
163  for (round = 0; round < ROUNDS; ++round) {
164  for (i = 0; i < LBA_D; ++i) {
165  for (j = 0; j < LBA_D; ++j) {
166  int64_t sector_from;
167  int64_t sector_to;
168 
169  sector_from = in_num_sect * i / LBA_D;
170  sector_to = in_num_sect * j / LBA_D;
171  /*
172  * another loop to average rotational latency
173  * out.
174  */
175  for (k = 0; k < TRACK_D; ++k) {
176  seekto(s, sector_from +
177  TRACK_S*k/TRACK_D, 1);
178  latency = seekto(s, sector_to +
179  TRACK_S*round/ROUNDS,
180  1);
181  seeklat[i][j] += latency;
182  seeksqr[i][j] += latency*latency;
183  }
184  }
185  printf(".");
186  }
187  printf("\n");
188  }
189  for (i = 0; i < LBA_D; ++i) {
190  for (j = 0; j < LBA_D; ++j) {
191  latency = seeklat[i][j] / ROUNDS / TRACK_D;
192  printf("[%6.0f %4.0f]", latency,
193  sqrt(seeksqr[i][j] / ROUNDS / TRACK_D -
194  latency*latency));
195  }
196  printf("\n");
197  }
198  for (i = 0; i < LBA_D; ++i) {
199  for (j = 0; j < LBA_D; ++j)
200  printf("%6.0f, ", seeklat[i][j] / ROUNDS / TRACK_D);
201  printf("\n");
202  }
203 
205 }
206 
207 static int seek_test_start(struct sim_callout *co)
208 {
210  return 1;
211 }
212 
213 int main(int argc, char **argv)
214 {
215  struct sim s;
216  int result;
217 
218  result = m0_init(NULL);
219  if (result == 0) {
223  sim_init(&s);
224 
226  sim_run(&s);
227 
228  cnt_dump_all();
229  sim_log(&s, SLL_WARN, "done\n");
230  sim_fini(&s);
231  m0_fini();
232  }
233  return result;
234 }
235 
238 /*
239  * Local variables:
240  * c-indentation-style: "K&R"
241  * c-basic-offset: 8
242  * tab-width: 8
243  * fill-column: 80
244  * scroll-step: 1
245  * End:
246  */
M0_INTERNAL void sim_thread_init(struct sim *state, struct sim_thread *thread, unsigned stacksize, sim_func_t func, void *arg)
Definition: sim.c:293
static int seek_test_start(struct sim_callout *co)
Definition: chs_test.c:207
Definition: sim.h:152
M0_INTERNAL void sim_init(struct sim *state)
Definition: sim.c:106
static struct chs_conf ST31000640SS
Definition: chs_test.c:79
#define NULL
Definition: misc.h:38
unsigned sc_sector_size
Definition: storage.h:39
static struct chs_dev disc
Definition: chs_test.c:101
void m0_fini(void)
Definition: init.c:318
static struct sim_thread seek_thr
Definition: chs_test.c:104
M0_INTERNAL void elevator_init(struct elevator *el, struct storage_dev *dev)
Definition: elevator.c:77
static void seek_test_thread(struct sim *s, struct sim_thread *t, void *arg)
Definition: chs_test.c:122
Definition: sim.h:285
M0_INTERNAL void sim_log(struct sim *s, enum sim_log_level level, const char *format,...)
Definition: sim.c:527
Definition: chs.h:41
int m0_init(struct m0 *instance)
Definition: init.c:310
M0_INTERNAL void sim_thread_exit(struct sim_thread *thread)
Definition: sim.c:346
M0_INTERNAL void sim_run(struct sim *state)
Definition: sim.c:129
int i
Definition: dir.c:1033
M0_INTERNAL void chs_conf_init(struct chs_conf *conf)
Definition: chs.c:43
static struct m0_thread t[8]
Definition: service_ut.c:1230
M0_INTERNAL void sim_timer_add(struct sim *state, sim_time_t delta, sim_call_t *cfunc, void *datum)
Definition: sim.c:189
unsigned long long sim_time_t
Definition: sim.h:111
M0_INTERNAL void elevator_io(struct elevator *el, enum storage_req_type type, sector_t sector, unsigned long count)
Definition: elevator.c:93
Definition: chs.h:76
static double seekto(struct sim *s, int64_t sector, int sectors)
Definition: chs_test.c:106
struct sim * sc_sim
Definition: sim.h:142
struct storage_conf cc_storage
Definition: chs.h:42
M0_INTERNAL void cnt_dump_all(void)
Definition: cnt.c:74
M0_INTERNAL void chs_dev_init(struct chs_dev *dev, struct sim *sim, struct chs_conf *conf)
Definition: chs.c:129
struct storage_dev cd_storage
Definition: chs.h:77
static struct elevator el
Definition: chs_test.c:102
M0_INTERNAL void sim_fini(struct sim *state)
Definition: sim.c:116
static struct m0_addb2_source * s
Definition: consumer.c:39
int main(int argc, char **argv)
Definition: chs_test.c:213