Stxxl  1.4.0
include/stxxl/bits/io/simdisk_file.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  include/stxxl/bits/io/simdisk_file.h
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2002-2003 Roman Dementiev <dementiev@mpi-sb.mpg.de>
00007  *  Copyright (C) 2008 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
00008  *  Copyright (C) 2009 Johannes Singler <singler@ira.uka.de>
00009  *
00010  *  Distributed under the Boost Software License, Version 1.0.
00011  *  (See accompanying file LICENSE_1_0.txt or copy at
00012  *  http://www.boost.org/LICENSE_1_0.txt)
00013  **************************************************************************/
00014 
00015 #ifndef STXXL_SIMDISK_FILE_HEADER
00016 #define STXXL_SIMDISK_FILE_HEADER
00017 
00018 #ifndef STXXL_HAVE_SIMDISK_FILE
00019 #ifdef STXXL_BOOST_CONFIG
00020  #include <boost/config.hpp>
00021 #endif
00022 
00023 #ifndef BOOST_MSVC
00024 // mmap call does not exist in Windows
00025  #define STXXL_HAVE_SIMDISK_FILE 1
00026 #else
00027  #define STXXL_HAVE_SIMDISK_FILE 0
00028 #endif
00029 #endif
00030 
00031 #if STXXL_HAVE_SIMDISK_FILE
00032 
00033 #include <set>
00034 #include <cmath>
00035 #include <sys/mman.h>
00036 
00037 #include <stxxl/bits/io/ufs_file_base.h>
00038 #include <stxxl/bits/io/disk_queued_file.h>
00039 
00040 
00041 __STXXL_BEGIN_NAMESPACE
00042 
00043 //! \addtogroup fileimpl
00044 //! \{
00045 
00046  #define AVERAGE_SPEED (15 * 1024 * 1024)
00047 
00048 class DiskGeometry : private noncopyable
00049 {
00050     struct Zone
00051     {
00052         // manufactured data
00053 #if 0
00054         int last_cyl;
00055         int sect_per_track;
00056 #endif
00057         // derived data
00058         int first_sector;
00059         int sectors;
00060         double sustained_data_rate;  // in MiB/s
00061         inline Zone(int _first_sector) : first_sector(_first_sector)
00062         { }                          // constructor for zone search
00063 
00064         inline Zone(
00065 #if 0
00066             int _last_cyl,
00067             int _sect_per_track,
00068 #endif
00069             int _first_sector,
00070             int _sectors,
00071             double _rate) :
00072 #if 0
00073             last_cyl(_last_cyl),
00074             sect_per_track(_sect_per_track),
00075 #endif
00076             first_sector(_first_sector),
00077             sectors(_sectors),
00078             sustained_data_rate(_rate)
00079         { }
00080     };
00081     struct ZoneCmp
00082     {
00083         inline bool operator () (const Zone & a, const Zone & b) const
00084         {
00085             return a.first_sector < b.first_sector;
00086         }
00087     };
00088 
00089 protected:
00090     int nsurfaces;
00091     int bytes_per_sector;
00092     double cmd_ovh;                     // in s
00093     double seek_time;                   // in s
00094     double rot_latency;                 // in s
00095     double head_switch_time;            // in s
00096     double cyl_switch_time;             // in s
00097     double revolution_time;             // in s
00098     double interface_speed;             // in byte/s
00099     std::set<Zone, ZoneCmp> zones;
00100 
00101     void add_zone(int & first_cyl, int last_cyl,
00102                   int sec_per_track, int & first_sect);
00103 
00104 public:
00105     inline DiskGeometry()
00106     { }
00107     double get_delay(file::offset_type offset, file::size_type size);                // returns delay in s
00108 
00109     inline ~DiskGeometry()
00110     { }
00111 };
00112 
00113 
00114 class IC35L080AVVA07 : public DiskGeometry              // IBM series 120GXP
00115 {
00116 public:
00117     IC35L080AVVA07();
00118 };
00119 
00120 //! \brief Implementation of disk emulation
00121 //! \remark It is emulation of IBM IC35L080AVVA07 disk's timings
00122 class sim_disk_file : public ufs_file_base, public disk_queued_file, public IC35L080AVVA07
00123 {
00124 public:
00125     //! \brief constructs file object
00126     //! \param filename path of file
00127     //! \attention filename must be resided at memory disk partition
00128     //! \param mode open mode, see \c stxxl::file::open_modes
00129     //! \param disk disk(file) identifier
00130     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)
00131     {
00132         std::cout << "Please, make sure that '" << filename <<
00133         "' is resided on swap memory partition!" <<
00134         std::endl;
00135     }
00136     void serve(const request * req) throw (io_error);
00137     void set_size(offset_type newsize);
00138     const char * io_type() const;
00139 };
00140 
00141 //! \}
00142 
00143 __STXXL_END_NAMESPACE
00144 
00145 #endif  // #if STXXL_HAVE_SIMDISK_FILE
00146 
00147 #endif  // !STXXL_SIMDISK_FILE_HEADER
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines