17585SAli.Saidi@arm.com/* 210037SARM gem5 Developers * Copyright (c) 2010-2013 ARM Limited 37585SAli.Saidi@arm.com * All rights reserved 47585SAli.Saidi@arm.com * 57585SAli.Saidi@arm.com * The license below extends only to copyright in the software and shall 67585SAli.Saidi@arm.com * not be construed as granting a license to any other intellectual 77585SAli.Saidi@arm.com * property including but not limited to intellectual property relating 87585SAli.Saidi@arm.com * to a hardware implementation of the functionality of the software 97585SAli.Saidi@arm.com * licensed hereunder. You may use the software subject to the license 107585SAli.Saidi@arm.com * terms below provided that you ensure that this notice is replicated 117585SAli.Saidi@arm.com * unmodified and in its entirety in all distributions of the software, 127585SAli.Saidi@arm.com * modified or unmodified, in source code or in binary form. 137585SAli.Saidi@arm.com * 147585SAli.Saidi@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 157585SAli.Saidi@arm.com * All rights reserved. 167585SAli.Saidi@arm.com * 177585SAli.Saidi@arm.com * Redistribution and use in source and binary forms, with or without 187585SAli.Saidi@arm.com * modification, are permitted provided that the following conditions are 197585SAli.Saidi@arm.com * met: redistributions of source code must retain the above copyright 207585SAli.Saidi@arm.com * notice, this list of conditions and the following disclaimer; 217585SAli.Saidi@arm.com * redistributions in binary form must reproduce the above copyright 227585SAli.Saidi@arm.com * notice, this list of conditions and the following disclaimer in the 237585SAli.Saidi@arm.com * documentation and/or other materials provided with the distribution; 247585SAli.Saidi@arm.com * neither the name of the copyright holders nor the names of its 257585SAli.Saidi@arm.com * contributors may be used to endorse or promote products derived from 267585SAli.Saidi@arm.com * this software without specific prior written permission. 277585SAli.Saidi@arm.com * 287585SAli.Saidi@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 297585SAli.Saidi@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 307585SAli.Saidi@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 317585SAli.Saidi@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 327585SAli.Saidi@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 337585SAli.Saidi@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 347585SAli.Saidi@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 357585SAli.Saidi@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 367585SAli.Saidi@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 377585SAli.Saidi@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 387585SAli.Saidi@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 397585SAli.Saidi@arm.com * 407585SAli.Saidi@arm.com * Authors: Ali Saidi 417585SAli.Saidi@arm.com */ 427585SAli.Saidi@arm.com 437585SAli.Saidi@arm.com#ifndef __ARCH_ARM_LINUX_SYSTEM_HH__ 447585SAli.Saidi@arm.com#define __ARCH_ARM_LINUX_SYSTEM_HH__ 457585SAli.Saidi@arm.com 469332Sdam.sunwoo@arm.com#include <cstdio> 479332Sdam.sunwoo@arm.com#include <map> 487585SAli.Saidi@arm.com#include <string> 497585SAli.Saidi@arm.com#include <vector> 507585SAli.Saidi@arm.com 517585SAli.Saidi@arm.com#include "arch/arm/system.hh" 529332Sdam.sunwoo@arm.com#include "base/output.hh" 537585SAli.Saidi@arm.com#include "kern/linux/events.hh" 547585SAli.Saidi@arm.com#include "params/LinuxArmSystem.hh" 559332Sdam.sunwoo@arm.com#include "sim/core.hh" 569332Sdam.sunwoo@arm.com 579332Sdam.sunwoo@arm.comclass DumpStatsPCEvent; 587585SAli.Saidi@arm.com 5910810Sbr@bsdpad.comclass LinuxArmSystem : public GenericArmSystem 607585SAli.Saidi@arm.com{ 619332Sdam.sunwoo@arm.com protected: 629332Sdam.sunwoo@arm.com DumpStatsPCEvent *dumpStatsPCEvent; 639332Sdam.sunwoo@arm.com 647585SAli.Saidi@arm.com public: 657585SAli.Saidi@arm.com /** Boilerplate params code */ 667585SAli.Saidi@arm.com typedef LinuxArmSystemParams Params; 677585SAli.Saidi@arm.com const Params * 687585SAli.Saidi@arm.com params() const 697585SAli.Saidi@arm.com { 707585SAli.Saidi@arm.com return dynamic_cast<const Params *>(_params); 717585SAli.Saidi@arm.com } 727585SAli.Saidi@arm.com 739332Sdam.sunwoo@arm.com /** When enabled, dump stats/task info on context switches for 749332Sdam.sunwoo@arm.com * Streamline and per-thread cache occupancy studies, etc. */ 759332Sdam.sunwoo@arm.com bool enableContextSwitchStatsDump; 769332Sdam.sunwoo@arm.com 779332Sdam.sunwoo@arm.com /** This map stores a mapping of OS process IDs to internal Task IDs. The 789332Sdam.sunwoo@arm.com * mapping is done because the stats system doesn't tend to like vectors 799332Sdam.sunwoo@arm.com * that are much greater than 1000 items and the entire process space is 809332Sdam.sunwoo@arm.com * 65K. */ 819332Sdam.sunwoo@arm.com std::map<uint32_t, uint32_t> taskMap; 829332Sdam.sunwoo@arm.com 839332Sdam.sunwoo@arm.com /** This is a file that is placed in the run directory that prints out 849332Sdam.sunwoo@arm.com * mappings between taskIds and OS process IDs */ 8511359Sandreas@sandberg.pp.se OutputStream* taskFile; 869332Sdam.sunwoo@arm.com 877585SAli.Saidi@arm.com LinuxArmSystem(Params *p); 887585SAli.Saidi@arm.com ~LinuxArmSystem(); 897585SAli.Saidi@arm.com 907733SAli.Saidi@ARM.com void initState(); 917733SAli.Saidi@ARM.com 929332Sdam.sunwoo@arm.com void startup(); 939332Sdam.sunwoo@arm.com 949332Sdam.sunwoo@arm.com /** This function creates a new task Id for the given pid. 959332Sdam.sunwoo@arm.com * @param tc thread context that is currentyl executing */ 969332Sdam.sunwoo@arm.com void mapPid(ThreadContext* tc, uint32_t pid); 979332Sdam.sunwoo@arm.com 9811538Sandreas.sandberg@arm.com public: // Exported Python methods 9911538Sandreas.sandberg@arm.com /** 10011538Sandreas.sandberg@arm.com * Dump the kernel's dmesg buffer to stdout 10111538Sandreas.sandberg@arm.com */ 10211538Sandreas.sandberg@arm.com void dumpDmesg(); 10311538Sandreas.sandberg@arm.com 1047585SAli.Saidi@arm.com private: 1057585SAli.Saidi@arm.com /** Event to halt the simulator if the kernel calls panic() */ 1069649SAndreas.Sandberg@ARM.com PCEvent *kernelPanicEvent; 1079649SAndreas.Sandberg@ARM.com 1089649SAndreas.Sandberg@ARM.com /** Event to halt the simulator if the kernel calls oopses */ 1099649SAndreas.Sandberg@ARM.com PCEvent *kernelOopsEvent; 1109649SAndreas.Sandberg@ARM.com 1118143SAli.Saidi@ARM.com /** 1128143SAli.Saidi@ARM.com * PC based event to skip udelay(<time>) calls and quiesce the 1138143SAli.Saidi@ARM.com * processor for the appropriate amount of time. This is not functionally 1148143SAli.Saidi@ARM.com * required but does speed up simulation. 1158143SAli.Saidi@ARM.com */ 1168143SAli.Saidi@ARM.com Linux::UDelayEvent *uDelaySkipEvent; 1178143SAli.Saidi@ARM.com 1188143SAli.Saidi@ARM.com /** Another PC based skip event for const_udelay(). Similar to the udelay 1198143SAli.Saidi@ARM.com * skip, but this function precomputes the first multiply that is done 1208143SAli.Saidi@ARM.com * in the generic case since the parameter is known at compile time. 1218143SAli.Saidi@ARM.com * Thus we need to do some division to get back to us. 1228143SAli.Saidi@ARM.com */ 1238143SAli.Saidi@ARM.com Linux::UDelayEvent *constUDelaySkipEvent; 1248527SAli.Saidi@ARM.com 1257585SAli.Saidi@arm.com}; 1267585SAli.Saidi@arm.com 1279332Sdam.sunwoo@arm.comclass DumpStatsPCEvent : public PCEvent 1289332Sdam.sunwoo@arm.com{ 1299332Sdam.sunwoo@arm.com public: 1309332Sdam.sunwoo@arm.com DumpStatsPCEvent(PCEventQueue *q, const std::string &desc, Addr addr) 1319332Sdam.sunwoo@arm.com : PCEvent(q, desc, addr) 1329332Sdam.sunwoo@arm.com {} 1339332Sdam.sunwoo@arm.com 1349332Sdam.sunwoo@arm.com virtual void process(ThreadContext* tc); 13512090Sprosenfeld@micron.com protected: 13612090Sprosenfeld@micron.com virtual void getTaskDetails(ThreadContext *tc, uint32_t &pid, 13712090Sprosenfeld@micron.com uint32_t &tgid, std::string &next_task_str, int32_t &mm); 13812090Sprosenfeld@micron.com 13912090Sprosenfeld@micron.com}; 14012090Sprosenfeld@micron.com 14112090Sprosenfeld@micron.comclass DumpStatsPCEvent64 : public DumpStatsPCEvent { 14212090Sprosenfeld@micron.com public: 14312090Sprosenfeld@micron.com DumpStatsPCEvent64(PCEventQueue *q, const std::string &desc, Addr addr) 14412090Sprosenfeld@micron.com : DumpStatsPCEvent(q, desc, addr) 14512090Sprosenfeld@micron.com {} 14612090Sprosenfeld@micron.com private: 14712090Sprosenfeld@micron.com void getTaskDetails(ThreadContext *tc, uint32_t &pid, uint32_t &tgid, 14812090Sprosenfeld@micron.com std::string &next_task_str, int32_t &mm) override; 1499332Sdam.sunwoo@arm.com}; 1509332Sdam.sunwoo@arm.com 1519332Sdam.sunwoo@arm.com 1527585SAli.Saidi@arm.com#endif // __ARCH_ARM_LINUX_SYSTEM_HH__ 1537585SAli.Saidi@arm.com 154