#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. 【转】WPS word 文档中的插入对象 为什么打不开

    点击桌面左下角开始按钮--所有程序,找到wps office文件夹--wps office工具--配置工具--高级--兼容设置,否选兼容第三方软件.

  2. Homework:小写字母转大写字母

    // 功能: // 从键盘上输入单个字符 // 如果是小写字母,则转换成大写后输出 // 否则,什么也不做,原样输出 #include <stdio.h> int main() { cha ...

  3. layui-xtree 设置单选框,只能选一个

    以下是js代码,首先获取所有节点,再设置只有当前点击的节点状态为选中状态 $.ajax({ type: 'get', url: url, error: function(err){ layer.ale ...

  4. C++ 数组和字符串

    数组和字符串的基本知识 目录 一.数组的声明 二.字符串 一.数组的声明 1.1.存储在每个元素中的值得类型: 1.2.数组名: 1.3.数组中的元素数. ];//short 数组元素值的类型,a数组 ...

  5. Java框架spring 学习笔记(十三):log4j介绍

    功能 日志功能,通过log4j可以看到程序运行过程的详细信息. 使用 导入log4j的jar包 复制log4j的配置文件,复制到src下面   3.设置日志级别 info:看到基本信息 debug:看 ...

  6. python 网络编程粘包解决方案2 + ftp上传 + socketserver

    一.struct 神奇的打包工具 struct 代码: import struct num = 156 #将int类型的数据打包成4个字节的数据 num_stru = struct.pack('i', ...

  7. List和符号分隔的字符串互相转换

    一.将逗号分隔的字符串转换成List: 1. 使用JDK的Arrays类: import java.util.Arrays; import java.util.List; public class T ...

  8. python之元组及其方法---整理集

    元组: 区别:与列表类似,是对列表的二次加工:用小括号包括起来:元素不可修改:不可增加.删除 技巧:创建元组的时候,一般在最后一个元素后面加一个逗号:为了与方法区分:并且这个逗号不算元素例如: tu= ...

  9. Windows 窗体

    Windows系统,顾名思义,就是窗口系统,每一个程序都可以用窗口来展示,所以,为了展示窗口,需要多做一系列的工作,当然,也有纯控制台应用,就不用附带窗口了. 首先就是窗口程序的入口地址,与传统的in ...

  10. JS-jquery对象和dom对象的属性操作区别

    <label class="">时间1</label> <label class="">时间2</label> ...