cmake_minimum_required(VERSION 2.8.11)
-set(CMAKE_CXX_FLAGS "-std=c++11 -Wno-write-strings ${CMAKE_CXX_FLAGS}")
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules")
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
-
-if(DO_NOT_DELAY_TAG_CALC)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDO_NOT_DELAY_TAG_CALC")
-endif()
-
-if(K_WAY_HEAP)
- if(K_WAY_HEAP LESS 2)
- message(FATAL_ERROR "K_WAY_HEAP value should be at least 2")
- else()
- set(CMAKE_CXX_SIM_FLAGS "-DK_WAY_HEAP=${K_WAY_HEAP}")
+if (NOT(TARGET gtest AND TARGET gtest_main))
+ if(NOT(GTEST_FOUND))
+ find_package(GTest REQUIRED)
endif()
endif()
-if (NOT(TARGET gtest AND TARGET gtest_main))
- find_package(gtest REQUIRED)
- include_directories(${GTEST_INCLUDE_DIRS})
+if (NOT(BOOST_FOUND))
+ find_package(Boost REQUIRED)
endif()
-find_package(Boost REQUIRED)
-include_directories(${Boost_INCLUDE_DIRS})
-
+# add_subdirectory(support/src)
add_subdirectory(src)
add_subdirectory(sim)
-add_subdirectory(support)
enable_testing()
add_subdirectory(test)
+add_subdirectory(support/test)
+add_test(NAME dmclock-tests
+ COMMAND $<TARGET_FILE:dmclock-tests>)
+add_test(NAME dmclock-data-struct-tests
+ COMMAND $<TARGET_FILE:dmclock-data-struct-tests>)
+++ /dev/null
-# - Find boost
-
-find_path(BOOST_INCLUDE_DIR NAMES boost/variant.hpp
- PATHS /usr/include /usr/local/include ${BOOST_DIR}/include)
-
-include(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(boost
- REQUIRED_VARS BOOST_INCLUDE_DIR)
-
-if(boost_FOUND)
- set(BOOST_FOUND 1)
-endif()
-if(BOOST_FOUND)
- set(BOOST_INCLUDES ${BOOST_INCLUDE_DIR})
-endif()
+++ /dev/null
-# - Find gtest
-#
-# GTEST_INCLUDE_DIRS - where to find mcas/mcas.h, etc.
-# GTEST_LIBRARIES - List of libraries when using mcas.
-# GTEST_FOUND - True if mcas found.
-#
-# GMOCK_INCLUDE_DIRS - where to find mcas/mcas.h, etc.
-# GMOCK_LIBRARIES - List of libraries when using mcas.
-# GMOCK_FOUND - True if mcas found.
-
-
-## GTEST
-
-find_path(GTEST_INCLUDE_DIRS NAMES gtest/gtest.h
- PATHS /usr/include /usr/local/include)
-
-find_library(GTEST_LIBRARY gtest
- PATHS /usr/local/lib /usr/lib64)
-
-find_library(GTEST_MAIN_LIBRARY gtest_main
- PATHS /usr/local/lib /usr/lib64)
-
-include(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(gtest
- REQUIRED_VARS GTEST_LIBRARY GTEST_MAIN_LIBRARY GTEST_INCLUDE_DIRS)
-
-if(gtest_FOUND)
- set(GTEST_FOUND 1)
-endif()
-
-## GMOCK
-
-find_path(GMOCK_INCLUDE_DIRS NAMES gmock/gmock.h
- PATHS /usr/include /usr/local/include)
-
-find_library(GMOCK_LIBRARY gmock
- PATHS /usr/local/lib /usr/lib64)
-
-find_library(GMOCK_MAIN_LIBRARY gmock_main
- PATHS /usr/local/lib /usr/lib64)
-
-include(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(gmock
- REQUIRED_VARS GMOCK_LIBRARY GMOCK_MAIN_LIBRARY GMOCK_INCLUDE_DIRS)
-
-if(gmock_FOUND)
- set(GMOCK_FOUND 1)
-endif()
+if(K_WAY_HEAP)
+ if(K_WAY_HEAP LESS 2)
+ message(FATAL_ERROR "K_WAY_HEAP value should be at least 2")
+ else()
+ set(CMAKE_CXX_SIM_FLAGS "-DK_WAY_HEAP=${K_WAY_HEAP}")
+ endif()
+endif()
+
add_subdirectory(src)
}
delete[] threads;
+
+ delete priority_queue;
}
void post(const TestRequest& request,
// empty
}
+ ~Simulation() {
+ for (auto c : clients) {
+ TC* cp = c.second;
+ delete cp;
+ }
+
+ for (auto s : servers) {
+ delete s.second;
+ }
+ }
+
uint get_client_count() const { return client_count; }
uint get_server_count() const { return server_count; }
TC& get_client(ClientId id) { return *clients[id]; }
simulation->display_stats(std::cout,
&test::server_data, &test::client_data,
server_disp_filter, client_disp_filter);
+
+ delete simulation;
} // main
+include_directories(${GTEST_INCLUDE_DIRS})
+include_directories(${Boost_INCLUDE_DIRS})
include_directories(../support/src)
-include_directories(${BOOST_INCLUDE_DIR})
-set(local_flags "-Wall -pthread")
+set(local_flags "-std=c++11 -Wno-write-strings -Wall -pthread")
+
+if(DO_NOT_DELAY_TAG_CALC)
+ set(local_flags "${local_flags} -DDO_NOT_DELAY_TAG_CALC")
+endif()
set(dmc_srcs dmclock_util.cc ../support/src/run_every.cc)
RequestTag(const RequestTag& prev_tag,
const ClientInfo& client,
- const ReqParams& req_params,
- const Time& time,
+ const uint32_t delta,
+ const uint32_t rho,
+ const Time time,
const double cost = 0.0) :
reservation(cost + tag_calc(time,
prev_tag.reservation,
client.reservation_inv,
- req_params.rho,
+ rho,
true)),
proportion(tag_calc(time,
prev_tag.proportion,
client.weight_inv,
- req_params.delta,
+ delta,
true)),
limit(tag_calc(time,
prev_tag.limit,
client.limit_inv,
- req_params.delta,
+ delta,
false)),
ready(false)
#ifndef DO_NOT_DELAY_TAG_CALC
assert(reservation < max_tag || proportion < max_tag);
}
- RequestTag(double _res, double _prop, double _lim, const Time& _arrival) :
+ RequestTag(const RequestTag& prev_tag,
+ const ClientInfo& client,
+ const ReqParams req_params,
+ const Time time,
+ const double cost = 0.0) :
+ RequestTag(prev_tag, client, req_params.delta, req_params.rho, time, cost)
+ { /* empty */ }
+
+ RequestTag(double _res, double _prop, double _lim, const Time _arrival) :
reservation(_res),
proportion(_prop),
limit(_lim),
private:
- static double tag_calc(const Time& time,
+ static double tag_calc(const Time time,
double prev,
double increment,
uint32_t dist_req_val,
// data_mtx must be held by caller
- void do_add_request(RequestRef&& request,
- const C& client_id,
+ void do_add_request(RequestRef&& request,
+ const C& client_id,
const ReqParams& req_params,
- const Time time,
- const double cost = 0.0) {
+ const Time time,
+ const double cost = 0.0) {
++tick;
// this pointer will help us create a reference to a shared
RequestTag tag(0, 0, 0, time);
if (!client.has_request()) {
- tag = RequestTag(client.get_req_tag(), client.info,
- req_params, time, cost);
+ tag = RequestTag(client.get_req_tag(),
+ client.info,
+ req_params,
+ time,
+ cost);
// copy tag to previous tag for client
client.update_req_tag(tag, tick);
RequestRef& request)> process) {
// gain access to data
ClientRec& top = heap.top();
- ClientReq& first = top.next_request();
- RequestRef request = std::move(first.request);
+
+ RequestRef request = std::move(top.next_request().request);
+ RequestTag tag = top.next_request().tag;
// pop request and adjust heaps
top.pop_request();
#ifndef DO_NOT_DELAY_TAG_CALC
if (top.has_request()) {
ClientReq& next_first = top.next_request();
- next_first.tag = RequestTag(first.tag, top.info,
- ReqParams(top.cur_delta, top.cur_rho),
+ next_first.tag = RequestTag(tag, top.info,
+ top.cur_delta, top.cur_rho,
next_first.tag.arrival);
// copy tag to previous tag for client
void add_request(typename super::RequestRef&& request,
- const C& client_id,
+ const C& client_id,
const ReqParams& req_params,
- const Time time,
- double addl_cost = 0.0) {
+ const Time time,
+ double addl_cost = 0.0) {
typename super::DataGuard g(this->data_mtx);
#ifdef PROFILE
add_request_timer.start();
void sched_at(Time when) {
std::lock_guard<std::mutex> l(sched_ahead_mtx);
+ if (this->finishing) return;
if (TimeZero == sched_ahead_when || when < sched_ahead_when) {
sched_ahead_when = when;
sched_ahead_cv.notify_one();
+++ /dev/null
-add_subdirectory(test)
}
void pop() {
- remove(0);
+ remove(HeapIndex(0));
}
void remove(Iterator& i) {
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
- * Copyright (C) 2016 Red Hat Inc.
+ * Copyright (C) 2017 Red Hat Inc.
*/
-#include <iostream>
-
#include "run_every.h"
crimson::RunEvery::~RunEvery() {
- finishing = true;
- cv.notify_all();
+ join();
+}
+
+
+void crimson::RunEvery::join() {
+ {
+ Guard l(mtx);
+ if (finishing) return;
+ finishing = true;
+ cv.notify_all();
+ }
thd.join();
}
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
- * Copyright (C) 2016 Red Hat Inc.
+ * Copyright (C) 2017 Red Hat Inc.
*/
~RunEvery();
+ void join();
+
protected:
void run();
target_link_libraries(dmclock-data-struct-tests
LINK_PRIVATE gtest gtest_main pthread)
-
-add_test(NAME dmclock-data-struct-tests
- COMMAND $<TARGET_FILE:dmclock-data-struct-tests>)
include_directories(../src)
include_directories(../support/src)
include_directories(../sim/src)
-include_directories(${BOOST_INCLUDE_DIR})
set(support_srcs ../sim/src/test_dmclock.cc)
set(test_srcs
$<TARGET_FILE:gtest_main>)
else()
target_link_libraries(dmclock-tests
- LINK_PRIVATE $<TARGET_FILE:dmclock> pthread ${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY})
+ LINK_PRIVATE $<TARGET_FILE:dmclock> pthread ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
endif()
add_dependencies(dmclock-tests dmclock)
-
-add_test(NAME dmclock-tests
- COMMAND $<TARGET_FILE:dmclock-tests>)
int milliseconds = (end - start) / std::chrono::milliseconds(1);
EXPECT_LT(10000, milliseconds) << "timing too fast to be correct";
EXPECT_GT(12000, milliseconds) << "timing suspiciously slow";
+
+ delete client;
}
EXPECT_LT(15000 - 500, milliseconds) << "timing too fast to be correct";
EXPECT_GT(17000 - 500, milliseconds) << "timing suspiciously slow";
t.join();
+
+ delete client;
}