ppt報告 - 國立成功大學
Download
Report
Transcript ppt報告 - 國立成功大學
2015/4/13
Gem 5 - activate
SoC CAD
張力升
電機系, Department of Electrical Engineering
國立成功大學, National Cheng Kung University
Tainan, Taiwan, R.O.C
1
NCKU
SoC CAD
template <class Impl>
FullO3CPU<Impl>::ActivateThreadEvent::ActivateThreadEvent():
Event(CPU_Switch_Pri){
}
ActivateThreadEvent - construct
負責將CPU_Switch_Pri的值assign到Event裡
CpuEvent Definition:
CpuEvent::replaceThreadContext(ThreadContext *oldTc, ThreadContext
*newTc){
CpuEventList::iterator I
for (i = cpuEventList.begin(); i != cpuEventList.end(); i++) {
if ((*i)->tc == oldTc)
(*i)->tc = newTc;
}
}
// 把舊的thread更新為新者
Li-Sheng Chang, 張力升
SoC & ASIC Lab K- 2
NCKU
SoC CAD
ActivateThreadEvent繼承圖
ActivateThreadEvent 繼承之diagram
FullO3CPU<Impl>
ActivateThreadEvent
init
Li-Sheng Chang, 張力升
process
description
SoC & ASIC Lab
3
NCKU
SoC CAD
Member function - init (1/3)
template <class Impl>
void
FullO3CPU<Impl>::ActivateThreadEvent::init(int thread_num,
FullO3CPU<Impl> *thread_cpu)
{
tid = thread_num;
cpu = thread_cpu;
}
負責初始化Event
Li-Sheng Chang, 張力升
SoC & ASIC Lab K- 4
NCKU
SoC CAD
Member function - process(2/3)
template <class Impl>
void
FullO3CPU<Impl>::ActivateThreadEvent::process()
{
cpu->activateThread(tid);
}
負責處理Event,並將activateThread(tid) 的值傳到Cpu
Li-Sheng Chang, 張力升
SoC & ASIC Lab K- 5
NCKU
SoC CAD
Member function (3/3)
template <class Impl>
const char *
FullO3CPU<Impl>::ActivateThreadEvent:: description() const
{
return "FullO3CPU \"Activate Thread\"";
}
將“FullO3CPU \”Activate Thread\“” 之值傳送回去
Li-Sheng Chang, 張力升
SoC & ASIC Lab K- 6
NCKU
SoC CAD
ThreadID active_threads
Definition:
if (FullSystem) {
active_threads = 1; }
else {
active_threads = params->workload.size();
}
/*反之則params寫
入active_threads*/
if (active_threads > Impl::MaxThreads) {
panic("Workload Size too large. Increase the 'MaxThreads' "
"constant in your O3CPU impl. file (e.g. o3/alpha/impl.hh) "
"or edit your workload size.");
}
Li-Sheng Chang, 張力升
SoC & ASIC Lab K- 7
NCKU
SoC CAD
ThreadID tid 繼承圖
ThreadID tid繼承之diagram
FullO3CPU<Impl>
activateThread
Li-Sheng Chang, 張力升
deactivateThread
SoC & ASIC Lab
8
NCKU
SoC CAD
ThreadID activate_threads
Definition:
template <class Impl>
void
FullO3CPU<Impl>::activateThread(ThreadID tid)
{
if (isActive == activeThreads.end()) {
DPRINTF(O3CPU, "[tid:%i]: Adding to active threads list\n",
tid);
activeThreads.push_back(tid);
}
}
將tid的值回傳
Li-Sheng Chang, 張力升
SoC & ASIC Lab K- 9
NCKU
SoC CAD
ThreadID deactivateThread
Definition:
template <class Impl>
void
FullO3CPU<Impl>::activateThread(ThreadID tid){
if (thread_it != activeThreads.end()) {
DPRINTF(O3CPU,"[tid:%i]: Removing from active threads list\n",
tid);
activeThreads.erase(thread_it);
}
}
將thread_it的值刪去
Li-Sheng Chang, 張力升
SoC & ASIC Lab K- 10
NCKU
SoC CAD
activateContext
template <class Impl>
void
FullO3CPU<Impl>::activateContext(ThreadID tid, Cycles delay){
assert(!switchedOut());
//在此須先設定每個stage的運作
if (delay){
DPRINTF(O3CPU, “[tid:%i]: Scheduling thread context to activate ”
“on cycle %d\n”, tid, clockEdge(delay));
scheduleActivateThreadEvent(tid, delay);
} else { activateThread(tid); }
if (getDrainState() == Drainable::Drained)
return;
//不希望當cpu drained時把他喚醒,故僅標記及排程
if (lastActivatedCycle == 0 || lastActivatedCycle < curTick()) {
scheduleTickEvent(delay); /*假如time=0或最後的activation time is in the past,
進入下一個tick並喚醒擷取單位*/
activityRec.activity();
fetch.wakeFromQuiesce();
//記得要標記cpu尚未deschedule 的activity
Cycles cycles(curCycle() - lastRunningCycle);
if (cycles != 0) --cycles;
quiesceCycles += cycles;
lastActivatedCycle = curTick();
_status = Running; }}
Li-Sheng Chang, 張力升
SoC & ASIC Lab K- 11
NCKU
SoC CAD
activateContext - Drained
template <class Impl>
unsigned int
FullO3CPU<Impl>::drain(DrainManager *drain_manager){
// If the CPU isn‘t doing anything, then return immediately.
if (switchedOut()) {setDrainState(Drainable::Drained);
return 0; }
DPRINTF(Drain, “Draining...\n”);
setDrainState(Drainable::Draining) ;
if (!isDrained()) {
drainManager = drain_manager;
wakeCPU();
activityRec.activity();
DPRINTF(Drain, “CPU not drained\n”);
return 1;}
……….
}
Li-Sheng Chang, 張力升
SoC & ASIC Lab K- 12
NCKU
SoC CAD
activateContext - wakeup
template <class Impl>
void
FullO3CPU<Impl>::wakeup()
{
if (this->thread[0]->status() != ThreadContext::Suspended)
return;
this->wakeCPU();
}
DPRINTF(Quiesce, "Suspended Processor woken\n");
this->threadContexts[0]->activate();
Li-Sheng Chang, 張力升
SoC & ASIC Lab K- 13
NCKU
SoC CAD
activateContext - tick
template <class Impl>
void
FullO3CPU<Impl>::tick(){
DPRINTF(O3CPU, "\n\nFullO3CPU: Ticking main, FullO3CPU.\n");
assert(!switchedOut());
assert(getDrainState() != Drainable::Drained);
++numCycles;
fetch.tick();
decode.tick();
rename.tick();
iew.tick();
commit.tick(); //Tick each of the stages
……….
FullO3CPU class, has each of the stages (fetch through commit) within it, as well as all of
the time buffers between stages.
The tick () function for the CPU is defined here
template <class Impl>
void
FullO3CPU<Impl>::TickEvent::process(){
cpu->tick();
}
Li-Sheng Chang, 張力升
SoC & ASIC Lab K- 14
2015/4/13
Gem 5 - python
SoC CAD
張力升
電機系, Department of Electrical Engineering
國立成功大學, National Cheng Kung University
Tainan, Taiwan, R.O.C
15
NCKU
SoC CAD
物件導向、直譯式電腦程式語言,具有近二十年的發展歷史,
成熟且穩定
python
語法簡捷和清晰,盡量使用無異義的英語單詞,與其它數程式設計語言
使用大括弧不一樣,它使用縮進來定義語句塊。
與Ruby、Perl等動態語言大多一樣,Python具備Garbage Collection
功能,能夠自動管理記憶體使用。
Python虛擬機本身幾乎可以在所有的OS中運行。
使用一些諸如py2exe、PyPy、Pylnstaller之類的工具可以將Python原始碼轉
換成可以脫離Python解釋器執行的程式。
Li-Sheng Chang, 張力升
SoC & ASIC Lab
16
SoC CAD
NCKU
Python – alarm example
from Tkinter import *
class Alarm(Frame):
def repeater(self):
self.bell()
self.after(self.msecs, self.repeater)
def __init__(self):
Frame.__init__(self)
self.msecs = 1000
self.pack()
stopper = Button(self, text='Stop the beeps!', command=self.quit)
stopper.pack()
stopper.config(bg='navy', fg='white', bd=8)
self.stopper = stopper
self.repeater()
if __name__ == '__main__':
Alarm().mainloop()
Li-Sheng Chang, 張力升
SoC & ASIC Lab
17