syntax = "proto2";

package dittosuiteproto;

enum Order {
  SEQUENTIAL = 0;
  RANDOM = 1;
}

enum Reseeding {
  ONCE = 0;
  EACH_ROUND_OF_CYCLES = 1;
  EACH_CYCLE = 2;
}

enum AccessMode {
  READ_ONLY = 1;
  WRITE_ONLY = 2;
  READ_WRITE = 3;
}

enum FreePolicy {
  FREE_POLICY_UNSPECIFIED = 0;
  FREE_POLICY_EVERY_PERIOD = 1;
  FREE_POLICY_LAST_PERIOD = 2;
  FREE_POLICY_KEEP = 3;
}

message MemoryAllocate {
  optional uint64 size = 1;
  optional FreePolicy free_policy = 2 [default = FREE_POLICY_KEEP];
}

message CpuWork {
  oneof type {
    uint64 cycles = 1;
    double utilization = 2;
    uint64 duration_us = 3;
  }
}

message BinderService {
  optional string name = 1;
  optional uint32 threads = 2;
}

message BinderRequest {
  enum RunningService {
    MOUNT_SERVICE = 0;
  };
  message GenericService {
    message ParcelInput {
      message NestedParcel {
        repeated ParcelInput parcel_inputs = 1;
      }
      enum Type {
        // Write the 32-bit integer into the send parcel.
        I32 = 0;
        // Write the 64-bit integer into the send parcel.
        I64 = 1;
        // Write the UTF-16 string STR  into the send parcel.
        STRING_16 = 2;
        // Write the 32-bit single-precision number into the send parcel.
        F = 3;
        // Write the 64-bit double-precision number into the send parcel.
        D = 4;
        // Write a null binder into the send parcel.
        NULL = 5;
        // Data: File name
        // Write a file descriptor for the file with given path into the send
        // parcel.
        FD_PATH = 6;
        // Data: File name
        // Write an ashmem file descriptor for a region containing the data
        // from file the given path into the send parcel.
        ASHMEM_FD_PATH = 7;
        // Data: FD number
        // Write the file descriptor into the send parcel.
        FD = 8;
        // Parcel input that is nested inside.
        PARCEL = 9;
      }
      optional Type type = 1;
      oneof data_oneof {
        string data = 2;
        NestedParcel nested_parcel = 3;
      }
    }
    optional string name = 1;
    optional int32 code = 2;
    repeated ParcelInput parcel_input = 3;
  }
  oneof service_oneof {
    string service_name = 1;
    RunningService running_service = 2;
    GenericService generic_service = 3;
  }
}

message OpenFile {
  oneof file {
    string path_name = 1;
    string input = 2;
  }
  optional string output_fd = 3;
  optional bool create = 4 [default = true];
  optional bool direct_io = 5 [default = false];
  optional AccessMode access_mode = 6 [default = READ_WRITE];
}

message DeleteFile {
  oneof file {
    string path_name = 1;
    string input = 2;
  }
}

message CloseFile {
  required string input_fd = 1;
}

message ResizeFile {
  required string input_fd = 1;
  required int64 size = 2;
}

message ResizeFileRandom {
  required string input_fd = 1;
  required int64 min = 2;
  required int64 max = 3;
  optional uint32 seed = 4;
  optional Reseeding reseeding = 5 [default = ONCE];
}

message WriteFile {
  required string input_fd = 1;
  optional int64 size = 2 [default = -1];
  optional int64 block_size = 3 [default = 4096];
  optional int64 starting_offset = 4 [default = 0];
  optional Order access_order = 5 [default = SEQUENTIAL];
  optional uint32 seed = 6;
  optional bool fsync = 7 [default = false];
  optional Reseeding reseeding = 8 [default = ONCE];
}

message ReadFile {
  enum ReadFAdvise {
    AUTOMATIC = 0;
    NORMAL = 1;
    SEQUENTIAL = 2;
    RANDOM = 3;
  }
  required string input_fd = 1;
  optional int64 size = 2 [default = -1];
  optional int64 block_size = 3 [default = 4096];
  optional int64 starting_offset = 4 [default = 0];
  optional Order access_order = 5 [default = SEQUENTIAL];
  optional uint32 seed = 6;
  optional ReadFAdvise fadvise = 7 [default = AUTOMATIC];
  optional Reseeding reseeding = 8 [default = ONCE];
}

message ReadDirectory {
  required string directory_name = 1;
  required string output = 2;
}

message Mutex {
  optional string name = 1;
}

message Lock {
  optional Mutex mutex = 1;
}

message Unlock {
  optional Mutex mutex = 1;
}

message Thread {
  required Instruction instruction = 1;
  optional int32 spawn = 2 [default = 1];
  optional string name = 3;
  optional SchedAttr sched_attr = 4;
  optional int64 sched_affinity = 5 [default = -1];
}

message SchedAttr {
  message SchedOther {
    enum SchedPolicy {
      OTHER = 1;
      BATCH = 2;
    }
    required SchedPolicy policy = 1;
    optional int32 nice = 2 [default = 10];
  }
  message SchedRt {
    enum SchedPolicy {
      FIFO = 1;
      RR = 2;
    }
    required SchedPolicy policy = 1;
    required uint32 priority = 2;
  }
  message SchedDeadline {
    enum SchedPolicy {
      DEADLINE = 1;
    }
    required SchedPolicy policy = 1;
    required uint64 runtime = 2;
    required uint64 deadline = 3;
    required uint64 period = 4;
  }

  optional uint64 flags = 1 [default = 0];
  oneof attributes {
    SchedOther other = 2;
    SchedRt rt = 3;
    SchedDeadline deadline = 4;
  }
}

message Multithreading {
  repeated Thread threads = 1;
  optional bool fork = 2 [default = false];
}

message InvalidateCache {}

message KernelLoadModule {
  optional string input_fd = 1;
}

message KernelUnloadModule {
  optional string name = 1;
}

message Instruction {
  optional int32 repeat = 1 [default = 1];
  oneof instruction_oneof {
    InstructionSet instruction_set = 2;
    OpenFile open_file = 3;
    DeleteFile delete_file = 4;
    CloseFile close_file = 5;
    ResizeFile resize_file = 6;
    WriteFile write_file = 7;
    ReadFile read_file = 8;
    ReadDirectory read_directory = 9;
    ResizeFileRandom resize_file_random = 10;
    Multithreading multithreading = 11;
    InvalidateCache invalidate_cache = 12;
    BinderRequest binder_request = 13;
    BinderService binder_service = 14;
    CpuWork cpu_work = 16;
    MemoryAllocate mem_alloc = 17;
    Lock lock = 19;
    Unlock unlock = 20;
    KernelLoadModule kernel_load_module = 21;
    KernelUnloadModule kernel_unload_module = 22;
  };
  optional uint64 period_us = 15 [default = 0];
  optional uint64 offset_us = 18 [default = 0];
}

message InstructionSet {
  repeated Instruction instructions = 1;
  optional InstructionSetIterate iterate_options = 2;
}

message InstructionSetIterate {
  required string list_name = 1;
  required string item_name = 2;
  optional Order access_order = 3 [default = SEQUENTIAL];
  optional Reseeding reseeding = 4 [default = ONCE];
  optional uint32 seed = 5;
}

message Global {
  optional string absolute_path = 1 [default = ""];
  optional Mutex mutex = 2;
}

message Benchmark {
  optional Instruction init = 1;
  required Instruction main = 2;
  optional Instruction clean_up = 3;
  required Global global = 4;
}
