Skip to content

Commit

Permalink
Remove process watchdog support (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperl authored Jun 30, 2022
1 parent 7245583 commit 1890135
Show file tree
Hide file tree
Showing 12 changed files with 11 additions and 78 deletions.
3 changes: 0 additions & 3 deletions lib/net/modules/tcp.toit
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ class TcpSocket_:
if state_bits & TOIT_TCP_NEEDS_GC_ != 0:
state_bits = null
tcp_gc_ state.group
// We can get connect requests so fast that this causes a watchdog
// to trigger, so insert a sleep here.
sleep --ms=1
if state_bits == 0:
return failure.call "NOT_CONNECTED"
if (state_bits & error_bits) == 0:
Expand Down
2 changes: 0 additions & 2 deletions lib/net/modules/udp.toit
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ class Socket implements net.Socket:
if state_bits & TOIT_UDP_NEEDS_GC_ != 0:
state_bits = null
udp_gc_ state.group
// Avoid watchdog trigger when we are overwhelmed with packets.
sleep --ms=1
if not state_.resource: return null // Closed from a different task.
assert: state_bits != 0
if (state_bits & TOIT_UDP_ERROR_) == 0:
Expand Down
1 change: 0 additions & 1 deletion src/compiler/program_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ void ProgramBuilder::set_up_skeleton_program() {
_program->set_read_failed(lookup_symbol("READ_FAILED"));
_program->set_stack_overflow(lookup_symbol("STACK_OVERFLOW"));
_program->set_unimplemented(lookup_symbol("UNIMPLEMENTED"));
_program->set_watchdog_interrupt(lookup_symbol("WATCHDOG_INTERRUPT"));
_program->set_wrong_object_type(lookup_symbol("WRONG_OBJECT_TYPE"));
_program->set_app_sdk_version(lookup_symbol(vm_git_version()));
_program->set_app_sdk_info(lookup_symbol(vm_git_info()));
Expand Down
3 changes: 1 addition & 2 deletions src/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ namespace toit {
FLAG_BOOL(debug, print_bytecodes, false, "Print the bytecodes for each method") \
FLAG_BOOL(debug, disable_tree_shaking, false, "Disables tree-shaking") \
FLAG_BOOL(debug, report_tree_shaking, false, "Report stats on tree shaking") \
FLAG_BOOL(debug, print_dependency_tree, false, "Prints the dependency tree used in the source-shaking") \
FLAG_BOOL(debug, print_dependency_tree, false, "Prints the dependency tree used in the source-shaking") \
FLAG_BOOL(deploy, enable_asserts, _ASSERT_DEFAULT, "Enables asserts") \
FLAG_BOOL(deploy, enable_watchdog, true, "Enables watchdog timeouts") \
FLAG_INT(deploy, max_recursion_depth, 2000, "Max recursion depth in the parser") \
FLAG_STRING(deploy, lib_path, null, "The library path") \
FLAG_STRING(deploy, archive_entry_path, null, "The entry path in an archive") \
Expand Down
20 changes: 4 additions & 16 deletions src/interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,24 +212,12 @@ Object** Interpreter::push_out_of_memory_error(Object** sp) {
return sp;
}

Object** Interpreter::handle_preempt(Object** sp, OverflowState* state) {
// Reset the watermark now that we're handling the preemption.
_watermark = null;

Process* process = _process;
if (process->signals() & Process::WATCHDOG) {
*state = OVERFLOW_EXCEPTION;
Object* type = process->program()->watchdog_interrupt();
return push_error(sp, type, "");
} else {
*state = OVERFLOW_PREEMPT;
}
return sp;
}

Object** Interpreter::handle_stack_overflow(Object** sp, OverflowState* state, Method method) {
if (_watermark == PREEMPTION_MARKER) {
return handle_preempt(sp, state);
// Reset the watermark now that we're handling the preemption.
_watermark = null;
*state = OVERFLOW_PREEMPT;
return sp;
}

Process* process = _process;
Expand Down
1 change: 0 additions & 1 deletion src/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ class Interpreter {
OVERFLOW_EXCEPTION,
};

Object** handle_preempt(Object** sp, OverflowState* state);
Object** handle_stack_overflow(Object** sp, OverflowState* state, Method target);

Object** push_error(Object** sp, Object* type, const char* message);
Expand Down
8 changes: 2 additions & 6 deletions src/interpreter_run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,10 @@ Method Program::find_method(Object* receiver, int offset) {
} \
}

// CHECK_PREEMPT checks for preemption and watchdog interrupts.
// CHECK_PREEMPT checks for preemption by looking at the watermark.
#define CHECK_PREEMPT(entry) \
if (_watermark == PREEMPTION_MARKER) { \
OverflowState state; \
sp = handle_preempt(sp, &state); \
if (state == OVERFLOW_EXCEPTION) { \
goto THROW_IMPLEMENTATION; \
} \
_watermark = null; \
_preemption_method_header_bcp = Method::header_from_entry(entry); \
static_assert(FRAME_SIZE == 2, "Unexpected frame size"); \
PUSH(reinterpret_cast<Object*>(bcp)); \
Expand Down
20 changes: 0 additions & 20 deletions src/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Process : public ProcessListFromProcessGroup::Element,
enum Signal {
KILL = 1 << 0,
PREEMPT = 1 << 1,
WATCHDOG = 1 << 2,
};

enum State {
Expand Down Expand Up @@ -194,22 +193,6 @@ class Process : public ProcessListFromProcessGroup::Element,
delete p;
}

void set_last_run(int64 us) {
_last_run_us = us;
}

void increment_unyielded_for(int64 us) {
_unyielded_for_us += us;
}

void clear_unyielded_for() {
_unyielded_for_us = 0;
}

int64 current_run_duration(int64 now) {
return _unyielded_for_us + (now - _last_run_us);
}

inline bool on_program_heap(HeapObject* object) {
uword address = reinterpret_cast<uword>(object);
return address - _program_heap_address < _program_heap_size;
Expand Down Expand Up @@ -257,9 +240,6 @@ class Process : public ProcessListFromProcessGroup::Element,
bool _construction_failed = false;
bool _idle_since_gc = true;

int64 _last_run_us = 0;
int64 _unyielded_for_us = 0;

Profiler* _profiler = null;

ResourceGroupListFromProcess _resource_groups;
Expand Down
1 change: 0 additions & 1 deletion src/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ namespace toit {
ROOT(String, read_failed) \
ROOT(String, stack_overflow) \
ROOT(String, unimplemented) \
ROOT(String, watchdog_interrupt) \
ROOT(String, wrong_object_type) \


Expand Down
16 changes: 0 additions & 16 deletions src/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,6 @@ Object* Scheduler::process_stats(Array* array, int group_id, int process_id, Pro
void Scheduler::run_process(Locker& locker, Process* process, SchedulerThread* scheduler_thread) {
wait_for_any_gc_to_complete(locker, process, Process::RUNNING);
process->set_scheduler_thread(scheduler_thread);
int64 start = OS::get_monotonic_time();
process->set_last_run(start);

ProcessRunner* runner = process->runner();
bool interpreted = (runner == null);
Expand Down Expand Up @@ -591,7 +589,6 @@ void Scheduler::run_process(Locker& locker, Process* process, SchedulerThread* s
result = runner->run();
}

process->increment_unyielded_for(OS::get_monotonic_time() - start);
process->set_scheduler_thread(null);

while (result.state() != Interpreter::Result::TERMINATED) {
Expand All @@ -604,8 +601,6 @@ void Scheduler::run_process(Locker& locker, Process* process, SchedulerThread* s
} else if (signals & Process::PREEMPT) {
result = Interpreter::Result(Interpreter::Result::PREEMPTED);
process->clear_signal(Process::PREEMPT);
} else if (signals & Process::WATCHDOG) {
process->clear_signal(Process::WATCHDOG);
} else {
UNREACHABLE();
}
Expand Down Expand Up @@ -633,7 +628,6 @@ void Scheduler::run_process(Locker& locker, Process* process, SchedulerThread* s
}

case Interpreter::Result::YIELDED:
process->clear_unyielded_for();
wait_for_any_gc_to_complete(locker, process, Process::IDLE);
if (process->has_messages()) {
process_ready(locker, process);
Expand Down Expand Up @@ -779,16 +773,6 @@ void Scheduler::terminate_execution(Locker& locker, ExitState exit) {
void Scheduler::tick(Locker& locker, int64 now) {
tick_schedule(locker, now, true);

for (SchedulerThread* thread : _threads) {
Process* process = thread->interpreter()->process();
if (process == null) continue;
if (process == _boot_process) continue;
int64 runtime = process->current_run_duration(now);
if (Flags::enable_watchdog && runtime > WATCHDOG_PERIOD_US) {
process->signal(Process::WATCHDOG);
}
}

if (_num_profiled_processes == 0 && _ready_processes.is_empty()) {
// No need to do preemption when there are no active profilers
// and no other processes ready to run.
Expand Down
6 changes: 0 additions & 6 deletions src/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,6 @@ class Scheduler {

SystemMessage* new_process_message(SystemMessage::Type type, int gid);

#ifdef TOIT_FREERTOS
static const int64 WATCHDOG_PERIOD_US = 10 * 1000 * 1000; // 10 s.
#else
static const int64 WATCHDOG_PERIOD_US = 600 * 1000 * 1000; // 10 m.
#endif

static const int TICK_PERIOD_US = 100 * 1000; // 100 ms.
#ifdef TOIT_FREERTOS
static const int TICK_PERIOD_PROFILING_US = 10 * 100; // 10 ms.
Expand Down
8 changes: 4 additions & 4 deletions third_party/benchmarks/toit/benchmark.toit
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
// and then printing the results.
log_execution_time name/string --iterations/int=1 --allocations/bool=true [block] -> none:
assert: iterations > 0
reset_watchdog := platform == PLATFORM_FREERTOS
stats := List 5
process_stats stats
bytes_allocated := stats[4]

duration ::= Duration.of:
iterations.repeat:
block.call
if reset_watchdog: sleep --ms=1
iterations.repeat: block.call

process_stats stats
bytes_allocated = stats[4] - bytes_allocated

if iterations == 1:
print "$name: $(%.2f duration.in_us/1000.0) ms"
if allocations: print "$name: $(%.3f bytes_allocated/1000.0) kb"
Expand Down

0 comments on commit 1890135

Please sign in to comment.