From: Nathan Binkert Date: Fri, 11 Mar 2005 23:28:38 +0000 (-0500) Subject: stick all python stuff into a top level python directory. X-Git-Tag: m5_1.0_tutorial~75^2~5^2~1 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cf05fa476df711f64d0481117cf075ce68676d57;p=gem5.git stick all python stuff into a top level python directory. create an m5 package in python/m5 move the objects package into the m5 package move the m5config into the m5 package as config leave both importers outside of the package. SConscript: sim/main.cc: move sim/pyconfig/* -> python python/SConscript: m5config.py -> m5/config.py (now automatically embedded) objects -> python/m5/objects embed all python files in python/m5 python/m5/config.py: importer renamed mpy_importer move code to m5/__init__.py test/genini.py: deal with new python organization keep track of paths we want to add and add them after parameters are parsed. --HG-- rename : sim/pyconfig/SConscript => python/SConscript rename : sim/pyconfig/m5config.py => python/m5/config.py rename : objects/AlphaConsole.mpy => python/m5/objects/AlphaConsole.mpy rename : objects/AlphaTLB.mpy => python/m5/objects/AlphaTLB.mpy rename : objects/BadDevice.mpy => python/m5/objects/BadDevice.mpy rename : objects/BaseCPU.mpy => python/m5/objects/BaseCPU.mpy rename : objects/BaseCache.mpy => python/m5/objects/BaseCache.mpy rename : objects/BaseSystem.mpy => python/m5/objects/BaseSystem.mpy rename : objects/Bus.mpy => python/m5/objects/Bus.mpy rename : objects/CoherenceProtocol.mpy => python/m5/objects/CoherenceProtocol.mpy rename : objects/Device.mpy => python/m5/objects/Device.mpy rename : objects/DiskImage.mpy => python/m5/objects/DiskImage.mpy rename : objects/Ethernet.mpy => python/m5/objects/Ethernet.mpy rename : objects/Ide.mpy => python/m5/objects/Ide.mpy rename : objects/IntrControl.mpy => python/m5/objects/IntrControl.mpy rename : objects/MemTest.mpy => python/m5/objects/MemTest.mpy rename : objects/Pci.mpy => python/m5/objects/Pci.mpy rename : objects/PhysicalMemory.mpy => python/m5/objects/PhysicalMemory.mpy rename : objects/Platform.mpy => python/m5/objects/Platform.mpy rename : objects/Process.mpy => python/m5/objects/Process.mpy rename : objects/Repl.mpy => python/m5/objects/Repl.mpy rename : objects/Root.mpy => python/m5/objects/Root.mpy rename : objects/SimConsole.mpy => python/m5/objects/SimConsole.mpy rename : objects/SimpleDisk.mpy => python/m5/objects/SimpleDisk.mpy rename : objects/Tsunami.mpy => python/m5/objects/Tsunami.mpy rename : objects/Uart.mpy => python/m5/objects/Uart.mpy extra : convert_revision : aebf6ccda33028b1125974ca8b6aeab6f7570f30 --- diff --git a/SConscript b/SConscript index 19f84f913..cff240a69 100644 --- a/SConscript +++ b/SConscript @@ -183,6 +183,9 @@ base_sources = Split(''' mem/trace/mem_trace_writer.cc mem/trace/m5_writer.cc + python/pyconfig.cc + python/embedded_py.cc + sim/builder.cc sim/configfile.cc sim/debug.cc @@ -199,8 +202,6 @@ base_sources = Split(''' sim/stat_control.cc sim/trace_context.cc sim/universe.cc - sim/pyconfig/pyconfig.cc - sim/pyconfig/embedded_py.cc ''') # MySql sources @@ -376,7 +377,7 @@ env.Command(Split('''arch/alpha/decoder.cc # SConscript-local is the per-config build, which just copies some # header files into a place where they can be found. SConscript('libelf/SConscript-local', exports = 'env', duplicate=0) -SConscript('sim/pyconfig/SConscript', exports = ['env'], duplicate=0) +SConscript('python/SConscript', exports = ['env'], duplicate=0) # This function adds the specified sources to the given build diff --git a/objects/AlphaConsole.mpy b/objects/AlphaConsole.mpy deleted file mode 100644 index 79918a01e..000000000 --- a/objects/AlphaConsole.mpy +++ /dev/null @@ -1,9 +0,0 @@ -from Device import PioDevice - -simobj AlphaConsole(PioDevice): - type = 'AlphaConsole' - cpu = Param.BaseCPU(Super, "Processor") - disk = Param.SimpleDisk("Simple Disk") - num_cpus = Param.Int(1, "Number of CPUs") - sim_console = Param.SimConsole(Super, "The Simulator Console") - system = Param.BaseSystem(Super, "system object") diff --git a/objects/AlphaTLB.mpy b/objects/AlphaTLB.mpy deleted file mode 100644 index 8e7cd62cc..000000000 --- a/objects/AlphaTLB.mpy +++ /dev/null @@ -1,12 +0,0 @@ -simobj AlphaTLB(SimObject): - type = 'AlphaTLB' - abstract = True - size = Param.Int("TLB size") - -simobj AlphaDTB(AlphaTLB): - type = 'AlphaDTB' - size = 64 - -simobj AlphaITB(AlphaTLB): - type = 'AlphaITB' - size = 48 diff --git a/objects/BadDevice.mpy b/objects/BadDevice.mpy deleted file mode 100644 index 35a12e0bf..000000000 --- a/objects/BadDevice.mpy +++ /dev/null @@ -1,5 +0,0 @@ -from Device import PioDevice - -simobj BadDevice(PioDevice): - type = 'BadDevice' - devicename = Param.String("Name of device to error on") diff --git a/objects/BaseCPU.mpy b/objects/BaseCPU.mpy deleted file mode 100644 index 484fcccd6..000000000 --- a/objects/BaseCPU.mpy +++ /dev/null @@ -1,25 +0,0 @@ -simobj BaseCPU(SimObject): - type = 'BaseCPU' - abstract = True - icache = Param.BaseMem(NULL, "L1 instruction cache object") - dcache = Param.BaseMem(NULL, "L1 data cache object") - - if Bool._convert(env.get('FULL_SYSTEM', 'False')): - dtb = Param.AlphaDTB("Data TLB") - itb = Param.AlphaITB("Instruction TLB") - mem = Param.FunctionalMemory("memory") - system = Param.BaseSystem(Super, "system object") - else: - workload = VectorParam.Process("processes to run") - - max_insts_all_threads = Param.Counter(0, - "terminate when all threads have reached this inst count") - max_insts_any_thread = Param.Counter(0, - "terminate when any thread reaches this inst count") - max_loads_all_threads = Param.Counter(0, - "terminate when all threads have reached this load count") - max_loads_any_thread = Param.Counter(0, - "terminate when any thread reaches this load count") - - defer_registration = Param.Bool(False, - "defer registration with system (for sampling)") diff --git a/objects/BaseCache.mpy b/objects/BaseCache.mpy deleted file mode 100644 index 98a422e30..000000000 --- a/objects/BaseCache.mpy +++ /dev/null @@ -1,38 +0,0 @@ -from BaseMem import BaseMem - -simobj BaseCache(BaseMem): - type = 'BaseCache' - adaptive_compression = Param.Bool(False, - "Use an adaptive compression scheme") - assoc = Param.Int("associativity") - block_size = Param.Int("block size in bytes") - compressed_bus = Param.Bool(False, - "This cache connects to a compressed memory") - compression_latency = Param.Int(0, - "Latency in cycles of compression algorithm") - do_copy = Param.Bool(False, "perform fast copies in the cache") - hash_delay = Param.Int(1, "time in cycles of hash access") - in_bus = Param.Bus(NULL, "incoming bus object") - lifo = Param.Bool(False, - "whether this NIC partition should use LIFO repl. policy") - max_miss_count = Param.Counter(0, - "number of misses to handle before calling exit") - mshrs = Param.Int("number of MSHRs (max outstanding requests)") - out_bus = Param.Bus("outgoing bus object") - prioritizeRequests = Param.Bool(False, - "always service demand misses first") - protocol = Param.CoherenceProtocol(NULL, "coherence protocol to use") - repl = Param.Repl(NULL, "replacement policy") - size = Param.Int("capacity in bytes") - split = Param.Bool(False, "whether or not this cache is split") - split_size = Param.Int(0, - "How many ways of the cache belong to CPU/LRU partition") - store_compressed = Param.Bool(False, - "Store compressed data in the cache") - subblock_size = Param.Int(0, - "Size of subblock in IIC used for compression") - tgts_per_mshr = Param.Int("max number of accesses per MSHR") - trace_addr = Param.Addr(0, "address to trace") - two_queue = Param.Bool(False, - "whether the lifo should have two queue replacement") - write_buffers = Param.Int(8, "number of write buffers") diff --git a/objects/BaseSystem.mpy b/objects/BaseSystem.mpy deleted file mode 100644 index 1cbdf4e99..000000000 --- a/objects/BaseSystem.mpy +++ /dev/null @@ -1,15 +0,0 @@ -simobj BaseSystem(SimObject): - type = 'BaseSystem' - abstract = True - memctrl = Param.MemoryController(Super, "memory controller") - physmem = Param.PhysicalMemory(Super, "phsyical memory") - kernel = Param.String("file that contains the kernel code") - console = Param.String("file that contains the console code") - pal = Param.String("file that contains palcode") - readfile = Param.String("", "file to read startup script from") - init_param = Param.UInt64(0, "numerical value to pass into simulator") - boot_osflags = Param.String("a", "boot flags to pass to the kernel") - system_type = Param.UInt64("Type of system we are emulating") - system_rev = Param.UInt64("Revision of system we are emulating") - bin = Param.Bool(False, "is this system binned") - binned_fns = VectorParam.String([], "functions broken down and binned") diff --git a/objects/Bus.mpy b/objects/Bus.mpy deleted file mode 100644 index 025d69785..000000000 --- a/objects/Bus.mpy +++ /dev/null @@ -1,6 +0,0 @@ -from BaseHier import BaseHier - -simobj Bus(BaseHier): - type = 'Bus' - clock_ratio = Param.Int("ratio of CPU to bus frequency") - width = Param.Int("bus width in bytes") diff --git a/objects/CoherenceProtocol.mpy b/objects/CoherenceProtocol.mpy deleted file mode 100644 index f3b0026b7..000000000 --- a/objects/CoherenceProtocol.mpy +++ /dev/null @@ -1,6 +0,0 @@ -class Coherence(Enum): vals = ['uni', 'msi', 'mesi', 'mosi', 'moesi'] - -simobj CoherenceProtocol(SimObject): - type = 'CoherenceProtocol' - do_upgrades = Param.Bool(True, "use upgrade transactions?") - protocol = Param.Coherence("name of coherence protocol") diff --git a/objects/Device.mpy b/objects/Device.mpy deleted file mode 100644 index 47f8db1cb..000000000 --- a/objects/Device.mpy +++ /dev/null @@ -1,33 +0,0 @@ -from FunctionalMemory import FunctionalMemory - -# This device exists only because there are some devices that I don't -# want to have a Platform parameter because it would cause a cycle in -# the C++ that cannot be easily solved. -# -# The real solution to this problem is to pass the ParamXXX structure -# to the constructor, but with the express condition that SimObject -# parameter values are not to be available at construction time. If -# some further configuration must be done, it must be done during the -# initialization phase at which point all SimObject pointers will be -# valid. -simobj FooPioDevice(FunctionalMemory): - type = 'PioDevice' - abstract = True - addr = Param.Addr("Device Address") - mmu = Param.MemoryController(Super, "Memory Controller") - io_bus = Param.Bus(NULL, "The IO Bus to attach to") - pio_latency = Param.Tick(1, "Programmed IO latency in bus cycles") - -simobj FooDmaDevice(FooPioDevice): - type = 'DmaDevice' - abstract = True - -simobj PioDevice(FooPioDevice): - type = 'PioDevice' - abstract = True - platform = Param.Platform(Super, "Platform") - -simobj DmaDevice(PioDevice): - type = 'DmaDevice' - abstract = True - diff --git a/objects/DiskImage.mpy b/objects/DiskImage.mpy deleted file mode 100644 index 80ef7b072..000000000 --- a/objects/DiskImage.mpy +++ /dev/null @@ -1,14 +0,0 @@ -simobj DiskImage(SimObject): - type = 'DiskImage' - abstract = True - image_file = Param.String("disk image file") - read_only = Param.Bool(False, "read only image") - -simobj RawDiskImage(DiskImage): - type = 'RawDiskImage' - -simobj CowDiskImage(DiskImage): - type = 'CowDiskImage' - child = Param.DiskImage("child image") - table_size = Param.Int(65536, "initial table size") - image_file = '' diff --git a/objects/Ethernet.mpy b/objects/Ethernet.mpy deleted file mode 100644 index 088df4b93..000000000 --- a/objects/Ethernet.mpy +++ /dev/null @@ -1,86 +0,0 @@ -from Device import DmaDevice -from Pci import PciDevice - -simobj EtherInt(SimObject): - type = 'EtherInt' - abstract = True - peer = Param.EtherInt(NULL, "peer interface") - -simobj EtherLink(SimObject): - type = 'EtherLink' - int1 = Param.EtherInt("interface 1") - int2 = Param.EtherInt("interface 2") - delay = Param.Tick(0, "transmit delay of packets in us") - speed = Param.Tick(100000000, "link speed in bits per second") - dump = Param.EtherDump(NULL, "dump object") - -simobj EtherBus(SimObject): - type = 'EtherBus' - loopback = Param.Bool(True, - "send packet back to the interface from which it came") - dump = Param.EtherDump(NULL, "dump object") - speed = Param.UInt64(100000000, "bus speed in bits per second") - -simobj EtherTap(EtherInt): - type = 'EtherTap' - bufsz = Param.Int(10000, "tap buffer size") - dump = Param.EtherDump(NULL, "dump object") - port = Param.UInt16(3500, "tap port") - -simobj EtherDump(SimObject): - type = 'EtherDump' - file = Param.String("dump file") - -simobj EtherDev(DmaDevice): - type = 'EtherDev' - hardware_address = Param.EthernetAddr(NextEthernetAddr, - "Ethernet Hardware Address") - - dma_data_free = Param.Bool(False, "DMA of Data is free") - dma_desc_free = Param.Bool(False, "DMA of Descriptors is free") - dma_read_delay = Param.Tick(0, "fixed delay for dma reads") - dma_read_factor = Param.Tick(0, "multiplier for dma reads") - dma_write_delay = Param.Tick(0, "fixed delay for dma writes") - dma_write_factor = Param.Tick(0, "multiplier for dma writes") - - rx_filter = Param.Bool(True, "Enable Receive Filter") - rx_delay = Param.Tick(1000, "Receive Delay") - tx_delay = Param.Tick(1000, "Transmit Delay") - - intr_delay = Param.Tick(0, "Interrupt Delay in microseconds") - payload_bus = Param.Bus(NULL, "The IO Bus to attach to for payload") - physmem = Param.PhysicalMemory(Super, "Physical Memory") - tlaser = Param.Turbolaser(Super, "Turbolaser") - -simobj NSGigE(PciDevice): - type = 'NSGigE' - hardware_address = Param.EthernetAddr(NextEthernetAddr, - "Ethernet Hardware Address") - - dma_data_free = Param.Bool(False, "DMA of Data is free") - dma_desc_free = Param.Bool(False, "DMA of Descriptors is free") - dma_read_delay = Param.Tick(0, "fixed delay for dma reads") - dma_read_factor = Param.Tick(0, "multiplier for dma reads") - dma_write_delay = Param.Tick(0, "fixed delay for dma writes") - dma_write_factor = Param.Tick(0, "multiplier for dma writes") - - rx_filter = Param.Bool(True, "Enable Receive Filter") - rx_delay = Param.Tick(1000, "Receive Delay") - tx_delay = Param.Tick(1000, "Transmit Delay") - - rx_fifo_size = Param.Int(131072, "max size in bytes of rxFifo") - tx_fifo_size = Param.Int(131072, "max size in bytes of txFifo") - - intr_delay = Param.Tick(0, "Interrupt Delay in microseconds") - payload_bus = Param.Bus(NULL, "The IO Bus to attach to for payload") - physmem = Param.PhysicalMemory(Super, "Physical Memory") - -simobj EtherDevInt(EtherInt): - type = 'EtherDevInt' - device = Param.EtherDev("Ethernet device of this interface") - -simobj NSGigEInt(EtherInt): - type = 'NSGigEInt' - device = Param.NSGigE("Ethernet device of this interface") - - diff --git a/objects/Ide.mpy b/objects/Ide.mpy deleted file mode 100644 index ce760ad96..000000000 --- a/objects/Ide.mpy +++ /dev/null @@ -1,14 +0,0 @@ -from Pci import PciDevice - -class IdeID(Enum): vals = ['master', 'slave'] - -simobj IdeDisk(SimObject): - type = 'IdeDisk' - delay = Param.Tick(1, "Fixed disk delay in microseconds") - driveID = Param.IdeID('master', "Drive ID") - image = Param.DiskImage("Disk image") - physmem = Param.PhysicalMemory(Super, "Physical memory") - -simobj IdeController(PciDevice): - type = 'IdeController' - disks = VectorParam.IdeDisk("IDE disks attached to this controller") diff --git a/objects/IntrControl.mpy b/objects/IntrControl.mpy deleted file mode 100644 index 1ef5a17ee..000000000 --- a/objects/IntrControl.mpy +++ /dev/null @@ -1,3 +0,0 @@ -simobj IntrControl(SimObject): - type = 'IntrControl' - cpu = Param.BaseCPU(Super, "the cpu") diff --git a/objects/MemTest.mpy b/objects/MemTest.mpy deleted file mode 100644 index af14ed9c3..000000000 --- a/objects/MemTest.mpy +++ /dev/null @@ -1,18 +0,0 @@ -simobj MemTest(SimObject): - type = 'MemTest' - cache = Param.BaseCache("L1 cache") - check_mem = Param.FunctionalMemory("check memory") - main_mem = Param.FunctionalMemory("hierarchical memory") - max_loads = Param.Counter("number of loads to execute") - memory_size = Param.Int(65536, "memory size") - percent_copies = Param.Percent(0, "target copy percentage") - percent_dest_unaligned = Param.Percent(50, - "percent of copy dest address that are unaligned") - percent_reads = Param.Percent(65, "target read percentage") - percent_source_unaligned = Param.Percent(50, - "percent of copy source address that are unaligned") - percent_uncacheable = Param.Percent(10, - "target uncacheable percentage") - progress_interval = Param.Counter(1000000, - "progress report interval (in accesses)") - trace_addr = Param.Addr(0, "address to trace") diff --git a/objects/Pci.mpy b/objects/Pci.mpy deleted file mode 100644 index caa3c52ff..000000000 --- a/objects/Pci.mpy +++ /dev/null @@ -1,52 +0,0 @@ -from Device import FooPioDevice, DmaDevice - -simobj PciConfigData(FooPioDevice): - type = 'PciConfigData' - addr = 0xffffffffffffffffL - VendorID = Param.UInt16("Vendor ID") - DeviceID = Param.UInt16("Device ID") - Command = Param.UInt16(0, "Command") - Status = Param.UInt16(0, "Status") - Revision = Param.UInt8(0, "Device") - ProgIF = Param.UInt8(0, "Programming Interface") - SubClassCode = Param.UInt8(0, "Sub-Class Code") - ClassCode = Param.UInt8(0, "Class Code") - CacheLineSize = Param.UInt8(0, "System Cacheline Size") - LatencyTimer = Param.UInt8(0, "PCI Latency Timer") - HeaderType = Param.UInt8(0, "PCI Header Type") - BIST = Param.UInt8(0, "Built In Self Test") - - BAR0 = Param.UInt32(0x00, "Base Address Register 0") - BAR1 = Param.UInt32(0x00, "Base Address Register 1") - BAR2 = Param.UInt32(0x00, "Base Address Register 2") - BAR3 = Param.UInt32(0x00, "Base Address Register 3") - BAR4 = Param.UInt32(0x00, "Base Address Register 4") - BAR5 = Param.UInt32(0x00, "Base Address Register 5") - BAR0Size = Param.UInt32(0, "Base Address Register 0 Size") - BAR1Size = Param.UInt32(0, "Base Address Register 1 Size") - BAR2Size = Param.UInt32(0, "Base Address Register 2 Size") - BAR3Size = Param.UInt32(0, "Base Address Register 3 Size") - BAR4Size = Param.UInt32(0, "Base Address Register 4 Size") - BAR5Size = Param.UInt32(0, "Base Address Register 5 Size") - - CardbusCIS = Param.UInt32(0x00, "Cardbus Card Information Structure") - SubsystemID = Param.UInt16(0x00, "Subsystem ID") - SubsystemVendorID = Param.UInt16(0x00, "Subsystem Vendor ID") - ExpansionROM = Param.UInt32(0x00, "Expansion ROM Base Address") - InterruptLine = Param.UInt8(0x00, "Interrupt Line") - InterruptPin = Param.UInt8(0x00, "Interrupt Pin") - MaximumLatency = Param.UInt8(0x00, "Maximum Latency") - MinimumGrant = Param.UInt8(0x00, "Minimum Grant") - -simobj PciConfigAll(FooPioDevice): - type = 'PciConfigAll' - -simobj PciDevice(DmaDevice): - type = 'PciDevice' - abstract = True - pci_bus = Param.Int("PCI bus") - pci_dev = Param.Int("PCI device number") - pci_func = Param.Int("PCI function code") - configdata = Param.PciConfigData(Super, "PCI Config data") - configspace = Param.PciConfigAll(Super, "PCI Configspace") - addr = 0xffffffffffffffffL diff --git a/objects/PhysicalMemory.mpy b/objects/PhysicalMemory.mpy deleted file mode 100644 index d1e4ad4b4..000000000 --- a/objects/PhysicalMemory.mpy +++ /dev/null @@ -1,7 +0,0 @@ -from FunctionalMemory import FunctionalMemory - -simobj PhysicalMemory(FunctionalMemory): - type = 'PhysicalMemory' - range = Param.AddrRange("Device Address") - file = Param.String('', "memory mapped file") - mmu = Param.MemoryController(Super, "Memory Controller") diff --git a/objects/Platform.mpy b/objects/Platform.mpy deleted file mode 100644 index d0510eaf8..000000000 --- a/objects/Platform.mpy +++ /dev/null @@ -1,5 +0,0 @@ -simobj Platform(SimObject): - type = 'Platform' - abstract = True - interrupt_frequency = Param.Tick(1200, "frequency of interrupts") - intrctrl = Param.IntrControl(Super, "interrupt controller") diff --git a/objects/Process.mpy b/objects/Process.mpy deleted file mode 100644 index 6a91c09c2..000000000 --- a/objects/Process.mpy +++ /dev/null @@ -1,15 +0,0 @@ -simobj Process(SimObject): - type = 'Process' - abstract = True - output = Param.String('cout', 'filename for stdout/stderr') - -simobj LiveProcess(Process): - type = 'LiveProcess' - cmd = VectorParam.String("command line (executable plus arguments)") - env = VectorParam.String('', "environment settings") - input = Param.String('cin', "filename for stdin") - -simobj EioProcess(Process): - type = 'EioProcess' - chkpt = Param.String('', "EIO checkpoint file name (optional)") - file = Param.String("EIO trace file name") diff --git a/objects/Repl.mpy b/objects/Repl.mpy deleted file mode 100644 index fff5a2a02..000000000 --- a/objects/Repl.mpy +++ /dev/null @@ -1,9 +0,0 @@ -simobj Repl(SimObject): - type = 'Repl' - abstract = True - -simobj GenRepl(Repl): - type = 'GenRepl' - fresh_res = Param.Int("associativity") - num_pools = Param.Int("capacity in bytes") - pool_res = Param.Int("block size in bytes") diff --git a/objects/Root.mpy b/objects/Root.mpy deleted file mode 100644 index 0e531054b..000000000 --- a/objects/Root.mpy +++ /dev/null @@ -1,15 +0,0 @@ -from HierParams import HierParams -from Serialize import Serialize -from Statistics import Statistics -from Trace import Trace - -simobj Root(SimObject): - type = 'Root' - frequency = Param.Tick(200000000, "tick frequency") - output_file = Param.String('cout', "file to dump simulator output to") - full_system = Param.Bool("Full system simulation?") - hier = HierParams(do_data = False, do_events = True) - checkpoint = Param.String('', "Checkpoint file") - stats = Statistics() - trace = Trace() - serialize = Serialize() diff --git a/objects/SimConsole.mpy b/objects/SimConsole.mpy deleted file mode 100644 index fb74f1775..000000000 --- a/objects/SimConsole.mpy +++ /dev/null @@ -1,11 +0,0 @@ -simobj ConsoleListener(SimObject): - type = 'ConsoleListener' - port = Param.UInt16(3456, "listen port") - -simobj SimConsole(SimObject): - type = 'SimConsole' - append_name = Param.Bool(True, "append name() to filename") - intr_control = Param.IntrControl(Super, "interrupt controller") - listener = Param.ConsoleListener("console listener") - number = Param.Int(0, "console number") - output = Param.String('console', "file to dump output to") diff --git a/objects/SimpleDisk.mpy b/objects/SimpleDisk.mpy deleted file mode 100644 index c4dd5435b..000000000 --- a/objects/SimpleDisk.mpy +++ /dev/null @@ -1,4 +0,0 @@ -simobj SimpleDisk(SimObject): - type = 'SimpleDisk' - disk = Param.DiskImage("Disk Image") - physmem = Param.PhysicalMemory(Super, "Physical Memory") diff --git a/objects/Tsunami.mpy b/objects/Tsunami.mpy deleted file mode 100644 index cfe23977e..000000000 --- a/objects/Tsunami.mpy +++ /dev/null @@ -1,25 +0,0 @@ -from Device import FooPioDevice -from Platform import Platform - -simobj Tsunami(Platform): - type = 'Tsunami' - pciconfig = Param.PciConfigAll("PCI configuration") - system = Param.BaseSystem(Super, "system") - interrupt_frequency = Param.Int(1024, "frequency of interrupts") - -simobj TsunamiCChip(FooPioDevice): - type = 'TsunamiCChip' - tsunami = Param.Tsunami(Super, "Tsunami") - -simobj TsunamiFake(FooPioDevice): - type = 'TsunamiFake' - -simobj TsunamiIO(FooPioDevice): - type = 'TsunamiIO' - time = Param.UInt64(1136073600, - "System time to use (0 for actual time, default is 1/1/06)") - tsunami = Param.Tsunami(Super, "Tsunami") - -simobj TsunamiPChip(FooPioDevice): - type = 'TsunamiPChip' - tsunami = Param.Tsunami(Super, "Tsunami") diff --git a/objects/Uart.mpy b/objects/Uart.mpy deleted file mode 100644 index 76ee8805f..000000000 --- a/objects/Uart.mpy +++ /dev/null @@ -1,6 +0,0 @@ -from Device import PioDevice - -simobj Uart(PioDevice): - type = 'Uart' - console = Param.SimConsole(Super, "The console") - size = Param.Addr(0x8, "Device size") diff --git a/python/SConscript b/python/SConscript new file mode 100644 index 000000000..81bc52286 --- /dev/null +++ b/python/SConscript @@ -0,0 +1,215 @@ +# -*- mode:python -*- + +# Copyright (c) 2005 The Regents of The University of Michigan +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer; +# redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution; +# neither the name of the copyright holders nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os, os.path, re + +def WriteEmbeddedPyFile(target, source, path, name, ext, filename): + if isinstance(source, str): + source = file(source, 'r') + + if isinstance(target, str): + target = file(target, 'w') + + print >>target, "AddModule(%s, %s, %s, %s, '''\\" % \ + (`path`, `name`, `ext`, `filename`) + + for line in source: + line = line + # escape existing backslashes + line = line.replace('\\', '\\\\') + # escape existing triple quotes + line = line.replace("'''", r"\'\'\'") + + print >>target, line, + + print >>target, "''')" + print >>target + +def WriteCFile(target, source, name): + if isinstance(source, str): + source = file(source, 'r') + + if isinstance(target, str): + target = file(target, 'w') + + print >>target, 'const char %s_string[] = {' % name + + count = 0 + from array import array + try: + while True: + foo = array('B') + foo.fromfile(source, 10000) + l = [ str(i) for i in foo.tolist() ] + count += len(l) + for i in xrange(0,9999,20): + print >>target, ','.join(l[i:i+20]) + ',' + except EOFError: + l = [ str(i) for i in foo.tolist() ] + count += len(l) + for i in xrange(0,len(l),20): + print >>target, ','.join(l[i:i+20]) + ',' + print >>target, ','.join(l[i:]) + ',' + + print >>target, '};' + print >>target, 'const int %s_length = %d;' % (name, count) + print >>target + +def splitpath(path): + dir,file = os.path.split(path) + path = [] + assert(file) + while dir: + dir,base = os.path.split(dir) + path.insert(0, base) + return path, file + +Import('env') +def MakeEmbeddedPyFile(target, source, env): + target = file(str(target[0]), 'w') + + tree = {} + for src in source: + src = str(src) + path,pyfile = splitpath(src) + node = tree + for dir in path: + if not node.has_key(dir): + node[dir] = { } + node = node[dir] + + name,ext = pyfile.split('.') + if name == '__init__': + node['.hasinit'] = True + node[pyfile] = (src,name,ext,src) + + done = False + while not done: + done = True + for name,entry in tree.items(): + if not isinstance(entry, dict): continue + if entry.has_key('.hasinit'): continue + + done = False + del tree[name] + for key,val in entry.iteritems(): + if tree.has_key(key): + raise NameError, \ + "dir already has %s can't add it again" % key + tree[key] = val + + files = [] + def populate(node, path = []): + names = node.keys() + names.sort() + for name in names: + if name == '.hasinit': + continue + + entry = node[name] + if isinstance(entry, dict): + if not entry.has_key('.hasinit'): + raise NameError, 'package directory missing __init__.py' + populate(entry, path + [ name ]) + else: + pyfile,name,ext,filename = entry + files.append((pyfile, path, name, ext, filename)) + populate(tree) + + for pyfile, path, name, ext, filename in files: + WriteEmbeddedPyFile(target, pyfile, path, name, ext, filename) + +def MakeDefinesPyFile(target, source, env): + target = file(str(target[0]), 'w') + + print >>target, "import os" + defines = env['CPPDEFINES'] + if isinstance(defines, list): + for var in defines: + if isinstance(var, tuple): + key,val = var + else: + key,val = var,'True' + + if not isinstance(key, basestring): + panic("invalid type for define: %s" % type(key)) + + print >>target, "os.environ['%s'] = '%s'" % (key, val) + + elif isinstance(defines, dict): + for key,val in defines.iteritems(): + print >>target, "os.environ['%s'] = '%s'" % (key, val) + else: + panic("invalid type for defines: %s" % type(defines)) + +CFileCounter = 0 +def MakePythonCFile(target, source, env): + global CFileCounter + target = file(str(target[0]), 'w') + + print >>target, '''\ +#include "base/embedfile.hh" + +namespace { +''' + for src in source: + src = str(src) + fname = os.path.basename(src) + name = 'embedded_file%d' % CFileCounter + CFileCounter += 1 + WriteCFile(target, src, name) + print >>target, '''\ +EmbedMap %(name)s("%(fname)s", + %(name)s_string, %(name)s_length); + +''' % locals() + print >>target, '''\ + +/* namespace */ } +''' + +embedded_py_files = [ 'mpy_importer.py', '../util/pbs/jobfile.py' ] +objpath = os.path.join(env['SRCDIR'], 'python/m5') +for root, dirs, files in os.walk(objpath, topdown=True): + for i,dir in enumerate(dirs): + if dir == 'SCCS': + del dirs[i] + break + + assert(root.startswith(objpath)) + for f in files: + if f.endswith('.mpy') or f.endswith('.py'): + embedded_py_files.append(os.path.join(root, f)) + +embedfile_hh = os.path.join(env['SRCDIR'], 'base/embedfile.hh') +env.Command('defines.py', None, MakeDefinesPyFile) +env.Command('embedded_py.py', embedded_py_files, MakeEmbeddedPyFile) +env.Depends('embedded_py.cc', embedfile_hh) +env.Command('embedded_py.cc', + ['string_importer.py', 'defines.py', 'embedded_py.py'], + MakePythonCFile) diff --git a/python/m5/__init__.py b/python/m5/__init__.py new file mode 100644 index 000000000..7cb3a32c6 --- /dev/null +++ b/python/m5/__init__.py @@ -0,0 +1,7 @@ +from mpy_importer import * +from config import * +from objects import * + +cpp_classes = MetaSimObject.cpp_classes +cpp_classes.sort() + diff --git a/python/m5/config.py b/python/m5/config.py new file mode 100644 index 000000000..b39a8b9a6 --- /dev/null +++ b/python/m5/config.py @@ -0,0 +1,1300 @@ +# Copyright (c) 2004 The Regents of The University of Michigan +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer; +# redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution; +# neither the name of the copyright holders nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from __future__ import generators +import os, re, sys, types, inspect + +from mpy_importer import AddToPath, LoadMpyFile + +noDot = False +try: + import pydot +except: + noDot = True + +env = {} +env.update(os.environ) + +def panic(string): + print >>sys.stderr, 'panic:', string + sys.exit(1) + +def issequence(value): + return isinstance(value, tuple) or isinstance(value, list) + +class Singleton(type): + def __call__(cls, *args, **kwargs): + if hasattr(cls, '_instance'): + return cls._instance + + cls._instance = super(Singleton, cls).__call__(*args, **kwargs) + return cls._instance + +##################################################################### +# +# M5 Python Configuration Utility +# +# The basic idea is to write simple Python programs that build Python +# objects corresponding to M5 SimObjects for the deisred simulation +# configuration. For now, the Python emits a .ini file that can be +# parsed by M5. In the future, some tighter integration between M5 +# and the Python interpreter may allow bypassing the .ini file. +# +# Each SimObject class in M5 is represented by a Python class with the +# same name. The Python inheritance tree mirrors the M5 C++ tree +# (e.g., SimpleCPU derives from BaseCPU in both cases, and all +# SimObjects inherit from a single SimObject base class). To specify +# an instance of an M5 SimObject in a configuration, the user simply +# instantiates the corresponding Python object. The parameters for +# that SimObject are given by assigning to attributes of the Python +# object, either using keyword assignment in the constructor or in +# separate assignment statements. For example: +# +# cache = BaseCache('my_cache', root, size=64*K) +# cache.hit_latency = 3 +# cache.assoc = 8 +# +# (The first two constructor arguments specify the name of the created +# cache and its parent node in the hierarchy.) +# +# The magic lies in the mapping of the Python attributes for SimObject +# classes to the actual SimObject parameter specifications. This +# allows parameter validity checking in the Python code. Continuing +# the example above, the statements "cache.blurfl=3" or +# "cache.assoc='hello'" would both result in runtime errors in Python, +# since the BaseCache object has no 'blurfl' parameter and the 'assoc' +# parameter requires an integer, respectively. This magic is done +# primarily by overriding the special __setattr__ method that controls +# assignment to object attributes. +# +# The Python module provides another class, ConfigNode, which is a +# superclass of SimObject. ConfigNode implements the parent/child +# relationship for building the configuration hierarchy tree. +# Concrete instances of ConfigNode can be used to group objects in the +# hierarchy, but do not correspond to SimObjects themselves (like a +# .ini section with "children=" but no "type=". +# +# Once a set of Python objects have been instantiated in a hierarchy, +# calling 'instantiate(obj)' (where obj is the root of the hierarchy) +# will generate a .ini file. See simple-4cpu.py for an example +# (corresponding to m5-test/simple-4cpu.ini). +# +##################################################################### + +##################################################################### +# +# ConfigNode/SimObject classes +# +# The Python class hierarchy rooted by ConfigNode (which is the base +# class of SimObject, which in turn is the base class of all other M5 +# SimObject classes) has special attribute behavior. In general, an +# object in this hierarchy has three categories of attribute-like +# things: +# +# 1. Regular Python methods and variables. These must start with an +# underscore to be treated normally. +# +# 2. SimObject parameters. These values are stored as normal Python +# attributes, but all assignments to these attributes are checked +# against the pre-defined set of parameters stored in the class's +# _params dictionary. Assignments to attributes that do not +# correspond to predefined parameters, or that are not of the correct +# type, incur runtime errors. +# +# 3. Hierarchy children. The child nodes of a ConfigNode are stored +# in the node's _children dictionary, but can be accessed using the +# Python attribute dot-notation (just as they are printed out by the +# simulator). Children cannot be created using attribute assigment; +# they must be added by specifying the parent node in the child's +# constructor or using the '+=' operator. + +# The SimObject parameters are the most complex, for a few reasons. +# First, both parameter descriptions and parameter values are +# inherited. Thus parameter description lookup must go up the +# inheritance chain like normal attribute lookup, but this behavior +# must be explicitly coded since the lookup occurs in each class's +# _params attribute. Second, because parameter values can be set +# on SimObject classes (to implement default values), the parameter +# checking behavior must be enforced on class attribute assignments as +# well as instance attribute assignments. Finally, because we allow +# class specialization via inheritance (e.g., see the L1Cache class in +# the simple-4cpu.py example), we must do parameter checking even on +# class instantiation. To provide all these features, we use a +# metaclass to define most of the SimObject parameter behavior for +# this class hierarchy. +# +##################################################################### + +class Proxy(object): + def __init__(self, path = ()): + self._object = None + self._path = path + + def __getattr__(self, attr): + return Proxy(self._path + (attr, )) + + def __setattr__(self, attr, value): + if not attr.startswith('_'): + raise AttributeError, 'cannot set attribute %s' % attr + super(Proxy, self).__setattr__(attr, value) + + def _convert(self): + obj = self._object + for attr in self._path: + obj = obj.__getattribute__(attr) + return obj + +Super = Proxy() + +def isSubClass(value, cls): + try: + return issubclass(value, cls) + except: + return False + +def isConfigNode(value): + try: + return issubclass(value, ConfigNode) + except: + return False + +def isSimObject(value): + try: + return issubclass(value, SimObject) + except: + return False + +def isSimObjSequence(value): + if not issequence(value): + return False + + for val in value: + if not isNullPointer(val) and not isConfigNode(val): + return False + + return True + +def isParamContext(value): + try: + return issubclass(value, ParamContext) + except: + return False + + +class_decorator = 'M5M5_SIMOBJECT_' +expr_decorator = 'M5M5_EXPRESSION_' +dot_decorator = '_M5M5_DOT_' + +# The metaclass for ConfigNode (and thus for everything that derives +# from ConfigNode, including SimObject). This class controls how new +# classes that derive from ConfigNode are instantiated, and provides +# inherited class behavior (just like a class controls how instances +# of that class are instantiated, and provides inherited instance +# behavior). +class MetaConfigNode(type): + # Attributes that can be set only at initialization time + init_keywords = {} + # Attributes that can be set any time + keywords = { 'check' : types.FunctionType, + 'children' : types.ListType } + + # __new__ is called before __init__, and is where the statements + # in the body of the class definition get loaded into the class's + # __dict__. We intercept this to filter out parameter assignments + # and only allow "private" attributes to be passed to the base + # __new__ (starting with underscore). + def __new__(mcls, name, bases, dict): + # Copy "private" attributes (including special methods such as __new__) + # to the official dict. Everything else goes in _init_dict to be + # filtered in __init__. + cls_dict = {} + for key,val in dict.items(): + if key.startswith('_'): + cls_dict[key] = val + del dict[key] + cls_dict['_init_dict'] = dict + return super(MetaConfigNode, mcls).__new__(mcls, name, bases, cls_dict) + + # initialization + def __init__(cls, name, bases, dict): + super(MetaConfigNode, cls).__init__(name, bases, dict) + + # initialize required attributes + cls._params = {} + cls._values = {} + cls._enums = {} + cls._bases = [c for c in cls.__mro__ if isConfigNode(c)] + cls._anon_subclass_counter = 0 + + # If your parent has a value in it that's a config node, clone + # it. Do this now so if we update any of the values' + # attributes we are updating the clone and not the original. + for base in cls._bases: + for key,val in base._values.iteritems(): + + # don't clone if (1) we're about to overwrite it with + # a local setting or (2) we've already cloned a copy + # from an earlier (more derived) base + if cls._init_dict.has_key(key) or cls._values.has_key(key): + continue + + if isConfigNode(val): + cls._values[key] = val() + elif isSimObjSequence(val): + cls._values[key] = [ v() for v in val ] + elif isNullPointer(val): + cls._values[key] = val + + # now process _init_dict items + for key,val in cls._init_dict.items(): + if isinstance(val, _Param): + cls._params[key] = val + + # init-time-only keywords + elif cls.init_keywords.has_key(key): + cls._set_keyword(key, val, cls.init_keywords[key]) + + # enums + elif isinstance(val, type) and issubclass(val, Enum): + cls._enums[key] = val + + # See description of decorators in the importer.py file. + # We just strip off the expr_decorator now since we don't + # need from this point on. + elif key.startswith(expr_decorator): + key = key[len(expr_decorator):] + # because it had dots into a list so that we can find the + # proper variable to modify. + key = key.split(dot_decorator) + c = cls + for item in key[:-1]: + c = getattr(c, item) + setattr(c, key[-1], val) + + # default: use normal path (ends up in __setattr__) + else: + setattr(cls, key, val) + + + def _isvalue(cls, name): + for c in cls._bases: + if c._params.has_key(name): + return True + + for c in cls._bases: + if c._values.has_key(name): + return True + + return False + + # generator that iterates across all parameters for this class and + # all classes it inherits from + def _getparams(cls): + params = {} + for c in cls._bases: + for p,v in c._params.iteritems(): + if not params.has_key(p): + params[p] = v + return params + + # Lookup a parameter description by name in the given class. + def _getparam(cls, name, default = AttributeError): + for c in cls._bases: + if c._params.has_key(name): + return c._params[name] + if isSubClass(default, Exception): + raise default, \ + "object '%s' has no attribute '%s'" % (cls.__name__, name) + else: + return default + + def _hasvalue(cls, name): + for c in cls._bases: + if c._values.has_key(name): + return True + + return False + + def _getvalues(cls): + values = {} + for i,c in enumerate(cls._bases): + for p,v in c._values.iteritems(): + if not values.has_key(p): + values[p] = v + for p,v in c._params.iteritems(): + if not values.has_key(p) and hasattr(v, 'default'): + try: + v.valid(v.default) + except TypeError: + panic("Invalid default %s for param %s in node %s" + % (v.default,p,cls.__name__)) + v = v.default + cls._setvalue(p, v) + values[p] = v + + return values + + def _getvalue(cls, name, default = AttributeError): + value = None + for c in cls._bases: + if c._values.has_key(name): + value = c._values[name] + break + if value is not None: + return value + + param = cls._getparam(name, None) + if param is not None and hasattr(param, 'default'): + param.valid(param.default) + value = param.default + cls._setvalue(name, value) + return value + + if isSubClass(default, Exception): + raise default, 'value for %s not found' % name + else: + return default + + def _setvalue(cls, name, value): + cls._values[name] = value + + def __getattr__(cls, attr): + if cls._isvalue(attr): + return Value(cls, attr) + + if attr == '_cpp_param_decl' and hasattr(cls, 'type'): + return cls.type + '*' + + raise AttributeError, \ + "object '%s' has no attribute '%s'" % (cls.__name__, attr) + + def _set_keyword(cls, keyword, val, kwtype): + if not isinstance(val, kwtype): + raise TypeError, 'keyword %s has bad type %s (expecting %s)' % \ + (keyword, type(val), kwtype) + if isinstance(val, types.FunctionType): + val = classmethod(val) + type.__setattr__(cls, keyword, val) + + # Set attribute (called on foo.attr = value when foo is an + # instance of class cls). + def __setattr__(cls, attr, value): + # normal processing for private attributes + if attr.startswith('_'): + type.__setattr__(cls, attr, value) + return + + if cls.keywords.has_key(attr): + cls._set_keyword(attr, value, cls.keywords[attr]) + return + + # must be SimObject param + param = cls._getparam(attr, None) + if param: + # It's ok: set attribute by delegating to 'object' class. + # Note the use of param.make_value() to verify/canonicalize + # the assigned value + param.valid(value) + cls._setvalue(attr, value) + elif isConfigNode(value) or isSimObjSequence(value): + cls._setvalue(attr, value) + else: + raise AttributeError, \ + "Class %s has no parameter %s" % (cls.__name__, attr) + + def add_child(cls, instance, name, child): + if isNullPointer(child) or instance.top_child_names.has_key(name): + return + + if issequence(child): + kid = [] + for i,c in enumerate(child): + n = '%s%d' % (name, i) + k = c.instantiate(n, instance) + + instance.children.append(k) + instance.child_names[n] = k + instance.child_objects[c] = k + kid.append(k) + else: + kid = child.instantiate(name, instance) + instance.children.append(kid) + instance.child_names[name] = kid + instance.child_objects[child] = kid + + instance.top_child_names[name] = kid + + # Print instance info to .ini file. + def instantiate(cls, name, parent = None): + instance = Node(name, cls, cls.type, parent, isParamContext(cls)) + + if hasattr(cls, 'check'): + cls.check() + + for key,value in cls._getvalues().iteritems(): + if isConfigNode(value): + cls.add_child(instance, key, value) + if issequence(value): + list = [ v for v in value if isConfigNode(v) ] + if len(list): + cls.add_child(instance, key, list) + + for pname,param in cls._getparams().iteritems(): + try: + value = cls._getvalue(pname) + except: + panic('Error getting %s' % pname) + + try: + if isConfigNode(value): + value = instance.child_objects[value] + elif issequence(value): + v = [] + for val in value: + if isConfigNode(val): + v.append(instance.child_objects[val]) + else: + v.append(val) + value = v + + p = NodeParam(pname, param, value) + instance.params.append(p) + instance.param_names[pname] = p + except: + print 'Exception while evaluating %s.%s' % \ + (instance.path, pname) + raise + + return instance + + def _convert(cls, value): + realvalue = value + if isinstance(value, Node): + realvalue = value.realtype + + if isinstance(realvalue, Proxy): + return value + + if realvalue == None or isNullPointer(realvalue): + return value + + if isSubClass(realvalue, cls): + return value + + raise TypeError, 'object %s type %s wrong type, should be %s' % \ + (repr(realvalue), realvalue, cls) + + def _string(cls, value): + if isNullPointer(value): + return 'Null' + return Node._string(value) + +# The ConfigNode class is the root of the special hierarchy. Most of +# the code in this class deals with the configuration hierarchy itself +# (parent/child node relationships). +class ConfigNode(object): + # Specify metaclass. Any class inheriting from ConfigNode will + # get this metaclass. + __metaclass__ = MetaConfigNode + + def __new__(cls, **kwargs): + name = cls.__name__ + ("_%d" % cls._anon_subclass_counter) + cls._anon_subclass_counter += 1 + return cls.__metaclass__(name, (cls, ), kwargs) + +class ParamContext(ConfigNode): + pass + +class MetaSimObject(MetaConfigNode): + # init_keywords and keywords are inherited from MetaConfigNode, + # with overrides/additions + init_keywords = MetaConfigNode.init_keywords + init_keywords.update({ 'abstract' : types.BooleanType, + 'type' : types.StringType }) + + keywords = MetaConfigNode.keywords + # no additional keywords + + cpp_classes = [] + + # initialization + def __init__(cls, name, bases, dict): + super(MetaSimObject, cls).__init__(name, bases, dict) + + if hasattr(cls, 'type'): + if name == 'SimObject': + cls._cpp_base = None + elif hasattr(cls._bases[1], 'type'): + cls._cpp_base = cls._bases[1].type + else: + panic("SimObject %s derives from a non-C++ SimObject %s "\ + "(no 'type')" % (cls, cls_bases[1].__name__)) + + # This class corresponds to a C++ class: put it on the global + # list of C++ objects to generate param structs, etc. + MetaSimObject.cpp_classes.append(cls) + + def _cpp_decl(cls): + name = cls.__name__ + code = "" + code += "\n".join([e.cpp_declare() for e in cls._enums.values()]) + code += "\n" + param_names = cls._params.keys() + param_names.sort() + code += "struct Params" + if cls._cpp_base: + code += " : public %s::Params" % cls._cpp_base + code += " {\n " + code += "\n ".join([cls._params[pname].cpp_decl(pname) \ + for pname in param_names]) + code += "\n};\n" + return code + +class NodeParam(object): + def __init__(self, name, param, value): + self.name = name + self.param = param + self.ptype = param.ptype + self.convert = param.convert + self.string = param.string + self.value = value + +class Node(object): + all = {} + def __init__(self, name, realtype, type, parent, paramcontext): + self.name = name + self.realtype = realtype + self.type = type + self.parent = parent + self.children = [] + self.child_names = {} + self.child_objects = {} + self.top_child_names = {} + self.params = [] + self.param_names = {} + self.paramcontext = paramcontext + + path = [ self.name ] + node = self.parent + while node is not None: + if node.name != 'root': + path.insert(0, node.name) + else: + assert(node.parent is None) + node = node.parent + self.path = '.'.join(path) + + def find(self, realtype, path): + if not path: + if issubclass(self.realtype, realtype): + return self, True + + obj = None + for child in self.children: + if issubclass(child.realtype, realtype): + if obj is not None: + raise AttributeError, \ + 'Super matched more than one: %s %s' % \ + (obj.path, child.path) + obj = child + return obj, obj is not None + + try: + obj = self + for node in path[:-1]: + obj = obj.child_names[node] + + last = path[-1] + if obj.child_names.has_key(last): + value = obj.child_names[last] + if issubclass(value.realtype, realtype): + return value, True + elif obj.param_names.has_key(last): + value = obj.param_names[last] + realtype._convert(value.value) + return value.value, True + except KeyError: + pass + + return None, False + + def unproxy(self, ptype, value): + if not isinstance(value, Proxy): + return value + + if value is None: + raise AttributeError, 'Error while fixing up %s' % self.path + + obj = self + done = False + while not done: + if obj is None: + raise AttributeError, \ + 'Parent of %s type %s not found at path %s' \ + % (self.name, ptype, value._path) + found, done = obj.find(ptype, value._path) + if isinstance(found, Proxy): + done = False + obj = obj.parent + + return found + + def fixup(self): + self.all[self.path] = self + + for param in self.params: + ptype = param.ptype + pval = param.value + + try: + if issequence(pval): + param.value = [ self.unproxy(ptype, pv) for pv in pval ] + else: + param.value = self.unproxy(ptype, pval) + except: + print 'Error while fixing up %s:%s' % (self.path, param.name) + raise + + for child in self.children: + assert(child != self) + child.fixup() + + # print type and parameter values to .ini file + def display(self): + print '[' + self.path + ']' # .ini section header + + if isSimObject(self.realtype): + print 'type = %s' % self.type + + if self.children: + # instantiate children in same order they were added for + # backward compatibility (else we can end up with cpu1 + # before cpu0). Changing ordering can also influence timing + # in the current memory system, as caches get added to a bus + # in different orders which affects their priority in the + # case of simulataneous requests. We should uncomment the + # following line once we take care of that issue. + # self.children.sort(lambda x,y: cmp(x.name, y.name)) + children = [ c.name for c in self.children if not c.paramcontext] + print 'children =', ' '.join(children) + + self.params.sort(lambda x,y: cmp(x.name, y.name)) + for param in self.params: + try: + if param.value is None: + raise AttributeError, 'Parameter with no value' + + value = param.convert(param.value) + string = param.string(value) + except: + print 'exception in %s:%s' % (self.path, param.name) + raise + + print '%s = %s' % (param.name, string) + + print + + # recursively dump out children + for c in self.children: + c.display() + + # print type and parameter values to .ini file + def outputDot(self, dot): + + + label = "{%s|" % self.path + if isSimObject(self.realtype): + label += '%s|' % self.type + + if self.children: + # instantiate children in same order they were added for + # backward compatibility (else we can end up with cpu1 + # before cpu0). + for c in self.children: + dot.add_edge(pydot.Edge(self.path,c.path, style="bold")) + + simobjs = [] + for param in self.params: + try: + if param.value is None: + raise AttributeError, 'Parameter with no value' + + value = param.convert(param.value) + string = param.string(value) + except: + print 'exception in %s:%s' % (self.name, param.name) + raise + if isConfigNode(param.ptype) and string != "Null": + simobjs.append(string) + else: + label += '%s = %s\\n' % (param.name, string) + + for so in simobjs: + label += "|<%s> %s" % (so, so) + dot.add_edge(pydot.Edge("%s:%s" % (self.path, so), so, tailport="w")) + label += '}' + dot.add_node(pydot.Node(self.path,shape="Mrecord",label=label)) + + # recursively dump out children + for c in self.children: + c.outputDot(dot) + + def _string(cls, value): + if not isinstance(value, Node): + raise AttributeError, 'expecting %s got %s' % (Node, value) + return value.path + _string = classmethod(_string) + +##################################################################### +# +# Parameter description classes +# +# The _params dictionary in each class maps parameter names to +# either a Param or a VectorParam object. These objects contain the +# parameter description string, the parameter type, and the default +# value (loaded from the PARAM section of the .odesc files). The +# _convert() method on these objects is used to force whatever value +# is assigned to the parameter to the appropriate type. +# +# Note that the default values are loaded into the class's attribute +# space when the parameter dictionary is initialized (in +# MetaConfigNode._setparams()); after that point they aren't used. +# +##################################################################### + +def isNullPointer(value): + return isinstance(value, NullSimObject) + +class Value(object): + def __init__(self, obj, attr): + super(Value, self).__setattr__('attr', attr) + super(Value, self).__setattr__('obj', obj) + + def _getattr(self): + return self.obj._getvalue(self.attr) + + def __setattr__(self, attr, value): + setattr(self._getattr(), attr, value) + + def __getattr__(self, attr): + return getattr(self._getattr(), attr) + + def __getitem__(self, index): + return self._getattr().__getitem__(index) + + def __call__(self, *args, **kwargs): + return self._getattr().__call__(*args, **kwargs) + + def __nonzero__(self): + return bool(self._getattr()) + + def __str__(self): + return str(self._getattr()) + +# Regular parameter. +class _Param(object): + def __init__(self, ptype, *args, **kwargs): + if isinstance(ptype, types.StringType): + self.ptype_string = ptype + elif isinstance(ptype, type): + self.ptype = ptype + else: + raise TypeError, "Param type is not a type (%s)" % ptype + + if args: + if len(args) == 1: + self.desc = args[0] + elif len(args) == 2: + self.default = args[0] + self.desc = args[1] + else: + raise TypeError, 'too many arguments' + + if kwargs.has_key('desc'): + assert(not hasattr(self, 'desc')) + self.desc = kwargs['desc'] + del kwargs['desc'] + + if kwargs.has_key('default'): + assert(not hasattr(self, 'default')) + self.default = kwargs['default'] + del kwargs['default'] + + if kwargs: + raise TypeError, 'extra unknown kwargs %s' % kwargs + + if not hasattr(self, 'desc'): + raise TypeError, 'desc attribute missing' + + def __getattr__(self, attr): + if attr == 'ptype': + try: + self.ptype = eval(self.ptype_string) + return self.ptype + except: + raise TypeError, 'Param.%s: undefined type' % self.ptype_string + else: + raise AttributeError, "'%s' object has no attribute '%s'" % \ + (type(self).__name__, attr) + + def valid(self, value): + if not isinstance(value, Proxy): + self.ptype._convert(value) + + def convert(self, value): + return self.ptype._convert(value) + + def string(self, value): + return self.ptype._string(value) + + def set(self, name, instance, value): + instance.__dict__[name] = value + + def cpp_decl(self, name): + return '%s %s;' % (self.ptype._cpp_param_decl, name) + +class _ParamProxy(object): + def __init__(self, type): + self.ptype = type + + # E.g., Param.Int(5, "number of widgets") + def __call__(self, *args, **kwargs): + # Param type could be defined only in context of caller (e.g., + # for locally defined Enum subclass). Need to go look up the + # type in that enclosing scope. + caller_frame = inspect.stack()[1][0] + ptype = caller_frame.f_locals.get(self.ptype, None) + if not ptype: ptype = caller_frame.f_globals.get(self.ptype, None) + if not ptype: ptype = globals().get(self.ptype, None) + # ptype could still be None due to circular references... we'll + # try one more time to evaluate lazily when ptype is first needed. + # In the meantime we'll save the type name as a string. + if not ptype: ptype = self.ptype + return _Param(ptype, *args, **kwargs) + + def __getattr__(self, attr): + if attr == '__bases__': + raise AttributeError, '' + cls = type(self) + return cls(attr) + + def __setattr__(self, attr, value): + if attr != 'ptype': + raise AttributeError, \ + 'Attribute %s not available in %s' % (attr, self.__class__) + super(_ParamProxy, self).__setattr__(attr, value) + + +Param = _ParamProxy(None) + +# Vector-valued parameter description. Just like Param, except that +# the value is a vector (list) of the specified type instead of a +# single value. +class _VectorParam(_Param): + def __init__(self, type, *args, **kwargs): + _Param.__init__(self, type, *args, **kwargs) + + def valid(self, value): + if value == None: + return True + + if issequence(value): + for val in value: + if not isinstance(val, Proxy): + self.ptype._convert(val) + elif not isinstance(value, Proxy): + self.ptype._convert(value) + + # Convert assigned value to appropriate type. If the RHS is not a + # list or tuple, it generates a single-element list. + def convert(self, value): + if value == None: + return [] + + if issequence(value): + # list: coerce each element into new list + return [ self.ptype._convert(v) for v in value ] + else: + # singleton: coerce & wrap in a list + return self.ptype._convert(value) + + def string(self, value): + if issequence(value): + return ' '.join([ self.ptype._string(v) for v in value]) + else: + return self.ptype._string(value) + + def cpp_decl(self, name): + return 'std::vector<%s> %s;' % (self.ptype._cpp_param_decl, name) + +class _VectorParamProxy(_ParamProxy): + # E.g., VectorParam.Int(5, "number of widgets") + def __call__(self, *args, **kwargs): + return _VectorParam(self.ptype, *args, **kwargs) + +VectorParam = _VectorParamProxy(None) + +##################################################################### +# +# Parameter Types +# +# Though native Python types could be used to specify parameter types +# (the 'ptype' field of the Param and VectorParam classes), it's more +# flexible to define our own set of types. This gives us more control +# over how Python expressions are converted to values (via the +# __init__() constructor) and how these values are printed out (via +# the __str__() conversion method). Eventually we'll need these types +# to correspond to distinct C++ types as well. +# +##################################################################### +# Integer parameter type. +class _CheckedInt(object): + def _convert(cls, value): + t = type(value) + if t == bool: + return int(value) + + if t != int and t != long and t != float and t != str: + raise TypeError, 'Integer parameter of invalid type %s' % t + + if t == str or t == float: + value = long(value) + + if not cls._min <= value <= cls._max: + raise TypeError, 'Integer parameter out of bounds %d < %d < %d' % \ + (cls._min, value, cls._max) + + return value + _convert = classmethod(_convert) + + def _string(cls, value): + return str(value) + _string = classmethod(_string) + +class CheckedInt(type): + def __new__(cls, cppname, min, max): + # New class derives from _CheckedInt base with proper bounding + # parameters + dict = { '_cpp_param_decl' : cppname, '_min' : min, '_max' : max } + return type.__new__(cls, cppname, (_CheckedInt, ), dict) + +class CheckedIntType(CheckedInt): + def __new__(cls, cppname, size, unsigned): + dict = {} + if unsigned: + min = 0 + max = 2 ** size - 1 + else: + min = -(2 ** (size - 1)) + max = (2 ** (size - 1)) - 1 + + return super(cls, CheckedIntType).__new__(cls, cppname, min, max) + +Int = CheckedIntType('int', 32, False) +Unsigned = CheckedIntType('unsigned', 32, True) + +Int8 = CheckedIntType('int8_t', 8, False) +UInt8 = CheckedIntType('uint8_t', 8, True) +Int16 = CheckedIntType('int16_t', 16, False) +UInt16 = CheckedIntType('uint16_t', 16, True) +Int32 = CheckedIntType('int32_t', 32, False) +UInt32 = CheckedIntType('uint32_t', 32, True) +Int64 = CheckedIntType('int64_t', 64, False) +UInt64 = CheckedIntType('uint64_t', 64, True) + +Counter = CheckedIntType('Counter', 64, True) +Addr = CheckedIntType('Addr', 64, True) +Tick = CheckedIntType('Tick', 64, True) + +Percent = CheckedInt('int', 0, 100) + +class Pair(object): + def __init__(self, first, second): + self.first = first + self.second = second + +class _Range(object): + def _convert(cls, value): + if not isinstance(value, Pair): + raise TypeError, 'value %s is not a Pair' % value + return Pair(cls._type._convert(value.first), + cls._type._convert(value.second)) + _convert = classmethod(_convert) + + def _string(cls, value): + return '%s:%s' % (cls._type._string(value.first), + cls._type._string(value.second)) + _string = classmethod(_string) + +def RangeSize(start, size): + return Pair(start, start + size - 1) + +class Range(type): + def __new__(cls, type): + dict = { '_cpp_param_decl' : 'Range<%s>' % type._cpp_param_decl, + '_type' : type } + clsname = 'Range_' + type.__name__ + return super(cls, Range).__new__(cls, clsname, (_Range, ), dict) + +AddrRange = Range(Addr) + +# Boolean parameter type. +class Bool(object): + _cpp_param_decl = 'bool' + def _convert(value): + t = type(value) + if t == bool: + return value + + if t == int or t == long: + return bool(value) + + if t == str: + v = value.lower() + if v == "true" or v == "t" or v == "yes" or v == "y": + return True + elif v == "false" or v == "f" or v == "no" or v == "n": + return False + + raise TypeError, 'Bool parameter (%s) of invalid type %s' % (v, t) + _convert = staticmethod(_convert) + + def _string(value): + if value: + return "true" + else: + return "false" + _string = staticmethod(_string) + +# String-valued parameter. +class String(object): + _cpp_param_decl = 'string' + + # Constructor. Value must be Python string. + def _convert(cls,value): + if value is None: + return '' + if isinstance(value, str): + return value + + raise TypeError, \ + "String param got value %s %s" % (repr(value), type(value)) + _convert = classmethod(_convert) + + # Generate printable string version. Not too tricky. + def _string(cls, value): + return value + _string = classmethod(_string) + + +def IncEthernetAddr(addr, val = 1): + bytes = map(lambda x: int(x, 16), addr.split(':')) + bytes[5] += val + for i in (5, 4, 3, 2, 1): + val,rem = divmod(bytes[i], 256) + bytes[i] = rem + if val == 0: + break + bytes[i - 1] += val + assert(bytes[0] <= 255) + return ':'.join(map(lambda x: '%02x' % x, bytes)) + +class NextEthernetAddr(object): + __metaclass__ = Singleton + addr = "00:90:00:00:00:01" + + def __init__(self, inc = 1): + self.value = self.addr + self.addr = IncEthernetAddr(self.addr, inc) + +class EthernetAddr(object): + _cpp_param_decl = 'EthAddr' + + def _convert(cls, value): + if value == NextEthernetAddr: + return value + + if not isinstance(value, str): + raise TypeError, "expected an ethernet address and didn't get one" + + bytes = value.split(':') + if len(bytes) != 6: + raise TypeError, 'invalid ethernet address %s' % value + + for byte in bytes: + if not 0 <= int(byte) <= 256: + raise TypeError, 'invalid ethernet address %s' % value + + return value + _convert = classmethod(_convert) + + def _string(cls, value): + if value == NextEthernetAddr: + value = value().value + return value + _string = classmethod(_string) + +# Special class for NULL pointers. Note the special check in +# make_param_value() above that lets these be assigned where a +# SimObject is required. +# only one copy of a particular node +class NullSimObject(object): + __metaclass__ = Singleton + + def __call__(cls): + return cls + + def _instantiate(self, parent = None, path = ''): + pass + + def _convert(cls, value): + if value == Nxone: + return + + if isinstance(value, cls): + return value + + raise TypeError, 'object %s %s of the wrong type, should be %s' % \ + (repr(value), type(value), cls) + _convert = classmethod(_convert) + + def _string(): + return 'NULL' + _string = staticmethod(_string) + +# The only instance you'll ever need... +Null = NULL = NullSimObject() + +# Enumerated types are a little more complex. The user specifies the +# type as Enum(foo) where foo is either a list or dictionary of +# alternatives (typically strings, but not necessarily so). (In the +# long run, the integer value of the parameter will be the list index +# or the corresponding dictionary value. For now, since we only check +# that the alternative is valid and then spit it into a .ini file, +# there's not much point in using the dictionary.) + +# What Enum() must do is generate a new type encapsulating the +# provided list/dictionary so that specific values of the parameter +# can be instances of that type. We define two hidden internal +# classes (_ListEnum and _DictEnum) to serve as base classes, then +# derive the new type from the appropriate base class on the fly. + + +# Metaclass for Enum types +class MetaEnum(type): + + def __init__(cls, name, bases, init_dict): + if init_dict.has_key('map'): + if not isinstance(cls.map, dict): + raise TypeError, "Enum-derived class attribute 'map' " \ + "must be of type dict" + # build list of value strings from map + cls.vals = cls.map.keys() + cls.vals.sort() + elif init_dict.has_key('vals'): + if not isinstance(cls.vals, list): + raise TypeError, "Enum-derived class attribute 'vals' " \ + "must be of type list" + # build string->value map from vals sequence + cls.map = {} + for idx,val in enumerate(cls.vals): + cls.map[val] = idx + else: + raise TypeError, "Enum-derived class must define "\ + "attribute 'map' or 'vals'" + + cls._cpp_param_decl = name + + super(MetaEnum, cls).__init__(name, bases, init_dict) + + def cpp_declare(cls): + s = 'enum %s {\n ' % cls.__name__ + s += ',\n '.join(['%s = %d' % (v,cls.map[v]) for v in cls.vals]) + s += '\n};\n' + return s + +# Base class for enum types. +class Enum(object): + __metaclass__ = MetaEnum + vals = [] + + def _convert(self, value): + if value not in self.map: + raise TypeError, "Enum param got bad value '%s' (not in %s)" \ + % (value, self.vals) + return value + _convert = classmethod(_convert) + + # Generate printable string version of value. + def _string(self, value): + return str(value) + _string = classmethod(_string) +# +# "Constants"... handy aliases for various values. +# + +# Some memory range specifications use this as a default upper bound. +MAX_ADDR = Addr._max +MaxTick = Tick._max + +# For power-of-two sizing, e.g. 64*K gives an integer value 65536. +K = 1024 +M = K*K +G = K*M + +##################################################################### + +# The final hook to generate .ini files. Called from configuration +# script once config is built. +def instantiate(root): + if not issubclass(root, Root): + raise AttributeError, 'Can only instantiate the Root of the tree' + + instance = root.instantiate('root') + instance.fixup() + instance.display() + if not noDot: + dot = pydot.Dot() + instance.outputDot(dot) + dot.orientation = "portrait" + dot.size = "8.5,11" + dot.ranksep="equally" + dot.rank="samerank" + dot.write("config.dot") + dot.write_ps("config.ps") + +# SimObject is a minimal extension of ConfigNode, implementing a +# hierarchy node that corresponds to an M5 SimObject. It prints out a +# "type=" line to indicate its SimObject class, prints out the +# assigned parameters corresponding to its class, and allows +# parameters to be set by keyword in the constructor. Note that most +# of the heavy lifting for the SimObject param handling is done in the +# MetaConfigNode metaclass. +class SimObject(ConfigNode): + __metaclass__ = MetaSimObject + type = 'SimObject' + +from objects import * diff --git a/python/m5/objects/AlphaConsole.mpy b/python/m5/objects/AlphaConsole.mpy new file mode 100644 index 000000000..79918a01e --- /dev/null +++ b/python/m5/objects/AlphaConsole.mpy @@ -0,0 +1,9 @@ +from Device import PioDevice + +simobj AlphaConsole(PioDevice): + type = 'AlphaConsole' + cpu = Param.BaseCPU(Super, "Processor") + disk = Param.SimpleDisk("Simple Disk") + num_cpus = Param.Int(1, "Number of CPUs") + sim_console = Param.SimConsole(Super, "The Simulator Console") + system = Param.BaseSystem(Super, "system object") diff --git a/python/m5/objects/AlphaTLB.mpy b/python/m5/objects/AlphaTLB.mpy new file mode 100644 index 000000000..8e7cd62cc --- /dev/null +++ b/python/m5/objects/AlphaTLB.mpy @@ -0,0 +1,12 @@ +simobj AlphaTLB(SimObject): + type = 'AlphaTLB' + abstract = True + size = Param.Int("TLB size") + +simobj AlphaDTB(AlphaTLB): + type = 'AlphaDTB' + size = 64 + +simobj AlphaITB(AlphaTLB): + type = 'AlphaITB' + size = 48 diff --git a/python/m5/objects/BadDevice.mpy b/python/m5/objects/BadDevice.mpy new file mode 100644 index 000000000..35a12e0bf --- /dev/null +++ b/python/m5/objects/BadDevice.mpy @@ -0,0 +1,5 @@ +from Device import PioDevice + +simobj BadDevice(PioDevice): + type = 'BadDevice' + devicename = Param.String("Name of device to error on") diff --git a/python/m5/objects/BaseCPU.mpy b/python/m5/objects/BaseCPU.mpy new file mode 100644 index 000000000..484fcccd6 --- /dev/null +++ b/python/m5/objects/BaseCPU.mpy @@ -0,0 +1,25 @@ +simobj BaseCPU(SimObject): + type = 'BaseCPU' + abstract = True + icache = Param.BaseMem(NULL, "L1 instruction cache object") + dcache = Param.BaseMem(NULL, "L1 data cache object") + + if Bool._convert(env.get('FULL_SYSTEM', 'False')): + dtb = Param.AlphaDTB("Data TLB") + itb = Param.AlphaITB("Instruction TLB") + mem = Param.FunctionalMemory("memory") + system = Param.BaseSystem(Super, "system object") + else: + workload = VectorParam.Process("processes to run") + + max_insts_all_threads = Param.Counter(0, + "terminate when all threads have reached this inst count") + max_insts_any_thread = Param.Counter(0, + "terminate when any thread reaches this inst count") + max_loads_all_threads = Param.Counter(0, + "terminate when all threads have reached this load count") + max_loads_any_thread = Param.Counter(0, + "terminate when any thread reaches this load count") + + defer_registration = Param.Bool(False, + "defer registration with system (for sampling)") diff --git a/python/m5/objects/BaseCache.mpy b/python/m5/objects/BaseCache.mpy new file mode 100644 index 000000000..98a422e30 --- /dev/null +++ b/python/m5/objects/BaseCache.mpy @@ -0,0 +1,38 @@ +from BaseMem import BaseMem + +simobj BaseCache(BaseMem): + type = 'BaseCache' + adaptive_compression = Param.Bool(False, + "Use an adaptive compression scheme") + assoc = Param.Int("associativity") + block_size = Param.Int("block size in bytes") + compressed_bus = Param.Bool(False, + "This cache connects to a compressed memory") + compression_latency = Param.Int(0, + "Latency in cycles of compression algorithm") + do_copy = Param.Bool(False, "perform fast copies in the cache") + hash_delay = Param.Int(1, "time in cycles of hash access") + in_bus = Param.Bus(NULL, "incoming bus object") + lifo = Param.Bool(False, + "whether this NIC partition should use LIFO repl. policy") + max_miss_count = Param.Counter(0, + "number of misses to handle before calling exit") + mshrs = Param.Int("number of MSHRs (max outstanding requests)") + out_bus = Param.Bus("outgoing bus object") + prioritizeRequests = Param.Bool(False, + "always service demand misses first") + protocol = Param.CoherenceProtocol(NULL, "coherence protocol to use") + repl = Param.Repl(NULL, "replacement policy") + size = Param.Int("capacity in bytes") + split = Param.Bool(False, "whether or not this cache is split") + split_size = Param.Int(0, + "How many ways of the cache belong to CPU/LRU partition") + store_compressed = Param.Bool(False, + "Store compressed data in the cache") + subblock_size = Param.Int(0, + "Size of subblock in IIC used for compression") + tgts_per_mshr = Param.Int("max number of accesses per MSHR") + trace_addr = Param.Addr(0, "address to trace") + two_queue = Param.Bool(False, + "whether the lifo should have two queue replacement") + write_buffers = Param.Int(8, "number of write buffers") diff --git a/python/m5/objects/BaseSystem.mpy b/python/m5/objects/BaseSystem.mpy new file mode 100644 index 000000000..1cbdf4e99 --- /dev/null +++ b/python/m5/objects/BaseSystem.mpy @@ -0,0 +1,15 @@ +simobj BaseSystem(SimObject): + type = 'BaseSystem' + abstract = True + memctrl = Param.MemoryController(Super, "memory controller") + physmem = Param.PhysicalMemory(Super, "phsyical memory") + kernel = Param.String("file that contains the kernel code") + console = Param.String("file that contains the console code") + pal = Param.String("file that contains palcode") + readfile = Param.String("", "file to read startup script from") + init_param = Param.UInt64(0, "numerical value to pass into simulator") + boot_osflags = Param.String("a", "boot flags to pass to the kernel") + system_type = Param.UInt64("Type of system we are emulating") + system_rev = Param.UInt64("Revision of system we are emulating") + bin = Param.Bool(False, "is this system binned") + binned_fns = VectorParam.String([], "functions broken down and binned") diff --git a/python/m5/objects/Bus.mpy b/python/m5/objects/Bus.mpy new file mode 100644 index 000000000..025d69785 --- /dev/null +++ b/python/m5/objects/Bus.mpy @@ -0,0 +1,6 @@ +from BaseHier import BaseHier + +simobj Bus(BaseHier): + type = 'Bus' + clock_ratio = Param.Int("ratio of CPU to bus frequency") + width = Param.Int("bus width in bytes") diff --git a/python/m5/objects/CoherenceProtocol.mpy b/python/m5/objects/CoherenceProtocol.mpy new file mode 100644 index 000000000..f3b0026b7 --- /dev/null +++ b/python/m5/objects/CoherenceProtocol.mpy @@ -0,0 +1,6 @@ +class Coherence(Enum): vals = ['uni', 'msi', 'mesi', 'mosi', 'moesi'] + +simobj CoherenceProtocol(SimObject): + type = 'CoherenceProtocol' + do_upgrades = Param.Bool(True, "use upgrade transactions?") + protocol = Param.Coherence("name of coherence protocol") diff --git a/python/m5/objects/Device.mpy b/python/m5/objects/Device.mpy new file mode 100644 index 000000000..47f8db1cb --- /dev/null +++ b/python/m5/objects/Device.mpy @@ -0,0 +1,33 @@ +from FunctionalMemory import FunctionalMemory + +# This device exists only because there are some devices that I don't +# want to have a Platform parameter because it would cause a cycle in +# the C++ that cannot be easily solved. +# +# The real solution to this problem is to pass the ParamXXX structure +# to the constructor, but with the express condition that SimObject +# parameter values are not to be available at construction time. If +# some further configuration must be done, it must be done during the +# initialization phase at which point all SimObject pointers will be +# valid. +simobj FooPioDevice(FunctionalMemory): + type = 'PioDevice' + abstract = True + addr = Param.Addr("Device Address") + mmu = Param.MemoryController(Super, "Memory Controller") + io_bus = Param.Bus(NULL, "The IO Bus to attach to") + pio_latency = Param.Tick(1, "Programmed IO latency in bus cycles") + +simobj FooDmaDevice(FooPioDevice): + type = 'DmaDevice' + abstract = True + +simobj PioDevice(FooPioDevice): + type = 'PioDevice' + abstract = True + platform = Param.Platform(Super, "Platform") + +simobj DmaDevice(PioDevice): + type = 'DmaDevice' + abstract = True + diff --git a/python/m5/objects/DiskImage.mpy b/python/m5/objects/DiskImage.mpy new file mode 100644 index 000000000..80ef7b072 --- /dev/null +++ b/python/m5/objects/DiskImage.mpy @@ -0,0 +1,14 @@ +simobj DiskImage(SimObject): + type = 'DiskImage' + abstract = True + image_file = Param.String("disk image file") + read_only = Param.Bool(False, "read only image") + +simobj RawDiskImage(DiskImage): + type = 'RawDiskImage' + +simobj CowDiskImage(DiskImage): + type = 'CowDiskImage' + child = Param.DiskImage("child image") + table_size = Param.Int(65536, "initial table size") + image_file = '' diff --git a/python/m5/objects/Ethernet.mpy b/python/m5/objects/Ethernet.mpy new file mode 100644 index 000000000..088df4b93 --- /dev/null +++ b/python/m5/objects/Ethernet.mpy @@ -0,0 +1,86 @@ +from Device import DmaDevice +from Pci import PciDevice + +simobj EtherInt(SimObject): + type = 'EtherInt' + abstract = True + peer = Param.EtherInt(NULL, "peer interface") + +simobj EtherLink(SimObject): + type = 'EtherLink' + int1 = Param.EtherInt("interface 1") + int2 = Param.EtherInt("interface 2") + delay = Param.Tick(0, "transmit delay of packets in us") + speed = Param.Tick(100000000, "link speed in bits per second") + dump = Param.EtherDump(NULL, "dump object") + +simobj EtherBus(SimObject): + type = 'EtherBus' + loopback = Param.Bool(True, + "send packet back to the interface from which it came") + dump = Param.EtherDump(NULL, "dump object") + speed = Param.UInt64(100000000, "bus speed in bits per second") + +simobj EtherTap(EtherInt): + type = 'EtherTap' + bufsz = Param.Int(10000, "tap buffer size") + dump = Param.EtherDump(NULL, "dump object") + port = Param.UInt16(3500, "tap port") + +simobj EtherDump(SimObject): + type = 'EtherDump' + file = Param.String("dump file") + +simobj EtherDev(DmaDevice): + type = 'EtherDev' + hardware_address = Param.EthernetAddr(NextEthernetAddr, + "Ethernet Hardware Address") + + dma_data_free = Param.Bool(False, "DMA of Data is free") + dma_desc_free = Param.Bool(False, "DMA of Descriptors is free") + dma_read_delay = Param.Tick(0, "fixed delay for dma reads") + dma_read_factor = Param.Tick(0, "multiplier for dma reads") + dma_write_delay = Param.Tick(0, "fixed delay for dma writes") + dma_write_factor = Param.Tick(0, "multiplier for dma writes") + + rx_filter = Param.Bool(True, "Enable Receive Filter") + rx_delay = Param.Tick(1000, "Receive Delay") + tx_delay = Param.Tick(1000, "Transmit Delay") + + intr_delay = Param.Tick(0, "Interrupt Delay in microseconds") + payload_bus = Param.Bus(NULL, "The IO Bus to attach to for payload") + physmem = Param.PhysicalMemory(Super, "Physical Memory") + tlaser = Param.Turbolaser(Super, "Turbolaser") + +simobj NSGigE(PciDevice): + type = 'NSGigE' + hardware_address = Param.EthernetAddr(NextEthernetAddr, + "Ethernet Hardware Address") + + dma_data_free = Param.Bool(False, "DMA of Data is free") + dma_desc_free = Param.Bool(False, "DMA of Descriptors is free") + dma_read_delay = Param.Tick(0, "fixed delay for dma reads") + dma_read_factor = Param.Tick(0, "multiplier for dma reads") + dma_write_delay = Param.Tick(0, "fixed delay for dma writes") + dma_write_factor = Param.Tick(0, "multiplier for dma writes") + + rx_filter = Param.Bool(True, "Enable Receive Filter") + rx_delay = Param.Tick(1000, "Receive Delay") + tx_delay = Param.Tick(1000, "Transmit Delay") + + rx_fifo_size = Param.Int(131072, "max size in bytes of rxFifo") + tx_fifo_size = Param.Int(131072, "max size in bytes of txFifo") + + intr_delay = Param.Tick(0, "Interrupt Delay in microseconds") + payload_bus = Param.Bus(NULL, "The IO Bus to attach to for payload") + physmem = Param.PhysicalMemory(Super, "Physical Memory") + +simobj EtherDevInt(EtherInt): + type = 'EtherDevInt' + device = Param.EtherDev("Ethernet device of this interface") + +simobj NSGigEInt(EtherInt): + type = 'NSGigEInt' + device = Param.NSGigE("Ethernet device of this interface") + + diff --git a/python/m5/objects/Ide.mpy b/python/m5/objects/Ide.mpy new file mode 100644 index 000000000..ce760ad96 --- /dev/null +++ b/python/m5/objects/Ide.mpy @@ -0,0 +1,14 @@ +from Pci import PciDevice + +class IdeID(Enum): vals = ['master', 'slave'] + +simobj IdeDisk(SimObject): + type = 'IdeDisk' + delay = Param.Tick(1, "Fixed disk delay in microseconds") + driveID = Param.IdeID('master', "Drive ID") + image = Param.DiskImage("Disk image") + physmem = Param.PhysicalMemory(Super, "Physical memory") + +simobj IdeController(PciDevice): + type = 'IdeController' + disks = VectorParam.IdeDisk("IDE disks attached to this controller") diff --git a/python/m5/objects/IntrControl.mpy b/python/m5/objects/IntrControl.mpy new file mode 100644 index 000000000..1ef5a17ee --- /dev/null +++ b/python/m5/objects/IntrControl.mpy @@ -0,0 +1,3 @@ +simobj IntrControl(SimObject): + type = 'IntrControl' + cpu = Param.BaseCPU(Super, "the cpu") diff --git a/python/m5/objects/MemTest.mpy b/python/m5/objects/MemTest.mpy new file mode 100644 index 000000000..af14ed9c3 --- /dev/null +++ b/python/m5/objects/MemTest.mpy @@ -0,0 +1,18 @@ +simobj MemTest(SimObject): + type = 'MemTest' + cache = Param.BaseCache("L1 cache") + check_mem = Param.FunctionalMemory("check memory") + main_mem = Param.FunctionalMemory("hierarchical memory") + max_loads = Param.Counter("number of loads to execute") + memory_size = Param.Int(65536, "memory size") + percent_copies = Param.Percent(0, "target copy percentage") + percent_dest_unaligned = Param.Percent(50, + "percent of copy dest address that are unaligned") + percent_reads = Param.Percent(65, "target read percentage") + percent_source_unaligned = Param.Percent(50, + "percent of copy source address that are unaligned") + percent_uncacheable = Param.Percent(10, + "target uncacheable percentage") + progress_interval = Param.Counter(1000000, + "progress report interval (in accesses)") + trace_addr = Param.Addr(0, "address to trace") diff --git a/python/m5/objects/Pci.mpy b/python/m5/objects/Pci.mpy new file mode 100644 index 000000000..caa3c52ff --- /dev/null +++ b/python/m5/objects/Pci.mpy @@ -0,0 +1,52 @@ +from Device import FooPioDevice, DmaDevice + +simobj PciConfigData(FooPioDevice): + type = 'PciConfigData' + addr = 0xffffffffffffffffL + VendorID = Param.UInt16("Vendor ID") + DeviceID = Param.UInt16("Device ID") + Command = Param.UInt16(0, "Command") + Status = Param.UInt16(0, "Status") + Revision = Param.UInt8(0, "Device") + ProgIF = Param.UInt8(0, "Programming Interface") + SubClassCode = Param.UInt8(0, "Sub-Class Code") + ClassCode = Param.UInt8(0, "Class Code") + CacheLineSize = Param.UInt8(0, "System Cacheline Size") + LatencyTimer = Param.UInt8(0, "PCI Latency Timer") + HeaderType = Param.UInt8(0, "PCI Header Type") + BIST = Param.UInt8(0, "Built In Self Test") + + BAR0 = Param.UInt32(0x00, "Base Address Register 0") + BAR1 = Param.UInt32(0x00, "Base Address Register 1") + BAR2 = Param.UInt32(0x00, "Base Address Register 2") + BAR3 = Param.UInt32(0x00, "Base Address Register 3") + BAR4 = Param.UInt32(0x00, "Base Address Register 4") + BAR5 = Param.UInt32(0x00, "Base Address Register 5") + BAR0Size = Param.UInt32(0, "Base Address Register 0 Size") + BAR1Size = Param.UInt32(0, "Base Address Register 1 Size") + BAR2Size = Param.UInt32(0, "Base Address Register 2 Size") + BAR3Size = Param.UInt32(0, "Base Address Register 3 Size") + BAR4Size = Param.UInt32(0, "Base Address Register 4 Size") + BAR5Size = Param.UInt32(0, "Base Address Register 5 Size") + + CardbusCIS = Param.UInt32(0x00, "Cardbus Card Information Structure") + SubsystemID = Param.UInt16(0x00, "Subsystem ID") + SubsystemVendorID = Param.UInt16(0x00, "Subsystem Vendor ID") + ExpansionROM = Param.UInt32(0x00, "Expansion ROM Base Address") + InterruptLine = Param.UInt8(0x00, "Interrupt Line") + InterruptPin = Param.UInt8(0x00, "Interrupt Pin") + MaximumLatency = Param.UInt8(0x00, "Maximum Latency") + MinimumGrant = Param.UInt8(0x00, "Minimum Grant") + +simobj PciConfigAll(FooPioDevice): + type = 'PciConfigAll' + +simobj PciDevice(DmaDevice): + type = 'PciDevice' + abstract = True + pci_bus = Param.Int("PCI bus") + pci_dev = Param.Int("PCI device number") + pci_func = Param.Int("PCI function code") + configdata = Param.PciConfigData(Super, "PCI Config data") + configspace = Param.PciConfigAll(Super, "PCI Configspace") + addr = 0xffffffffffffffffL diff --git a/python/m5/objects/PhysicalMemory.mpy b/python/m5/objects/PhysicalMemory.mpy new file mode 100644 index 000000000..d1e4ad4b4 --- /dev/null +++ b/python/m5/objects/PhysicalMemory.mpy @@ -0,0 +1,7 @@ +from FunctionalMemory import FunctionalMemory + +simobj PhysicalMemory(FunctionalMemory): + type = 'PhysicalMemory' + range = Param.AddrRange("Device Address") + file = Param.String('', "memory mapped file") + mmu = Param.MemoryController(Super, "Memory Controller") diff --git a/python/m5/objects/Platform.mpy b/python/m5/objects/Platform.mpy new file mode 100644 index 000000000..d0510eaf8 --- /dev/null +++ b/python/m5/objects/Platform.mpy @@ -0,0 +1,5 @@ +simobj Platform(SimObject): + type = 'Platform' + abstract = True + interrupt_frequency = Param.Tick(1200, "frequency of interrupts") + intrctrl = Param.IntrControl(Super, "interrupt controller") diff --git a/python/m5/objects/Process.mpy b/python/m5/objects/Process.mpy new file mode 100644 index 000000000..6a91c09c2 --- /dev/null +++ b/python/m5/objects/Process.mpy @@ -0,0 +1,15 @@ +simobj Process(SimObject): + type = 'Process' + abstract = True + output = Param.String('cout', 'filename for stdout/stderr') + +simobj LiveProcess(Process): + type = 'LiveProcess' + cmd = VectorParam.String("command line (executable plus arguments)") + env = VectorParam.String('', "environment settings") + input = Param.String('cin', "filename for stdin") + +simobj EioProcess(Process): + type = 'EioProcess' + chkpt = Param.String('', "EIO checkpoint file name (optional)") + file = Param.String("EIO trace file name") diff --git a/python/m5/objects/Repl.mpy b/python/m5/objects/Repl.mpy new file mode 100644 index 000000000..fff5a2a02 --- /dev/null +++ b/python/m5/objects/Repl.mpy @@ -0,0 +1,9 @@ +simobj Repl(SimObject): + type = 'Repl' + abstract = True + +simobj GenRepl(Repl): + type = 'GenRepl' + fresh_res = Param.Int("associativity") + num_pools = Param.Int("capacity in bytes") + pool_res = Param.Int("block size in bytes") diff --git a/python/m5/objects/Root.mpy b/python/m5/objects/Root.mpy new file mode 100644 index 000000000..0e531054b --- /dev/null +++ b/python/m5/objects/Root.mpy @@ -0,0 +1,15 @@ +from HierParams import HierParams +from Serialize import Serialize +from Statistics import Statistics +from Trace import Trace + +simobj Root(SimObject): + type = 'Root' + frequency = Param.Tick(200000000, "tick frequency") + output_file = Param.String('cout', "file to dump simulator output to") + full_system = Param.Bool("Full system simulation?") + hier = HierParams(do_data = False, do_events = True) + checkpoint = Param.String('', "Checkpoint file") + stats = Statistics() + trace = Trace() + serialize = Serialize() diff --git a/python/m5/objects/SimConsole.mpy b/python/m5/objects/SimConsole.mpy new file mode 100644 index 000000000..fb74f1775 --- /dev/null +++ b/python/m5/objects/SimConsole.mpy @@ -0,0 +1,11 @@ +simobj ConsoleListener(SimObject): + type = 'ConsoleListener' + port = Param.UInt16(3456, "listen port") + +simobj SimConsole(SimObject): + type = 'SimConsole' + append_name = Param.Bool(True, "append name() to filename") + intr_control = Param.IntrControl(Super, "interrupt controller") + listener = Param.ConsoleListener("console listener") + number = Param.Int(0, "console number") + output = Param.String('console', "file to dump output to") diff --git a/python/m5/objects/SimpleDisk.mpy b/python/m5/objects/SimpleDisk.mpy new file mode 100644 index 000000000..c4dd5435b --- /dev/null +++ b/python/m5/objects/SimpleDisk.mpy @@ -0,0 +1,4 @@ +simobj SimpleDisk(SimObject): + type = 'SimpleDisk' + disk = Param.DiskImage("Disk Image") + physmem = Param.PhysicalMemory(Super, "Physical Memory") diff --git a/python/m5/objects/Tsunami.mpy b/python/m5/objects/Tsunami.mpy new file mode 100644 index 000000000..cfe23977e --- /dev/null +++ b/python/m5/objects/Tsunami.mpy @@ -0,0 +1,25 @@ +from Device import FooPioDevice +from Platform import Platform + +simobj Tsunami(Platform): + type = 'Tsunami' + pciconfig = Param.PciConfigAll("PCI configuration") + system = Param.BaseSystem(Super, "system") + interrupt_frequency = Param.Int(1024, "frequency of interrupts") + +simobj TsunamiCChip(FooPioDevice): + type = 'TsunamiCChip' + tsunami = Param.Tsunami(Super, "Tsunami") + +simobj TsunamiFake(FooPioDevice): + type = 'TsunamiFake' + +simobj TsunamiIO(FooPioDevice): + type = 'TsunamiIO' + time = Param.UInt64(1136073600, + "System time to use (0 for actual time, default is 1/1/06)") + tsunami = Param.Tsunami(Super, "Tsunami") + +simobj TsunamiPChip(FooPioDevice): + type = 'TsunamiPChip' + tsunami = Param.Tsunami(Super, "Tsunami") diff --git a/python/m5/objects/Uart.mpy b/python/m5/objects/Uart.mpy new file mode 100644 index 000000000..76ee8805f --- /dev/null +++ b/python/m5/objects/Uart.mpy @@ -0,0 +1,6 @@ +from Device import PioDevice + +simobj Uart(PioDevice): + type = 'Uart' + console = Param.SimConsole(Super, "The console") + size = Param.Addr(0x8, "Device size") diff --git a/sim/main.cc b/sim/main.cc index c15d24453..ee59cb83b 100644 --- a/sim/main.cc +++ b/sim/main.cc @@ -51,6 +51,7 @@ #include "base/time.hh" #include "cpu/base_cpu.hh" #include "cpu/full_cpu/smt.hh" +#include "python/pyconfig.hh" #include "sim/async.hh" #include "sim/builder.hh" #include "sim/configfile.hh" @@ -61,7 +62,6 @@ #include "sim/stat_control.hh" #include "sim/stats.hh" #include "sim/universe.hh" -#include "sim/pyconfig/pyconfig.hh" using namespace std; diff --git a/sim/pyconfig/SConscript b/sim/pyconfig/SConscript deleted file mode 100644 index 2799ef64f..000000000 --- a/sim/pyconfig/SConscript +++ /dev/null @@ -1,215 +0,0 @@ -# -*- mode:python -*- - -# Copyright (c) 2005 The Regents of The University of Michigan -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer; -# redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution; -# neither the name of the copyright holders nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import os, os.path, re - -def WriteEmbeddedPyFile(target, source, path, name, ext, filename): - if isinstance(source, str): - source = file(source, 'r') - - if isinstance(target, str): - target = file(target, 'w') - - print >>target, "AddModule(%s, %s, %s, %s, '''\\" % \ - (`path`, `name`, `ext`, `filename`) - - for line in source: - line = line - # escape existing backslashes - line = line.replace('\\', '\\\\') - # escape existing triple quotes - line = line.replace("'''", r"\'\'\'") - - print >>target, line, - - print >>target, "''')" - print >>target - -def WriteCFile(target, source, name): - if isinstance(source, str): - source = file(source, 'r') - - if isinstance(target, str): - target = file(target, 'w') - - print >>target, 'const char %s_string[] = {' % name - - count = 0 - from array import array - try: - while True: - foo = array('B') - foo.fromfile(source, 10000) - l = [ str(i) for i in foo.tolist() ] - count += len(l) - for i in xrange(0,9999,20): - print >>target, ','.join(l[i:i+20]) + ',' - except EOFError: - l = [ str(i) for i in foo.tolist() ] - count += len(l) - for i in xrange(0,len(l),20): - print >>target, ','.join(l[i:i+20]) + ',' - print >>target, ','.join(l[i:]) + ',' - - print >>target, '};' - print >>target, 'const int %s_length = %d;' % (name, count) - print >>target - -def splitpath(path): - dir,file = os.path.split(path) - path = [] - assert(file) - while dir: - dir,base = os.path.split(dir) - path.insert(0, base) - return path, file - -Import('env') -def MakeEmbeddedPyFile(target, source, env): - target = file(str(target[0]), 'w') - - tree = {} - for src in source: - src = str(src) - path,pyfile = splitpath(src) - node = tree - for dir in path: - if not node.has_key(dir): - node[dir] = { } - node = node[dir] - - name,ext = pyfile.split('.') - if name == '__init__': - node['.hasinit'] = True - node[pyfile] = (src,name,ext,src) - - done = False - while not done: - done = True - for name,entry in tree.items(): - if not isinstance(entry, dict): continue - if entry.has_key('.hasinit'): continue - - done = False - del tree[name] - for key,val in entry.iteritems(): - if tree.has_key(key): - raise NameError, \ - "dir already has %s can't add it again" % key - tree[key] = val - - files = [] - def populate(node, path = []): - names = node.keys() - names.sort() - for name in names: - if name == '.hasinit': - continue - - entry = node[name] - if isinstance(entry, dict): - if not entry.has_key('.hasinit'): - raise NameError, 'package directory missing __init__.py' - populate(entry, path + [ name ]) - else: - pyfile,name,ext,filename = entry - files.append((pyfile, path, name, ext, filename)) - populate(tree) - - for pyfile, path, name, ext, filename in files: - WriteEmbeddedPyFile(target, pyfile, path, name, ext, filename) - -def MakeDefinesPyFile(target, source, env): - target = file(str(target[0]), 'w') - - print >>target, "import os" - defines = env['CPPDEFINES'] - if isinstance(defines, list): - for var in defines: - if isinstance(var, tuple): - key,val = var - else: - key,val = var,'True' - - if not isinstance(key, basestring): - panic("invalid type for define: %s" % type(key)) - - print >>target, "os.environ['%s'] = '%s'" % (key, val) - - elif isinstance(defines, dict): - for key,val in defines.iteritems(): - print >>target, "os.environ['%s'] = '%s'" % (key, val) - else: - panic("invalid type for defines: %s" % type(defines)) - -CFileCounter = 0 -def MakePythonCFile(target, source, env): - global CFileCounter - target = file(str(target[0]), 'w') - - print >>target, '''\ -#include "base/embedfile.hh" - -namespace { -''' - for src in source: - src = str(src) - fname = os.path.basename(src) - name = 'embedded_file%d' % CFileCounter - CFileCounter += 1 - WriteCFile(target, src, name) - print >>target, '''\ -EmbedMap %(name)s("%(fname)s", - %(name)s_string, %(name)s_length); - -''' % locals() - print >>target, '''\ - -/* namespace */ } -''' - -embedded_py_files = ['m5config.py', 'importer.py', '../../util/pbs/jobfile.py'] -objpath = os.path.join(env['SRCDIR'], 'objects') -for root, dirs, files in os.walk(objpath, topdown=True): - for i,dir in enumerate(dirs): - if dir == 'SCCS': - del dirs[i] - break - - assert(root.startswith(objpath)) - for f in files: - if f.endswith('.mpy') or f.endswith('.py'): - embedded_py_files.append(os.path.join(root, f)) - -embedfile_hh = os.path.join(env['SRCDIR'], 'base/embedfile.hh') -env.Command('defines.py', None, MakeDefinesPyFile) -env.Command('embedded_py.py', embedded_py_files, MakeEmbeddedPyFile) -env.Depends('embedded_py.cc', embedfile_hh) -env.Command('embedded_py.cc', - ['string_importer.py', 'defines.py', 'embedded_py.py'], - MakePythonCFile) diff --git a/sim/pyconfig/m5config.py b/sim/pyconfig/m5config.py deleted file mode 100644 index e6201b3ad..000000000 --- a/sim/pyconfig/m5config.py +++ /dev/null @@ -1,1303 +0,0 @@ -# Copyright (c) 2004 The Regents of The University of Michigan -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer; -# redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution; -# neither the name of the copyright holders nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -from __future__ import generators -import os, re, sys, types, inspect - -from importer import AddToPath, LoadMpyFile - -noDot = False -try: - import pydot -except: - noDot = True - -env = {} -env.update(os.environ) - -def panic(string): - print >>sys.stderr, 'panic:', string - sys.exit(1) - -def issequence(value): - return isinstance(value, tuple) or isinstance(value, list) - -class Singleton(type): - def __call__(cls, *args, **kwargs): - if hasattr(cls, '_instance'): - return cls._instance - - cls._instance = super(Singleton, cls).__call__(*args, **kwargs) - return cls._instance - -##################################################################### -# -# M5 Python Configuration Utility -# -# The basic idea is to write simple Python programs that build Python -# objects corresponding to M5 SimObjects for the deisred simulation -# configuration. For now, the Python emits a .ini file that can be -# parsed by M5. In the future, some tighter integration between M5 -# and the Python interpreter may allow bypassing the .ini file. -# -# Each SimObject class in M5 is represented by a Python class with the -# same name. The Python inheritance tree mirrors the M5 C++ tree -# (e.g., SimpleCPU derives from BaseCPU in both cases, and all -# SimObjects inherit from a single SimObject base class). To specify -# an instance of an M5 SimObject in a configuration, the user simply -# instantiates the corresponding Python object. The parameters for -# that SimObject are given by assigning to attributes of the Python -# object, either using keyword assignment in the constructor or in -# separate assignment statements. For example: -# -# cache = BaseCache('my_cache', root, size=64*K) -# cache.hit_latency = 3 -# cache.assoc = 8 -# -# (The first two constructor arguments specify the name of the created -# cache and its parent node in the hierarchy.) -# -# The magic lies in the mapping of the Python attributes for SimObject -# classes to the actual SimObject parameter specifications. This -# allows parameter validity checking in the Python code. Continuing -# the example above, the statements "cache.blurfl=3" or -# "cache.assoc='hello'" would both result in runtime errors in Python, -# since the BaseCache object has no 'blurfl' parameter and the 'assoc' -# parameter requires an integer, respectively. This magic is done -# primarily by overriding the special __setattr__ method that controls -# assignment to object attributes. -# -# The Python module provides another class, ConfigNode, which is a -# superclass of SimObject. ConfigNode implements the parent/child -# relationship for building the configuration hierarchy tree. -# Concrete instances of ConfigNode can be used to group objects in the -# hierarchy, but do not correspond to SimObjects themselves (like a -# .ini section with "children=" but no "type=". -# -# Once a set of Python objects have been instantiated in a hierarchy, -# calling 'instantiate(obj)' (where obj is the root of the hierarchy) -# will generate a .ini file. See simple-4cpu.py for an example -# (corresponding to m5-test/simple-4cpu.ini). -# -##################################################################### - -##################################################################### -# -# ConfigNode/SimObject classes -# -# The Python class hierarchy rooted by ConfigNode (which is the base -# class of SimObject, which in turn is the base class of all other M5 -# SimObject classes) has special attribute behavior. In general, an -# object in this hierarchy has three categories of attribute-like -# things: -# -# 1. Regular Python methods and variables. These must start with an -# underscore to be treated normally. -# -# 2. SimObject parameters. These values are stored as normal Python -# attributes, but all assignments to these attributes are checked -# against the pre-defined set of parameters stored in the class's -# _params dictionary. Assignments to attributes that do not -# correspond to predefined parameters, or that are not of the correct -# type, incur runtime errors. -# -# 3. Hierarchy children. The child nodes of a ConfigNode are stored -# in the node's _children dictionary, but can be accessed using the -# Python attribute dot-notation (just as they are printed out by the -# simulator). Children cannot be created using attribute assigment; -# they must be added by specifying the parent node in the child's -# constructor or using the '+=' operator. - -# The SimObject parameters are the most complex, for a few reasons. -# First, both parameter descriptions and parameter values are -# inherited. Thus parameter description lookup must go up the -# inheritance chain like normal attribute lookup, but this behavior -# must be explicitly coded since the lookup occurs in each class's -# _params attribute. Second, because parameter values can be set -# on SimObject classes (to implement default values), the parameter -# checking behavior must be enforced on class attribute assignments as -# well as instance attribute assignments. Finally, because we allow -# class specialization via inheritance (e.g., see the L1Cache class in -# the simple-4cpu.py example), we must do parameter checking even on -# class instantiation. To provide all these features, we use a -# metaclass to define most of the SimObject parameter behavior for -# this class hierarchy. -# -##################################################################### - -class Proxy(object): - def __init__(self, path = ()): - self._object = None - self._path = path - - def __getattr__(self, attr): - return Proxy(self._path + (attr, )) - - def __setattr__(self, attr, value): - if not attr.startswith('_'): - raise AttributeError, 'cannot set attribute %s' % attr - super(Proxy, self).__setattr__(attr, value) - - def _convert(self): - obj = self._object - for attr in self._path: - obj = obj.__getattribute__(attr) - return obj - -Super = Proxy() - -def isSubClass(value, cls): - try: - return issubclass(value, cls) - except: - return False - -def isConfigNode(value): - try: - return issubclass(value, ConfigNode) - except: - return False - -def isSimObject(value): - try: - return issubclass(value, SimObject) - except: - return False - -def isSimObjSequence(value): - if not issequence(value): - return False - - for val in value: - if not isNullPointer(val) and not isConfigNode(val): - return False - - return True - -def isParamContext(value): - try: - return issubclass(value, ParamContext) - except: - return False - - -class_decorator = 'M5M5_SIMOBJECT_' -expr_decorator = 'M5M5_EXPRESSION_' -dot_decorator = '_M5M5_DOT_' - -# The metaclass for ConfigNode (and thus for everything that derives -# from ConfigNode, including SimObject). This class controls how new -# classes that derive from ConfigNode are instantiated, and provides -# inherited class behavior (just like a class controls how instances -# of that class are instantiated, and provides inherited instance -# behavior). -class MetaConfigNode(type): - # Attributes that can be set only at initialization time - init_keywords = {} - # Attributes that can be set any time - keywords = { 'check' : types.FunctionType, - 'children' : types.ListType } - - # __new__ is called before __init__, and is where the statements - # in the body of the class definition get loaded into the class's - # __dict__. We intercept this to filter out parameter assignments - # and only allow "private" attributes to be passed to the base - # __new__ (starting with underscore). - def __new__(mcls, name, bases, dict): - # Copy "private" attributes (including special methods such as __new__) - # to the official dict. Everything else goes in _init_dict to be - # filtered in __init__. - cls_dict = {} - for key,val in dict.items(): - if key.startswith('_'): - cls_dict[key] = val - del dict[key] - cls_dict['_init_dict'] = dict - return super(MetaConfigNode, mcls).__new__(mcls, name, bases, cls_dict) - - # initialization - def __init__(cls, name, bases, dict): - super(MetaConfigNode, cls).__init__(name, bases, dict) - - # initialize required attributes - cls._params = {} - cls._values = {} - cls._enums = {} - cls._bases = [c for c in cls.__mro__ if isConfigNode(c)] - cls._anon_subclass_counter = 0 - - # If your parent has a value in it that's a config node, clone - # it. Do this now so if we update any of the values' - # attributes we are updating the clone and not the original. - for base in cls._bases: - for key,val in base._values.iteritems(): - - # don't clone if (1) we're about to overwrite it with - # a local setting or (2) we've already cloned a copy - # from an earlier (more derived) base - if cls._init_dict.has_key(key) or cls._values.has_key(key): - continue - - if isConfigNode(val): - cls._values[key] = val() - elif isSimObjSequence(val): - cls._values[key] = [ v() for v in val ] - elif isNullPointer(val): - cls._values[key] = val - - # now process _init_dict items - for key,val in cls._init_dict.items(): - if isinstance(val, _Param): - cls._params[key] = val - - # init-time-only keywords - elif cls.init_keywords.has_key(key): - cls._set_keyword(key, val, cls.init_keywords[key]) - - # enums - elif isinstance(val, type) and issubclass(val, Enum): - cls._enums[key] = val - - # See description of decorators in the importer.py file. - # We just strip off the expr_decorator now since we don't - # need from this point on. - elif key.startswith(expr_decorator): - key = key[len(expr_decorator):] - # because it had dots into a list so that we can find the - # proper variable to modify. - key = key.split(dot_decorator) - c = cls - for item in key[:-1]: - c = getattr(c, item) - setattr(c, key[-1], val) - - # default: use normal path (ends up in __setattr__) - else: - setattr(cls, key, val) - - - def _isvalue(cls, name): - for c in cls._bases: - if c._params.has_key(name): - return True - - for c in cls._bases: - if c._values.has_key(name): - return True - - return False - - # generator that iterates across all parameters for this class and - # all classes it inherits from - def _getparams(cls): - params = {} - for c in cls._bases: - for p,v in c._params.iteritems(): - if not params.has_key(p): - params[p] = v - return params - - # Lookup a parameter description by name in the given class. - def _getparam(cls, name, default = AttributeError): - for c in cls._bases: - if c._params.has_key(name): - return c._params[name] - if isSubClass(default, Exception): - raise default, \ - "object '%s' has no attribute '%s'" % (cls.__name__, name) - else: - return default - - def _hasvalue(cls, name): - for c in cls._bases: - if c._values.has_key(name): - return True - - return False - - def _getvalues(cls): - values = {} - for i,c in enumerate(cls._bases): - for p,v in c._values.iteritems(): - if not values.has_key(p): - values[p] = v - for p,v in c._params.iteritems(): - if not values.has_key(p) and hasattr(v, 'default'): - try: - v.valid(v.default) - except TypeError: - panic("Invalid default %s for param %s in node %s" - % (v.default,p,cls.__name__)) - v = v.default - cls._setvalue(p, v) - values[p] = v - - return values - - def _getvalue(cls, name, default = AttributeError): - value = None - for c in cls._bases: - if c._values.has_key(name): - value = c._values[name] - break - if value is not None: - return value - - param = cls._getparam(name, None) - if param is not None and hasattr(param, 'default'): - param.valid(param.default) - value = param.default - cls._setvalue(name, value) - return value - - if isSubClass(default, Exception): - raise default, 'value for %s not found' % name - else: - return default - - def _setvalue(cls, name, value): - cls._values[name] = value - - def __getattr__(cls, attr): - if cls._isvalue(attr): - return Value(cls, attr) - - if attr == '_cpp_param_decl' and hasattr(cls, 'type'): - return cls.type + '*' - - raise AttributeError, \ - "object '%s' has no attribute '%s'" % (cls.__name__, attr) - - def _set_keyword(cls, keyword, val, kwtype): - if not isinstance(val, kwtype): - raise TypeError, 'keyword %s has bad type %s (expecting %s)' % \ - (keyword, type(val), kwtype) - if isinstance(val, types.FunctionType): - val = classmethod(val) - type.__setattr__(cls, keyword, val) - - # Set attribute (called on foo.attr = value when foo is an - # instance of class cls). - def __setattr__(cls, attr, value): - # normal processing for private attributes - if attr.startswith('_'): - type.__setattr__(cls, attr, value) - return - - if cls.keywords.has_key(attr): - cls._set_keyword(attr, value, cls.keywords[attr]) - return - - # must be SimObject param - param = cls._getparam(attr, None) - if param: - # It's ok: set attribute by delegating to 'object' class. - # Note the use of param.make_value() to verify/canonicalize - # the assigned value - param.valid(value) - cls._setvalue(attr, value) - elif isConfigNode(value) or isSimObjSequence(value): - cls._setvalue(attr, value) - else: - raise AttributeError, \ - "Class %s has no parameter %s" % (cls.__name__, attr) - - def add_child(cls, instance, name, child): - if isNullPointer(child) or instance.top_child_names.has_key(name): - return - - if issequence(child): - kid = [] - for i,c in enumerate(child): - n = '%s%d' % (name, i) - k = c.instantiate(n, instance) - - instance.children.append(k) - instance.child_names[n] = k - instance.child_objects[c] = k - kid.append(k) - else: - kid = child.instantiate(name, instance) - instance.children.append(kid) - instance.child_names[name] = kid - instance.child_objects[child] = kid - - instance.top_child_names[name] = kid - - # Print instance info to .ini file. - def instantiate(cls, name, parent = None): - instance = Node(name, cls, cls.type, parent, isParamContext(cls)) - - if hasattr(cls, 'check'): - cls.check() - - for key,value in cls._getvalues().iteritems(): - if isConfigNode(value): - cls.add_child(instance, key, value) - if issequence(value): - list = [ v for v in value if isConfigNode(v) ] - if len(list): - cls.add_child(instance, key, list) - - for pname,param in cls._getparams().iteritems(): - try: - value = cls._getvalue(pname) - except: - panic('Error getting %s' % pname) - - try: - if isConfigNode(value): - value = instance.child_objects[value] - elif issequence(value): - v = [] - for val in value: - if isConfigNode(val): - v.append(instance.child_objects[val]) - else: - v.append(val) - value = v - - p = NodeParam(pname, param, value) - instance.params.append(p) - instance.param_names[pname] = p - except: - print 'Exception while evaluating %s.%s' % \ - (instance.path, pname) - raise - - return instance - - def _convert(cls, value): - realvalue = value - if isinstance(value, Node): - realvalue = value.realtype - - if isinstance(realvalue, Proxy): - return value - - if realvalue == None or isNullPointer(realvalue): - return value - - if isSubClass(realvalue, cls): - return value - - raise TypeError, 'object %s type %s wrong type, should be %s' % \ - (repr(realvalue), realvalue, cls) - - def _string(cls, value): - if isNullPointer(value): - return 'Null' - return Node._string(value) - -# The ConfigNode class is the root of the special hierarchy. Most of -# the code in this class deals with the configuration hierarchy itself -# (parent/child node relationships). -class ConfigNode(object): - # Specify metaclass. Any class inheriting from ConfigNode will - # get this metaclass. - __metaclass__ = MetaConfigNode - - def __new__(cls, **kwargs): - name = cls.__name__ + ("_%d" % cls._anon_subclass_counter) - cls._anon_subclass_counter += 1 - return cls.__metaclass__(name, (cls, ), kwargs) - -class ParamContext(ConfigNode): - pass - -class MetaSimObject(MetaConfigNode): - # init_keywords and keywords are inherited from MetaConfigNode, - # with overrides/additions - init_keywords = MetaConfigNode.init_keywords - init_keywords.update({ 'abstract' : types.BooleanType, - 'type' : types.StringType }) - - keywords = MetaConfigNode.keywords - # no additional keywords - - cpp_classes = [] - - # initialization - def __init__(cls, name, bases, dict): - super(MetaSimObject, cls).__init__(name, bases, dict) - - if hasattr(cls, 'type'): - if name == 'SimObject': - cls._cpp_base = None - elif hasattr(cls._bases[1], 'type'): - cls._cpp_base = cls._bases[1].type - else: - panic("SimObject %s derives from a non-C++ SimObject %s "\ - "(no 'type')" % (cls, cls_bases[1].__name__)) - - # This class corresponds to a C++ class: put it on the global - # list of C++ objects to generate param structs, etc. - MetaSimObject.cpp_classes.append(cls) - - def _cpp_decl(cls): - name = cls.__name__ - code = "" - code += "\n".join([e.cpp_declare() for e in cls._enums.values()]) - code += "\n" - param_names = cls._params.keys() - param_names.sort() - code += "struct Params" - if cls._cpp_base: - code += " : public %s::Params" % cls._cpp_base - code += " {\n " - code += "\n ".join([cls._params[pname].cpp_decl(pname) \ - for pname in param_names]) - code += "\n};\n" - return code - -class NodeParam(object): - def __init__(self, name, param, value): - self.name = name - self.param = param - self.ptype = param.ptype - self.convert = param.convert - self.string = param.string - self.value = value - -class Node(object): - all = {} - def __init__(self, name, realtype, type, parent, paramcontext): - self.name = name - self.realtype = realtype - self.type = type - self.parent = parent - self.children = [] - self.child_names = {} - self.child_objects = {} - self.top_child_names = {} - self.params = [] - self.param_names = {} - self.paramcontext = paramcontext - - path = [ self.name ] - node = self.parent - while node is not None: - if node.name != 'root': - path.insert(0, node.name) - else: - assert(node.parent is None) - node = node.parent - self.path = '.'.join(path) - - def find(self, realtype, path): - if not path: - if issubclass(self.realtype, realtype): - return self, True - - obj = None - for child in self.children: - if issubclass(child.realtype, realtype): - if obj is not None: - raise AttributeError, \ - 'Super matched more than one: %s %s' % \ - (obj.path, child.path) - obj = child - return obj, obj is not None - - try: - obj = self - for node in path[:-1]: - obj = obj.child_names[node] - - last = path[-1] - if obj.child_names.has_key(last): - value = obj.child_names[last] - if issubclass(value.realtype, realtype): - return value, True - elif obj.param_names.has_key(last): - value = obj.param_names[last] - realtype._convert(value.value) - return value.value, True - except KeyError: - pass - - return None, False - - def unproxy(self, ptype, value): - if not isinstance(value, Proxy): - return value - - if value is None: - raise AttributeError, 'Error while fixing up %s' % self.path - - obj = self - done = False - while not done: - if obj is None: - raise AttributeError, \ - 'Parent of %s type %s not found at path %s' \ - % (self.name, ptype, value._path) - found, done = obj.find(ptype, value._path) - if isinstance(found, Proxy): - done = False - obj = obj.parent - - return found - - def fixup(self): - self.all[self.path] = self - - for param in self.params: - ptype = param.ptype - pval = param.value - - try: - if issequence(pval): - param.value = [ self.unproxy(ptype, pv) for pv in pval ] - else: - param.value = self.unproxy(ptype, pval) - except: - print 'Error while fixing up %s:%s' % (self.path, param.name) - raise - - for child in self.children: - assert(child != self) - child.fixup() - - # print type and parameter values to .ini file - def display(self): - print '[' + self.path + ']' # .ini section header - - if isSimObject(self.realtype): - print 'type = %s' % self.type - - if self.children: - # instantiate children in same order they were added for - # backward compatibility (else we can end up with cpu1 - # before cpu0). Changing ordering can also influence timing - # in the current memory system, as caches get added to a bus - # in different orders which affects their priority in the - # case of simulataneous requests. We should uncomment the - # following line once we take care of that issue. - # self.children.sort(lambda x,y: cmp(x.name, y.name)) - children = [ c.name for c in self.children if not c.paramcontext] - print 'children =', ' '.join(children) - - self.params.sort(lambda x,y: cmp(x.name, y.name)) - for param in self.params: - try: - if param.value is None: - raise AttributeError, 'Parameter with no value' - - value = param.convert(param.value) - string = param.string(value) - except: - print 'exception in %s:%s' % (self.path, param.name) - raise - - print '%s = %s' % (param.name, string) - - print - - # recursively dump out children - for c in self.children: - c.display() - - # print type and parameter values to .ini file - def outputDot(self, dot): - - - label = "{%s|" % self.path - if isSimObject(self.realtype): - label += '%s|' % self.type - - if self.children: - # instantiate children in same order they were added for - # backward compatibility (else we can end up with cpu1 - # before cpu0). - for c in self.children: - dot.add_edge(pydot.Edge(self.path,c.path, style="bold")) - - simobjs = [] - for param in self.params: - try: - if param.value is None: - raise AttributeError, 'Parameter with no value' - - value = param.convert(param.value) - string = param.string(value) - except: - print 'exception in %s:%s' % (self.name, param.name) - raise - if isConfigNode(param.ptype) and string != "Null": - simobjs.append(string) - else: - label += '%s = %s\\n' % (param.name, string) - - for so in simobjs: - label += "|<%s> %s" % (so, so) - dot.add_edge(pydot.Edge("%s:%s" % (self.path, so), so, tailport="w")) - label += '}' - dot.add_node(pydot.Node(self.path,shape="Mrecord",label=label)) - - # recursively dump out children - for c in self.children: - c.outputDot(dot) - - def _string(cls, value): - if not isinstance(value, Node): - raise AttributeError, 'expecting %s got %s' % (Node, value) - return value.path - _string = classmethod(_string) - -##################################################################### -# -# Parameter description classes -# -# The _params dictionary in each class maps parameter names to -# either a Param or a VectorParam object. These objects contain the -# parameter description string, the parameter type, and the default -# value (loaded from the PARAM section of the .odesc files). The -# _convert() method on these objects is used to force whatever value -# is assigned to the parameter to the appropriate type. -# -# Note that the default values are loaded into the class's attribute -# space when the parameter dictionary is initialized (in -# MetaConfigNode._setparams()); after that point they aren't used. -# -##################################################################### - -def isNullPointer(value): - return isinstance(value, NullSimObject) - -class Value(object): - def __init__(self, obj, attr): - super(Value, self).__setattr__('attr', attr) - super(Value, self).__setattr__('obj', obj) - - def _getattr(self): - return self.obj._getvalue(self.attr) - - def __setattr__(self, attr, value): - setattr(self._getattr(), attr, value) - - def __getattr__(self, attr): - return getattr(self._getattr(), attr) - - def __getitem__(self, index): - return self._getattr().__getitem__(index) - - def __call__(self, *args, **kwargs): - return self._getattr().__call__(*args, **kwargs) - - def __nonzero__(self): - return bool(self._getattr()) - - def __str__(self): - return str(self._getattr()) - -# Regular parameter. -class _Param(object): - def __init__(self, ptype, *args, **kwargs): - if isinstance(ptype, types.StringType): - self.ptype_string = ptype - elif isinstance(ptype, type): - self.ptype = ptype - else: - raise TypeError, "Param type is not a type (%s)" % ptype - - if args: - if len(args) == 1: - self.desc = args[0] - elif len(args) == 2: - self.default = args[0] - self.desc = args[1] - else: - raise TypeError, 'too many arguments' - - if kwargs.has_key('desc'): - assert(not hasattr(self, 'desc')) - self.desc = kwargs['desc'] - del kwargs['desc'] - - if kwargs.has_key('default'): - assert(not hasattr(self, 'default')) - self.default = kwargs['default'] - del kwargs['default'] - - if kwargs: - raise TypeError, 'extra unknown kwargs %s' % kwargs - - if not hasattr(self, 'desc'): - raise TypeError, 'desc attribute missing' - - def __getattr__(self, attr): - if attr == 'ptype': - try: - self.ptype = eval(self.ptype_string) - return self.ptype - except: - raise TypeError, 'Param.%s: undefined type' % self.ptype_string - else: - raise AttributeError, "'%s' object has no attribute '%s'" % \ - (type(self).__name__, attr) - - def valid(self, value): - if not isinstance(value, Proxy): - self.ptype._convert(value) - - def convert(self, value): - return self.ptype._convert(value) - - def string(self, value): - return self.ptype._string(value) - - def set(self, name, instance, value): - instance.__dict__[name] = value - - def cpp_decl(self, name): - return '%s %s;' % (self.ptype._cpp_param_decl, name) - -class _ParamProxy(object): - def __init__(self, type): - self.ptype = type - - # E.g., Param.Int(5, "number of widgets") - def __call__(self, *args, **kwargs): - # Param type could be defined only in context of caller (e.g., - # for locally defined Enum subclass). Need to go look up the - # type in that enclosing scope. - caller_frame = inspect.stack()[1][0] - ptype = caller_frame.f_locals.get(self.ptype, None) - if not ptype: ptype = caller_frame.f_globals.get(self.ptype, None) - if not ptype: ptype = globals().get(self.ptype, None) - # ptype could still be None due to circular references... we'll - # try one more time to evaluate lazily when ptype is first needed. - # In the meantime we'll save the type name as a string. - if not ptype: ptype = self.ptype - return _Param(ptype, *args, **kwargs) - - def __getattr__(self, attr): - if attr == '__bases__': - raise AttributeError, '' - cls = type(self) - return cls(attr) - - def __setattr__(self, attr, value): - if attr != 'ptype': - raise AttributeError, \ - 'Attribute %s not available in %s' % (attr, self.__class__) - super(_ParamProxy, self).__setattr__(attr, value) - - -Param = _ParamProxy(None) - -# Vector-valued parameter description. Just like Param, except that -# the value is a vector (list) of the specified type instead of a -# single value. -class _VectorParam(_Param): - def __init__(self, type, *args, **kwargs): - _Param.__init__(self, type, *args, **kwargs) - - def valid(self, value): - if value == None: - return True - - if issequence(value): - for val in value: - if not isinstance(val, Proxy): - self.ptype._convert(val) - elif not isinstance(value, Proxy): - self.ptype._convert(value) - - # Convert assigned value to appropriate type. If the RHS is not a - # list or tuple, it generates a single-element list. - def convert(self, value): - if value == None: - return [] - - if issequence(value): - # list: coerce each element into new list - return [ self.ptype._convert(v) for v in value ] - else: - # singleton: coerce & wrap in a list - return self.ptype._convert(value) - - def string(self, value): - if issequence(value): - return ' '.join([ self.ptype._string(v) for v in value]) - else: - return self.ptype._string(value) - - def cpp_decl(self, name): - return 'std::vector<%s> %s;' % (self.ptype._cpp_param_decl, name) - -class _VectorParamProxy(_ParamProxy): - # E.g., VectorParam.Int(5, "number of widgets") - def __call__(self, *args, **kwargs): - return _VectorParam(self.ptype, *args, **kwargs) - -VectorParam = _VectorParamProxy(None) - -##################################################################### -# -# Parameter Types -# -# Though native Python types could be used to specify parameter types -# (the 'ptype' field of the Param and VectorParam classes), it's more -# flexible to define our own set of types. This gives us more control -# over how Python expressions are converted to values (via the -# __init__() constructor) and how these values are printed out (via -# the __str__() conversion method). Eventually we'll need these types -# to correspond to distinct C++ types as well. -# -##################################################################### -# Integer parameter type. -class _CheckedInt(object): - def _convert(cls, value): - t = type(value) - if t == bool: - return int(value) - - if t != int and t != long and t != float and t != str: - raise TypeError, 'Integer parameter of invalid type %s' % t - - if t == str or t == float: - value = long(value) - - if not cls._min <= value <= cls._max: - raise TypeError, 'Integer parameter out of bounds %d < %d < %d' % \ - (cls._min, value, cls._max) - - return value - _convert = classmethod(_convert) - - def _string(cls, value): - return str(value) - _string = classmethod(_string) - -class CheckedInt(type): - def __new__(cls, cppname, min, max): - # New class derives from _CheckedInt base with proper bounding - # parameters - dict = { '_cpp_param_decl' : cppname, '_min' : min, '_max' : max } - return type.__new__(cls, cppname, (_CheckedInt, ), dict) - -class CheckedIntType(CheckedInt): - def __new__(cls, cppname, size, unsigned): - dict = {} - if unsigned: - min = 0 - max = 2 ** size - 1 - else: - min = -(2 ** (size - 1)) - max = (2 ** (size - 1)) - 1 - - return super(cls, CheckedIntType).__new__(cls, cppname, min, max) - -Int = CheckedIntType('int', 32, False) -Unsigned = CheckedIntType('unsigned', 32, True) - -Int8 = CheckedIntType('int8_t', 8, False) -UInt8 = CheckedIntType('uint8_t', 8, True) -Int16 = CheckedIntType('int16_t', 16, False) -UInt16 = CheckedIntType('uint16_t', 16, True) -Int32 = CheckedIntType('int32_t', 32, False) -UInt32 = CheckedIntType('uint32_t', 32, True) -Int64 = CheckedIntType('int64_t', 64, False) -UInt64 = CheckedIntType('uint64_t', 64, True) - -Counter = CheckedIntType('Counter', 64, True) -Addr = CheckedIntType('Addr', 64, True) -Tick = CheckedIntType('Tick', 64, True) - -Percent = CheckedInt('int', 0, 100) - -class Pair(object): - def __init__(self, first, second): - self.first = first - self.second = second - -class _Range(object): - def _convert(cls, value): - if not isinstance(value, Pair): - raise TypeError, 'value %s is not a Pair' % value - return Pair(cls._type._convert(value.first), - cls._type._convert(value.second)) - _convert = classmethod(_convert) - - def _string(cls, value): - return '%s:%s' % (cls._type._string(value.first), - cls._type._string(value.second)) - _string = classmethod(_string) - -def RangeSize(start, size): - return Pair(start, start + size - 1) - -class Range(type): - def __new__(cls, type): - dict = { '_cpp_param_decl' : 'Range<%s>' % type._cpp_param_decl, - '_type' : type } - clsname = 'Range_' + type.__name__ - return super(cls, Range).__new__(cls, clsname, (_Range, ), dict) - -AddrRange = Range(Addr) - -# Boolean parameter type. -class Bool(object): - _cpp_param_decl = 'bool' - def _convert(value): - t = type(value) - if t == bool: - return value - - if t == int or t == long: - return bool(value) - - if t == str: - v = value.lower() - if v == "true" or v == "t" or v == "yes" or v == "y": - return True - elif v == "false" or v == "f" or v == "no" or v == "n": - return False - - raise TypeError, 'Bool parameter (%s) of invalid type %s' % (v, t) - _convert = staticmethod(_convert) - - def _string(value): - if value: - return "true" - else: - return "false" - _string = staticmethod(_string) - -# String-valued parameter. -class String(object): - _cpp_param_decl = 'string' - - # Constructor. Value must be Python string. - def _convert(cls,value): - if value is None: - return '' - if isinstance(value, str): - return value - - raise TypeError, \ - "String param got value %s %s" % (repr(value), type(value)) - _convert = classmethod(_convert) - - # Generate printable string version. Not too tricky. - def _string(cls, value): - return value - _string = classmethod(_string) - - -def IncEthernetAddr(addr, val = 1): - bytes = map(lambda x: int(x, 16), addr.split(':')) - bytes[5] += val - for i in (5, 4, 3, 2, 1): - val,rem = divmod(bytes[i], 256) - bytes[i] = rem - if val == 0: - break - bytes[i - 1] += val - assert(bytes[0] <= 255) - return ':'.join(map(lambda x: '%02x' % x, bytes)) - -class NextEthernetAddr(object): - __metaclass__ = Singleton - addr = "00:90:00:00:00:01" - - def __init__(self, inc = 1): - self.value = self.addr - self.addr = IncEthernetAddr(self.addr, inc) - -class EthernetAddr(object): - _cpp_param_decl = 'EthAddr' - - def _convert(cls, value): - if value == NextEthernetAddr: - return value - - if not isinstance(value, str): - raise TypeError, "expected an ethernet address and didn't get one" - - bytes = value.split(':') - if len(bytes) != 6: - raise TypeError, 'invalid ethernet address %s' % value - - for byte in bytes: - if not 0 <= int(byte) <= 256: - raise TypeError, 'invalid ethernet address %s' % value - - return value - _convert = classmethod(_convert) - - def _string(cls, value): - if value == NextEthernetAddr: - value = value().value - return value - _string = classmethod(_string) - -# Special class for NULL pointers. Note the special check in -# make_param_value() above that lets these be assigned where a -# SimObject is required. -# only one copy of a particular node -class NullSimObject(object): - __metaclass__ = Singleton - - def __call__(cls): - return cls - - def _instantiate(self, parent = None, path = ''): - pass - - def _convert(cls, value): - if value == Nxone: - return - - if isinstance(value, cls): - return value - - raise TypeError, 'object %s %s of the wrong type, should be %s' % \ - (repr(value), type(value), cls) - _convert = classmethod(_convert) - - def _string(): - return 'NULL' - _string = staticmethod(_string) - -# The only instance you'll ever need... -Null = NULL = NullSimObject() - -# Enumerated types are a little more complex. The user specifies the -# type as Enum(foo) where foo is either a list or dictionary of -# alternatives (typically strings, but not necessarily so). (In the -# long run, the integer value of the parameter will be the list index -# or the corresponding dictionary value. For now, since we only check -# that the alternative is valid and then spit it into a .ini file, -# there's not much point in using the dictionary.) - -# What Enum() must do is generate a new type encapsulating the -# provided list/dictionary so that specific values of the parameter -# can be instances of that type. We define two hidden internal -# classes (_ListEnum and _DictEnum) to serve as base classes, then -# derive the new type from the appropriate base class on the fly. - - -# Metaclass for Enum types -class MetaEnum(type): - - def __init__(cls, name, bases, init_dict): - if init_dict.has_key('map'): - if not isinstance(cls.map, dict): - raise TypeError, "Enum-derived class attribute 'map' " \ - "must be of type dict" - # build list of value strings from map - cls.vals = cls.map.keys() - cls.vals.sort() - elif init_dict.has_key('vals'): - if not isinstance(cls.vals, list): - raise TypeError, "Enum-derived class attribute 'vals' " \ - "must be of type list" - # build string->value map from vals sequence - cls.map = {} - for idx,val in enumerate(cls.vals): - cls.map[val] = idx - else: - raise TypeError, "Enum-derived class must define "\ - "attribute 'map' or 'vals'" - - cls._cpp_param_decl = name - - super(MetaEnum, cls).__init__(name, bases, init_dict) - - def cpp_declare(cls): - s = 'enum %s {\n ' % cls.__name__ - s += ',\n '.join(['%s = %d' % (v,cls.map[v]) for v in cls.vals]) - s += '\n};\n' - return s - -# Base class for enum types. -class Enum(object): - __metaclass__ = MetaEnum - vals = [] - - def _convert(self, value): - if value not in self.map: - raise TypeError, "Enum param got bad value '%s' (not in %s)" \ - % (value, self.vals) - return value - _convert = classmethod(_convert) - - # Generate printable string version of value. - def _string(self, value): - return str(value) - _string = classmethod(_string) -# -# "Constants"... handy aliases for various values. -# - -# Some memory range specifications use this as a default upper bound. -MAX_ADDR = Addr._max -MaxTick = Tick._max - -# For power-of-two sizing, e.g. 64*K gives an integer value 65536. -K = 1024 -M = K*K -G = K*M - -##################################################################### - -# The final hook to generate .ini files. Called from configuration -# script once config is built. -def instantiate(root): - if not issubclass(root, Root): - raise AttributeError, 'Can only instantiate the Root of the tree' - - instance = root.instantiate('root') - instance.fixup() - instance.display() - if not noDot: - dot = pydot.Dot() - instance.outputDot(dot) - dot.orientation = "portrait" - dot.size = "8.5,11" - dot.ranksep="equally" - dot.rank="samerank" - dot.write("config.dot") - dot.write_ps("config.ps") - -# SimObject is a minimal extension of ConfigNode, implementing a -# hierarchy node that corresponds to an M5 SimObject. It prints out a -# "type=" line to indicate its SimObject class, prints out the -# assigned parameters corresponding to its class, and allows -# parameters to be set by keyword in the constructor. Note that most -# of the heavy lifting for the SimObject param handling is done in the -# MetaConfigNode metaclass. -class SimObject(ConfigNode): - __metaclass__ = MetaSimObject - type = 'SimObject' - -from objects import * - -cpp_classes = MetaSimObject.cpp_classes -cpp_classes.sort() diff --git a/test/genini.py b/test/genini.py index f4d1575db..025ba998a 100755 --- a/test/genini.py +++ b/test/genini.py @@ -30,12 +30,10 @@ from os.path import join as joinpath, realpath mypath = sys.path[0] sys.path.append(joinpath(mypath, '..')) +sys.path.append(joinpath(mypath, '../python')) sys.path.append(joinpath(mypath, '../util/pbs')) -sys.path.append(joinpath(mypath, '../sim/pyconfig')) -from importer import AddToPath, LoadMpyFile - -AddToPath('.') +pathlist = [ '.' ] try: opts, args = getopt.getopt(sys.argv[1:], '-E:I:') @@ -50,11 +48,14 @@ try: value = arg[offset+1:] os.environ[name] = value if opt == '-I': - AddToPath(arg) + pathlist.append(arg) except getopt.GetoptError: sys.exit('Improper Usage') -from m5config import * +from m5 import * + +for path in pathlist: + AddToPath(path) for arg in args: LoadMpyFile(arg)