{
  "entity_types": [
    {"name": "Process"},
    {"name": "Signal"}
  ],

  "containers": [
    {"name": "READY",      "kind": "simple", "entity_type": "Process"},
    {"name": "CPU0",       "kind": "slot",   "entity_type": "Process"},
    {"name": "BLOCKED",    "kind": "simple", "entity_type": "Process"},
    {"name": "TERMINATED", "kind": "simple", "entity_type": "Process"},

    {"name": "TIMER_EXPIRED", "kind": "simple", "entity_type": "Signal"},
    {"name": "KILL_SIG",      "kind": "simple", "entity_type": "Signal"},
    {"name": "BLOCK_SIG",     "kind": "simple", "entity_type": "Signal"},
    {"name": "UNBLOCK_SIG",   "kind": "simple", "entity_type": "Signal"},
    {"name": "BOOST_SIG",     "kind": "simple", "entity_type": "Signal"},
    {"name": "SIG_DONE",      "kind": "simple", "entity_type": "Signal"}
  ],

  "moves": [
    {
      "name": "schedule",
      "from": ["READY"],
      "to": ["CPU0"],
      "entity_type": "Process"
    },
    {
      "name": "preempt",
      "from": ["CPU0"],
      "to": ["READY"],
      "entity_type": "Process"
    },
    {
      "name": "block_proc",
      "from": ["CPU0"],
      "to": ["BLOCKED"],
      "entity_type": "Process"
    },
    {
      "name": "unblock",
      "from": ["BLOCKED"],
      "to": ["READY"],
      "entity_type": "Process"
    },
    {
      "name": "terminate",
      "from": ["CPU0"],
      "to": ["TERMINATED"],
      "entity_type": "Process"
    },
    {
      "name": "consume_signal",
      "from": ["TIMER_EXPIRED", "KILL_SIG", "BLOCK_SIG", "UNBLOCK_SIG", "BOOST_SIG"],
      "to": ["SIG_DONE"],
      "entity_type": "Signal"
    }
  ],

  "tensions": [
    {
      "name": "schedule_ready",
      "priority": 10,
      "match": [
        {"bind": "proc", "in": "READY", "select": "max_by", "key": "priority"},
        {"bind": "cpu", "empty_in": ["CPU0"]}
      ],
      "emit": [
        {"move": "schedule", "entity": "proc", "to": "cpu"}
      ]
    },

    {
      "name": "timer_preempt",
      "priority": 20,
      "match": [
        {"bind": "sig", "in": "TIMER_EXPIRED", "select": "first"},
        {"bind": "proc", "in": "CPU0", "select": "first", "required": false}
      ],
      "emit": [
        {"set": "proc", "property": "time_slice",
         "value": {"op": "-",
                   "left": {"prop": "time_slice", "of": "proc"},
                   "right": 1}},
        {"move": "consume_signal", "entity": "sig", "to": "SIG_DONE"}
      ]
    },

    {
      "name": "preempt_expired",
      "priority": 15,
      "match": [
        {"bind": "proc", "in": "CPU0",
         "where": {"op": "<=",
                   "left": {"prop": "time_slice", "of": "proc"},
                   "right": 0}}
      ],
      "emit": [
        {"move": "preempt", "entity": "proc", "to": "READY"},
        {"set": "proc", "property": "time_slice", "value": 3}
      ]
    },

    {
      "name": "kill_running",
      "priority": 25,
      "match": [
        {"bind": "sig", "in": "KILL_SIG", "select": "first"},
        {"bind": "proc", "in": "CPU0", "select": "first"}
      ],
      "emit": [
        {"move": "terminate", "entity": "proc", "to": "TERMINATED"},
        {"move": "consume_signal", "entity": "sig", "to": "SIG_DONE"}
      ]
    },

    {
      "name": "block_running",
      "priority": 25,
      "match": [
        {"bind": "sig", "in": "BLOCK_SIG", "select": "first"},
        {"bind": "proc", "in": "CPU0", "select": "first"}
      ],
      "emit": [
        {"move": "block_proc", "entity": "proc", "to": "BLOCKED"},
        {"move": "consume_signal", "entity": "sig", "to": "SIG_DONE"}
      ]
    },

    {
      "name": "unblock_first",
      "priority": 25,
      "match": [
        {"bind": "sig", "in": "UNBLOCK_SIG", "select": "first"},
        {"bind": "proc", "in": "BLOCKED", "select": "first"}
      ],
      "emit": [
        {"move": "unblock", "entity": "proc", "to": "READY"},
        {"move": "consume_signal", "entity": "sig", "to": "SIG_DONE"}
      ]
    },

    {
      "name": "boost_running",
      "priority": 25,
      "match": [
        {"bind": "sig", "in": "BOOST_SIG", "select": "first"},
        {"bind": "proc", "in": "CPU0", "select": "first"}
      ],
      "emit": [
        {"set": "proc", "property": "priority",
         "value": {"op": "+",
                   "left": {"prop": "priority", "of": "proc"},
                   "right": 1}},
        {"move": "consume_signal", "entity": "sig", "to": "SIG_DONE"}
      ]
    }
  ],

  "entities": [
    {"name": "init",    "type": "Process", "in": "READY",
     "properties": {"priority": 1, "time_slice": 3}},
    {"name": "shell",   "type": "Process", "in": "READY",
     "properties": {"priority": 5, "time_slice": 3}},
    {"name": "daemon",  "type": "Process", "in": "READY",
     "properties": {"priority": 8, "time_slice": 3}},
    {"name": "logger",  "type": "Process", "in": "BLOCKED",
     "properties": {"priority": 3, "time_slice": 3}}
  ]
}
