Stxxl  1.3.2
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 <[email protected]>
7  * Copyright (C) 2008 Andreas Beckmann <[email protected]>
8  * Copyright (C) 2009 Johannes Singler <[email protected]>
9  *
10  * Distributed under the Boost Software License, Version 1.0.
11  * (See accompanying file LICENSE_1_0.txt or copy at
12  * http://www.boost.org/LICENSE_1_0.txt)
13  **************************************************************************/
14 
15 #ifndef STXXL_SIMDISK_FILE_HEADER
16 #define STXXL_SIMDISK_FILE_HEADER
17 
18 #ifndef STXXL_HAVE_SIMDISK_FILE
19 #ifdef STXXL_BOOST_CONFIG
20  #include <boost/config.hpp>
21 #endif
22 
23 #ifndef BOOST_MSVC
24 // mmap call does not exist in Windows
25  #define STXXL_HAVE_SIMDISK_FILE 1
26 #else
27  #define STXXL_HAVE_SIMDISK_FILE 0
28 #endif
29 #endif
30 
31 #if STXXL_HAVE_SIMDISK_FILE
32 
33 #include <set>
34 #include <cmath>
35 #include <sys/mman.h>
36 
37 #include <stxxl/bits/io/ufs_file_base.h>
38 #include <stxxl/bits/io/disk_queued_file.h>
39 
40 
41 __STXXL_BEGIN_NAMESPACE
42 
45 
46  #define AVERAGE_SPEED (15 * 1024 * 1024)
47 
48 class DiskGeometry : private noncopyable
49 {
50  struct Zone
51  {
52  // manufactured data
53 #if 0
54  int last_cyl;
55  int sect_per_track;
56 #endif
57  // derived data
58  int first_sector;
59  int sectors;
60  double sustained_data_rate; // in MiB/s
61  inline Zone(int _first_sector) : first_sector(_first_sector)
62  { } // constructor for zone search
63 
64  inline Zone(
65 #if 0
66  int _last_cyl,
67  int _sect_per_track,
68 #endif
69  int _first_sector,
70  int _sectors,
71  double _rate) :
72 #if 0
73  last_cyl(_last_cyl),
74  sect_per_track(_sect_per_track),
75 #endif
76  first_sector(_first_sector),
77  sectors(_sectors),
78  sustained_data_rate(_rate)
79  { }
80  };
81  struct ZoneCmp
82  {
83  inline bool operator () (const Zone & a, const Zone & b) const
84  {
85  return a.first_sector < b.first_sector;
86  }
87  };
88 
89 protected:
90  int nsurfaces;
91  int bytes_per_sector;
92  double cmd_ovh; // in s
93  double seek_time; // in s
94  double rot_latency; // in s
95  double head_switch_time; // in s
96  double cyl_switch_time; // in s
97  double revolution_time; // in s
98  double interface_speed; // in byte/s
99  std::set<Zone, ZoneCmp> zones;
100 
101  void add_zone(int & first_cyl, int last_cyl,
102  int sec_per_track, int & first_sect);
103 
104 public:
105  inline DiskGeometry()
106  { }
107  double get_delay(file::offset_type offset, file::size_type size); // returns delay in s
108 
109  inline ~DiskGeometry()
110  { }
111 };
112 
113 
114 class IC35L080AVVA07 : public DiskGeometry // IBM series 120GXP
115 {
116 public:
117  IC35L080AVVA07();
118 };
119 
122 class sim_disk_file : public ufs_file_base, public disk_queued_file, public IC35L080AVVA07
123 {
124 public:
130  inline sim_disk_file(const std::string & filename, int mode, int queue_id = DEFAULT_QUEUE, int allocator_id = NO_ALLOCATOR) : ufs_file_base(filename, mode), disk_queued_file(queue_id, allocator_id)
131  {
132  std::cout << "Please, make sure that '" << filename <<
133  "' is resided on swap memory partition!" <<
134  std::endl;
135  }
136  void serve(const request * req) throw (io_error);
137  void set_size(offset_type newsize);
138  const char * io_type() const;
139 };
140 
142 
143 __STXXL_END_NAMESPACE
144 
145 #endif // #if STXXL_HAVE_SIMDISK_FILE
146 
147 #endif // !STXXL_SIMDISK_FILE_HEADER
Base for UNIX file system implementations.
Definition: ufs_file_base.h:30
const char * io_type() const
Identifies the type of I/O implementation.
Request with basic properties like file and offset.
Definition: request.h:39
Implementation of disk emulation.
Definition: simdisk_file.h:122
Implementation of some file methods based on serving_request.
Definition: disk_queued_file.h:26
void set_size(offset_type newsize)
Changes the size of the file.
sim_disk_file(const std::string &filename, int mode, int queue_id=DEFAULT_QUEUE, int allocator_id=NO_ALLOCATOR)
constructs file object
Definition: simdisk_file.h:130