Buffer.h
#ifndef __NOXIMBUFFER_H__
#define __NOXIMBUFFER_H__ #include <cassert>
#include <queue>
#include "DataStructs.h"
using namespace std;
class Buffer {
.................
};
#endif
public:
Buffer(); //构造函数
virtual ~ Buffer() {//虚析构函数解决因delete基类指针导致的资源泄漏
}
Buffer::Buffer()
{
SetMaxBufferSize(GlobalParams::buffer_depth);
max_occupancy = ;
hold_time = 0.0;
last_event = 0.0;
hold_time_sum = 0.0;
previous_occupancy = ;
mean_occupancy = 0.0;
true_buffer = true;
full_cycles_counter = ;
last_front_flit_seq = NOT_VALID;
deadlock_detected = false;
}
Buffer()
void SetMaxBufferSize(const unsigned int bms); // Set buffer max size (in flits)
unsigned int GetMaxBufferSize() const; // Get max buffer size
unsigned int getCurrentFreeSlots() const; // free buffer slots
bool IsFull() const; // Returns true if buffer is full
bool IsEmpty() const; // Returns true if buffer is empty
virtual void Drop(const Flit & flit) const; // Called by Push() when buffer is full
virtual void Empty() const; // Called by Pop() when buffer is empty
void Push(const Flit & flit); // Push a flit. Calls Drop method if buffer is full
Flit Pop(); // Pop a flit
Flit Front() const; // Return a copy of the first flit in the buffer
unsigned int Size() const;
void ShowStats(std::ostream & out);
void Disable();
void Print();
bool deadlockFree();
void deadlockCheck();
void setLabel(string);
string getLabel() const;
void Buffer::SetMaxBufferSize(const unsigned int bms)
{
assert(bms > ); max_buffer_size = bms;
}
SetMaxBufferSize(const unsigned int bms)
unsigned int Buffer::GetMaxBufferSize() const
{
return max_buffer_size;
}
GetMaxBufferSize() const
unsigned int Buffer::getCurrentFreeSlots() const
{
return (GetMaxBufferSize() - Size());
}
getCurrentFreeSlots() const
unsigned int Buffer::Size() const
{
return buffer.size();
}
Size() const
bool Buffer::IsFull() const
{
return buffer.size() == max_buffer_size;
} bool Buffer::IsEmpty() const
{
return buffer.size() == ;
} void Buffer::Drop(const Flit & flit) const
{
assert(false);
} void Buffer::Empty() const
{
assert(false);
}
void Buffer::Push(const Flit & flit)
{
SaveOccupancyAndTime(); if (IsFull())
Drop(flit);
else
buffer.push(flit); UpdateMeanOccupancy(); if (max_occupancy < buffer.size())
max_occupancy = buffer.size();
}
Push(const Flit & flit)
Flit Buffer::Pop()
{
Flit f; SaveOccupancyAndTime(); if (IsEmpty())
Empty();
else {
f = buffer.front();
buffer.pop();
} UpdateMeanOccupancy(); return f;
}
Pop()
Flit Buffer::Front() const
{
Flit f; if (IsEmpty())
Empty();
else
f = buffer.front(); return f;
}
Front() const
void Buffer::SaveOccupancyAndTime()
{
previous_occupancy = buffer.size();
hold_time = (sc_time_stamp().to_double() / GlobalParams::clock_period_ps) - last_event;
last_event = sc_time_stamp().to_double() / GlobalParams::clock_period_ps;
}
SaveOccupancyAndTime()
void Buffer::UpdateMeanOccupancy()
{
double current_time = sc_time_stamp().to_double() / GlobalParams::clock_period_ps;
if (current_time - GlobalParams::reset_time < GlobalParams::stats_warm_up_time)
return; mean_occupancy = mean_occupancy * (hold_time_sum/(hold_time_sum+hold_time)) + (1.0/(hold_time_sum+hold_time)) * hold_time * buffer.size();
hold_time_sum += hold_time;
}
UpdateMeanOccupancy()
void Buffer::ShowStats(std::ostream & out)
{
if (true_buffer)
out << "\t" << mean_occupancy << "\t" << max_occupancy;
else
out << "\t\t";
}
ShowStats(std::ostream & out)
void Buffer::setLabel(string l)
{
//cout << "\n BUFFER LABEL: " << l << endl;
label = l;
} string Buffer::getLabel() const
{
return label;
} void Buffer::Print()
{
queue<Flit> m = buffer; string bstr = ""; char t[] = "HBT"; cout << label << " | ";
while (!(m.empty()))
{
Flit f = m.front();
m.pop();
cout << bstr << t[f.flit_type] << f.sequence_no << "(" << f.dst_id << ") | ";
}
cout << endl;
}
void Buffer::deadlockCheck()
{
// TOOD: add as parameter
int check_threshold = ; if (IsEmpty()) return; Flit f = buffer.front();
int seq = f.sequence_no; if (last_front_flit_seq == seq)
{
full_cycles_counter++;
}
else
{
if (deadlock_detected)
{
cout << " WRONG DEADLOCK detection, please increase the check_threshold " << endl;
assert(false);
}
last_front_flit_seq = seq;
full_cycles_counter=;
} if (full_cycles_counter>check_threshold && !deadlock_detected)
{
double current_time = sc_time_stamp().to_double() / GlobalParams::clock_period_ps;
cout << "WARNING: DEADLOCK DETECTED at cycle " << current_time << " in buffer: " << getLabel() << endl;
deadlock_detected = true;
}
}
deadlockCheck()
bool Buffer::deadlockFree()
{
if (IsEmpty()) return true; Flit f = buffer.front(); int seq = f.sequence_no; if (last_front_flit_seq==seq)
{
full_cycles_counter++;
}
else
{
last_front_flit_seq = seq;
full_cycles_counter=;
}
if (full_cycles_counter>)
{
return false;
}
return true;
}
deadlockFree()
void Buffer::Disable()
{
true_buffer = false;
}
private:
bool true_buffer;
bool deadlock_detected; int full_cycles_counter;
int last_front_flit_seq; string label; unsigned int max_buffer_size; queue < Flit > buffer; unsigned int max_occupancy;
double hold_time, last_event, hold_time_sum;
double mean_occupancy;
int previous_occupancy; void SaveOccupancyAndTime();
void UpdateMeanOccupancy();
Buffer.h的更多相关文章
- Libevent源码学习笔记一:event2/event.h
一.libevent标准使用方法: 每个程序使用Libevent必须include <event2/event.h> 头文件,并 传给 -levent 链接器.如果只是想使用主要的eve ...
- 一种循环buffer结构
最新数据循环在buffer[H] -> buffer[L] 放置,记录最新放置Index,对外接口获取数据时,进行两次数据拷贝,Index-H ,index-L 拷贝到数组里
- 反应器(Reactor)和主动器(Proactor)
网络方面用的比较多的库是libevent和boost.asio,两者都是跨平台的.其中libevent是基于Reactor实现的,而boost.asio是基于Proactor实现的.Reactor和P ...
- 简单编写Makefile
相信很多朋友都有过这样的经历,看着开源项目中好几页的makefile文件,不知所云.在日常学习和工作中,也有意无意的去回避makefile,能改就不写,能用ide就用ide.其实makefile并没有 ...
- Makefile文件学习总结
Makefile文件相当于是一种脚本编程语言,目的是实现自动化编译.编写makefile文件的过程中可以使用变量.控制结构和函数等一般编程语言的特性. Makefile文件的组成内容.makefile ...
- 怎么写makefile?(转)
跟我一起写 Makefile 陈皓 第一章.概述 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和 pr ...
- 【转】Linux makefile 教程 非常详细,且易懂
From: http://blog.csdn.net/liang13664759/article/details/1771246 最近在学习Linux下的C编程,买了一本叫<Linux环境下的C ...
- POCO库——Foundation组件之核心Core
核心Core: Version.h:版本控制信息,宏POCO_VERSION,值格式采用0xAABBCCDD,分别代表主版本.次版本.补丁版本.预发布版本: Poco.h:简单地包含了头文件Found ...
- Libevent初探
Libevent 是一个用C语言编写的.轻量级的开源高性能网络库,主要有以下几个亮点:事件驱动( event-driven),高性能;轻量级,专注于网络,不如 ACE 那么臃肿庞大:源代码相当精炼.易 ...
随机推荐
- setCapture 使用方法
setCapture 可以捕获到 移动到浏览器外的鼠标事件. 例如拖动过程中,即使鼠标移动到了浏览器外,拖动程序依然可以执行! 作用就是把 把鼠标事件 捕获到 当前文档指定的对象! setCaptur ...
- CentOS7搭建Zookeeper环境
Linux下安装JDK 1.检查一下系统中的jdk版本 [root@localhost software]# java -version 显示: openjdk version "1.8.0 ...
- c3p0数据源的第一次尝试
开始补习 以前学习过的基础 正在尝试从c3p0 获取到connection 好的,首先上代码吧 public static DataSource ds = null; static { ComboPo ...
- python标准库之operator(运算符模块)
operator模块提供了一系列与Python自带操作一样有效的函数.例如:operator.add(x, y)和表达式x+y是等效的.那些特殊类的方法都有自己的函数名:为了方便起见,一些函数名是没有 ...
- C#给checkboxList设置js选中事件
C#: for (int i = 0; i < this.CheckBoxList1.Items.Count; i++) { this.CheckBoxL ...
- 长短steamId互转
/** * steam_id转换account_id * @param $steamId * @return mixed */ public static function formatAccount ...
- Unity PRO 2018.3.3f1 for MAC+完美pojie补丁!!!
Unity Pro 2018 for mac是游戏开发必备的软件之一,Unity mac 版主要用于创建2D和3D跨平台游戏,比如三维视频游戏.实时三维动画.建筑可视化等类型,最新版本的Unity P ...
- 如何看iOS崩溃日志
重点:Triggered by Thread这句话后边的线程号,快速定位问题出现在那个线程,是否是你的锅:Triggered by Thread所指的线程表示导致异常.崩溃的线程 下边内容转自简书 简 ...
- 进军的socket
在学socket有时候我们会遇到这种问题: 解决方法一: 在服务端中加入:severTCP.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) ...
- python课程安排
作为最流行的脚本语言之一,python具有内置的高级数据结构和简单面向对象编程思想实现.同时,其语法简洁而清晰,类库丰富而强大,非常适合进行快速原型开发.另外,python可以运行在多种系统平台下,从 ...