github.com/dara-project/godist@v0.0.0-20200823115410-e0c80c8f0c78/src/dara/types.go (about)

     1  package dara
     2  
     3  type TypeNum int
     4  
     5  const (
     6  	INTEGER TypeNum = iota
     7  	INTEGER64
     8  	BOOL
     9  	FLOAT
    10  	STRING
    11  	ARRAY
    12  	ERROR
    13  	POINTER
    14  	FILE
    15  	FILEINFO
    16  	CONNECTION
    17  	TIME
    18  	PROCESS
    19  	SIGNAL
    20  	CONTEXT
    21  	SOCKADDR
    22  )
    23  
    24  //Event Types
    25  const (
    26  	LOG_EVENT = iota
    27  	SYSCALL_EVENT
    28  	SEND_EVENT
    29  	REC_EVENT
    30  	SCHED_EVENT
    31      INIT_EVENT
    32      END_EVENT
    33      THREAD_EVENT
    34  	CRASH_EVENT
    35  	DELETEVAR_EVENT
    36  	TIMER_EVENT
    37  )
    38  
    39  
    40  
    41  //DaraProc is used to communicate control and data information between
    42  //a single instrumented go runtime and the global scheduler. One of
    43  //these structures is mapped into shared memory for each process that
    44  //is launched during an execution. If there are more runtimes active
    45  //Than DaraProcs the additional runtimes will not be controlled by the
    46  //global scheduler, or Segfault immediately 
    47  type DaraProc struct {
    48  
    49  	//Lock is used to control the execution of a process. A process
    50  	//which is running but Not scheduled will spin on this lock using
    51  	//checkandset operations If the lock is held The owner can modify
    52  	//the state of the DaraProc
    53  	Lock uint32
    54  
    55  	//SyscallLock is used to control the reporting of the syscalls.
    56  	SyscallLock uint32
    57  
    58  	//PID is the Linux Process ID. Since we are limited to GOMAXPROCS=1
    59  	//there is only 1 system thread/process ID.
    60  	PID uint64
    61  
    62  	//Run is a deprecated var with multiple purposes. Procs set their
    63  	//Run to -1 when they Are done running (in replay mode) to let the
    64  	//scheduler know they are done. The global scheduler sets this
    65  	//value to 2 to let the runtime know its replay, and 3 for record
    66  	//1 is used to denote the first event, and 0 indicates this
    67  	//variable has not been initialized Originally Run was intended to
    68  	//report the id of the goroutine that was executed, but that was
    69  	//not always the same so the program counter  was needed, now
    70  	//RunningRoutine is used to report this. The global scheduler sets
    71  	// this to -4 to inform the local schedulers that replay is ended
    72  	Run int
    73  	// Syscall number at which the running routine is blocked on. -1 means that
    74  	// there is no syscall on which the daraproc is blocked
    75  	Syscall int
    76  	//RunningRoutine is the goroutine scheduled, running, or ran, for
    77  	//any single replayed event in a schedule. In Record, the
    78  	//executed goroutine is reported via this variable, in Replay the
    79  	//global scheduler tells the runtime which routine to run with
    80  	//RunningRoutine
    81  	RunningRoutine RoutineInfo
    82  	//Routines is the full set of goroutines a process is allowed to
    83  	//run. The total number is allocated upfront so that shared memory
    84  	//does not need to be resized dynamically. After each iteration
    85  	//of scheduling runtimes update the states of all their routines
    86  	//via this structure
    87  	Routines [MAXGOROUTINES]RoutineInfo
    88  	//TODO document
    89  	Epoch int
    90  	LogIndex int
    91  	Log [MAXLOGENTRIES]EncEvent
    92      CoverageIndex int
    93      Coverage [MAXBLOCKS]CovInfo
    94  }
    95  
    96  //RoutineInfo contains data specific to a single goroutine
    97  type RoutineInfo struct {
    98          //Set to one of the statuses in the constant block above
    99          Status uint32
   100          //Goroutine id as set by the runtime. This is sometimes usefull
   101          //for detecting which routine is which, but it is not always the
   102          //same between runs. However 1 is allways main, while 2 is a
   103          //finalizer, and 3 is a garbage collection invocator.
   104          Gid int
   105          //Program counter that this goroutine was launched from
   106          Gpc uintptr
   107          //A count of how many other goroutines were launched on the same
   108          //pc prior to this goroutine. (Gpc,Routinecount) is a unique id
   109          //for a goroutine on a given processor.
   110          RoutineCount int
   111          //A textual description of the function this goroutine was forked
   112          //from.In the future it can be removed.
   113          FuncInfo [64]byte
   114  }
   115  
   116  type EncEvent struct {
   117  	Type int
   118  	P int
   119  	G RoutineInfo
   120  	Epoch int
   121  	ELE EncLogEntry
   122  	SyscallInfo GeneralSyscall
   123  	EM EncodedMessage
   124  }
   125  
   126  type EncLogEntry struct {
   127  	Length int
   128  	LogID [VARBUFLEN]byte
   129  	Vars [MAXLOGVARIABLES] EncNameValuePair
   130  }
   131  
   132  type GeneralType struct {
   133  	Type TypeNum
   134  	Integer int
   135  	Bool bool
   136  	Float float32
   137  	Integer64 int64
   138  	String [256]byte
   139  	Unsupported rune
   140  }
   141  
   142  type GeneralSyscall struct {
   143  	SyscallNum int
   144  	NumArgs int
   145  	NumRets int
   146  	Args [10]GeneralType
   147  	Rets [10]GeneralType
   148  }
   149  
   150  //TODO fill out this structure
   151  type EncodedMessage struct {
   152  	Body [VARBUFLEN]byte
   153  }
   154  
   155  type EncNameValuePair struct {
   156  	VarName [VARBUFLEN]byte
   157  	Value [VARBUFLEN]byte
   158  	Type [VARBUFLEN]byte
   159  }
   160  
   161  type CovInfo struct {
   162      BlockID [BLOCKIDLEN]byte
   163      Count uint64
   164  }
   165  
   166  type Event struct {
   167  	Type int
   168  	P int
   169  	G RoutineInfo
   170  	Epoch int
   171  	LE LogEntry
   172  	SyscallInfo GeneralSyscall
   173  	Msg Message
   174  }
   175  
   176  type CoverageEvent struct {
   177  	CoverageInfo map[string]uint64
   178  	SnapshotCoverage float64
   179  	TotalCoverage float64
   180  	EventIndex int
   181  }
   182  
   183  type FailedPropertyEvent struct {
   184  	Name string
   185  	Context map[string]interface{}
   186  }
   187  
   188  type PropCheckEvent struct {
   189  	PropFailures []FailedPropertyEvent
   190  	EventIndex int
   191  }
   192  
   193  func CreatePropCheckEvent(propertyEvents []FailedPropertyEvent, index int) PropCheckEvent {
   194  	return PropCheckEvent{propertyEvents, index}
   195  }
   196  
   197  type LogEntry struct {
   198  	LogID string
   199  	Vars []NameValuePair
   200  }
   201  
   202  type NameValuePair struct {
   203  	VarName string
   204  	Value interface{}
   205  	Type string
   206  }
   207  
   208  type Message struct {
   209  	Body string
   210  }
   211  
   212  
   213  type DaraProcStatus uint32
   214  
   215  // The numbering has to match the Goroutine states from runtime/proc.go
   216  const (
   217          Idle DaraProcStatus = iota // 0
   218          Runnable // 1
   219          Running // 2
   220          Syscall // 3
   221          Waiting // 4
   222          Moribound_Unused // 5
   223          Dead // 6
   224          Enqueue_Unused // 7
   225          Copystack // 8
   226          Scan DaraProcStatus = 0x1000
   227          ScanRunnable = Scan + Runnable // 0x1001
   228          ScanRunning  = Scan + Running  // 0x1002
   229          ScanSyscall  = Scan + Syscall  // 0x1003
   230          ScanWaiting  = Scan + Waiting  // 0x1004
   231  )
   232  
   233  func GetDaraProcStatus(status uint32) DaraProcStatus {
   234  	return DaraProcStatus(status)
   235  }
   236  
   237  
   238  // Status is used to control between Global and Local Schedulers
   239  type DaraNodeStatus int
   240  
   241  const (
   242  	// THe global scheduler has asked us the local scheduler
   243  	// to record events of interest and report them to the global scheduler
   244  	RECORD DaraNodeStatus = -3
   245  	INIT = -1
   246  	// The local scheduler has finished its execution
   247  	FINISH = -100
   248  	// The global scheduler has told the local scheduler to kill its execution.
   249  	KILL = -4
   250  	// The local scheduler needs to do polling on the net. It can't do anything else for now :/
   251  	NET_BLOCK = -6
   252  	// The local scheduler has woken up from a network block. This value notifies
   253  	// the global scheduler that it wants the lock back
   254  	NET_WAKEUP = -7
   255  	// The global scheduler has specified the next GoRoutine that must be executed
   256  	// This value is only used during replay and explore
   257  	ROUTINE_SCHEDULE = -5
   258  )
   259  
   260  //Type which encapsulates a single schedule
   261  type Schedule struct {
   262  	LogEvents  []Event
   263  	CovEvents  []CoverageEvent
   264  	PropEvents []PropCheckEvent
   265  }