cpu_sampler: avoid spinning on unavailable state

Fixes #3826
This commit is contained in:
Alexander Boettcher
2020-07-16 13:34:24 +02:00
committed by Norman Feske
parent ed15a46ca4
commit b7ffeb51aa
3 changed files with 36 additions and 88 deletions

View File

@ -77,24 +77,32 @@ void Cpu_sampler::Cpu_thread_component::take_sample()
return;
}
try {
enum { MAX_LOOP_CNT = 100 };
unsigned loop_cnt = 0;
for (; loop_cnt < MAX_LOOP_CNT; loop_cnt++) {
_parent_cpu_thread.pause();
Thread_state thread_state = _parent_cpu_thread.state();
try {
Thread_state thread_state = _parent_cpu_thread.state();
_sample_buf[_sample_buf_index++] = thread_state.ip;
} catch (State_access_failed) {
continue;
}
_parent_cpu_thread.resume();
_sample_buf[_sample_buf_index++] = thread_state.ip;
if (_sample_buf_index == SAMPLE_BUF_SIZE)
flush();
} catch (Cpu_thread::State_access_failed) {
Genode::log("thread state access failed");
break;
}
if (loop_cnt >= MAX_LOOP_CNT)
log("thread state access failed, ", _label.string());
}