示例#1
0
        public bool AllocateBuffer(ulong Size)
        {
            unsafe {
                //  Allocate the memory indicated as parameter, as nonGC

#if SINGULARITY_KERNEL
                UIntPtr pages = Microsoft.Singularity.Memory.MemoryManager.PagesFromBytes(Size);

                bufferMemory = (byte *)Microsoft.Singularity.Memory.MemoryManager.KernelAllocate(
                    pages, null, 0, System.GCs.PageType.NonGC).ToPointer();

                //  Allocation at page granularity. Preserve the actual size of the buffer
                BufferSize = (ulong)pages * Microsoft.Singularity.Memory.MemoryManager.PageSize;
#else  // !SINGULARITY_KERNEL
                bufferMemory = (byte *)PageTableService.Allocate(Size);
                BufferSize   = Size;
#endif  //SINGULARITY_KERNEL

                if (bufferMemory == null)
                {
                    BufferSize = 0;
                    return(false);
                }
            }

            return(true);
        }
示例#2
0
        internal static unsafe void Initialize()
        {
            Tracing.Log(Tracing.Debug, "Initialize.");

            processTag        = PageTableService.GetProcessTag();
            baseAddr          = PageTableService.GetBaseAddress();
            pageTableCount    = PageTableService.GetPageCount();
            limitAddr         = baseAddr + (pageTableCount << PageBits);
            halPageDescriptor = PageTableService.GetPageTable();
        }
示例#3
0
        internal static bool QueryMemory(UIntPtr queryAddr,
                                         out UIntPtr regionAddr,
                                         out UIntPtr regionSize)
        {
#if SINGULARITY_KERNEL
            PageType type = Sing_MemoryManager.KernelQuery(
                queryAddr, out regionAddr, out regionSize);
            return(type != PageType.Unknown);
#elif SINGULARITY_PROCESS
            return(PageTableService.Query(queryAddr, out regionAddr, out regionSize));
#endif
        }
示例#4
0
        internal static void FreeMemory(UIntPtr startAddr, UIntPtr size)
        {
#if SINGULARITY_KERNEL
            DebugStub.Assert(Sing_MemoryManager.IsPageAligned(size));
            Sing_MemoryManager.KernelFree(
                startAddr, Sing_MemoryManager.PagesFromBytes(size),
                Process.kernelProcess);
#elif SINGULARITY_PROCESS
            VTable.Assert((size & PageTable.PageMask) == 0);
            PageTableService.Free(startAddr, size);
#endif
        }
示例#5
0
        // Initialization, prior to attempting to set this profiler into the GC.  It's
        // inappropriate to do this stuff inside a constructor.
        internal void Initialize(ulong Size, ulong Flags)
        {
            options             = Flags;
            typeTable           = new Hashtable();
            stackTable          = new Hashtable();
            funcTable           = new Hashtable();
            stackEips           = new UIntPtr[stackSize];
            stackNos            = new uint[stackSize];
            generations         = new int[maxGeneration];
            functionsIDs        = new uint[stackSize];
            Buffer              = new ProfilerBuffer();
            tempGCBuffer        = new UIntPtr[tempBufferSize];
            tempGCBufferEntries = 0;
#if LEGACY_GCTRACING
            bufferSize = Size;
            unsafe {
                //  Allocate the memory indicated as parameter, as nonGC

#if SINGULARITY_KERNEL
                UIntPtr pages = Microsoft.Singularity.Memory.MemoryManager.PagesFromBytes(bufferSize);
                bufferMemory = (byte *)Microsoft.Singularity.Memory.MemoryManager.KernelAllocate(
                    pages, null, 0, System.GCs.PageType.NonGC).ToPointer();
#else  // !SINGULARITY_KERNEL
                bufferMemory = (byte *)PageTableService.Allocate(bufferSize);
#endif  //SINGULARITY_KERNEL

                if (bufferMemory != null)
                {
                    // When we set this, we are no longer single-threaded:
                    ProfilerBuffer.SetupBuffer(bufferMemory, bufferSize);
                    this.enabled = true;
                }
            }
#else  // LEGACY_GCTRACING
            typeSource  = GCTypeSource.Create("GC.TypeDefinitions", (uint)Size, options);
            EventSource = GCEventSource.Create("GC.Events", (uint)Size, options);

            if ((typeSource == null) || (EventSource == null))
            {
                typeSource   = null;
                EventSource  = null;
                this.enabled = false;
            }
            else
            {
                TypeStorageHandle = typeSource.Storage.GetHandle();
                StorageHandle     = EventSource.Storage.GetHandle();
                this.enabled      = true;
            }
#endif // LEGACY_GCTRACING
        }
