#include #include #include #include #include #include "Events.h" #include "Simulations.h" // Author: Douglas Wilhelm Harder // Copyright (c) 2012 by Douglas Wilhelm Harder. All rights reserved. /* We will assume that requests arrive via a Poisson process with * a mean of lambda. Therefore, the inter-arrival periods are * exponentially distributed with mean 1/lambda. * * Therefore, we assume an event occurs at time t = 0 and we will * proceed by finding random variables that come from the * exponential distribution. * * The probability density function (pdf) of the exponential distribution * with mean 1/lambda is given by lambda*exp(-lambda*t)*u(t) where u(t) is * the unit step function. * * The cumulative distribution function is given by (1 - exp(-lambda*t))*u(t) * which grows from 0 to 1 with 0 <= t < Inf. * * The inverse is t = -ln(1 - X)/lambda. * * Tracks per disk 36 000 tracks * Rotational latency 2 ms * Average seek time 8 ms * Read time 2.5 ms * Head speed 2 tracks/us */ int const TRACKS_PER_DISK = 36000; int const ROTATIONAL_LATENCY = 2000; // 2 ms or 2,000 us int const READ_TIME = 2500; // 2500 us int const HEAD_SPEED = 2; // 2 tracks/us int main() { srand48( std::time(0) ); int const N = 1000; double const mean_arrivals = 0.0002; // One arrival per 5000 us or 10 ms Event event_list[N]; std::cout << "Uniform Distribution of Requests" << std::endl; generate_uniform_events( event_list, N, mean_arrivals, TRACKS_PER_DISK ); std::cout << "First come, first serve" << std::endl; simulate_fcfs( event_list, N, ROTATIONAL_LATENCY + READ_TIME, HEAD_SPEED ); // print( event_list, N ); analyze( event_list, N ); std::cout << std::endl; std::cout << "Shortest service time first" << std::endl; simulate_sstf( event_list, N, ROTATIONAL_LATENCY + READ_TIME, HEAD_SPEED ); // print( event_list, N ); analyze( event_list, N ); std::cout << std::endl; std::cout << "LOOK" << std::endl; simulate_look( event_list, N, ROTATIONAL_LATENCY + READ_TIME, HEAD_SPEED ); // print( event_list, N ); analyze( event_list, N ); std::cout << std::endl; std::cout << "C-LOOK" << std::endl; simulate_c_look( event_list, N, ROTATIONAL_LATENCY + READ_TIME, HEAD_SPEED ); // print( event_list, N ); analyze( event_list, N ); std::cout << std::endl; std::cout << "F-LOOK" << std::endl; simulate_f_look( event_list, N, ROTATIONAL_LATENCY + READ_TIME, HEAD_SPEED ); // print( event_list, N ); analyze( event_list, N ); std::cout << std::endl; std::cout << std::endl << "Uniform Distribution of Requests with Probability 0.2 with Others Targetted" << std::endl; generate_uniform_and_targetted_events( event_list, N, mean_arrivals, TRACKS_PER_DISK, 0.2, 40 ); std::cout << "First come, first serve" << std::endl; simulate_fcfs( event_list, N, ROTATIONAL_LATENCY + READ_TIME, HEAD_SPEED ); // print( event_list, N ); analyze( event_list, N ); std::cout << std::endl; std::cout << "Shortest service time first" << std::endl; simulate_sstf( event_list, N, ROTATIONAL_LATENCY + READ_TIME, HEAD_SPEED ); // print( event_list, N ); analyze( event_list, N ); std::cout << std::endl; std::cout << "LOOK" << std::endl; simulate_look( event_list, N, ROTATIONAL_LATENCY + READ_TIME, HEAD_SPEED ); // print( event_list, N ); analyze( event_list, N ); std::cout << std::endl; std::cout << "C-LOOK" << std::endl; simulate_c_look( event_list, N, ROTATIONAL_LATENCY + READ_TIME, HEAD_SPEED ); // print( event_list, N ); analyze( event_list, N ); std::cout << std::endl; std::cout << "F-LOOK" << std::endl; simulate_f_look( event_list, N, ROTATIONAL_LATENCY + READ_TIME, HEAD_SPEED ); // print( event_list, N ); analyze( event_list, N ); std::cout << std::endl; return 0; }