Permalink
Browse files

During recording, only emit a SCHED event if the current thread actua…

…lly changed.
  • Loading branch information...
rocallahan committed Nov 29, 2015
1 parent 650123c commit 02f9d479871e9910e674a0235a7866503602ce7a
View
@@ -499,6 +499,7 @@ set(BASIC_TESTS
tcgets
tgkill
thread_stress
thread_yield
timer
timerfd
times
View
@@ -1200,12 +1200,6 @@ void RecordSession::runnable_state_changed(Task* t, RecordResult* step_result,
t->record_current_event();
t->pop_event(t->ev().type());
break;
case EV_SCHED:
t->record_current_event();
t->pop_event(t->ev().type());
last_task_switchable = ALLOW_SWITCH;
step_state->continue_type = DONT_CONTINUE;
break;
case EV_SENTINEL:
case EV_SIGNAL_HANDLER:
@@ -1275,6 +1269,11 @@ bool RecordSession::prepare_to_inject_signal(Task* t, StepState* step_state) {
return false;
case SIGNAL_HANDLED:
LOG(debug) << "Signal " << si.si_signo << " handled";
if (t->ev().type() == EV_SCHED) {
// Allow switching after a SCHED. We'll flush the SCHED if and only
// if we really do a switch.
last_task_switchable = ALLOW_SWITCH;
}
break;
}
step_state->continue_type = DONT_CONTINUE;
@@ -1392,6 +1391,14 @@ RecordSession::RecordResult RecordSession::record_step() {
// (e.g. terminate the recording).
return result;
}
if (last_recorded_task && last_recorded_task->ev().type() == EV_SCHED) {
if (last_recorded_task != t) {
// We did do a context switch, so record the SCHED event. Otherwise
// we'll just discard it.
last_recorded_task->record_current_event();
}
last_recorded_task->pop_event(EV_SCHED);
}
last_recorded_task = t;
// Have to disable context-switching until we know it's safe
@@ -10,11 +10,23 @@ static void handle_usr1(int sig) {
caught_usr1 = 1;
}
static void* do_thread(void* p) {
while (1) {
sched_yield();
}
return NULL;
}
int main(int argc, char** argv) {
struct timespec ts;
struct timeval tv;
int num_its;
int i;
pthread_t thread;
/* Create an extra thread so context switches can happen
and SCHED events will be recorded. */
pthread_create(&thread, NULL, do_thread, NULL);
test_assert(argc == 2);
num_its = atoi(argv[1]);
@@ -4,7 +4,7 @@ source `dirname $0`/util.sh
# of CPU binding.
GLOBAL_OPTIONS="$GLOBAL_OPTIONS_BIND_CPU"
# Ensure that the test records some USR_SCHED interrupt events.
# Ensure that the test records some SCHED interrupt events.
timeslice=100
RECORD_ARGS="-c$timeslice"
@@ -26,9 +26,22 @@
#define STATEMENT128(i) STATEMENT64(i) STATEMENT64(i + 64)
#define STATEMENT256(i) STATEMENT128(i) STATEMENT128(i + 128)
static void* do_thread(void* p) {
while (1) {
sched_yield();
}
return NULL;
}
int main(int argc, char** argv) {
int a = atoi(argv[1]);
int b = atoi(argv[2]);
pthread_t thread;
/* Create an extra thread so context switches can happen
and SCHED events will be recorded. */
pthread_create(&thread, NULL, do_thread, NULL);
/* This syscall signals the test that we're in the test body proper */
getgid();
STATEMENT256(0)
View
@@ -1,7 +1,5 @@
source `dirname $0`/util.sh
# Ensure that the test records some USR_SCHED interrupt events.
exe=simple$bitness
cp ${OBJDIR}/bin/$exe $exe-$nonce
PATH="${PATH}:." just_record $exe-$nonce
View
@@ -0,0 +1,34 @@
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */
#include "rrutil.h"
int spin(int iterations) {
int i, dummy = 0;
atomic_puts("spinning");
for (i = 1; i < iterations; ++i) {
dummy += i % (1 << 20);
dummy += i % (79 * (1 << 20));
}
return dummy;
}
static int ran_thread = 0;
static void* do_thread(void* p) {
ran_thread = 1;
return NULL;
}
int main(int argc, char* argv[]) {
pthread_t t;
pthread_create(&t, NULL, do_thread, NULL);
spin(1 << 28);
test_assert(ran_thread);
atomic_puts("EXIT-SUCCESS");
return 0;
}

0 comments on commit 02f9d47

Please sign in to comment.