示例#6
0
            public void Finish(long iterations)
            {
                endCycleCount = unchecked ((long)Processor.CycleCount);

#if X64_PERF
                x64_p0 = Processor.ReadPmc(0);
                x64_p1 = Processor.ReadPmc(1);
                x64_p2 = Processor.ReadPmc(2);
                x64_p3 = Processor.ReadPmc(3);
#endif

                endInterruptCount = ProcessService.GetKernelInterruptCount();
                endSwitchCount    = ProcessService.GetContextSwitchCount();
                endKernelGcCount  = ProcessService.GetKernelGcCount();

                int  collectorCount;
                long collectorMillis;
                long collectorBytes;
                GC.PerformanceCounters(out collectorCount,
                                       out collectorMillis,
                                       out collectorBytes);
                endProcessGcCount = collectorCount;

                ulong allocatedCount;
                ulong allocatedBytes;
                ulong freedCount;
                ulong freedBytes;
                PageTableService.GetUsageStatistics(out allocatedCount,
                                                    out allocatedBytes,
                                                    out freedCount,
                                                    out freedBytes);
                endAllocatedCount = allocatedCount;
                endAllocatedBytes = allocatedBytes;
                endFreedCount     = freedCount;
                endFreedBytes     = freedBytes;

                ulong stackGets;
                ulong stackRets;
                StackService.GetUsageStatistics(out stackGets,
                                                out stackRets);
                endStackGets = stackGets;
                endStackRets = stackRets;

                if (!AtRing3)
                {
                    Processor.RestoreLocalPreemption(disabled);
                }

                this.iterations = iterations;
            }
示例#7
0
        public static int Main()
        {
#if TEST_CONSOLE
            int  i = 10;
            long l = 100;
            byte b = 1;
            bool o = true;
#endif
            DebugStub.Print("Hello from NullTest::Main\n");
#if TEST_CONSOLE
            DebugStub.Print(b);
            DebugStub.Print("\n");
            DebugStub.Print(i);
            DebugStub.Print("\n");
            DebugStub.Print(l);
            DebugStub.Print("\n");
            DebugStub.Print(o);
            DebugStub.Print("\n");
#endif

#if TEST_MEMORY_ABI
            uint tag = PageTableService.GetProcessTag();
            DebugStub.Print("Process Tag: ");
            DebugStub.Print((ulong)tag);
            DebugStub.Print("\n");

            uint pages = PageTableService.GetPageCount();
            DebugStub.Print("Pages:       ");
            DebugStub.Print(pages);
            DebugStub.Print("\n");

            uint addr = PageTableService.Allocate(0x1000);
            DebugStub.Print("Allocation:  ");
            DebugStub.Print((ulong)addr);
            DebugStub.Print("\n");

            Probe(addr);

            addr = 1;
            for (i = 0; i < 20 && addr != 0 && addr < 0xc0000000; i++)
            {
                addr = Probe(addr);
            }
#endif // TEST_MEMORY_ABI
#if TEST_STACK_ABI
            Test1(1);
#endif // TEST_STACK_ABI

            return(0);
        }
示例#8
0
        public static int Main()
        {
            int  i = 10;
            long l = 100;
            byte b = 1;
            bool o = true;

            DebugService.Print('H');
            DebugService.Print(b);
            DebugService.Print(',');
            DebugService.Print(i);
            DebugService.Print(',');
            DebugService.Print(l);
            DebugService.Print(',');
            DebugService.Print(o);
            DebugService.Print('\n');

#if TEST_MEMORY_ABI
            uint tag = PageTableService.GetProcessTag();
            DebugService.Print('p');
            DebugService.Print((ulong)tag);
            DebugService.Print('\n');

            uint pages = PageTableService.GetPageCount();
            DebugService.Print('n');
            DebugService.Print(pages);
            DebugService.Print('\n');

            uint addr = PageTableService.Allocate(0x1000);
            DebugService.Print('a');
            DebugService.Print((ulong)addr);
            DebugService.Print('\n');

            Probe(addr);

            addr = 1;
            for (i = 0; i < 20 && addr != 0 && addr < 0xc0000000; i++)
            {
                addr = Probe(addr);
            }
#endif // TEST_MEMORY_ABI
#if TEST_STACK_ABI
            Test1(1);
#endif // TEST_STACK_ABI

            return(999);
        }
示例#9
0
        public static uint Probe(uint addr)
        {
            uint begin;
            uint bytes;
            bool used = PageTableService.Query(addr, out begin, out bytes);

            DebugService.Print(' ');
            DebugService.Print((ulong)begin);
            DebugService.Print('.');
            DebugService.Print((ulong)begin + bytes);
            DebugService.Print(' ');
            if (used)
            {
                DebugService.Print('u');
            }
            DebugService.Print('\n');
            return(begin + bytes);
        }
