Stxxl  1.2.1
simdisk_file.h
1 /***************************************************************************
2  * include/stxxl/bits/io/simdisk_file.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2002-2003 Roman Dementiev <dementiev@mpi-sb.mpg.de>
7  *
8  * Distributed under the Boost Software License, Version 1.0.
9  * (See accompanying file LICENSE_1_0.txt or copy at
10  * http://www.boost.org/LICENSE_1_0.txt)
11  **************************************************************************/
12 
13 #ifndef STXXL_SIMDISK_FILE_HEADER
14 #define STXXL_SIMDISK_FILE_HEADER
15 
16 #ifdef STXXL_BOOST_CONFIG
17  #include <boost/config.hpp>
18 #endif
19 
20 #ifndef BOOST_MSVC
21 // mmap call does not exist in Windows
22 
23 #include <cmath>
24 #include <sys/mman.h>
25 
26 #include <stxxl/bits/io/ufs_file.h>
27 
28 
29 __STXXL_BEGIN_NAMESPACE
30 
33 
34  #define AVERAGE_SPEED (15 * 1024 * 1024)
35 
36 class DiskGeometry : private noncopyable
37 {
38  struct Zone
39  {
40  // manufactured data
41  // int last_cyl;
42  // int sect_per_track;
43  // derived data
44  int first_sector;
45  int sectors;
46  double sustained_data_rate; // in Mb/s
47  inline Zone(int _first_sector) : first_sector(_first_sector)
48  { } // constructor for zone search
49 
50  inline Zone(
51  //int _last_cyl,
52  //int _sect_per_track,
53  int _first_sector,
54  int _sectors, double _rate) :
55  //last_cyl(_last_cyl),
56  //sect_per_track(_sect_per_track) ,
57  first_sector(_first_sector),
58  sectors(_sectors),
59  sustained_data_rate(_rate)
60  { }
61  };
62  struct ZoneCmp
63  {
64  inline bool operator () (const Zone & a, const Zone & b) const
65  {
66  return a.first_sector < b.first_sector;
67  }
68  };
69 
70 protected:
71  int nsurfaces;
72  int bytes_per_sector;
73  double cmd_ovh; // in s
74  double seek_time; // in s
75  double rot_latency; // in s
76  double head_switch_time; // in s
77  double cyl_switch_time; // in s
78  double revolution_time; // in s
79  double interface_speed; // in byte/s
80  std::set<Zone, ZoneCmp> zones;
81 
82  void add_zone(int & first_cyl, int last_cyl,
83  int sec_per_track, int & first_sect);
84 
85 public:
86  inline DiskGeometry()
87  { }
88  double get_delay(stxxl::int64 offset, size_t size); // returns delay in s
89 
90  inline ~DiskGeometry()
91  { }
92 };
93 
94 
95 class IC35L080AVVA07 : public DiskGeometry // IBM series 120GXP
96 {
97 public:
98  IC35L080AVVA07();
99 };
100 
101 class sim_disk_request;
102 
105 class sim_disk_file : public ufs_file_base, public IC35L080AVVA07
106 {
107 public:
113  inline sim_disk_file(const std::string & filename, int mode, int disk) : ufs_file_base(filename, mode, disk)
114  {
115  std::cout << "Please, make sure that '" << filename <<
116  "' is resided on swap memory partition!" <<
117  std::endl;
118  }
119  request_ptr aread(void * buffer, stxxl::int64 pos, size_t bytes,
120  completion_handler on_cmpl);
121  request_ptr awrite(void * buffer, stxxl::int64 pos, size_t bytes,
122  completion_handler on_cmpl);
123  void set_size(stxxl::int64 newsize);
124 };
125 
126 
129 {
130  friend class sim_disk_file;
131 
132 protected:
133  inline sim_disk_request(sim_disk_file * f, void * buf, stxxl::int64 off,
134  size_t b, request_type t,
135  completion_handler on_cmpl) :
137  buf,
138  off,
139  b,
140  t,
141  on_cmpl)
142  { }
143  void serve();
144 
145 public:
146  inline const char * io_type()
147  {
148  return "simdisk";
149  }
150 };
151 
153 
154 __STXXL_END_NAMESPACE
155 
156 #endif // #ifndef BOOST_MSVC
157 
158 #endif // !STXXL_SIMDISK_FILE_HEADER