From 85af7552ddbbbc1df76bf2412ffbfb1e039d6c2c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 9 Jan 2009 08:17:46 +0100 Subject: [PATCH] add SchedulerType global variable --- src/simulator/calendar-scheduler.cc | 14 ++++++++++++- src/simulator/calendar-scheduler.h | 16 ++++++++++++++- src/simulator/heap-scheduler.cc | 11 ++++++++++ src/simulator/heap-scheduler.h | 2 ++ src/simulator/list-scheduler.cc | 12 +++++++++++ src/simulator/list-scheduler.h | 2 ++ src/simulator/map-scheduler.cc | 12 +++++++++++ src/simulator/map-scheduler.h | 2 ++ src/simulator/simulator.cc | 32 ++++++++++++++++++++--------- 9 files changed, 91 insertions(+), 12 deletions(-) diff --git a/src/simulator/calendar-scheduler.cc b/src/simulator/calendar-scheduler.cc index 9ec14b182..904ecfcf2 100644 --- a/src/simulator/calendar-scheduler.cc +++ b/src/simulator/calendar-scheduler.cc @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2005 INRIA + * Copyright (c) 2009 INRIA * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -30,6 +30,18 @@ namespace ns3 { NS_LOG_COMPONENT_DEFINE ("CalendarScheduler"); +NS_OBJECT_ENSURE_REGISTERED (CalendarScheduler); + +TypeId +CalendarScheduler::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::CalendarScheduler") + .SetParent () + .AddConstructor () + ; + return tid; +} + CalendarScheduler::CalendarScheduler () { NS_LOG_FUNCTION (this); diff --git a/src/simulator/calendar-scheduler.h b/src/simulator/calendar-scheduler.h index a034c685a..79f420fe6 100644 --- a/src/simulator/calendar-scheduler.h +++ b/src/simulator/calendar-scheduler.h @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2005 INRIA + * Copyright (c) 2009 INRIA * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -31,10 +31,24 @@ class EventImpl; /** * \ingroup scheduler + * \brief a calendar queue event scheduler + * + * This event scheduler is a direct implementation of the algorithm known as a calendar queue. + * first published in 1988 in "Calendar Queues: A Fast O(1) Priority Queue Implementation for + * the Simulation Event Set Problem" by Randy Brown. There are many refinements published + * later but this class implements the original algorithm (to the best of my knowledge). + * + * Note: This queue is much slower than I expected (much slower than the std::map queue) + * and this seems to be because the original resizing policy is horribly bad. This is + * most likely the reason why there have been so many variations published which all + * slightly tweak the resizing heuristics to obtain a better distribution of events + * across buckets. */ class CalendarScheduler : public Scheduler { public: + static TypeId GetTypeId (void); + CalendarScheduler (); virtual ~CalendarScheduler (); diff --git a/src/simulator/heap-scheduler.cc b/src/simulator/heap-scheduler.cc index 6795f64fd..fa39011b9 100644 --- a/src/simulator/heap-scheduler.cc +++ b/src/simulator/heap-scheduler.cc @@ -29,6 +29,17 @@ NS_LOG_COMPONENT_DEFINE ("HeapScheduler"); namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (HeapScheduler); + +TypeId +HeapScheduler::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::HeapScheduler") + .SetParent () + .AddConstructor () + ; + return tid; +} HeapScheduler::HeapScheduler () { diff --git a/src/simulator/heap-scheduler.h b/src/simulator/heap-scheduler.h index ca4a38be5..600f26dc9 100644 --- a/src/simulator/heap-scheduler.h +++ b/src/simulator/heap-scheduler.h @@ -47,6 +47,8 @@ namespace ns3 { class HeapScheduler : public Scheduler { public: + static TypeId GetTypeId (void); + HeapScheduler (); virtual ~HeapScheduler (); diff --git a/src/simulator/list-scheduler.cc b/src/simulator/list-scheduler.cc index 822cfe4a8..9c4bc3b40 100644 --- a/src/simulator/list-scheduler.cc +++ b/src/simulator/list-scheduler.cc @@ -27,6 +27,18 @@ namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (ListScheduler); + +TypeId +ListScheduler::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::ListScheduler") + .SetParent () + .AddConstructor () + ; + return tid; +} + ListScheduler::ListScheduler () {} ListScheduler::~ListScheduler () diff --git a/src/simulator/list-scheduler.h b/src/simulator/list-scheduler.h index 064ae1d17..55317c02a 100644 --- a/src/simulator/list-scheduler.h +++ b/src/simulator/list-scheduler.h @@ -40,6 +40,8 @@ class EventImpl; class ListScheduler : public Scheduler { public: + static TypeId GetTypeId (void); + ListScheduler (); virtual ~ListScheduler (); diff --git a/src/simulator/map-scheduler.cc b/src/simulator/map-scheduler.cc index ce861b8d0..cb1d6573b 100644 --- a/src/simulator/map-scheduler.cc +++ b/src/simulator/map-scheduler.cc @@ -29,6 +29,18 @@ NS_LOG_COMPONENT_DEFINE ("MapScheduler"); namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (MapScheduler); + +TypeId +MapScheduler::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::MapScheduler") + .SetParent () + .AddConstructor () + ; + return tid; +} + MapScheduler::MapScheduler () {} MapScheduler::~MapScheduler () diff --git a/src/simulator/map-scheduler.h b/src/simulator/map-scheduler.h index d82eb7fec..c07102a03 100644 --- a/src/simulator/map-scheduler.h +++ b/src/simulator/map-scheduler.h @@ -38,6 +38,8 @@ namespace ns3 { class MapScheduler : public Scheduler { public: + static TypeId GetTypeId (void); + MapScheduler (); virtual ~MapScheduler (); diff --git a/src/simulator/simulator.cc b/src/simulator/simulator.cc index b399d806f..efd1c80bc 100644 --- a/src/simulator/simulator.cc +++ b/src/simulator/simulator.cc @@ -23,7 +23,6 @@ #include "default-simulator-impl.h" #include "realtime-simulator-impl.h" #include "scheduler.h" -#include "map-scheduler.h" #include "event-impl.h" #include "ns3/ptr.h" @@ -48,6 +47,12 @@ GlobalValue g_simTypeImpl = GlobalValue ("SimulatorImplementationType", StringValue ("ns3::DefaultSimulatorImpl"), MakeStringChecker ()); +GlobalValue g_schedTypeImpl = GlobalValue ("SchedulerType", + "The object class to use as the scheduler implementation", + StringValue ("ns3::MapScheduler"), + MakeStringChecker ()); + + #ifdef NS3_LOG_ENABLE // @@ -77,15 +82,21 @@ static SimulatorImpl * GetImpl (void) */ if (impl == 0) { - ObjectFactory factory; - StringValue s; - - g_simTypeImpl.GetValue (s); - factory.SetTypeId (s.Get ()); - impl = factory.Create (); - - Ptr scheduler = CreateObject (); - impl->SetScheduler (scheduler); + { + ObjectFactory factory; + StringValue s; + + g_simTypeImpl.GetValue (s); + factory.SetTypeId (s.Get ()); + impl = factory.Create (); + } + { + ObjectFactory factory; + StringValue s; + g_schedTypeImpl.GetValue (s); + factory.SetTypeId (s.Get ()); + impl->SetScheduler (factory.Create ()); + } // // Note: we call LogSetTimePrinter _after_ creating the implementation @@ -302,6 +313,7 @@ Simulator::GetImplementation (void) #include "ns3/ptr.h" #include "list-scheduler.h" #include "heap-scheduler.h" +#include "map-scheduler.h" namespace ns3 {