示例#10
0
        public static uint Probe(uint addr)
        {
            uint begin;
            uint bytes;
            bool used = PageTableService.Query(addr, out begin, out bytes);

            DebugStub.Print("   ");
            DebugStub.Print((ulong)begin);
            DebugStub.Print("..");
            DebugStub.Print((ulong)begin + bytes);
            DebugStub.Print("  ");
            if (used)
            {
                DebugStub.Print("[used]");
            }
            DebugStub.Print("\n");
            return(begin + bytes);
        }
示例#11
0
        //////////////////////////////////// Allocation and Free Routines.
        //
        // Allocation is optimized for the case where an allocation starts
        // with a relatively small amount of memory and grows over time.
        // This is exactly the behavior exhibited by stacks and GC heaps.
        //
        // The allocation strategy also works well for large initial
        // allocations.  The strategy would be very inefficient if a very
        // large number of small, completely independent allocations are
        // made.
        //
        // AllocateMemory(size) performs an initial allocation.
        // AllocateMemory(startAddr, size) performs growing allocations.
        //
        internal static unsafe UIntPtr AllocateMemory(UIntPtr size)
        {
            VTable.Assert(PageTable.PageAligned(size));
#if SINGULARITY_KERNEL
            UIntPtr addr = Sing_MemoryManager.KernelAllocate(
                Sing_MemoryManager.PagesFromBytes(size),
                Process.kernelProcess, 0, PageType.Unknown);
#elif SINGULARITY_PROCESS
            UIntPtr addr = PageTableService.Allocate(size);
#endif

#if SINGULARITY_KERNEL
            Kernel.Waypoint((int)size);
            Kernel.Waypoint(811);
#endif // SINGULARITY_KERNEL

            if (addr != UIntPtr.Zero)
            {
                Util.MemClear(addr, size);
            }
            return(addr);
        }
示例#12
0
        internal static unsafe bool AllocateMemory(UIntPtr startAddr,
                                                   UIntPtr size)
        {
            VTable.Deny(inAllocator);
            inAllocator = true;
            VTable.Assert(PageTable.PageAligned(startAddr));
            VTable.Assert(PageTable.PageAligned(size));

#if SINGULARITY_KERNEL
            UIntPtr addr = Sing_MemoryManager.KernelExtend(
                startAddr, Sing_MemoryManager.PagesFromBytes(size),
                Process.kernelProcess, PageType.Unknown);
#elif SINGULARITY_PROCESS
            UIntPtr addr = PageTableService.AllocateExtend(startAddr, size);
#endif
            inAllocator = false;
            if (addr != UIntPtr.Zero)
            {
                Util.MemClear(addr, size);
                return(true);
            }
            return(false);
        }
示例#13
0
            public void Start()
            {
                if (!AtRing3)
                {
                    disabled = Processor.DisableLocalPreemption();
                }

                int  collectorCount;
                long collectorMillis;
                long collectorBytes;

                GC.PerformanceCounters(out collectorCount,
                                       out collectorMillis,
                                       out collectorBytes);

                ulong stackGets;
                ulong stackRets;

                StackService.GetUsageStatistics(out stackGets,
                                                out stackRets);
                begStackGets = stackGets;
                begStackRets = stackRets;

                ulong allocatedCount;
                ulong allocatedBytes;
                ulong freedCount;
                ulong freedBytes;

                PageTableService.GetUsageStatistics(out allocatedCount,
                                                    out allocatedBytes,
                                                    out freedCount,
                                                    out freedBytes);
                begAllocatedCount = allocatedCount;
                begAllocatedBytes = allocatedBytes;
                begFreedCount     = freedCount;
                begFreedBytes     = freedBytes;

                begInterruptCount = ProcessService.GetKernelInterruptCount();
                begSwitchCount    = ProcessService.GetContextSwitchCount();
                begKernelGcCount  = ProcessService.GetKernelGcCount();
                begProcessGcCount = collectorCount;

#if x64_PERF
                // Set up for perf counting
                if (!AtRing3)
                {
                    // Reset the performance counters to what we're interested in.
                    Reset(0, PerfEvtSel.COUNT | PerfEvtSel.CyclesNotHalted);
                    Reset(1, PerfEvtSel.COUNT | PerfEvtSel.RetiredInstructions);
                    Reset(2, PerfEvtSel.COUNT | PerfEvtSel.RetiredBranchInstructions);
                    Reset(3, PerfEvtSel.COUNT | PerfEvtSel.RequestsToL2Cache | 0x400);
                }
                else
                {
                    // We're not allowed to reset the perf counters, so take note
                    // of their current values; we will subtract from this later.
                    x64_i0 = Processor.ReadPmc(0);
                    x64_i1 = Processor.ReadPmc(1);
                    x64_i2 = Processor.ReadPmc(2);
                    x64_i3 = Processor.ReadPmc(3);
                }
#endif

                begCycleCount = unchecked ((long)Processor.CycleCount);
            }