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 那么臃肿庞大:源代码相当精炼.易 ...
随机推荐
- springboot的打包方式
先写一个测试接口 package com.example.demo; import org.springframework.web.bind.annotation.RequestMapping; im ...
- xmlns 啥意思
参考:https://blog.csdn.net/zhch152/article/details/8191377 前提科普:DTD 文档类型定义(Document Type Definition) 问 ...
- step_by_step_Angularjs-UI-Grid使用简介
了解 Angularjs UI-Grid 起因:项目需要一个可以固定列和表头的表格,因为表格要显示很多列,当水平滚动条拉至后边时可能无法看到前边的某些信息. 以前在angularjs 1.x 中一直都 ...
- 思科模拟器GNS3-2.1.8安装笔记 (适用于版本2.0.3以上的GNS3)
当前现阶段学习经常使用的路由交换设备主要来自于思科.华为和华三三家,这三家的设备操作配置大致类似,却又不尽相同.因为实体设备通常都非常昂贵,所以作为学习,我们通常会使用它们提供的模拟器.华为的模拟器是 ...
- ViewPager中Fragment的重复创建、复用问题
在ViewPager中的Fragment的生命周期 随着页面的切换 当前的展示页相邻的页面生命周期一直在变化 一开始 刚进入Activity时候,ViewPager默认初始化好前两个Fragment ...
- 转载:如何优雅的实现INotifyPropertyChanged接口
转载来源:http://www.cnblogs.com/TianFang/p/6240933.html 如何优雅的实现INotifyPropertyChanged接口 INotifyPropertyC ...
- node.js中对 redis 的安装和基本操作
一.win下安装redis https://github.com/MicrosoftArchive/redis/releases 下载Redis-x64-3.2.100.zip,然后解压,放到自定义目 ...
- jenkins远程执行脚本时报Bad version number in .class file
这几天在学习jenkins的持续集成和部署,到了最后一步启动服务的时候,遇到了一个这个Bad version number in .class file的报错(如下图). 这个报错在最开始手工部署的时 ...
- 自学elastic search
工作也有一段时间了,虽然来这个公司之后学会了几门不同的语言,但想拨尖还是任重道远. 想往高级程序员甚至是架构师方向发展.他仍然是我的学习对象.我现在做着的,无非是他玩剩下的罢了. luncene之前有 ...
- Lonsdor K518ISE programs 2005 Ford Focus key in two minutes
A quick demonstration of Lonsdor K518ISE programming key for 2005 Ford Focus in two minutes. And for ...