#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的更多相关文章

  1. Libevent源码学习笔记一:event2/event.h

    一.libevent标准使用方法: 每个程序使用Libevent必须include <event2/event.h> 头文件,并 传给 -levent  链接器.如果只是想使用主要的eve ...

  2. 一种循环buffer结构

    最新数据循环在buffer[H] -> buffer[L] 放置,记录最新放置Index,对外接口获取数据时,进行两次数据拷贝,Index-H ,index-L 拷贝到数组里

  3. 反应器(Reactor)和主动器(Proactor)

    网络方面用的比较多的库是libevent和boost.asio,两者都是跨平台的.其中libevent是基于Reactor实现的,而boost.asio是基于Proactor实现的.Reactor和P ...

  4. 简单编写Makefile

    相信很多朋友都有过这样的经历,看着开源项目中好几页的makefile文件,不知所云.在日常学习和工作中,也有意无意的去回避makefile,能改就不写,能用ide就用ide.其实makefile并没有 ...

  5. Makefile文件学习总结

    Makefile文件相当于是一种脚本编程语言,目的是实现自动化编译.编写makefile文件的过程中可以使用变量.控制结构和函数等一般编程语言的特性. Makefile文件的组成内容.makefile ...

  6. 怎么写makefile?(转)

    跟我一起写 Makefile 陈皓 第一章.概述 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和 pr ...

  7. 【转】Linux makefile 教程 非常详细,且易懂

    From: http://blog.csdn.net/liang13664759/article/details/1771246 最近在学习Linux下的C编程,买了一本叫<Linux环境下的C ...

  8. POCO库——Foundation组件之核心Core

    核心Core: Version.h:版本控制信息,宏POCO_VERSION,值格式采用0xAABBCCDD,分别代表主版本.次版本.补丁版本.预发布版本: Poco.h:简单地包含了头文件Found ...

  9. Libevent初探

    Libevent 是一个用C语言编写的.轻量级的开源高性能网络库,主要有以下几个亮点:事件驱动( event-driven),高性能;轻量级,专注于网络,不如 ACE 那么臃肿庞大:源代码相当精炼.易 ...

随机推荐

  1. ExtJS4.2下将表单元素放在菜单时不能进行拷贝的问题解决办法

    通过浏览器F12我们发现,在菜单对应的dom元素上面,有几个系统附加的事件处理函数,只要我们将它去掉就可以了.示意代码如下: { xtype: "button", scope: z ...

  2. 【读书笔记】segment routing mpls数据平面-1

  3. H5页面移动端IOS键盘收起焦点错位

    出现场景:IOS端,在弹出层点击input时调起键盘页面会被顶上去document.body.scrollOffset大于0,收起键盘时scrollOffset不变,造成焦点错位. 注:安卓手机点击时 ...

  4. JS工具类

    封装了开发中常用的操作 并添加了一些扩展方法供调用 var util = { //获取Url中的参数(不支持中文) getParams: function() { var url = location ...

  5. 简单的页面互点Javascript代码

    简单的页面互点Javascript代码,可以适用于前端$(function(){ $('.ip_b_con_item li,.pro_index_list li').mouseover(functio ...

  6. django之组件

    (Django) 组件:本质上就是将一个写好的功能模块的html文件直接引入html目标文件,利用其功能. 标准语法: {% include 'html文件名' %} 如:{% include 'na ...

  7. fail-fast和fail-safe的区别

    fail-fast(快速失败):多线程情况下,一个线程通过迭代器读取集合中的值时,另一个线程修改了集合,则会抛出ConcurrentModificationException异常: 集合中通过modC ...

  8. Opencv-Python学习笔记(二)

    2. 使用OpenCV3处理图像 2.1 不同色彩空间的转换 OpenCV中有数百种关于在不同色彩空间之间转换的方法. 三种常用色彩空间:灰度.BGR.HSV(Hue色调,Saturation饱和度, ...

  9. CentOS 7 lnmp环境配置laravel项目的问题总结!

    一.最常见的几个问题 1.部署好站点后,访问站点的时候始终是“File Not Found”!(nginx中的路由配置问题) 2.除了根目录可以访问其它的访问全是403问题!(权限问题) 3.除了根目 ...

  10. layerweb弹层组件(SSH框架下)

    action类 这里主要看业务方法中表单路径中的(isClose = "1";return resUri;) public class MaterialsAction extend ...