scheduler.cc revision 12953:ddfd5e4643a9
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright 2018 Google, Inc. 36145Snate@binkert.org * 46145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 56145Snate@binkert.org * modification, are permitted provided that the following conditions are 66145Snate@binkert.org * met: redistributions of source code must retain the above copyright 76145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 86145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 96145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 106145Snate@binkert.org * documentation and/or other materials provided with the distribution; 116145Snate@binkert.org * neither the name of the copyright holders nor the names of its 126145Snate@binkert.org * contributors may be used to endorse or promote products derived from 136145Snate@binkert.org * this software without specific prior written permission. 146145Snate@binkert.org * 156145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 166145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 176145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 186145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 196145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 206145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 216145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 226145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 236145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 246145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 256145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 266145Snate@binkert.org * 276145Snate@binkert.org * Authors: Gabe Black 286145Snate@binkert.org */ 296145Snate@binkert.org 307054Snate@binkert.org#include "systemc/core/scheduler.hh" 317054Snate@binkert.org 327054Snate@binkert.org#include "base/fiber.hh" 337054Snate@binkert.org 346145Snate@binkert.orgnamespace sc_gem5 356145Snate@binkert.org{ 367054Snate@binkert.org 377054Snate@binkert.orgScheduler::Scheduler() : _numCycles(0), _current(nullptr) {} 386145Snate@binkert.org 397002Snate@binkert.orgvoid 407454Snate@binkert.orgScheduler::initialize() 417002Snate@binkert.org{ 426154Snate@binkert.org update(); 437054Snate@binkert.org 446154Snate@binkert.org while (!initList.empty()) 456145Snate@binkert.org ready(initList.getNext()); 466145Snate@binkert.org 476145Snate@binkert.org delta(); 486145Snate@binkert.org} 496145Snate@binkert.org 507054Snate@binkert.orgvoid 517054Snate@binkert.orgScheduler::runCycles() 527054Snate@binkert.org{ 537054Snate@binkert.org while (!readyList.empty()) { 546145Snate@binkert.org evaluate(); 556145Snate@binkert.org update(); 567054Snate@binkert.org delta(); 577054Snate@binkert.org } 587054Snate@binkert.org} 597054Snate@binkert.org 607054Snate@binkert.orgvoid 616145Snate@binkert.orgScheduler::yield() 627454Snate@binkert.org{ 637454Snate@binkert.org _current = readyList.getNext(); 647054Snate@binkert.org if (!_current) { 657054Snate@binkert.org // There are no more processes, so return control to evaluate. 667054Snate@binkert.org Fiber::primaryFiber()->run(); 677054Snate@binkert.org } else { 687054Snate@binkert.org _current->popListNode(); 697054Snate@binkert.org // Switch to whatever Fiber is supposed to run this process. All 706145Snate@binkert.org // Fibers which aren't running should be parked at this line. 717054Snate@binkert.org _current->fiber()->run(); 726145Snate@binkert.org // If the current process hasn't been started yet, start it. This 737054Snate@binkert.org // should always be true for methods, but may not be true for threads. 747054Snate@binkert.org if (_current && !_current->running()) 757054Snate@binkert.org _current->run(); 766145Snate@binkert.org } 777054Snate@binkert.org} 786145Snate@binkert.org 797054Snate@binkert.orgvoid 807054Snate@binkert.orgScheduler::evaluate() 817054Snate@binkert.org{ 827054Snate@binkert.org if (!readyList.empty()) 836145Snate@binkert.org _numCycles++; 847054Snate@binkert.org 856145Snate@binkert.org do { 867054Snate@binkert.org yield(); 877454Snate@binkert.org } while (!readyList.empty()); 887454Snate@binkert.org} 897454Snate@binkert.org 907454Snate@binkert.orgvoid 917054Snate@binkert.orgScheduler::update() 927054Snate@binkert.org{ 937054Snate@binkert.org} 947054Snate@binkert.org 956145Snate@binkert.orgvoid 966145Snate@binkert.orgScheduler::delta() 977054Snate@binkert.org{ 987054Snate@binkert.org} 996145Snate@binkert.org 1007054Snate@binkert.orgScheduler scheduler; 1017054Snate@binkert.org 1027054Snate@binkert.org} // namespace sc_gem5 1036145Snate@binkert.org