#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. 基于Keepalived的MySQL高可用

    keepalived负责的是故障转移,至于故障转以后的节点之间数据的一致性问题依赖于具体的复制模式.不管是主从.一主多从还是双主.集群节点个数.主从具体的模式无关(常规复制,半同步复制,GTID复制, ...

  2. 小A买彩票-(组合数)

    链接:https://ac.nowcoder.com/acm/contest/549/C来源:牛客网 题目描述 小A最近开始沉迷买彩票,并且希望能够通过买彩票发家致富.已知购买一张彩票需要3元,而彩票 ...

  3. webpack 4.0配置2

    上个博客记录了webpack 的基本配置今天主要是css-loader的介绍,包括单独提出css,压缩css.js文件 这里使用的插件npm 地址:https://www.npmjs.com/pack ...

  4. window备忘录

    1.window.name属性是一个字符串,表示当前窗口的名字,只有当浏览器窗口关闭的时候,此属性才会消失. 2.window.closed属性返回一个布尔值,表示窗口是否关闭.此属性一般用来检查使用 ...

  5. SpringCloud-day09-Feign与Hystrix整合

    8.5.Feign 与 Hystrix整合 服务熔断服务降级彻底解耦 前面的代码,用@HystrixCommand fallbackMethod是很不好的,因为和业务代码耦合度太高,不利于维护,所以需 ...

  6. phpstorm界面不停的indexing,不停的闪烁

    选择 File->Invalidate Caches / Restart...->Invalidate and Restart,就行了!

  7. Arrays和String单元测试-20175218

    Arrays和String单元测试 一.题目 在IDEA中以TDD的方式对String类和Arrays类进行学习 测试相关方法的正常,错误和边界情况 String类 charAt split Arra ...

  8. Ubuntu 增加swap空间大小

    1. create a 1G file for the swap. sudo fallocate -l 1G /swapfile we can verify that the correct amou ...

  9. Hillstone防火墙sslvpn配置与使用

    1.山石的sslvpn称为Secure Connect VPN,即scvpn. 2.WEB界面登陆防火墙,“用户”,“AAA服务器”,新建用户: 3.定义源IP池 即用户通过sslvpn拨号成功后获取 ...

  10. UML图之类图(转)

    基本概念 类图(Class Diagram): 类图是面向对象系统建模中最常用和最重要的图,是定义其它图的基础.类图主要是用来显示系统中的类.接口以及它们之间的静态结构和关系的一种静态模型. 类图的3 ...