RDK 1.1
This commit is contained in:
commit
4e1c631ec8
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,25 @@
|
|||
<!--
|
||||
###############################################################################
|
||||
#
|
||||
# Microsoft Research Singularity
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
#
|
||||
###############################################################################
|
||||
-->
|
||||
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\Paths.targets" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AssemblyName>AppendFormat</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="AppendFormat.sg" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\ConsoleCategory.targets" />
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,59 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Microsoft.Singularity.Directory;
|
||||
using Microsoft.Singularity.Channels;
|
||||
using Microsoft.Singularity.FileSystem;
|
||||
using Microsoft.Singularity.V1.Services;
|
||||
|
||||
using Microsoft.Contracts;
|
||||
using Microsoft.SingSharp.Reflection;
|
||||
using Microsoft.Singularity.Applications;
|
||||
using Microsoft.Singularity.Io;
|
||||
using Microsoft.Singularity.Configuration;
|
||||
[assembly: Transform(typeof(ApplicationResourceTransform))]
|
||||
|
||||
|
||||
namespace Microsoft.Singularity.Applications
|
||||
{
|
||||
[ConsoleCategory( DefaultAction=true)]
|
||||
internal class Parameters
|
||||
{
|
||||
[InputEndpoint("data")]
|
||||
public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
|
||||
|
||||
[OutputEndpoint("data")]
|
||||
public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
|
||||
|
||||
reflective internal Parameters();
|
||||
|
||||
internal int AppMain() {
|
||||
return AppendFormat.AppMain(this);
|
||||
}
|
||||
}
|
||||
|
||||
public class AppendFormat
|
||||
{
|
||||
public static string ToLegibleString(byte[]! b)
|
||||
{
|
||||
StringBuilder legible = new StringBuilder();
|
||||
for (int i = 0; i < b.Length; i++) {
|
||||
legible.AppendFormat("{0:x2}", b[i]);
|
||||
}
|
||||
return legible.ToString();
|
||||
}
|
||||
|
||||
internal static int AppMain(Parameters! config)
|
||||
{
|
||||
byte [] key = new byte[2];
|
||||
string s = ToLegibleString(key);
|
||||
Console.WriteLine("s="+s);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<!--
|
||||
##############################################################################
|
||||
|
||||
Microsoft Research Singularity
|
||||
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
File: Applications\Applications.proj
|
||||
|
||||
Note: This file is a convenience project for building all projects under
|
||||
Applications. This file is not involved in building "distro" projects.
|
||||
|
||||
##############################################################################
|
||||
-->
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<Import Project="..\Paths.targets"/>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="Runtime\AppRuntime.proj"/>
|
||||
<ProjectReference Include="*\*.proj;*\*.csproj" Exclude="Runtime\*;Pong\Pong.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\Dirs.targets"/>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,43 @@
|
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
|
||||
<Import Project="..\..\..\..\Paths.targets" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AssemblyName>bartokp</AssemblyName>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AssumeFieldsNonNull>true</AssumeFieldsNonNull>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Child.sg" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="..\MSIL\Bartok.Analysis.dll"/>
|
||||
<Reference Include="..\MSIL\Bartok.CfgUtil.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Convert.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Datatype.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.DebugInfo.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Ir.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Lir.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Mangle.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Marshal.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Opt.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Regalloc.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Regreal.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Utility.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Cheap.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Msil.dll" />
|
||||
|
||||
<ProjectReference Include="..\Contracts\BartokHContracts.csproj"/>
|
||||
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\System.IO\System.IO.csproj"/>
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\FileSystem.Utils\FileSystem.Utils.csproj"/>
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\DirectoryService.Utils\DirectoryService.Utils.csproj"/>
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\Security\Security.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\ConsoleCategory.targets" />
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,397 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Microsoft Research Singularity
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// File: BartokP.sg
|
||||
//
|
||||
// Note: Compiler Phase
|
||||
//
|
||||
|
||||
//#define NONONNULLTYPECHECK // required on Singularity, no affect on other Windows.
|
||||
|
||||
using Microsoft.SingSharp;
|
||||
using Microsoft.Singularity.Channels;
|
||||
using Microsoft.Singularity.Endpoint;
|
||||
using Microsoft.Singularity.V1.Services;
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
using Microsoft.Singularity;
|
||||
using Microsoft.Singularity.Io;
|
||||
using Microsoft.Singularity.Extending;
|
||||
using Microsoft.Singularity.Configuration;
|
||||
using Microsoft.SingSharp.Reflection;
|
||||
using Microsoft.Singularity.Applications;
|
||||
|
||||
using Bartok.Contracts;
|
||||
using Bartok.Analysis.Lir;
|
||||
using Bartok.Convert;
|
||||
using Bartok.Datatype;
|
||||
using Bartok.CfgUtil;
|
||||
using Bartok.Lir;
|
||||
using Bartok.Opt.Lir;
|
||||
using Bartok.Utility;
|
||||
using Bartok.DebugInfo;
|
||||
using Bartok.Regalloc;
|
||||
using Bartok.Marshal;
|
||||
|
||||
[assembly: Transform(typeof(WebAppResourceTransform))]
|
||||
|
||||
namespace Bartok.Child
|
||||
{
|
||||
[Category("WebApp")]
|
||||
internal class Parameters
|
||||
{
|
||||
[Endpoint]
|
||||
public readonly TRef<ExtensionContract.Exp:Start> sendRef;
|
||||
|
||||
[BoolParameter("where", Default=false,
|
||||
HelpMessage="Show what space we are running in")]
|
||||
internal bool doWhere;
|
||||
|
||||
reflective private Parameters();
|
||||
|
||||
internal int AppMain() {
|
||||
return BartokP.AppMain(this);
|
||||
}
|
||||
}
|
||||
|
||||
public class BartokP
|
||||
{
|
||||
internal static int AppMain(Parameters! config)
|
||||
{
|
||||
// DebugStub.WriteLine("Child::GC Verify enabled");
|
||||
// AppRuntime.EnableGCVerify = true;
|
||||
//AppRuntime.EnableGCAccounting = true;
|
||||
//DebugStub.WriteLine("Child: Enabled GC Accounting");
|
||||
//DebugStub.WriteLine("Child: Began execution!");
|
||||
|
||||
if (config.doWhere) {
|
||||
DebugStub.WriteLine("BartokP running!");
|
||||
}
|
||||
|
||||
ExtensionContract.Exp ep = config.sendRef.Acquire();
|
||||
|
||||
CompilerPhaseContract.Exp cp = ep as CompilerPhaseContract.Exp;
|
||||
|
||||
if (cp != null) {
|
||||
DoPhase(cp);
|
||||
delete cp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Wrong contract type!
|
||||
delete ep;
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static void ReadOpen(CheapState! cs, byte[]! in ExHeap bytes)
|
||||
{
|
||||
uint regionSize;
|
||||
uint region;
|
||||
regionSize = (uint)bytes.Length;
|
||||
unsafe {
|
||||
fixed (byte *pdst = &bytes[0]) {
|
||||
region = (uint)pdst;
|
||||
cs.ReadOpen(region, regionSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ReadClose(CheapState! cs)
|
||||
{
|
||||
#if false
|
||||
if (cs.oig != null) {
|
||||
DebugStub.WriteLine("--- Stub .Read Close {0,8} bytes {1,5} objects",
|
||||
__arglist(cs.read, cs.loadCount));
|
||||
}
|
||||
#endif
|
||||
cs.ReadClose();
|
||||
}
|
||||
|
||||
private static void WriteOpen(CheapState! cs, byte[]! in ExHeap bytes)
|
||||
{
|
||||
uint regionSize;
|
||||
uint region;
|
||||
regionSize = (uint)bytes.Length;
|
||||
unsafe {
|
||||
fixed (byte *pdst = &bytes[0]) {
|
||||
region = (uint)pdst;
|
||||
cs.WriteOpen(region, regionSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteClose(CheapState! cs)
|
||||
{
|
||||
#if false
|
||||
if (cs.oig != null) {
|
||||
DebugStub.WriteLine("--- Stub .WriteClose {0,8} bytes {1,5} objects",
|
||||
__arglist(cs.used, cs.oig.m_currentCount));
|
||||
}
|
||||
#endif
|
||||
cs.WriteClose();
|
||||
}
|
||||
|
||||
private static void DoPhase(CompilerPhaseContract.Exp! cp)
|
||||
{
|
||||
GraphColoringReal gcr;
|
||||
CheapState! cs = new CheapState(0, false);
|
||||
|
||||
CheapMarshal.InitTypes();
|
||||
|
||||
// Track statics before they can be replicated in a method call.
|
||||
RegisterX86.TrackAsGlobal(cs);
|
||||
OpCodesX86.TrackAsGlobal(cs);
|
||||
|
||||
cp.SendReadyToInit();
|
||||
bool halt = false;
|
||||
#if USE_SWITCH_RECEIVE
|
||||
switch receive
|
||||
{
|
||||
case cp.InitPhaseReq(byte[]! in ExHeap buffer):
|
||||
RegDesc regs;
|
||||
CallConv conv;
|
||||
AbstractTarget target;
|
||||
GlobalLayoutData globalLayoutData;
|
||||
int pageSize;
|
||||
int stackThreshhold;
|
||||
bool isNoisy;
|
||||
CSRT runtime;
|
||||
StageControlProxy controls;
|
||||
|
||||
beg = Processor.GetCycleCount();
|
||||
ReadOpen(cs, buffer);
|
||||
RegDesc.CheapRead(cs, out regs);
|
||||
CallConv.CheapRead(cs, out conv);
|
||||
AbstractTarget.CheapRead(cs, out target);
|
||||
GlobalLayoutData.CheapRead(cs, out globalLayoutData);
|
||||
cs.Read(out pageSize);
|
||||
cs.Read(out stackThreshhold);
|
||||
cs.Read(out isNoisy);
|
||||
CSRT.CheapRead(cs, out runtime);
|
||||
StageControlProxy.CheapRead(cs, out controls);
|
||||
ReadClose(cs);
|
||||
|
||||
DebugStub.AddToPerfCounter(1, Processor.GetCycleCount() - beg);
|
||||
|
||||
CSRT.runtime = runtime;
|
||||
if (controls != null) {
|
||||
controls.SetValues();
|
||||
}
|
||||
|
||||
if (globalLayoutData != null) {
|
||||
RepInfo.LayoutInfoFactory = globalLayoutData.LayoutInfoFactory;
|
||||
RepInfo.SetX86Layout();
|
||||
}
|
||||
|
||||
target.TrackAsGlobal(cs);
|
||||
regs.TrackAsGlobal(cs);
|
||||
conv.TrackAsGlobal(cs);
|
||||
runtime.TrackAsGlobal(cs);
|
||||
cs.DumpGlobal("chld");
|
||||
|
||||
#if false
|
||||
DebugStub.WriteLine("-------- GraphColoring::Stub Init -----");
|
||||
#endif
|
||||
|
||||
gcr = new GraphColoringReal(regs,
|
||||
conv,
|
||||
target,
|
||||
globalLayoutData,
|
||||
pageSize,
|
||||
stackThreshhold,
|
||||
isNoisy);
|
||||
|
||||
beg = Processor.GetCycleCount();
|
||||
WriteOpen(cs, buffer);
|
||||
WriteClose(cs);
|
||||
DebugStub.AddToPerfCounter(2, Processor.GetCycleCount() - beg);
|
||||
cp.SendInitPhaseRsp(buffer);
|
||||
break;
|
||||
case cp.ChannelClosed():
|
||||
Console.WriteLine("Compiler channel closed unexpectedly before init.");
|
||||
return;
|
||||
}
|
||||
#else
|
||||
byte[]! in ExHeap buffer;
|
||||
cp.RecvInitPhaseReq(out buffer);
|
||||
|
||||
RegDesc regs;
|
||||
CallConv conv;
|
||||
AbstractTarget target;
|
||||
GlobalLayoutData globalLayoutData;
|
||||
int pageSize;
|
||||
int stackThreshhold;
|
||||
bool isNoisy;
|
||||
CSRT runtime;
|
||||
StageControlProxy controls;
|
||||
|
||||
ulong beg = Processor.GetCycleCount();
|
||||
ReadOpen(cs, buffer);
|
||||
RegDesc.CheapRead(cs, out regs);
|
||||
CallConv.CheapRead(cs, out conv);
|
||||
AbstractTarget.CheapRead(cs, out target);
|
||||
GlobalLayoutData.CheapRead(cs, out globalLayoutData);
|
||||
cs.Read(out pageSize);
|
||||
cs.Read(out stackThreshhold);
|
||||
cs.Read(out isNoisy);
|
||||
CSRT.CheapRead(cs, out runtime);
|
||||
StageControlProxy.CheapRead(cs, out controls);
|
||||
ReadClose(cs);
|
||||
|
||||
DebugStub.AddToPerfCounter(1, Processor.GetCycleCount() - beg);
|
||||
|
||||
CSRT.runtime = runtime;
|
||||
if (controls != null) {
|
||||
controls.SetValues();
|
||||
}
|
||||
|
||||
if (globalLayoutData != null) {
|
||||
RepInfo.LayoutInfoFactory = globalLayoutData.LayoutInfoFactory;
|
||||
RepInfo.SetX86Layout();
|
||||
}
|
||||
|
||||
// DebugStub.WriteLine(":: Chld Targ Globals");
|
||||
((!)target).TrackAsGlobal(cs);
|
||||
// DebugStub.WriteLine(":: Chld Regs Globals");
|
||||
((!)regs).TrackAsGlobal(cs);
|
||||
// DebugStub.WriteLine(":: Chld Conv Globals");
|
||||
((!)conv).TrackAsGlobal(cs);
|
||||
// DebugStub.WriteLine(":: Chld CSRT Globals");
|
||||
((!)runtime).TrackAsGlobal(cs);
|
||||
|
||||
// cs.DumpGlobal("chld");
|
||||
|
||||
#if false
|
||||
DebugStub.WriteLine("-------- GraphColoring::Stub Init -----");
|
||||
#endif
|
||||
|
||||
gcr = new GraphColoringReal(regs,
|
||||
conv,
|
||||
target,
|
||||
globalLayoutData,
|
||||
pageSize,
|
||||
stackThreshhold,
|
||||
isNoisy);
|
||||
|
||||
beg = Processor.GetCycleCount();
|
||||
WriteOpen(cs, buffer);
|
||||
WriteClose(cs);
|
||||
DebugStub.AddToPerfCounter(2, Processor.GetCycleCount() - beg);
|
||||
cp.SendInitPhaseRsp(buffer);
|
||||
#endif
|
||||
|
||||
while (!halt) {
|
||||
#if USE_SWITCH_RECEIVE
|
||||
switch receive
|
||||
{
|
||||
case cp.GetPhaseNameReq():
|
||||
char[]! in ExHeap name = (!)Bitter.FromString(gcr.PhaseName);
|
||||
cp.SendGetPhaseNameRsp(name);
|
||||
break;
|
||||
|
||||
case cp.ProcessFunctionReq(byte[]! in ExHeap buffer):
|
||||
FunctionDef f;
|
||||
ChooseRepResult r;
|
||||
|
||||
beg = Processor.GetCycleCount();
|
||||
ReadOpen(cs, buffer);
|
||||
FunctionDef.CheapRead(cs, out f);
|
||||
ChooseRepResult.CheapRead(cs, out r);
|
||||
ReadClose(cs);
|
||||
DebugStub.AddToPerfCounter(1, Processor.GetCycleCount() - beg);
|
||||
|
||||
gcr.Go(f, r);
|
||||
|
||||
beg = Processor.GetCycleCount();
|
||||
WriteOpen(cs, buffer);
|
||||
if (f != null) {
|
||||
OperandArray.CheapWrite(cs, f.actualArgs);
|
||||
LirBasicBlock.CheapWrite(cs, f.prolog);
|
||||
LirBasicBlock.CheapWrite(cs, f.epilog);
|
||||
LirBasicBlock.CheapWrite(cs, f.unwind);
|
||||
cs.Write(f.omitFramePointer);
|
||||
cs.Write(f.spillSlotCount);
|
||||
Operand.CheapWrite(cs, f.stackSlotMap);
|
||||
SequencedCfg.CheapWrite(cs, f.code);
|
||||
OperandArray.CheapWrite(cs, f.pinned);
|
||||
OperandArray.CheapWrite(cs, f.formals);
|
||||
Operand.CheapWrite(cs, f.ret);
|
||||
}
|
||||
WriteClose(cs);
|
||||
DebugStub.AddToPerfCounter(2, Processor.GetCycleCount() - beg);
|
||||
cp.SendProcessFunctionRsp(buffer);
|
||||
break;
|
||||
|
||||
case cp.TermPhaseReq():
|
||||
gcr.Term();
|
||||
cp.SendTermPhaseRsp();
|
||||
halt = true;
|
||||
break;
|
||||
|
||||
case cp.ChannelClosed():
|
||||
halt = true;
|
||||
Console.WriteLine("Compiler channel closed unexpectedly.");
|
||||
break;
|
||||
}
|
||||
#else
|
||||
int which;
|
||||
|
||||
cp.RecvRequest(out which, out buffer);
|
||||
if (which == (int)RequestKind.ProcessFunction) {
|
||||
FunctionDef f;
|
||||
ChooseRepResult r;
|
||||
|
||||
beg = Processor.GetCycleCount();
|
||||
ReadOpen(cs, buffer);
|
||||
FunctionDef.CheapRead(cs, out f);
|
||||
ChooseRepResult.CheapRead(cs, out r);
|
||||
ReadClose(cs);
|
||||
DebugStub.AddToPerfCounter(1, Processor.GetCycleCount() - beg);
|
||||
|
||||
#if DEBUG_FUNCTION_CALLS
|
||||
DebugStub.WriteLine();
|
||||
DebugStub.WriteLine("*** {0} ***", __arglist(((!)f).name.ToString()));
|
||||
#endif
|
||||
gcr.Go(f, r);
|
||||
|
||||
beg = Processor.GetCycleCount();
|
||||
WriteOpen(cs, buffer);
|
||||
if (f != null) {
|
||||
OperandArray.CheapWrite(cs, f.actualArgs);
|
||||
LirBasicBlock.CheapWrite(cs, f.prolog);
|
||||
LirBasicBlock.CheapWrite(cs, f.epilog);
|
||||
LirBasicBlock.CheapWrite(cs, f.unwind);
|
||||
cs.Write(f.omitFramePointer);
|
||||
cs.Write(f.spillSlotCount);
|
||||
Operand.CheapWrite(cs, f.stackSlotMap);
|
||||
SequencedCfg.CheapWrite(cs, f.code);
|
||||
OperandArray.CheapWrite(cs, f.pinned);
|
||||
OperandArray.CheapWrite(cs, f.formals);
|
||||
Operand.CheapWrite(cs, f.ret);
|
||||
}
|
||||
WriteClose(cs);
|
||||
DebugStub.AddToPerfCounter(2, Processor.GetCycleCount() - beg);
|
||||
#if DEBUG_FUNCTION_CALLS
|
||||
DebugStub.WriteLine("--- {0} ---", __arglist(((!)f).name.ToString()));
|
||||
DebugStub.WriteLine();
|
||||
#endif
|
||||
}
|
||||
else if (which == (int)RequestKind.Terminate) {
|
||||
gcr.Term();
|
||||
halt = true;
|
||||
}
|
||||
else {
|
||||
DebugStub.WriteLine("Unknown request: {0}", __arglist(which));
|
||||
}
|
||||
cp.SendResponse(buffer);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
|
||||
<Import Project="..\..\..\..\Paths.targets" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<AssemblyName>Bartok.Contracts</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="CompilerPhaseContract.sg" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\App.targets" />
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,69 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Microsoft Research Singularity
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// File: CompilerPhaseContract.sg
|
||||
//
|
||||
|
||||
using Microsoft.Singularity.Channels;
|
||||
using Microsoft.Singularity.Endpoint;
|
||||
using Microsoft.Singularity.V1.Services;
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
using Microsoft.Singularity.Extending;
|
||||
|
||||
namespace Bartok.Contracts
|
||||
{
|
||||
public enum RequestKind {
|
||||
GetPhaseName = 1,
|
||||
ProcessFunction = 2,
|
||||
Terminate = 3,
|
||||
};
|
||||
|
||||
public contract CompilerPhaseContract : ExtensionContract
|
||||
{
|
||||
in message InitPhaseReq(byte[]! in ExHeap buffer);
|
||||
out message InitPhaseRsp(byte[]! in ExHeap buffer);
|
||||
|
||||
#if USE_SWITCH_RECEIVE
|
||||
in message GetPhaseNameReq();
|
||||
out message GetPhaseNameRsp(char[]! in ExHeap name);
|
||||
|
||||
in message ProcessFunctionReq(byte[]! in ExHeap buffer);
|
||||
out message ProcessFunctionRsp(byte[]! in ExHeap buffer);
|
||||
|
||||
in message TermPhaseReq();
|
||||
out message TermPhaseRsp();
|
||||
#else
|
||||
in message Request(int which, byte[]! in ExHeap buffer);
|
||||
out message Response(byte[]! in ExHeap buffer);
|
||||
#endif
|
||||
|
||||
out message ReadyToInit();
|
||||
|
||||
override state Start : one {
|
||||
ReadyToInit! -> PreInit;
|
||||
}
|
||||
|
||||
state PreInit : one {
|
||||
InitPhaseReq? -> InitPhaseRsp! -> Running;
|
||||
}
|
||||
|
||||
state Running : one {
|
||||
#if USE_SWITCH_RECEIVE
|
||||
GetPhaseNameReq? -> GetPhaseNameRsp! -> Running;
|
||||
ProcessFunctionReq? -> ProcessFunctionRsp! -> Running;
|
||||
TermPhaseReq? -> TermPhaseRsp! -> End;
|
||||
#else
|
||||
Request? -> Response! -> Running;
|
||||
#endif
|
||||
}
|
||||
|
||||
state End: ;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,48 @@
|
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
|
||||
<Import Project="..\..\..\..\Paths.targets" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AssemblyName>bartok</AssemblyName>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Bartok.cs" />
|
||||
<Compile Include="Proxy.sg" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="..\MSIL\Bartok.Analysis.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Backend.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.CfgUtil.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Coff.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Convert.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Datatype.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.DebugInfo.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Encode.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Ir.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Lir.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Mangle.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.MSIL.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Opt.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Profile.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Regalloc.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Tables.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Utility.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Cheap.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Marshal.dll" />
|
||||
<Reference Include="..\MSIL\Bartok.Regreal.dll" />
|
||||
|
||||
<ProjectReference Include="..\Contracts\BartokHContracts.csproj"/>
|
||||
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\System.IO\System.IO.csproj"/>
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\FileSystem.Utils\FileSystem.Utils.csproj"/>
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\DirectoryService.Utils\DirectoryService.Utils.csproj"/>
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\Security\Security.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\ConsoleCategory.targets" />
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,392 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Microsoft Research Singularity
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// File: Proxy.sg
|
||||
//
|
||||
// Note: Compiler Phase
|
||||
//
|
||||
|
||||
//#define DO_LOCAL
|
||||
|
||||
using Microsoft.SingSharp;
|
||||
using Microsoft.Singularity.Channels;
|
||||
using Microsoft.Singularity.Endpoint;
|
||||
using Microsoft.Singularity.V1.Services;
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
using Microsoft.Singularity;
|
||||
using Microsoft.Singularity.Io;
|
||||
using Microsoft.Singularity.Extending;
|
||||
using Microsoft.Singularity.Configuration;
|
||||
using Microsoft.SingSharp.Reflection;
|
||||
using Microsoft.Singularity.Applications;
|
||||
|
||||
using Bartok.Contracts;
|
||||
using Bartok.Analysis.Lir;
|
||||
using Bartok.Convert;
|
||||
using Bartok.Datatype;
|
||||
using Bartok.CfgUtil;
|
||||
using Bartok.Lir;
|
||||
using Bartok.Opt.Lir;
|
||||
using Bartok.Utility;
|
||||
using Bartok.DebugInfo;
|
||||
using Bartok.Regalloc;
|
||||
using Bartok.Marshal;
|
||||
using Bartok.Regalloc;
|
||||
|
||||
namespace Bartok.Regalloc
|
||||
{
|
||||
public class GraphColoring : Phase{
|
||||
private CheapState! cs;
|
||||
private VContainer<byte> bufferData;
|
||||
#if DO_LOCAL
|
||||
private GraphColoringReal gcr;
|
||||
#else
|
||||
private TRef<CompilerPhaseContract.Imp:Running> child;
|
||||
#endif
|
||||
|
||||
private static void ReadOpen(CheapState! cs, byte[]! in ExHeap bytes)
|
||||
{
|
||||
uint regionSize;
|
||||
uint region;
|
||||
regionSize = (uint)bytes.Length;
|
||||
unsafe {
|
||||
fixed (byte *pdst = &bytes[0]) {
|
||||
region = (uint)pdst;
|
||||
cs.ReadOpen(region, regionSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ReadClose(CheapState! cs)
|
||||
{
|
||||
#if false
|
||||
if (cs.oig != null) {
|
||||
DebugStub.WriteLine("--- Proxy.Read Close {0,8} bytes {1,5} objects",
|
||||
__arglist(cs.read, cs.loadCount));
|
||||
}
|
||||
#endif
|
||||
cs.ReadClose();
|
||||
}
|
||||
|
||||
private static void WriteOpen(CheapState! cs, byte[]! in ExHeap bytes)
|
||||
{
|
||||
uint regionSize;
|
||||
uint region;
|
||||
regionSize = (uint)bytes.Length;
|
||||
unsafe {
|
||||
fixed (byte *pdst = &bytes[0]) {
|
||||
region = (uint)pdst;
|
||||
cs.WriteOpen(region, regionSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteClose(CheapState! cs)
|
||||
{
|
||||
#if false
|
||||
if (cs.oig != null) {
|
||||
DebugStub.WriteLine("--- Proxy.WriteClose {0,8} bytes {1,5} objects",
|
||||
__arglist(cs.used, cs.oig.m_currentCount));
|
||||
}
|
||||
#endif
|
||||
cs.WriteClose();
|
||||
}
|
||||
|
||||
[Microsoft.Contracts.NotDelayed]
|
||||
public GraphColoring(RegDesc regs, CallConv conv, AbstractTarget target,
|
||||
GlobalLayoutData globalLayoutData,
|
||||
int pageSize, int stackThreshhold,
|
||||
bool isNoisy)
|
||||
{
|
||||
CheapMarshal.InitTypes();
|
||||
|
||||
cs = new CheapState(0, true);
|
||||
base();
|
||||
#if false
|
||||
|
||||
Console.WriteLine("-------- GraphColoring Init -----");
|
||||
DebugStub.WriteLine("-------- GraphColoring::Proxy Init -----");
|
||||
#endif
|
||||
|
||||
#if DO_LOCAL
|
||||
gcr = new GraphColoringReal(regs,
|
||||
conv,
|
||||
target,
|
||||
globalLayoutData,
|
||||
pageSize,
|
||||
stackThreshhold,
|
||||
isNoisy);
|
||||
#else // !DO_LOCAL
|
||||
// Make a new channel.
|
||||
CompilerPhaseContract.Imp! cp;
|
||||
CompilerPhaseContract.Exp! ep;
|
||||
CompilerPhaseContract.NewChannel(out cp, out ep);
|
||||
|
||||
// Start up our child
|
||||
string[] args = new string[3];
|
||||
args[0] = "BartokP.x86";
|
||||
args[1] = "-where";
|
||||
args[2] = "!";
|
||||
Process cproc = new Process(args, (Endpoint * in ExHeap)ep);
|
||||
|
||||
// set the where parameter to true
|
||||
ParameterCode code;
|
||||
code = cproc.SetStartupBoolArg(0, true);
|
||||
if (code != ParameterCode.Success){
|
||||
Console.WriteLine("unable to set bool index 0. error={0}", code);
|
||||
delete cp;
|
||||
return;
|
||||
}
|
||||
|
||||
byte[]! in ExHeap bytes = (!)new [ExHeap] byte [2 * 1024 * 1024];
|
||||
|
||||
cproc.Start();
|
||||
|
||||
// Track statics before they can be replicated in a method call.
|
||||
RegisterX86.TrackAsGlobal(cs);
|
||||
OpCodesX86.TrackAsGlobal(cs);
|
||||
|
||||
cp.RecvReadyToInit();
|
||||
|
||||
StageControlProxy controls = new StageControlProxy();
|
||||
controls.GetValues();
|
||||
|
||||
ulong beg = Processor.GetCycleCount();
|
||||
WriteOpen(cs, bytes);
|
||||
RegDesc.CheapWrite(cs, regs);
|
||||
CallConv.CheapWrite(cs, conv);
|
||||
AbstractTarget.CheapWrite(cs, target);
|
||||
GlobalLayoutData.CheapWrite(cs, globalLayoutData);
|
||||
cs.Write(pageSize);
|
||||
cs.Write(stackThreshhold);
|
||||
cs.Write(isNoisy);
|
||||
CSRT.CheapWrite(cs, CSRT.runtime);
|
||||
StageControlProxy.CheapWrite(cs, controls);
|
||||
WriteClose(cs);
|
||||
DebugStub.AddToPerfCounter(0, Processor.GetCycleCount() - beg);
|
||||
|
||||
//DebugStub.WriteLine(":: Host Targ Globals");
|
||||
target.TrackAsGlobal(cs);
|
||||
//DebugStub.WriteLine(":: Host Regs Globals");
|
||||
regs.TrackAsGlobal(cs);
|
||||
//DebugStub.WriteLine(":: Host Conv Globals");
|
||||
conv.TrackAsGlobal(cs);
|
||||
//DebugStub.WriteLine(":: Host CSRT Globals");
|
||||
CSRT.runtime.TrackAsGlobal(cs);
|
||||
|
||||
//cs.DumpGlobal("host");
|
||||
|
||||
cp.SendInitPhaseReq(bytes);
|
||||
#if USE_SWITCH_RECEIVE
|
||||
switch receive
|
||||
{
|
||||
case cp.InitPhaseRsp(byte[]! in ExHeap obytes):
|
||||
ReadOpen(cs, obytes);
|
||||
ReadClose(cs);
|
||||
bufferData = new VContainer<byte> (obytes);
|
||||
child = new TRef<CompilerPhaseContract.Imp:Running>(cp);
|
||||
return;
|
||||
case cp.ChannelClosed():
|
||||
Console.WriteLine("Child closed channel!");
|
||||
throw new Exception("Child closed channel!");
|
||||
}
|
||||
#else
|
||||
byte[]! in ExHeap obytes;
|
||||
cp.RecvInitPhaseRsp(out obytes);
|
||||
ReadOpen(cs, obytes);
|
||||
ReadClose(cs);
|
||||
bufferData = new VContainer<byte> (obytes);
|
||||
child = new TRef<CompilerPhaseContract.Imp:Running>(cp);
|
||||
#endif
|
||||
#endif // !DO_LOCAL
|
||||
}
|
||||
|
||||
private string GetPhaseName()
|
||||
{
|
||||
#if DO_LOCAL
|
||||
return gcr.PhaseName;
|
||||
#else // !DO_LOCAL
|
||||
if (child == null) {
|
||||
Console.WriteLine("!!! Internal Error!");
|
||||
return "<error>";
|
||||
}
|
||||
|
||||
#if USE_SWITCH_RECEIVE
|
||||
CompilerPhaseContract.Imp! cp = child.Acquire();
|
||||
|
||||
cp.SendGetPhaseNameReq();
|
||||
switch receive
|
||||
{
|
||||
case cp.GetPhaseNameRsp(char[]! in ExHeap name):
|
||||
string ph = Bitter.ToString(name);
|
||||
child.Release(cp);
|
||||
delete name;
|
||||
return ph;
|
||||
case cp.ChannelClosed():
|
||||
Console.WriteLine("Child closed channel!");
|
||||
throw new Exception("Child closed channel!");
|
||||
}
|
||||
#else
|
||||
return "[regalloc]";
|
||||
#endif
|
||||
#endif // !DO_LOCAL
|
||||
}
|
||||
|
||||
public override string PhaseName
|
||||
{
|
||||
get {
|
||||
return GetPhaseName();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Term()
|
||||
{
|
||||
#if DO_LOCAL
|
||||
gcr.Term();
|
||||
#else // !DO_LOCAL
|
||||
if (child == null) {
|
||||
Console.WriteLine("!!! Internal Error!");
|
||||
return;
|
||||
}
|
||||
|
||||
#if USE_SWITCH_RECEIVE
|
||||
CompilerPhaseContract.Imp! cp = child.Acquire();
|
||||
|
||||
cp.SendTermPhaseReq();
|
||||
switch receive
|
||||
{
|
||||
case cp.TermPhaseRsp():
|
||||
ReadOpen(cs, obytes);
|
||||
ReadClose(cs);
|
||||
child.Release(cp);
|
||||
return;
|
||||
case cp.ChannelClosed():
|
||||
Console.WriteLine("Child closed channel!");
|
||||
throw new Exception("Child closed channel!");
|
||||
}
|
||||
#else
|
||||
if (bufferData == null) {
|
||||
Console.WriteLine("!!! Internal Error!");
|
||||
return;
|
||||
}
|
||||
|
||||
CompilerPhaseContract.Imp! cp = child.Acquire();
|
||||
byte[]! in ExHeap bytes = bufferData.Acquire();
|
||||
WriteOpen(cs, bytes);
|
||||
WriteClose(cs);
|
||||
cp.SendRequest((int)RequestKind.Terminate, bytes);
|
||||
cp.RecvResponse(out bytes);
|
||||
ReadOpen(cs, bytes);
|
||||
ReadClose(cs);
|
||||
bufferData.Release(bytes);
|
||||
child.Release(cp);
|
||||
#endif
|
||||
#endif // !DO_LOCAL
|
||||
}
|
||||
|
||||
protected override void run(FunctionDef f, object r)
|
||||
{
|
||||
#if DO_LOCAL
|
||||
gcr.Go(f, r);
|
||||
#else // !DO_LOCAL
|
||||
if (child == null || bufferData == null || f == null || r == null) {
|
||||
Console.WriteLine("!!! Internal Error!");
|
||||
return;
|
||||
}
|
||||
|
||||
#if false
|
||||
Console.WriteLine("-------- GraphColoring Run {0} -----", f.ToString());
|
||||
#endif
|
||||
|
||||
CompilerPhaseContract.Imp! cp = child.Acquire();
|
||||
byte[]! in ExHeap bytes = bufferData.Acquire();
|
||||
|
||||
ulong beg = Processor.GetCycleCount();
|
||||
WriteOpen(cs, bytes);
|
||||
FunctionDef.CheapWrite(cs, f);
|
||||
ChooseRepResult.CheapWrite(cs, (ChooseRepResult)r);
|
||||
WriteClose(cs);
|
||||
DebugStub.AddToPerfCounter(0, Processor.GetCycleCount() - beg);
|
||||
|
||||
#if USE_SWITCH_RECEIVE
|
||||
cp.SendProcessFunctionReq(bytes);
|
||||
switch receive
|
||||
{
|
||||
case cp.ProcessFunctionRsp(obytes):
|
||||
beg = Processor.GetCycleCount();
|
||||
ReadOpen(cs, obytes);
|
||||
OperandArray.CheapRead(cs, out f.actualArgs);
|
||||
LirBasicBlock.CheapRead(cs, out f.prolog);
|
||||
LirBasicBlock.CheapRead(cs, out f.epilog);
|
||||
LirBasicBlock.CheapRead(cs, out f.unwind);
|
||||
cs.Read(out f.omitFramePointer);
|
||||
cs.Read(out f.spillSlotCount);
|
||||
Operand.CheapRead(cs, out f.stackSlotMap);
|
||||
SequencedCfg.CheapRead(cs, out f.code);
|
||||
OperandArray.CheapRead(cs, out f.pinned);
|
||||
OperandArray.CheapRead(cs, out f.formals);
|
||||
Operand.CheapRead(cs, out f.ret);
|
||||
ReadClose(cs);
|
||||
DebugStub.AddToPerfCounter(3, Processor.GetCycleCount() - beg);
|
||||
|
||||
bufferData.Release(obytes);
|
||||
child.Release(cp);
|
||||
return;
|
||||
|
||||
case cp.ChannelClosed():
|
||||
Console.WriteLine("Child closed channel!");
|
||||
throw new Exception("Child closed channel!");
|
||||
}
|
||||
#else
|
||||
cp.SendRequest((int)RequestKind.ProcessFunction, bytes);
|
||||
cp.RecvResponse(out bytes);
|
||||
|
||||
beg = Processor.GetCycleCount();
|
||||
ReadOpen(cs, bytes);
|
||||
OperandArray.CheapRead(cs, out f.actualArgs);
|
||||
LirBasicBlock.CheapRead(cs, out f.prolog);
|
||||
LirBasicBlock.CheapRead(cs, out f.epilog);
|
||||
LirBasicBlock.CheapRead(cs, out f.unwind);
|
||||
cs.Read(out f.omitFramePointer);
|
||||
cs.Read(out f.spillSlotCount);
|
||||
Operand.CheapRead(cs, out f.stackSlotMap);
|
||||
SequencedCfg.CheapRead(cs, out f.code);
|
||||
OperandArray.CheapRead(cs, out f.pinned);
|
||||
OperandArray.CheapRead(cs, out f.formals);
|
||||
Operand.CheapRead(cs, out f.ret);
|
||||
ReadClose(cs);
|
||||
DebugStub.AddToPerfCounter(3, Processor.GetCycleCount() - beg);
|
||||
|
||||
bufferData.Release(bytes);
|
||||
child.Release(cp);
|
||||
#endif
|
||||
#endif // !DO_LOCAL
|
||||
}
|
||||
|
||||
#if TIMING
|
||||
private const string componentName = "Back End Coloring";
|
||||
private static int componentId;
|
||||
private const string allocFunctionName = "Back End Coloring allocFunction";
|
||||
private static int allocFunctionId;
|
||||
private const string deadCodeName = "Back End Coloring dead code elimination";
|
||||
private static int deadCodeId;
|
||||
private const string copyPropName = "Back End Coloring copy propagation";
|
||||
private static int copyPropId;
|
||||
private const string coalesceName = "Back End Coloring coalescing";
|
||||
private static int coalesceId;
|
||||
private const string interferenceName = "Back End Coloring interference";
|
||||
private static int interferenceId;
|
||||
private const string colorAndSpillName = "Back End Coloring ColorAndSpill";
|
||||
private static int colorAndSpillId;
|
||||
private const string coloringName = "Back End Coloring Coloring";
|
||||
private static int coloringId;
|
||||
#endif
|
||||
} /* class GraphColoring */
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,11 @@
|
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<Import Project="..\..\Paths.targets"/>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="*\*.csproj;*\*.proj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\Dirs.targets"/>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,431 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Microsoft Research Singularity
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// File: CreateProcess.cs
|
||||
//
|
||||
// Note: Singularity micro-benchmark program.
|
||||
//
|
||||
using Microsoft.Singularity;
|
||||
using Microsoft.Singularity.V1.Services;
|
||||
using Microsoft.Singularity.V1.Threads;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
using Microsoft.Singularity.Channels;
|
||||
using Microsoft.Contracts;
|
||||
using Microsoft.SingSharp.Reflection;
|
||||
using Microsoft.Singularity.Applications;
|
||||
using Microsoft.Singularity.Io;
|
||||
using Microsoft.Singularity.Configuration;
|
||||
[assembly: Transform(typeof(ApplicationResourceTransform))]
|
||||
|
||||
namespace Microsoft.Singularity.Applications
|
||||
{
|
||||
[ConsoleCategory(HelpMessage="CreateProcess benchmark test", DefaultAction=true)]
|
||||
internal class Parameters
|
||||
{
|
||||
[InputEndpoint("data")]
|
||||
public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
|
||||
|
||||
[OutputEndpoint("data")]
|
||||
public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
|
||||
|
||||
[BoolParameter( "q", Default=false, HelpMessage="Quiet Mode.")]
|
||||
internal bool quietMode;
|
||||
|
||||
[LongParameter( "r", Default=1, HelpMessage="Repetition count.")]
|
||||
internal long repetitions;
|
||||
|
||||
reflective internal Parameters();
|
||||
|
||||
internal int AppMain() {
|
||||
return CreateProcessTest.AppMain(this);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// The goal of this test is to time how long it takes to
|
||||
// create a process.
|
||||
//
|
||||
public class CreateProcessTest
|
||||
{
|
||||
private static bool AtRing3;
|
||||
|
||||
#if x64_PERF
|
||||
[CLSCompliant(false)]
|
||||
public struct PerfEvtSel
|
||||
{
|
||||
// Bits and Flags
|
||||
public const uint CNT_MASK = 0xff000000;
|
||||
public const uint INV = 0x00800000;
|
||||
public const uint EN = 0x00400000;
|
||||
public const uint INT = 0x00100000;
|
||||
public const uint PC = 0x00080000;
|
||||
public const uint E = 0x00040000;
|
||||
public const uint OS = 0x00020000;
|
||||
public const uint USR = 0x00010000;
|
||||
public const uint UNIT_MASK = 0x0000ff00;
|
||||
public const uint SELECTOR = 0x000000ff;
|
||||
|
||||
// Common setting: Count all, but don't interrupt,
|
||||
public const uint COUNT = (EN | PC | OS | USR);
|
||||
|
||||
// Selector values.
|
||||
public const uint DtlbL1MissL2Hit = 0x45; // Speculative
|
||||
public const uint DtlbL1MissL2Miss = 0x46; // Speculative
|
||||
public const uint CyclesNotHalted = 0x76;
|
||||
public const uint RequestsToL2Cache = 0x7d;
|
||||
public const uint ItlbL1MissL2Hit = 0x84;
|
||||
public const uint ItlbL1MissL2Miss = 0x85;
|
||||
public const uint RetiredInstructions = 0xc0;
|
||||
public const uint RetiredBranchInstructions = 0xc2;
|
||||
public const uint RetiredBranchesMispredicted = 0xc3;
|
||||
public const uint RetiredBranchesTaken = 0xc4;
|
||||
public const uint CyclesInterruptsMasked = 0xcd;
|
||||
public const uint CyclesInterruptsBlocked = 0xce;
|
||||
}
|
||||
|
||||
public static void Reset(uint pmc, ulong value)
|
||||
{
|
||||
// Clear the event selector.
|
||||
Processor.WriteMsr(0xc0010000 + pmc, 0);
|
||||
// Clear the performance counter.
|
||||
Processor.WriteMsr(0xc0010004 + pmc, 0);
|
||||
// Enable the event selector.
|
||||
Processor.WriteMsr(0xc0010000 + pmc, value);
|
||||
}
|
||||
|
||||
public static string EvtSelToString(ulong value)
|
||||
{
|
||||
switch (value & 0xff) {
|
||||
case PerfEvtSel.DtlbL1MissL2Hit: return "DTLB_L2_Hit";
|
||||
case PerfEvtSel.DtlbL1MissL2Miss: return "DTBL_L2_Miss";
|
||||
case PerfEvtSel.CyclesNotHalted: return "CyclesNotHalted";
|
||||
case PerfEvtSel.RequestsToL2Cache: return "TLB_L2_Requests";
|
||||
case PerfEvtSel.ItlbL1MissL2Hit: return "ITLB_L2_Hit";
|
||||
case PerfEvtSel.ItlbL1MissL2Miss: return "ITLB_L2_Miss";
|
||||
case PerfEvtSel.RetiredInstructions: return "Retired_Inst.";
|
||||
case PerfEvtSel.RetiredBranchInstructions: return "Branches";
|
||||
case PerfEvtSel.RetiredBranchesMispredicted:return "Br_Mispredicted";
|
||||
case PerfEvtSel.RetiredBranchesTaken: return "Br_Taken";
|
||||
case PerfEvtSel.CyclesInterruptsMasked: return "Ints_Masked (cyc)";
|
||||
case PerfEvtSel.CyclesInterruptsBlocked: return "Ints_Blocked (cyc)";
|
||||
default:
|
||||
return String.Format("{0:x16}", value);
|
||||
}
|
||||
}
|
||||
|
||||
private static ulong x64_i0, x64_p0;
|
||||
private static ulong x64_i1, x64_p1;
|
||||
private static ulong x64_i2, x64_p2;
|
||||
private static ulong x64_i3, x64_p3;
|
||||
#endif
|
||||
|
||||
private static void DualWriteLine(string message)
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
DebugStub.WriteLine(message);
|
||||
}
|
||||
|
||||
public struct PerfSnap
|
||||
{
|
||||
private bool disabled;
|
||||
private long begCycleCount;
|
||||
private long endCycleCount;
|
||||
private long begSwitchCount;
|
||||
private long endSwitchCount;
|
||||
private long begInterruptCount;
|
||||
private long endInterruptCount;
|
||||
private long begKernelGcCount;
|
||||
private long endKernelGcCount;
|
||||
private long begProcessGcCount;
|
||||
private long endProcessGcCount;
|
||||
private long iterations;
|
||||
private ulong begAllocatedCount;
|
||||
private ulong begAllocatedBytes;
|
||||
private ulong begFreedCount;
|
||||
private ulong begFreedBytes;
|
||||
private ulong endAllocatedCount;
|
||||
private ulong endAllocatedBytes;
|
||||
private ulong endFreedCount;
|
||||
private ulong endFreedBytes;
|
||||
private ulong begStackGets;
|
||||
private ulong begStackRets;
|
||||
private ulong endStackGets;
|
||||
private ulong endStackRets;
|
||||
|
||||
|
||||
public long Cycles { get { return endCycleCount - begCycleCount; } }
|
||||
public long Interrupts { get { return endInterruptCount - begInterruptCount; } }
|
||||
public long Switches { get { return endSwitchCount - begSwitchCount; } }
|
||||
public long KernelGCs { get { return endKernelGcCount - begKernelGcCount; } }
|
||||
public long ProcessGCs { get { return endProcessGcCount - begProcessGcCount; } }
|
||||
public ulong AllocatedCount { get { return endAllocatedCount-begAllocatedCount; } }
|
||||
public ulong AllocatedBytes { get { return endAllocatedBytes-begAllocatedBytes; } }
|
||||
public ulong FreedCount { get { return endFreedCount - begFreedCount; } }
|
||||
public ulong FreedBytes { get { return endFreedBytes - begFreedBytes; } }
|
||||
public ulong StackGets { get { return endStackGets - begStackGets; } }
|
||||
public ulong StackRets { get { return endStackRets - begStackRets; } }
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (!AtRing3) {
|
||||
disabled = Processor.DisableInterrupts();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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.RestoreInterrupts(disabled);
|
||||
}
|
||||
|
||||
this.iterations = iterations;
|
||||
}
|
||||
|
||||
public void Display(string name)
|
||||
{
|
||||
DualWriteLine(
|
||||
String.Format("{0,-16} {1,6:d} x{2,8:d} ={3,12:d} " +
|
||||
"[swi={4,6:d} int={5,3:d} gc={6:d}/{7:d}]",
|
||||
name,
|
||||
iterations,
|
||||
Cycles / iterations,
|
||||
Cycles,
|
||||
Switches,
|
||||
Interrupts,
|
||||
KernelGCs,
|
||||
ProcessGCs)
|
||||
);
|
||||
|
||||
|
||||
if (AllocatedCount != 0 || FreedCount != 0 || StackGets != 0) {
|
||||
DualWriteLine(
|
||||
string.Format(
|
||||
" " +
|
||||
"[alloc={0,4:d}/{1,8:x} free={2,4:d}/{3,8:x} " +
|
||||
"stack={4,4:d}/{5,4:d}]",
|
||||
AllocatedCount,
|
||||
AllocatedBytes,
|
||||
FreedCount,
|
||||
FreedBytes,
|
||||
StackGets,
|
||||
StackRets)
|
||||
);
|
||||
}
|
||||
|
||||
#if x64_PERF
|
||||
if (!AtRing3) {
|
||||
// Read off the current MSR values and turn them
|
||||
// into nice labels
|
||||
ulong e0 = Processor.ReadMsr(0xc0010000);
|
||||
ulong e1 = Processor.ReadMsr(0xc0010001);
|
||||
ulong e2 = Processor.ReadMsr(0xc0010002);
|
||||
ulong e3 = Processor.ReadMsr(0xc0010003);
|
||||
|
||||
DualWriteLine(
|
||||
String.Format("evt: {0,16} {1,16} {2,16} {3,16}",
|
||||
EvtSelToString(e0),
|
||||
EvtSelToString(e1),
|
||||
EvtSelToString(e2),
|
||||
EvtSelToString(e3)));
|
||||
} else {
|
||||
// Subtract from the initial perf-counter values to
|
||||
// get the delta we want
|
||||
x64_p0 -= x64_i0;
|
||||
x64_p1 -= x64_i1;
|
||||
x64_p2 -= x64_i2;
|
||||
x64_p3 -= x64_i3;
|
||||
}
|
||||
|
||||
DualWriteLine(
|
||||
String.Format("pmc: {0:d16} {1:d16} {2:d16} {3:d16} {4:d16}\n\n",
|
||||
Cycles, x64_p0, x64_p1, x64_p2, x64_p3));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal static int AppMain(Parameters! config)
|
||||
{
|
||||
bool runQuiet = config.quietMode;
|
||||
long repetitions = config.repetitions;
|
||||
|
||||
Console.Write("\nProcess creation test\n\n");
|
||||
string [] arguments;
|
||||
for (long i = 0; i < repetitions; i++) {
|
||||
arguments = new string[2];
|
||||
arguments[0] = "testpe.x86";
|
||||
arguments[1] = "!"; // Special flag to not notify debugger.
|
||||
TimeProcess(arguments, runQuiet);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void TimeProcess(String[]! args, bool runQuiet)
|
||||
{
|
||||
ulong baseline;
|
||||
ulong created;
|
||||
ulong started;
|
||||
ulong exited;
|
||||
Process process = null;
|
||||
|
||||
PerfSnap snap = new PerfSnap();
|
||||
|
||||
snap.Start();
|
||||
try {
|
||||
ProcessService.Waypoint0();
|
||||
baseline = Processor.CycleCount;
|
||||
|
||||
//
|
||||
// Time process creation.
|
||||
//
|
||||
ProcessService.Waypoint(1500);
|
||||
process = new Process(args);
|
||||
created = Processor.CycleCount;
|
||||
|
||||
//
|
||||
// Time process start.
|
||||
//
|
||||
ProcessService.Waypoint(1501);
|
||||
|
||||
process.Start();
|
||||
started = Processor.CycleCount;
|
||||
|
||||
ProcessService.Waypoint(1502);
|
||||
//
|
||||
// Time process execution.
|
||||
//
|
||||
process.Join();
|
||||
ProcessService.Waypoint(1503);
|
||||
exited = Processor.CycleCount;
|
||||
}
|
||||
finally {
|
||||
snap.Finish(1);
|
||||
}
|
||||
|
||||
snap.Display("CreateProc");
|
||||
|
||||
ProcessService.Waypoint(1504);
|
||||
process.Dispose(true);
|
||||
ProcessService.Waypoint(1505);
|
||||
ProcessService.WaypointDump();
|
||||
|
||||
|
||||
if (runQuiet) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Tell the world.
|
||||
//
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Tested process: {0}", args[0]);
|
||||
Console.WriteLine("Create process: {0,15:d} cycles", created - baseline);
|
||||
Console.WriteLine("Start process: {0,15:d} cycles", started - created);
|
||||
Console.WriteLine("Run process: {0,15:d} cycles", exited - started);
|
||||
Console.WriteLine("Total: {0,15:d} cycles", exited - baseline);
|
||||
Console.WriteLine("Process.Create: {0,15:d} cycles", started - baseline);
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<!--
|
||||
###############################################################################
|
||||
#
|
||||
# Microsoft Research Singularity
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
#
|
||||
###############################################################################
|
||||
-->
|
||||
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\..\Paths.targets" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AssemblyName>CreateProcess</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="CreateProcess.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\ConsoleCategory.targets" />
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,107 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Microsoft Research Singularity
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// File: SharedHeapBench.cs
|
||||
//
|
||||
// Note: Singularity micro-benchmark program.
|
||||
//
|
||||
using Microsoft.Singularity;
|
||||
using Microsoft.Singularity.V1.Services;
|
||||
using Microsoft.Singularity.V1.Threads;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
using Microsoft.Singularity.Channels;
|
||||
using Microsoft.Contracts;
|
||||
using Microsoft.SingSharp.Reflection;
|
||||
using Microsoft.Singularity.Applications;
|
||||
using Microsoft.Singularity.Io;
|
||||
using Microsoft.Singularity.Configuration;
|
||||
[assembly: Transform(typeof(ApplicationResourceTransform))]
|
||||
|
||||
namespace Microsoft.Singularity.Applications {
|
||||
[ConsoleCategory(HelpMessage="Show attributes associated with a file", DefaultAction=true)]
|
||||
internal class Parameters {
|
||||
[InputEndpoint("data")]
|
||||
public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
|
||||
|
||||
[OutputEndpoint("data")]
|
||||
public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
|
||||
|
||||
[BoolParameter( "q", Default=false, HelpMessage="Quiet Mode.")]
|
||||
internal bool quietMode;
|
||||
|
||||
[LongParameter( "r", Default=1, HelpMessage="Repetition count.")]
|
||||
internal long repetitions;
|
||||
|
||||
reflective internal Parameters();
|
||||
|
||||
internal int AppMain() {
|
||||
return SharedHeapBench.AppMain(this);
|
||||
}
|
||||
}
|
||||
//
|
||||
// The goal of this test is to time how long it takes to
|
||||
// create a process.
|
||||
//
|
||||
public class SharedHeapBench
|
||||
{
|
||||
internal static int AppMain(Parameters! config)
|
||||
{
|
||||
int iterations = 10000;
|
||||
|
||||
Console.Write("\nTime alloc/free ops in the shared heap\n\n");
|
||||
|
||||
TimeCycle(10, iterations);
|
||||
|
||||
Thread.Sleep(1000);
|
||||
|
||||
TimeCycle(100, iterations);
|
||||
|
||||
Thread.Sleep(1000);
|
||||
|
||||
TimeCycle(1000, iterations);
|
||||
|
||||
Thread.Sleep(1000);
|
||||
|
||||
TimeCycle(10000, iterations);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// The goal of this routine is to focus on the shared heap operations
|
||||
// themselves. So we allocate and then free the same amount of memory
|
||||
// repeatedly, which (for small region allocations) won't cause us to
|
||||
// go to the Page manager in steady state.
|
||||
//
|
||||
public static void TimeCycle(int bytes, int iterations)
|
||||
{
|
||||
|
||||
ulong before = Processor.CycleCount;
|
||||
|
||||
for (int loop = 0; loop < iterations; loop++) {
|
||||
SharedHeapService.Allocation *mem;
|
||||
|
||||
mem = (SharedHeapService.Allocation *)
|
||||
SharedHeapService.Allocate((UIntPtr)bytes, typeof(byte).GetSystemType(), 0);
|
||||
SharedHeapService.Free(mem);
|
||||
}
|
||||
|
||||
ulong after = Processor.CycleCount;
|
||||
|
||||
//
|
||||
// Tell the world.
|
||||
//
|
||||
Console.Write("\nTested {0} alloc/free iterations of {1} bytes\n",
|
||||
iterations, bytes);
|
||||
Console.Write("Total cycles: {0}\n", after - before);
|
||||
Console.Write("\n\n");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<!--
|
||||
###############################################################################
|
||||
#
|
||||
# Microsoft Research Singularity
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
#
|
||||
###############################################################################
|
||||
-->
|
||||
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\..\Paths.targets" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AssemblyName>SharedHeapBench</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="SharedHeapBench.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\ConsoleCategory.targets" />
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,118 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Microsoft Research Singularity
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// File: BenchChild.sg
|
||||
//
|
||||
// Note: Simple ping-pong second child process
|
||||
//
|
||||
|
||||
using Microsoft.Singularity.Channels;
|
||||
using Microsoft.Singularity.Diagnostics.Contracts;
|
||||
using Microsoft.Singularity.Endpoint;
|
||||
using Microsoft.Singularity.Directory;
|
||||
using Microsoft.Singularity.V1.Services;
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
using Microsoft.Singularity.Io;
|
||||
using Microsoft.Singularity.Extending;
|
||||
using Microsoft.Singularity.Configuration;
|
||||
using Microsoft.SingSharp.Reflection;
|
||||
using Microsoft.Singularity.Applications;
|
||||
[assembly: Transform(typeof(WebAppResourceTransform))]
|
||||
|
||||
|
||||
namespace Microsoft.Singularity.Applications.Singbench
|
||||
{
|
||||
[Category("WebApp")]
|
||||
internal class Parameters
|
||||
{
|
||||
[Endpoint]
|
||||
public readonly TRef<ExtensionContract.Exp:Start> sendRef;
|
||||
|
||||
[BoolParameter("where", Default=false, HelpMessage="Show what space we are running in")]
|
||||
internal bool doWhere;
|
||||
|
||||
reflective private Parameters();
|
||||
|
||||
internal int AppMain() {
|
||||
return BenchChild.AppMain(this);
|
||||
}
|
||||
}
|
||||
|
||||
public class BenchChild
|
||||
{
|
||||
internal static int AppMain(Parameters! config)
|
||||
{
|
||||
if (config.doWhere) {
|
||||
if (Processor.AtKernelPrivilege()) {
|
||||
DualWriteLine("Benchchild running at KERNEL privilege");
|
||||
} else {
|
||||
DualWriteLine("Benchchild running at USER privilege");
|
||||
}
|
||||
}
|
||||
|
||||
ExtensionContract.Exp ep = (config.sendRef).Acquire();
|
||||
|
||||
|
||||
SendTestContract.Exp simpleConn = ep as SendTestContract.Exp;
|
||||
|
||||
if (simpleConn != null) {
|
||||
DoSimpleTest(simpleConn);
|
||||
}
|
||||
|
||||
BufferTestContract.Exp bufferConn = ep as BufferTestContract.Exp;
|
||||
|
||||
if (bufferConn != null) {
|
||||
DoBufferTest(bufferConn);
|
||||
}
|
||||
|
||||
// Wrong contract type!
|
||||
delete ep;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void DoSimpleTest(SendTestContract.Exp! conn)
|
||||
{
|
||||
conn.SendTestReady();
|
||||
int arg;
|
||||
|
||||
while(true) {
|
||||
conn.RecvReq(out arg);
|
||||
|
||||
if (arg == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
conn.SendResp(arg);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoBufferTest(BufferTestContract.Exp! conn)
|
||||
{
|
||||
int arg;
|
||||
byte[]! in ExHeap buffer;
|
||||
|
||||
conn.SendBufferReady();
|
||||
|
||||
while (true) {
|
||||
conn.RecvReq(out arg, out buffer);
|
||||
conn.SendResp(buffer);
|
||||
if (arg == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DualWriteLine(string message)
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
DebugStub.WriteLine(message);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<!--
|
||||
###############################################################################
|
||||
#
|
||||
# Microsoft Research Singularity
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
#
|
||||
###############################################################################
|
||||
-->
|
||||
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\..\..\Paths.targets" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AssemblyName>benchchild</AssemblyName>
|
||||
<AssumeFieldsNonNull>true</AssumeFieldsNonNull>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="BenchChild.sg" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Contracts\SingBench.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\ConsoleCategory.targets" />
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,44 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Microsoft Research Singularity
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// File: MemoryContract.sg
|
||||
// Note: Contract definition for the memory diagnostic module
|
||||
//
|
||||
|
||||
using Microsoft.Singularity.Channels;
|
||||
using Microsoft.Singularity.Endpoint;
|
||||
using Microsoft.Singularity.V1.Services;
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
using Microsoft.Singularity.Extending;
|
||||
|
||||
namespace Microsoft.Singularity.Applications.Singbench
|
||||
{
|
||||
public contract SendTestContract : ExtensionContract
|
||||
{
|
||||
in message Req(int x);
|
||||
out message Resp(int x);
|
||||
|
||||
out message TestReady();
|
||||
|
||||
override state Start : TestReady! -> ReadyState;
|
||||
state ReadyState : Req? -> Resp! -> ReadyState;
|
||||
}
|
||||
|
||||
public contract BufferTestContract : ExtensionContract
|
||||
{
|
||||
in message Req(int remain, byte[]! in ExHeap buffer);
|
||||
out message Resp(byte[]! in ExHeap buffer);
|
||||
|
||||
out message BufferReady();
|
||||
|
||||
override state Start : BufferReady! -> ReadyState;
|
||||
state ReadyState : Req? -> Resp! -> ReadyState;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<!--
|
||||
###############################################################################
|
||||
#
|
||||
# Microsoft Research Singularity
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
#
|
||||
###############################################################################
|
||||
-->
|
||||
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\..\..\Paths.targets" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<AssemblyName>SingBench.Contracts</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="ChannelTestContract.sg" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Contracts\Directory.Contracts\Directory.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\App.targets" />
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,11 @@
|
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<Import Project="..\..\..\Paths.targets"/>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="*\*.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\Dirs.targets"/>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,293 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Microsoft Research Singularity
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// File: PerfSnap.sg
|
||||
//
|
||||
// Note: Performance measurer for Singularity Benchmark
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Microsoft.Singularity.V1.Services;
|
||||
|
||||
namespace Microsoft.Singularity.Applications.Singbench
|
||||
{
|
||||
public struct PerfSnap
|
||||
{
|
||||
// Global options for all instances
|
||||
static bool xmlOutput = false;
|
||||
static bool atRing3 = false;
|
||||
|
||||
private bool disabled;
|
||||
private long begCycleCount;
|
||||
private long endCycleCount;
|
||||
private long begSwitchCount;
|
||||
private long endSwitchCount;
|
||||
private long begInterruptCount;
|
||||
private long endInterruptCount;
|
||||
private long begKernelGcCount;
|
||||
private long endKernelGcCount;
|
||||
private long begProcessGcCount;
|
||||
private long endProcessGcCount;
|
||||
private long iterations;
|
||||
private ulong begAllocatedCount;
|
||||
private ulong begAllocatedBytes;
|
||||
private ulong begFreedCount;
|
||||
private ulong begFreedBytes;
|
||||
private ulong endAllocatedCount;
|
||||
private ulong endAllocatedBytes;
|
||||
private ulong endFreedCount;
|
||||
private ulong endFreedBytes;
|
||||
private ulong begStackGets;
|
||||
private ulong begStackRets;
|
||||
private ulong endStackGets;
|
||||
private ulong endStackRets;
|
||||
|
||||
|
||||
public long Cycles { get { return endCycleCount - begCycleCount; } }
|
||||
public long Interrupts { get { return endInterruptCount - begInterruptCount; } }
|
||||
public long Switches { get { return endSwitchCount - begSwitchCount; } }
|
||||
public long KernelGCs { get { return endKernelGcCount - begKernelGcCount; } }
|
||||
public long ProcessGCs { get { return endProcessGcCount - begProcessGcCount; } }
|
||||
public ulong AllocatedCount { get { return endAllocatedCount-begAllocatedCount; } }
|
||||
public ulong AllocatedBytes { get { return endAllocatedBytes-begAllocatedBytes; } }
|
||||
public ulong FreedCount { get { return endFreedCount - begFreedCount; } }
|
||||
public ulong FreedBytes { get { return endFreedBytes - begFreedBytes; } }
|
||||
public ulong StackGets { get { return endStackGets - begStackGets; } }
|
||||
public ulong StackRets { get { return endStackRets - begStackRets; } }
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (!atRing3) {
|
||||
disabled = Processor.DisableInterrupts();
|
||||
// flush out pending IO interrupts
|
||||
Thread.Yield();
|
||||
Thread.Yield();
|
||||
Thread.Yield();
|
||||
Thread.Yield();
|
||||
Thread.Yield();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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.RestoreInterrupts(disabled);
|
||||
}
|
||||
|
||||
this.iterations = iterations;
|
||||
}
|
||||
|
||||
public void Display(string name)
|
||||
{
|
||||
if (xmlOutput) {
|
||||
DisplayXml(name);
|
||||
} else {
|
||||
DisplayText(name);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteXmlValue(string name, long value)
|
||||
{
|
||||
DualWriteLine(
|
||||
String.Format(" <Measurement> <name> {0} </name> <value> {1:d} </value> </Measurement>", name, value)
|
||||
);
|
||||
}
|
||||
|
||||
private static void WriteXmlValue(string name, ulong value)
|
||||
{
|
||||
DualWriteLine(
|
||||
String.Format(" <Measurement> <name> {0} </name> <value> {1:d} </value> </Measurement>", name, value)
|
||||
);
|
||||
}
|
||||
|
||||
private void DisplayXml(string name)
|
||||
{
|
||||
DualWriteLine(
|
||||
String.Format("<Microbenchmark Name=\"{0}\">", name)
|
||||
);
|
||||
WriteXmlValue("CyclesPerIteration", Cycles / iterations);
|
||||
WriteXmlValue("Cycles", Cycles);
|
||||
WriteXmlValue("Iterations", iterations);
|
||||
WriteXmlValue("Switches", Switches);
|
||||
WriteXmlValue("Interrupts", Interrupts);
|
||||
WriteXmlValue("KernelGCs", KernelGCs);
|
||||
WriteXmlValue("ProcessGCs", ProcessGCs);
|
||||
WriteXmlValue("AllocationCount", AllocatedCount);
|
||||
WriteXmlValue("AllocationBytes", AllocatedBytes);
|
||||
WriteXmlValue("FreedCount", FreedCount);
|
||||
WriteXmlValue("FreedBytes", FreedBytes);
|
||||
WriteXmlValue("StackGetCount", StackGets);
|
||||
WriteXmlValue("StackReturnCount", StackRets);
|
||||
DualWriteLine("</Microbenchmark>");
|
||||
}
|
||||
|
||||
private void DisplayText(string name)
|
||||
{
|
||||
DualWriteLine(
|
||||
String.Format("{0,-16} {1,6:d} x{2,8:d} ={3,12:d} " +
|
||||
"[swi={4,6:d} int={5,3:d} gc={6:d}/{7:d}]",
|
||||
name,
|
||||
iterations,
|
||||
Cycles / iterations,
|
||||
Cycles,
|
||||
Switches,
|
||||
Interrupts,
|
||||
KernelGCs,
|
||||
ProcessGCs)
|
||||
);
|
||||
|
||||
if (AllocatedCount > 1 || FreedCount > 1 || StackGets > 1) {
|
||||
DualWriteLine(
|
||||
string.Format(
|
||||
" " +
|
||||
"[alloc={0,4:d}/{1,8:x} free={2,4:d}/{3,8:x} " +
|
||||
"stack={4,4:d}/{5,4:d}]",
|
||||
AllocatedCount,
|
||||
AllocatedBytes,
|
||||
FreedCount,
|
||||
FreedBytes,
|
||||
StackGets,
|
||||
StackRets)
|
||||
);
|
||||
}
|
||||
|
||||
#if x64_PERF
|
||||
if (!atRing3) {
|
||||
// Read off the current MSR values and turn them
|
||||
// into nice labels
|
||||
ulong e0 = Processor.ReadMsr(0xc0010000);
|
||||
ulong e1 = Processor.ReadMsr(0xc0010001);
|
||||
ulong e2 = Processor.ReadMsr(0xc0010002);
|
||||
ulong e3 = Processor.ReadMsr(0xc0010003);
|
||||
|
||||
DualWriteLine(
|
||||
String.Format("evt: {0,16} {1,16} {2,16} {3,16}",
|
||||
EvtSelToString(e0),
|
||||
EvtSelToString(e1),
|
||||
EvtSelToString(e2),
|
||||
EvtSelToString(e3)));
|
||||
} else {
|
||||
// Subtract from the initial perf-counter values to
|
||||
// get the delta we want
|
||||
x64_p0 -= x64_i0;
|
||||
x64_p1 -= x64_i1;
|
||||
x64_p2 -= x64_i2;
|
||||
x64_p3 -= x64_i3;
|
||||
}
|
||||
|
||||
DualWriteLine(
|
||||
String.Format("pmc: {0:d16} {1:d16} {2:d16} {3:d16} {4:d16}\n\n",
|
||||
Cycles, x64_p0, x64_p1, x64_p2, x64_p3));
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void DualWriteLine(string message)
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
DebugStub.WriteLine(message);
|
||||
}
|
||||
|
||||
public static void SetOptions(bool ring3, bool doXmlOutput)
|
||||
{
|
||||
PerfSnap.atRing3 = ring3;
|
||||
PerfSnap.xmlOutput = doXmlOutput;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,30 @@
|
|||
<!--
|
||||
###############################################################################
|
||||
#
|
||||
# Microsoft Research Singularity
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
#
|
||||
###############################################################################
|
||||
-->
|
||||
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\..\..\Paths.targets" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AssemblyName>singbench</AssemblyName>
|
||||
<AssumeFieldsNonNull>true</AssumeFieldsNonNull>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="PerfSnap.sg" />
|
||||
<Compile Include="SingBench.sg" />
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Contracts\Diagnostics.Contracts\Diagnostics.Contracts.csproj" />
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\DirectoryService.Utils\DirectoryService.Utils.csproj" />
|
||||
<ProjectReference Include="..\Contracts\SingBench.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\ConsoleCategory.targets" />
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,29 @@
|
|||
From: Mark Aiken
|
||||
Sent: Sunday, October 16, 2005 4:19 PM
|
||||
To: Chris Hawblitzel
|
||||
Subject: Running SPECweb
|
||||
|
||||
Here is how to run webfiles:
|
||||
|
||||
On Windows:
|
||||
in Applications\Benchmarks\SpecWeb99\webfiles type
|
||||
"msb"
|
||||
|
||||
On Singularity:
|
||||
|
||||
First run:
|
||||
- "mkfs /dev/vol2"
|
||||
- "fsmount /dev/vol2 /fs -n" [no caching]
|
||||
- "wafgen99 -v 10 /fs" [Generates lots of files]
|
||||
- "fsunmount"
|
||||
- reboot to clear the log.
|
||||
|
||||
Second boot:
|
||||
- "fsmount /dev/vol2 /fs"
|
||||
- "webfiles -r:60"
|
||||
|
||||
Alternatively, to run an fixed benchmark size, use the -f:X, forced
|
||||
iteration, parameter:
|
||||
- "webfiles -f:20000"
|
||||
|
||||
|
|
@ -0,0 +1,355 @@
|
|||
#define NO_ZIPF_SPIKE
|
||||
|
||||
/*
|
||||
* (C)1997 Standard Performance Evaluation Corporation (SPEC)
|
||||
*
|
||||
* This suite contains code acquired from several sources who
|
||||
* understand and agree with SPEC's goal of creating fair and
|
||||
* objective benchmarks to measure computer performance.
|
||||
*
|
||||
* This copyright notice is placed here only to protect SPEC in the
|
||||
* event the source is misused in any manner that is contrary to
|
||||
* the spirit, the goals and the intent of SPEC.
|
||||
*
|
||||
* The source code is provided to the user or company under the
|
||||
* license agreement for the SPEC Benchmark Suite for this suite.
|
||||
*/
|
||||
|
||||
/*****************************************************************
|
||||
* *
|
||||
* Copyright 1991,1992 Legato Systems, Inc. *
|
||||
* Copyright 1991,1992 Auspex Systems, Inc. *
|
||||
* Copyright 1991,1992 Data General Corporation *
|
||||
* Copyright 1991,1992 Digital Equipment Corporation *
|
||||
* Copyright 1991,1992 Interphase Corporation *
|
||||
* Copyright 1991,1992 Sun Microsystems, Inc. *
|
||||
* *
|
||||
*****************************************************************/
|
||||
|
||||
/*
|
||||
* ---------------------- laddis_c_rnd.c ---------------------
|
||||
*
|
||||
* Random number generator.
|
||||
*
|
||||
*.Exported_routines
|
||||
* double Spec_random (RandomState *theState);
|
||||
* long Spec_nrandom (RandomState *theState);
|
||||
* void Spec_srandom (RandomState *theState, int seed);
|
||||
*
|
||||
*.Local_routines
|
||||
* None
|
||||
*
|
||||
*.Revision_History
|
||||
* 06-Nov-05 Convert to Sing#
|
||||
* 24-May-97 Chan-Nui Re-write to make thread-safe
|
||||
* 28-Nov-91 Teelucksingh ANSI C
|
||||
* 01-Aug-91 Wiryaman laddis_srandom() and laddis_random()whee
|
||||
* now use spec_srand() and spec_rand()
|
||||
* instead of srandom() and random().
|
||||
* 17-Apr-91 Wittle Created.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Here's the source for the random number generator that SPEC uses.
|
||||
* The function to be called is "spec_rand" which returns an integer
|
||||
* between 1 and MAX_INT-1.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* UNIFORM Distribution *
|
||||
*****************************************************************************/
|
||||
using System;
|
||||
using Singularity.Application.SPECWeb99;
|
||||
|
||||
//using Microsoft.Singularity.Math;
|
||||
//using Microsoft.Singularity;
|
||||
//using Microsoft.Singularity.Directory;
|
||||
//using Microsoft.Singularity.V1.Services;
|
||||
//using Microsoft.Singularity.Io;
|
||||
#if SINGULARITY
|
||||
using Microsoft.Contracts;
|
||||
#endif
|
||||
|
||||
namespace Singularity.Application.SPECWeb99.WebFiles
|
||||
{
|
||||
public class Random
|
||||
{
|
||||
public const int A_MULTIPLIER = 16807;
|
||||
public const int M_MODULUS = 2147483647; /* (2**31)-1 */
|
||||
public const int Q_QUOTIENT = 127773; /* 2147483647 / 16807 */
|
||||
public const int R_REMAINDER = 2836; /* 2147483647 % 16807 */
|
||||
/*
|
||||
* Compute the next random number.
|
||||
*/
|
||||
public class RandomState
|
||||
{
|
||||
public int val;
|
||||
|
||||
public RandomState(int val)
|
||||
{
|
||||
this.val = val;
|
||||
}
|
||||
}
|
||||
|
||||
public class ZipfState
|
||||
{
|
||||
public RandomState rstate;
|
||||
public int size;
|
||||
public double []table;
|
||||
|
||||
#if SINGULARITY
|
||||
[NotDelayed]
|
||||
#endif
|
||||
public ZipfState (RandomState rstate, int size)
|
||||
{
|
||||
this.size = size;
|
||||
this.rstate = rstate;
|
||||
table= new double[size+1];
|
||||
if (table == null) {
|
||||
Console.WriteLine("ZipfState constructor: can't create {0} entries for table",
|
||||
size+1);
|
||||
}
|
||||
}
|
||||
} // ZipfState
|
||||
|
||||
|
||||
#if STATIC_NORMAL_DIST
|
||||
public class NormalState {
|
||||
public RandomState rstate;
|
||||
public int size;
|
||||
public int []table;
|
||||
};
|
||||
#else
|
||||
public class NormalState {
|
||||
public RandomState rstate;
|
||||
public double mean, stddev, y2;
|
||||
public bool use_last;
|
||||
};
|
||||
#endif
|
||||
|
||||
public double Spec_random(RandomState /*!*/ theState)
|
||||
/* See "Random Number Generators: Good Ones Are Hard To Find", */
|
||||
/* Park & Miller, CACM 31#10 October 1988 pages 1192-1201. */
|
||||
/***********************************************************/
|
||||
/* THIS IMPLEMENTATION REQUIRES AT LEAST 32 BIT INTEGERS ! */
|
||||
/***********************************************************/
|
||||
{
|
||||
int lo;
|
||||
int hi;
|
||||
int test;
|
||||
|
||||
hi = theState.val / Q_QUOTIENT;
|
||||
lo = theState.val % Q_QUOTIENT;
|
||||
test = A_MULTIPLIER * lo - R_REMAINDER * hi;
|
||||
if (test > 0) {
|
||||
theState.val = test;
|
||||
} else {
|
||||
theState.val = test + M_MODULUS;
|
||||
}
|
||||
return((float) theState.val / M_MODULUS);
|
||||
}
|
||||
|
||||
/*
|
||||
* Seed the random number generator.
|
||||
*/
|
||||
public void Spec_srandom( RandomState /*!*/ theState, int seed ) {
|
||||
theState.val = seed;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a random number.
|
||||
*/
|
||||
public int Spec_nrandom( RandomState/*!*/ theState ) {
|
||||
Spec_random(theState);
|
||||
return(theState.val);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* ZIPF Distribution *
|
||||
*****************************************************************************/
|
||||
|
||||
public ZipfState spec_zipf_setup(RandomState rstate, int size, double Z)
|
||||
{
|
||||
int i;
|
||||
double zipf_sum;
|
||||
|
||||
ZipfState theState = new ZipfState(rstate, size);
|
||||
if (theState == null) return null;
|
||||
|
||||
/* compute zipf values for samples 1-n */
|
||||
for (i = 1; i <= size; i++) {
|
||||
theState.table[i] = Math.Pow(((double)1.0/((double)i)), Z);
|
||||
//theState.table[i] = 1; // SPL TOTAL HACK until POW works!!
|
||||
}
|
||||
|
||||
/* sum the values so we can compute probabilities. */
|
||||
/* at the same time, make the values cumulative */
|
||||
zipf_sum = 0.0;
|
||||
for (i = 1; i <= size; i++) {
|
||||
zipf_sum += theState.table[i] ;
|
||||
theState.table[i] = zipf_sum;
|
||||
}
|
||||
theState.table[size] = 0.0;
|
||||
theState.table[0] = 0.0;
|
||||
|
||||
/* compute probability values by dividing by the sum. */
|
||||
/* also reverse the table so we have values starting at 1.0 */
|
||||
/* and descending to 0.0 (this is what spec_zipf needs) */
|
||||
for (i = 0; i < size; i++) {
|
||||
theState.table[i] = 1.0 - (theState.table[i]/zipf_sum);
|
||||
}
|
||||
|
||||
|
||||
return theState;
|
||||
}
|
||||
|
||||
private void spec_zipf_free( ZipfState/*!*/ theState) {
|
||||
if (theState.table != null) {
|
||||
theState.table = null;
|
||||
}
|
||||
}
|
||||
|
||||
public int spec_zipf(ZipfState/*!*/ theState) {
|
||||
double r;
|
||||
int i;
|
||||
|
||||
#if NO_ZIPF_SPIKE
|
||||
do{
|
||||
#endif
|
||||
r = Spec_random(theState.rstate);
|
||||
i = 0;
|
||||
while (r < theState.table[i]) {
|
||||
i++;
|
||||
}
|
||||
#if NO_ZIPF_SPIKE
|
||||
} while (i>theState.size);
|
||||
#endif
|
||||
return i-1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#if STATIC_NORMAL_DIST
|
||||
/* Right now, mean and stddev are ignored. If someone has a good function to
|
||||
generate the cdf for normal distributions, let me know... */
|
||||
/* size=20, mean = 10, stddev = 3.5, will generate numbers from 0 to 20 */
|
||||
NormalState spec_normal_setup(, RandomState rstate, double mean, double stddev) {
|
||||
|
||||
double normal_dist[] = {
|
||||
0.002137432,
|
||||
0.005064024,
|
||||
0.011135458,
|
||||
0.022750062,
|
||||
0.043238098,
|
||||
0.076563771,
|
||||
0.126549006,
|
||||
0.19568292,
|
||||
0.283854542,
|
||||
0.387548544,
|
||||
0.5,
|
||||
0.612451456,
|
||||
0.716145458,
|
||||
0.80431708,
|
||||
0.873450994,
|
||||
0.923436229,
|
||||
0.956761902,
|
||||
0.977249938,
|
||||
0.988864542,
|
||||
0.994935976,
|
||||
1
|
||||
};
|
||||
int i, index = 0;
|
||||
|
||||
theState.size = 1000;
|
||||
theState.rstate = rstate;
|
||||
|
||||
theState.table=(int *)malloc(sizeof(int)*(theState.size+1));
|
||||
if (theState.table == NULL) {
|
||||
fprintf(stderr, "spec_normal_setup: can't malloc %d bytes for table\n",
|
||||
sizeof(double)*theState.size);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
for (i = 0; i < theState.size; i++) {
|
||||
if ((double)i / (double)theState.size > normal_dist[index]) {
|
||||
index++;
|
||||
}
|
||||
theState.table[i] = index;
|
||||
}
|
||||
|
||||
return theState;
|
||||
}
|
||||
|
||||
void spec_normal_free(NormalState theState) {
|
||||
if (theState.table) {
|
||||
free(theState.table);
|
||||
}
|
||||
}
|
||||
|
||||
int spec_nnormal(NormalState theState) {
|
||||
int rval = spec_nrandom(theState.rstate.val);
|
||||
rval = rval % theState.size;
|
||||
return theState.table[rval];
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* Guts of this routine are based on: */
|
||||
/* boxmuller.c Implements the Polar form of the Box-Muller
|
||||
Transformation
|
||||
|
||||
(c) Copyright 1994, Everett F. Carter Jr.
|
||||
Permission is granted by the author to use
|
||||
this software for any application provided this
|
||||
copyright notice is preserved.
|
||||
|
||||
*/
|
||||
|
||||
private NormalState spec_normal_setup(NormalState/*!*/ theState,
|
||||
RandomState/*!*/ rstate,
|
||||
double mean,
|
||||
double stddev)
|
||||
{
|
||||
theState.mean = mean;
|
||||
theState.stddev = stddev;
|
||||
theState.rstate = rstate;
|
||||
theState.use_last = false;
|
||||
return null;
|
||||
}
|
||||
|
||||
void spec_normal_free(NormalState theState)
|
||||
{
|
||||
}
|
||||
|
||||
private double Spec_normal(NormalState/*!*/ theState)
|
||||
{
|
||||
double x1, x2, w, y1;
|
||||
|
||||
if (theState.use_last ) { /* use value from previous call */
|
||||
y1 = theState.y2;
|
||||
}
|
||||
else {
|
||||
do {
|
||||
x1 = 2.0 * Spec_random(theState.rstate) - 1.0;
|
||||
x2 = 2.0 * Spec_random(theState.rstate) - 1.0;
|
||||
w = x1 * x1 + x2 * x2;
|
||||
} while ( w >= 1.0 );
|
||||
|
||||
w = Math.Sqrt( (-2.0 * Math.Log( w ) ) / w );
|
||||
y1 = x1 * w;
|
||||
theState.y2 = x2 * w;
|
||||
}
|
||||
theState.use_last = !(theState.use_last);
|
||||
return( theState.mean + y1 * theState.stddev );
|
||||
}
|
||||
|
||||
private int spec_nnormal(NormalState/*!*/ theState)
|
||||
{
|
||||
return (int)(Spec_normal(theState));
|
||||
}
|
||||
#endif
|
||||
} //random
|
||||
} //namespace
|
|
@ -0,0 +1,99 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Microsoft Research Singularity
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
|
||||
namespace Singularity.Application.SPECWeb99.WebFiles
|
||||
{
|
||||
class Cache {
|
||||
private const bool verbose = false;
|
||||
private UrlSet cache;
|
||||
private UrlSet free;
|
||||
private int size;
|
||||
|
||||
public Cache(int cacheSize, int deckSize)
|
||||
{
|
||||
cache = new UrlSet(cacheSize);
|
||||
free = new UrlSet(deckSize);
|
||||
this.size = cacheSize;
|
||||
}
|
||||
|
||||
public FileSpec GetUrl(Client/*!*/ client, int id) {
|
||||
// first check the local cache
|
||||
// then see if anyone else is generating the global
|
||||
|
||||
if (cache.pos > 0) {
|
||||
return cache.urls[--cache.pos];
|
||||
}
|
||||
|
||||
// return local free to global free pool
|
||||
|
||||
client.globalLock.WaitOne();
|
||||
while (free.pos > 0) {
|
||||
if (client.freeDeck.pos >= client.freeDeck.urls.Length) {
|
||||
//Console.WriteLine(" too many free slots!");
|
||||
free.urls[--free.pos] = null;
|
||||
//DebugStub.Break();
|
||||
free.pos--;
|
||||
}
|
||||
else {
|
||||
client.freeDeck.urls[client.freeDeck.pos++] =
|
||||
free.urls[--free.pos];
|
||||
}
|
||||
}
|
||||
|
||||
// now see if there are any urls available
|
||||
// if not either wait on or generate the global deck
|
||||
|
||||
while (client.urlDeck.pos == 0){
|
||||
if (client.generatingUrls == false) {
|
||||
//Console.WriteLine("Generating cache");
|
||||
UrlSet temp = client.urlDeck;
|
||||
client.urlDeck = client.spareDeck;
|
||||
client.spareDeck = temp;
|
||||
client.generatingUrls = true;
|
||||
client.syncLock.WaitOne();
|
||||
client.globalLock.ReleaseMutex();
|
||||
client.GenerateFileSpecs();
|
||||
client.globalLock.WaitOne();
|
||||
client.generatingUrls = false;
|
||||
client.syncLock.ReleaseMutex();
|
||||
}
|
||||
else {
|
||||
//Console.WriteLine("Waiting for cache");
|
||||
client.globalLock.ReleaseMutex();
|
||||
client.syncLock.WaitOne();
|
||||
client.syncLock.ReleaseMutex();
|
||||
client.globalLock.WaitOne();
|
||||
}
|
||||
}
|
||||
|
||||
// the global deck is ok -- prime our cache
|
||||
|
||||
if (client.urlDeck.pos > 0 ) {
|
||||
for (int i =0; i < cache.urls.Length && (client.urlDeck.pos > 0); i++) {
|
||||
cache.urls[cache.pos++] =
|
||||
client.urlDeck.urls[--client.urlDeck.pos];
|
||||
}
|
||||
}
|
||||
client.globalLock.ReleaseMutex();
|
||||
return cache.urls[--cache.pos];
|
||||
}
|
||||
|
||||
public void FreeUrl(FileSpec url) {
|
||||
if (free.pos+1 >= free.urls.Length) {
|
||||
//Console.WriteLine("free cache full! de-allocating");
|
||||
url = null;
|
||||
return;
|
||||
}
|
||||
free.urls[free.pos++] = url;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,35 @@
|
|||
<!--
|
||||
###############################################################################
|
||||
#
|
||||
# Microsoft Research Singularity
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
#
|
||||
###############################################################################
|
||||
-->
|
||||
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\..\..\Paths.targets" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AssemblyName>webfiles</AssemblyName>
|
||||
<NoNullCheck>true</NoNullCheck>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="webfiles.cs" />
|
||||
<Compile Include="random.cs" />
|
||||
<Compile Include="urlcache.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\FileSystem.Utils\FileSystem.Utils.csproj" />
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\DirectoryService.Utils\DirectoryService.Utils.csproj" />
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\FileSystem.Utils\FileSystem.Utils.csproj" />
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Contracts\FileSystem.Contracts\FileSystem.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\ConsoleCategory.targets" />
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,11 @@
|
|||
clear
|
||||
mkfs '/dev/vol0.2'
|
||||
fsmount '/dev/vol0.2' '/fs' '-n'
|
||||
wafgen99 '-v' '60' '/fs'
|
||||
clear
|
||||
echo '=============================================================================='
|
||||
echo 'When fsunmount says that the volume has been unmounted, initialization is
|
||||
echo 'complete. You must manually reset the machine to start the xwebfile benchmark.'
|
||||
echo '=============================================================================='
|
||||
echo 'fsunmount:'
|
||||
fsunmount
|
|
@ -0,0 +1,5 @@
|
|||
clear
|
||||
fsmount '/dev/vol0.2' '/fs'
|
||||
perfcnt '-g'
|
||||
webfiles '-f:50000'
|
||||
perfcnt '-s'
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,62 @@
|
|||
<!--
|
||||
##############################################################################
|
||||
|
||||
Microsoft Research Singularity
|
||||
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
File: Applications\YourApp\YourApp.csproj
|
||||
|
||||
Note: This is the template for a basic console app.
|
||||
|
||||
##############################################################################
|
||||
-->
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<!--
|
||||
Provide the relative walk-up path to $(SINGULARITY_ROOT)\Paths.targets.
|
||||
This is annoying, but is necessary in order to get VS builds to work,
|
||||
without requiring that you set environment variables for VS.
|
||||
-->
|
||||
<Import Project="..\..\Paths.targets"/>
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyName>Bartok</AssemblyName>
|
||||
<OutputType>Exe</OutputType>
|
||||
<DefineConstants>ON_SINGULARITY</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Bartok.cs"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Declare references to the projects you need, for example: -->
|
||||
|
||||
<Reference Include="msil\Bartok.Analysis.dll"/>
|
||||
<Reference Include="msil\Bartok.Backend.dll"/>
|
||||
<Reference Include="msil\Bartok.CfgUtil.dll"/>
|
||||
<Reference Include="msil\Bartok.Coff.dll"/>
|
||||
<Reference Include="msil\Bartok.Convert.dll"/>
|
||||
<Reference Include="msil\Bartok.Datatype.dll"/>
|
||||
<Reference Include="msil\Bartok.DebugInfo.dll"/>
|
||||
<Reference Include="msil\Bartok.Encode.dll"/>
|
||||
<Reference Include="msil\Bartok.Ir.dll"/>
|
||||
<Reference Include="msil\Bartok.Lir.dll"/>
|
||||
<Reference Include="msil\Bartok.Mangle.dll"/>
|
||||
<Reference Include="msil\Bartok.MSIL.dll"/>
|
||||
<Reference Include="msil\Bartok.Opt.dll"/>
|
||||
<Reference Include="msil\Bartok.Profile.dll"/>
|
||||
<Reference Include="msil\Bartok.Regalloc.dll"/>
|
||||
<Reference Include="msil\Bartok.Tables.dll"/>
|
||||
<Reference Include="msil\Bartok.Utility.dll"/>
|
||||
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Contracts\FileSystem.Contracts\FileSystem.Contracts.csproj"/>
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\System.IO\System.IO.csproj"/>
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\FileSystem.Utils\FileSystem.Utils.csproj"/>
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\DirectoryService.Utils\DirectoryService.Utils.csproj"/>
|
||||
<ProjectReference Include="$(SINGULARITY_ROOT)\Libraries\Security\Security.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(SINGULARITY_ROOT)\Targets\ConsoleCategory.targets"/>
|
||||
</Project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue