Transform all aserts into unconditional checks

This commit is contained in:
Rodrigo Arias 2021-12-07 19:52:48 +01:00
parent 2046833700
commit 75c32f3a99
13 changed files with 285 additions and 176 deletions

65
chan.c
View File

@ -17,8 +17,6 @@
#include "chan.h" #include "chan.h"
#include <assert.h>
#include "emu.h" #include "emu.h"
#include "prv.h" #include "prv.h"
#include "utlist.h" #include "utlist.h"
@ -43,8 +41,11 @@ chan_init(struct ovni_chan *chan, enum chan_track track, int row, int type, FILE
static void static void
mark_dirty(struct ovni_chan *chan, enum chan_dirty dirty) mark_dirty(struct ovni_chan *chan, enum chan_dirty dirty)
{ {
assert(chan->dirty == CHAN_CLEAN); if(chan->dirty != CHAN_CLEAN)
assert(dirty != CHAN_CLEAN); die("mark_dirty: chan %d already dirty\n", chan->id);
if(dirty == CHAN_CLEAN)
die("mark_dirty: cannot use CHAN_CLEAN\n");
dbg("adding dirty chan %d to list\n", chan->id); dbg("adding dirty chan %d to list\n", chan->id);
chan->dirty = dirty; chan->dirty = dirty;
@ -170,14 +171,12 @@ chan_set(struct ovni_chan *chan, int st)
dbg("chan_set chan %d st=%d\n", chan->id, st); dbg("chan_set chan %d st=%d\n", chan->id, st);
assert(chan->enabled); if(!chan->enabled)
die("chan_set: chan %d not enabled\n", chan->id);
/* Only chan_set can set the 0 state */ /* Only chan_set can set the 0 state */
if(st < 0) if(st < 0)
{ die("chan_set: cannot set a negative state %d\n", st);
err("chan_set: cannot set a negative state %d\n", st);
abort();
}
/* Don't enforce this check if we are dirty because the channel was /* Don't enforce this check if we are dirty because the channel was
* just enabled; it may collide with a new state 0 set via chan_set() * just enabled; it may collide with a new state 0 set via chan_set()
@ -222,7 +221,8 @@ chan_push(struct ovni_chan *chan, int st)
{ {
dbg("chan_push chan %d st=%d\n", chan->id, st); dbg("chan_push chan %d st=%d\n", chan->id, st);
assert(chan->enabled); if(!chan->enabled)
die("chan_push: chan %d not enabled\n", chan->id);
if(st <= 0) if(st <= 0)
{ {
@ -231,7 +231,8 @@ chan_push(struct ovni_chan *chan, int st)
} }
/* Cannot be dirty */ /* Cannot be dirty */
assert(chan->dirty == 0); if(chan->dirty != CHAN_CLEAN)
die("chan_push: chan %d not clean", chan->id);
if(chan->lastst >= 0 && chan->lastst == st) if(chan->lastst >= 0 && chan->lastst == st)
{ {
@ -259,10 +260,12 @@ chan_pop(struct ovni_chan *chan, int expected_st)
dbg("chan_pop chan %d expected_st=%d\n", chan->id, expected_st); dbg("chan_pop chan %d expected_st=%d\n", chan->id, expected_st);
assert(chan->enabled); if(!chan->enabled)
die("chan_pop: chan %d not enabled\n", chan->id);
/* Cannot be dirty */ /* Cannot be dirty */
assert(chan->dirty == 0); if(chan->dirty != CHAN_CLEAN)
die("chan_pop: chan %d not clean", chan->id);
if(chan->n <= 0) if(chan->n <= 0)
{ {
@ -310,23 +313,19 @@ chan_ev(struct ovni_chan *chan, int ev)
{ {
dbg("chan_ev chan %d ev=%d\n", chan->id, ev); dbg("chan_ev chan %d ev=%d\n", chan->id, ev);
assert(chan->enabled); if(!chan->enabled)
die("chan_ev: chan %d not enabled\n", chan->id);
/* Cannot be dirty */ /* Cannot be dirty */
assert(chan->dirty == 0); if(chan->dirty != CHAN_CLEAN)
die("chan_ev: chan %d is dirty\n", chan->id);
if(ev <= 0) if(ev <= 0)
{ die("chan_ev: cannot emit non-positive state %d\n", ev);
err("chan_ev: cannot emit non-positive state %d\n", ev);
abort();
}
if(chan->lastst >= 0 && chan->lastst == ev) if(chan->lastst >= 0 && chan->lastst == ev)
{ die("chan_ev id=%d cannot emit the state %d twice\n",
err("chan_ev id=%d cannot emit the state %d twice\n",
chan->id, ev); chan->id, ev);
abort();
}
chan->ev = ev; chan->ev = ev;
chan->t = *chan->clock; chan->t = *chan->clock;
@ -343,14 +342,17 @@ chan_get_st(struct ovni_chan *chan)
if(chan->n == 0) if(chan->n == 0)
return 0; return 0;
assert(chan->n > 0); if(chan->n < 0)
die("chan_get_st: chan %d has negative n\n", chan->id);
return chan->stack[chan->n-1]; return chan->stack[chan->n-1];
} }
static void static void
emit(struct ovni_chan *chan, int64_t t, int state) emit(struct ovni_chan *chan, int64_t t, int state)
{ {
assert(chan->dirty != CHAN_CLEAN); if(chan->dirty == CHAN_CLEAN)
die("emit: chan %d is not dirty\n", chan->id);
/* A channel can only emit the same state as lastst if is dirty because /* A channel can only emit the same state as lastst if is dirty because
* it has been enabled or disabled. Otherwise is a bug (ie. you have two * it has been enabled or disabled. Otherwise is a bug (ie. you have two
@ -360,9 +362,8 @@ emit(struct ovni_chan *chan, int64_t t, int state)
&& chan->lastst == state) && chan->lastst == state)
{ {
/* TODO: Print the raw clock of the offending event */ /* TODO: Print the raw clock of the offending event */
err("chan: id=%d cannot emit the same state %d twice\n", die("emit: chan %d cannot emit the same state %d twice\n",
chan->id, state); chan->id, state);
abort();
} }
if(chan->lastst != state) if(chan->lastst != state)
@ -378,8 +379,11 @@ emit_ev(struct ovni_chan *chan)
{ {
int new, last; int new, last;
assert(chan->enabled); if(!chan->enabled)
assert(chan->ev != -1); die("emit_ev: chan %d is not enabled\n", chan->id);
if(chan->ev == -1)
die("emit_ev: chan %d cannot emit -1 ev\n", chan->id);
new = chan->ev; new = chan->ev;
last = chan_get_st(chan); last = chan_get_st(chan);
@ -413,7 +417,8 @@ chan_emit(struct ovni_chan *chan)
if(chan->enabled == 0) if(chan->enabled == 0)
{ {
/* No punctual events allowed when disabled */ /* No punctual events allowed when disabled */
assert(chan->ev == -1); if(chan->ev != -1)
die("chan_emit: no punctual event allowed when disabled\n");
emit_st(chan); emit_st(chan);
goto shower; goto shower;

123
emu.c
View File

@ -26,7 +26,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <stdatomic.h> #include <stdatomic.h>
#include <dirent.h> #include <dirent.h>
#include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
@ -85,8 +84,6 @@ cpu_update_tracking_chan(struct ovni_chan *cpu_chan, struct ovni_ethread *th)
int th_enabled, cpu_enabled, st; int th_enabled, cpu_enabled, st;
struct ovni_chan *th_chan; struct ovni_chan *th_chan;
assert(th);
switch (cpu_chan->track) switch (cpu_chan->track)
{ {
case CHAN_TRACK_TH_RUNNING: case CHAN_TRACK_TH_RUNNING:
@ -179,7 +176,8 @@ emu_cpu_update_chan(struct ovni_cpu *cpu, struct ovni_chan *cpu_chan)
} }
else if(count == 1) else if(count == 1)
{ {
assert(th); if(th == NULL)
die("emu_cpu_update_chan: tracking thread is NULL\n");
/* A unique thread found: copy the state */ /* A unique thread found: copy the state */
dbg("cpu_update_chan: unique thread %d found, updating chan %d\n", dbg("cpu_update_chan: unique thread %d found, updating chan %d\n",
@ -210,7 +208,8 @@ propagate_channels(struct ovni_emu *emu)
DL_FOREACH_SAFE(emu->th_chan, th_chan, tmp) DL_FOREACH_SAFE(emu->th_chan, th_chan, tmp)
{ {
assert(th_chan->thread); if(th_chan->thread == NULL)
die("propagate_channels: channel thread is NULL\n");
thread = th_chan->thread; thread = th_chan->thread;
@ -241,14 +240,12 @@ emit_channels(struct ovni_emu *emu)
DL_FOREACH(emu->th_chan, th_chan) DL_FOREACH(emu->th_chan, th_chan)
{ {
dbg("emu emits th chan %d\n", th_chan->id); dbg("emu emits th chan %d\n", th_chan->id);
//assert(th_chan->dirty);
chan_emit(th_chan); chan_emit(th_chan);
} }
DL_FOREACH(emu->cpu_chan, cpu_chan) DL_FOREACH(emu->cpu_chan, cpu_chan)
{ {
dbg("emu emits cpu chan %d\n", cpu_chan->id); dbg("emu emits cpu chan %d\n", cpu_chan->id);
//assert(cpu_chan->dirty);
chan_emit(cpu_chan); chan_emit(cpu_chan);
} }
@ -406,7 +403,8 @@ next_event(struct ovni_emu *emu)
stream = heap_elem(node, struct ovni_stream, hh); stream = heap_elem(node, struct ovni_stream, hh);
assert(stream); if(stream == NULL)
die("next_event: heap_elem returned NULL\n");
set_current(emu, stream); set_current(emu, stream);
@ -433,7 +431,7 @@ next_event(struct ovni_emu *emu)
emu->lastclock, stream->lastclock, stream->tid); emu->lastclock, stream->lastclock, stream->tid);
if(emu->enable_linter) if(emu->enable_linter)
exit(EXIT_FAILURE); abort();
} }
emu->lastclock = stream->lastclock; emu->lastclock = stream->lastclock;
@ -470,11 +468,13 @@ emu_load_first_events(struct ovni_emu *emu)
if(emu_step_stream(emu, stream) < 0) if(emu_step_stream(emu, stream) < 0)
{ {
dbg("warning: empty stream for tid %d\n", stream->tid); err("warning: empty stream for tid %d\n", stream->tid);
if(emu->enable_linter)
abort();
continue; continue;
} }
assert(stream->active);
} }
} }
@ -545,13 +545,12 @@ add_new_cpu(struct ovni_emu *emu, struct ovni_loom *loom, int i, int phyid)
cpu = &loom->cpu[i]; cpu = &loom->cpu[i];
if(i < 0 || i >= (int) loom->ncpus) if(i < 0 || i >= (int) loom->ncpus)
{ die("CPU with index %d in loom %s is out of bounds\n",
err("CPU with index %d in loom %s is out of bounds\n", i, i, loom->hostname);
loom->hostname);
abort();
}
assert(cpu->state == CPU_ST_UNKNOWN); if(cpu->state != CPU_ST_UNKNOWN)
die("new cpu %d in unexpected state in loom %s\n",
i, loom->hostname);
cpu->state = CPU_ST_READY; cpu->state = CPU_ST_READY;
cpu->i = i; cpu->i = i;
@ -562,56 +561,49 @@ add_new_cpu(struct ovni_emu *emu, struct ovni_loom *loom, int i, int phyid)
dbg("new cpu %d at phyid=%d\n", cpu->gindex, phyid); dbg("new cpu %d at phyid=%d\n", cpu->gindex, phyid);
} }
static void static int
proc_load_cpus(struct ovni_emu *emu, struct ovni_loom *loom, struct ovni_eproc *proc) proc_load_cpus(struct ovni_emu *emu, struct ovni_loom *loom,
struct ovni_eproc *proc,
struct ovni_eproc *metadata_proc)
{ {
JSON_Array *cpuarray; JSON_Object *meta = json_value_get_object(proc->meta);
JSON_Object *cpu; if(meta == NULL)
JSON_Object *meta; die("json_value_get_object() failed\n");
size_t i, index, phyid;
struct ovni_cpu *vcpu;
meta = json_value_get_object(proc->meta); JSON_Array *cpuarray = json_object_get_array(meta, "cpus");
assert(meta);
cpuarray = json_object_get_array(meta, "cpus");
/* This process doesn't have the cpu list */ /* This process doesn't have the cpu list */
if(cpuarray == NULL) if(cpuarray == NULL)
return; return -1;
assert(loom->ncpus == 0); if(metadata_proc)
die("duplicated metadata for proc %d and %d in loom %s\n",
metadata_proc->pid, proc->pid,
loom->hostname);
if(loom->ncpus != 0)
die("loom %s already has CPUs\n", loom->hostname);
loom->ncpus = json_array_get_count(cpuarray); loom->ncpus = json_array_get_count(cpuarray);
if(loom->ncpus <= 0) if(loom->ncpus == 0)
{ die("loom %s proc %d has metadata but no CPUs\n",
err("loom %s proc %d has read %ld cpus, but required > 0\n", loom->hostname, proc->pid);
loom->hostname, proc->pid, loom->ncpus);
abort();
}
loom->cpu = calloc(loom->ncpus, sizeof(struct ovni_cpu)); loom->cpu = calloc(loom->ncpus, sizeof(struct ovni_cpu));
if(loom->cpu == NULL) if(loom->cpu == NULL)
{ die("calloc failed: %s\n", strerror(errno));
perror("calloc failed");
abort();
}
for(i = 0; i < loom->ncpus; i++) for(size_t i = 0; i < loom->ncpus; i++)
{ {
cpu = json_array_get_object(cpuarray, i); JSON_Object *cpu = json_array_get_object(cpuarray, i);
if(cpu == NULL) if(cpu == NULL)
{ die("proc_load_cpus: json_array_get_object() failed\n");
err("json_array_get_object returned NULL\n");
abort();
}
index = (int) json_object_get_number(cpu, "index"); size_t index = (int) json_object_get_number(cpu, "index");
phyid = (int) json_object_get_number(cpu, "phyid"); size_t phyid = (int) json_object_get_number(cpu, "phyid");
add_new_cpu(emu, loom, index, phyid); add_new_cpu(emu, loom, index, phyid);
} }
@ -619,8 +611,10 @@ proc_load_cpus(struct ovni_emu *emu, struct ovni_loom *loom, struct ovni_eproc *
/* If we reach this point, all CPUs are in the ready state */ /* If we reach this point, all CPUs are in the ready state */
/* Init the vcpu as well */ /* Init the vcpu as well */
vcpu = &loom->vcpu; struct ovni_cpu *vcpu = &loom->vcpu;
assert(vcpu->state == CPU_ST_UNKNOWN); if(vcpu->state != CPU_ST_UNKNOWN)
die("unexpected virtual CPU state in loom %s\n",
loom->hostname);
vcpu->state = CPU_ST_READY; vcpu->state = CPU_ST_READY;
vcpu->i = -1; vcpu->i = -1;
@ -629,6 +623,8 @@ proc_load_cpus(struct ovni_emu *emu, struct ovni_loom *loom, struct ovni_eproc *
vcpu->loom = loom; vcpu->loom = loom;
dbg("new vcpu %d\n", vcpu->gindex); dbg("new vcpu %d\n", vcpu->gindex);
return 0;
} }
/* Obtain CPUs in the metadata files and other data */ /* Obtain CPUs in the metadata files and other data */
@ -647,16 +643,29 @@ load_metadata(struct ovni_emu *emu)
loom = &trace->loom[i]; loom = &trace->loom[i];
loom->offset_ncpus = emu->total_ncpus; loom->offset_ncpus = emu->total_ncpus;
struct ovni_eproc *metadata_proc = NULL;
for(j=0; j<loom->nprocs; j++) for(j=0; j<loom->nprocs; j++)
{ {
proc = &loom->proc[j]; proc = &loom->proc[j];
proc_load_cpus(emu, loom, proc); if(proc_load_cpus(emu, loom, proc, metadata_proc) < 0)
continue;
if(metadata_proc)
die("duplicated metadata found in pid %d and %d\n",
metadata_proc->pid,
proc->pid);
metadata_proc = proc;
} }
/* One of the process must have the list of CPUs */ /* One of the process must have the list of CPUs */
/* FIXME: The CPU list should be at the loom dir */ if(metadata_proc == NULL)
assert(loom->ncpus > 0); die("no metadata found in loom %s\n", loom->hostname);
if(loom->ncpus == 0)
die("no CPUs found in loom %s\n", loom->hostname);
} }
} }
@ -677,7 +686,9 @@ destroy_metadata(struct ovni_emu *emu)
{ {
proc = &loom->proc[j]; proc = &loom->proc[j];
assert(proc->meta); if(proc->meta == NULL)
die("cannot destroy metadata: is NULL\n");
json_value_free(proc->meta); json_value_free(proc->meta);
} }

View File

@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <assert.h>
#include "uthash.h" #include "uthash.h"
#include "ovni.h" #include "ovni.h"
@ -91,7 +90,9 @@ context_switch(struct ovni_emu *emu)
void void
hook_pre_kernel(struct ovni_emu *emu) hook_pre_kernel(struct ovni_emu *emu)
{ {
assert(emu->cur_ev->header.model == 'K'); if(emu->cur_ev->header.model != 'K')
die("hook_pre_kernel: unexpected event with model %c\n",
emu->cur_ev->header.model);
switch(emu->cur_ev->header.category) switch(emu->cur_ev->header.category)
{ {

View File

@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <assert.h>
#include "uthash.h" #include "uthash.h"
#include "ovni.h" #include "ovni.h"
@ -89,9 +88,13 @@ pre_subsystem(struct ovni_emu *emu, int st)
void void
hook_pre_nanos6(struct ovni_emu *emu) hook_pre_nanos6(struct ovni_emu *emu)
{ {
// Ensure that the thread is running if(emu->cur_ev->header.model != 'L')
assert(emu->cur_thread->is_running != 0); die("hook_pre_nanos6: unexpected event with model %c\n",
assert(emu->cur_ev->header.model == 'L'); emu->cur_ev->header.model);
if(!emu->cur_thread->is_running)
die("hook_pre_nanos6: current thread %d not running\n",
emu->cur_thread->tid);
switch(emu->cur_ev->header.category) switch(emu->cur_ev->header.category)
{ {

View File

@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <assert.h>
#include "uthash.h" #include "uthash.h"
#include "ovni.h" #include "ovni.h"
@ -119,9 +118,14 @@ pre_task_execute(struct ovni_emu *emu)
HASH_FIND_INT(emu->cur_proc->tasks, &taskid, task); HASH_FIND_INT(emu->cur_proc->tasks, &taskid, task);
assert(task != NULL); if(task == NULL)
assert(emu->cur_thread->state == TH_ST_RUNNING); die("cannot find task with id %d\n", taskid);
assert(emu->cur_thread->task == NULL);
if(emu->cur_thread->state != TH_ST_RUNNING)
die("thread state is not running\n");
if(emu->cur_thread->task != NULL)
die("thread already has a task\n");
task->state = TASK_ST_RUNNING; task->state = TASK_ST_RUNNING;
task->thread = emu->cur_thread; task->thread = emu->cur_thread;
@ -142,11 +146,20 @@ pre_task_pause(struct ovni_emu *emu)
HASH_FIND_INT(emu->cur_proc->tasks, &taskid, task); HASH_FIND_INT(emu->cur_proc->tasks, &taskid, task);
assert(task != NULL); if(task == NULL)
assert(task->state == TASK_ST_RUNNING); die("cannot find task with id %d\n", taskid);
assert(emu->cur_thread->state == TH_ST_RUNNING);
assert(emu->cur_thread->task == task); if(task->state != TASK_ST_RUNNING)
assert(emu->cur_thread == task->thread); die("task state is not running\n");
if(emu->cur_thread->state != TH_ST_RUNNING)
die("thread state is not running\n");
if(emu->cur_thread->task != task)
die("thread has assigned a different task\n");
if(emu->cur_thread != task->thread)
die("task is assigned to a different thread\n");
task->state = TASK_ST_PAUSED; task->state = TASK_ST_PAUSED;
@ -165,11 +178,20 @@ pre_task_resume(struct ovni_emu *emu)
HASH_FIND_INT(emu->cur_proc->tasks, &taskid, task); HASH_FIND_INT(emu->cur_proc->tasks, &taskid, task);
assert(task != NULL); if(task == NULL)
assert(task->state == TASK_ST_PAUSED); die("cannot find task with id %d\n", taskid);
assert(emu->cur_thread->state == TH_ST_RUNNING);
assert(emu->cur_thread->task == task); if(task->state != TASK_ST_PAUSED)
assert(emu->cur_thread == task->thread); die("task state is not paused\n");
if(emu->cur_thread->state != TH_ST_RUNNING)
die("thread is not running\n");
if(emu->cur_thread->task != task)
die("thread has assigned a different task\n");
if(emu->cur_thread != task->thread)
die("task is assigned to a different thread\n");
task->state = TASK_ST_RUNNING; task->state = TASK_ST_RUNNING;
@ -189,11 +211,20 @@ pre_task_end(struct ovni_emu *emu)
HASH_FIND_INT(emu->cur_proc->tasks, &taskid, task); HASH_FIND_INT(emu->cur_proc->tasks, &taskid, task);
assert(task != NULL); if(task == NULL)
assert(task->state == TASK_ST_RUNNING); die("cannot find task with id %d\n", taskid);
assert(emu->cur_thread->state == TH_ST_RUNNING);
assert(emu->cur_thread->task == task); if(task->state != TASK_ST_RUNNING)
assert(emu->cur_thread == task->thread); die("task state is not running\n");
if(emu->cur_thread->state != TH_ST_RUNNING)
die("thread is not running\n");
if(emu->cur_thread->task != task)
die("thread has assigned a different task\n");
if(emu->cur_thread != task->thread)
die("task is assigned to a different thread\n");
task->state = TASK_ST_DEAD; task->state = TASK_ST_DEAD;
task->thread = NULL; task->thread = NULL;
@ -213,9 +244,14 @@ pre_task_running(struct ovni_emu *emu, struct nosv_task *task)
th = emu->cur_thread; th = emu->cur_thread;
proc = emu->cur_proc; proc = emu->cur_proc;
assert(task->id > 0); if(task->id <= 0)
assert(task->type_id > 0); die("task id must be positive\n");
assert(proc->appid > 0);
if(task->type_id <= 0)
die("task type id must be positive\n");
if(proc->appid <= 0)
die("app id must be positive\n");
chan_set(&th->chan[CHAN_NOSV_TASKID], task->id); chan_set(&th->chan[CHAN_NOSV_TASKID], task->id);
chan_set(&th->chan[CHAN_NOSV_TYPEID], task->type_id); chan_set(&th->chan[CHAN_NOSV_TYPEID], task->type_id);
@ -440,7 +476,6 @@ pre_ss(struct ovni_emu *emu, int st)
th = emu->cur_thread; th = emu->cur_thread;
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM]; chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
assert(chan_th->id == CHAN_NOSV_SUBSYSTEM);
dbg("pre_ss chan id %d st=%d\n", chan_th->id, st); dbg("pre_ss chan id %d st=%d\n", chan_th->id, st);
switch(emu->cur_ev->header.value) switch(emu->cur_ev->header.value)
@ -481,10 +516,13 @@ check_affinity(struct ovni_emu *emu)
void void
hook_pre_nosv(struct ovni_emu *emu) hook_pre_nosv(struct ovni_emu *emu)
{ {
assert(emu->cur_ev->header.model == 'V'); if(emu->cur_ev->header.model != 'V')
die("hook_pre_nosv: unexpected event with model %c\n",
emu->cur_ev->header.model);
/* Ensure the thread is active */ if(!emu->cur_thread->is_active)
assert(emu->cur_thread->is_active); die("hook_pre_nosv: current thread %d not active\n",
emu->cur_thread->tid);
switch(emu->cur_ev->header.category) switch(emu->cur_ev->header.category)
{ {

View File

@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <assert.h>
#include "uthash.h" #include "uthash.h"
#include "ovni.h" #include "ovni.h"
@ -90,8 +89,13 @@ pre_mode(struct ovni_emu *emu, int st)
void void
hook_pre_openmp(struct ovni_emu *emu) hook_pre_openmp(struct ovni_emu *emu)
{ {
assert(emu->cur_ev->header.model == 'M'); if(emu->cur_ev->header.model != 'M')
assert(emu->cur_thread->is_active); die("hook_pre_openmp: unexpected event with model %c\n",
emu->cur_ev->header.model);
if(!emu->cur_thread->is_active)
die("hook_pre_openmp: current thread %d not active\n",
emu->cur_thread->tid);
switch(emu->cur_ev->header.category) switch(emu->cur_ev->header.category)
{ {

View File

@ -21,8 +21,6 @@
#include "chan.h" #include "chan.h"
#include "utlist.h" #include "utlist.h"
#include <assert.h>
/* The emulator ovni module provides the execution model by tracking the thread /* The emulator ovni module provides the execution model by tracking the thread
* state and which threads run in each CPU */ * state and which threads run in each CPU */
@ -79,7 +77,8 @@ chan_tracking_update(struct ovni_chan *chan, struct ovni_ethread *th)
{ {
int enabled; int enabled;
assert(th); if(th == NULL)
die("chan_tracking_update: thread is NULL");
switch (chan->track) switch (chan->track)
{ {
@ -112,7 +111,9 @@ thread_set_state(struct ovni_ethread *th, enum ethread_state state)
int i; int i;
/* The state must be updated when a cpu is set */ /* The state must be updated when a cpu is set */
assert(th->cpu); if(th->cpu == NULL)
die("thread_set_state: thread %d doesn't have a CPU\n",
th->tid);
dbg("thread_set_state: setting thread %d state %d\n", dbg("thread_set_state: setting thread %d state %d\n",
th->tid, state); th->tid, state);
@ -187,12 +188,11 @@ update_cpu(struct ovni_cpu *cpu)
struct ovni_cpu * struct ovni_cpu *
emu_get_cpu(struct ovni_loom *loom, int cpuid) emu_get_cpu(struct ovni_loom *loom, int cpuid)
{ {
assert(cpuid < (int) loom->ncpus); if(cpuid >= (int) loom->ncpus)
die("emu_get_cpu: CPU index out of bounds\n");
if(cpuid < 0) if(cpuid < 0)
{
return &loom->vcpu; return &loom->vcpu;
}
return &loom->cpu[cpuid]; return &loom->cpu[cpuid];
} }
@ -265,7 +265,10 @@ cpu_migrate_thread(struct ovni_cpu *cpu,
static void static void
thread_set_cpu(struct ovni_ethread *th, struct ovni_cpu *cpu) thread_set_cpu(struct ovni_ethread *th, struct ovni_cpu *cpu)
{ {
assert(th->cpu == NULL); if(th->cpu != NULL)
die("thread_set_cpu: thread %d already has a CPU\n",
th->tid);
dbg("thread_set_cpu: setting thread %d cpu to %s\n", dbg("thread_set_cpu: setting thread %d cpu to %s\n",
th->tid, cpu->name); th->tid, cpu->name);
th->cpu = cpu; th->cpu = cpu;
@ -279,7 +282,10 @@ thread_set_cpu(struct ovni_ethread *th, struct ovni_cpu *cpu)
static void static void
thread_unset_cpu(struct ovni_ethread *th) thread_unset_cpu(struct ovni_ethread *th)
{ {
assert(th->cpu != NULL); if(th->cpu == NULL)
die("thread_unset_cpu: thread %d doesn't have a CPU\n",
th->tid);
th->cpu = NULL; th->cpu = NULL;
chan_enable(&th->chan[CHAN_OVNI_CPU], 0); chan_enable(&th->chan[CHAN_OVNI_CPU], 0);
@ -290,10 +296,11 @@ thread_unset_cpu(struct ovni_ethread *th)
static void static void
thread_migrate_cpu(struct ovni_ethread *th, struct ovni_cpu *cpu) thread_migrate_cpu(struct ovni_ethread *th, struct ovni_cpu *cpu)
{ {
assert(th->cpu != NULL); if(th->cpu == NULL)
die("thread_migrate_cpu: thread %d doesn't have a CPU\n",
th->tid);
th->cpu = cpu; th->cpu = cpu;
assert(chan_is_enabled(&th->chan[CHAN_OVNI_CPU]));
chan_set(&th->chan[CHAN_OVNI_CPU], cpu->gindex + 1); chan_set(&th->chan[CHAN_OVNI_CPU], cpu->gindex + 1);
} }
@ -304,7 +311,9 @@ pre_thread_execute(struct ovni_emu *emu, struct ovni_ethread *th)
int cpuid; int cpuid;
/* The thread cannot be already running */ /* The thread cannot be already running */
assert(th->state != TH_ST_RUNNING); if(th->state == TH_ST_RUNNING)
die("pre_thread_execute: thread %d already running\n",
th->tid);
cpuid = emu->cur_ev->payload.i32[0]; cpuid = emu->cur_ev->payload.i32[0];
@ -325,8 +334,13 @@ pre_thread_execute(struct ovni_emu *emu, struct ovni_ethread *th)
static void static void
pre_thread_end(struct ovni_ethread *th) pre_thread_end(struct ovni_ethread *th)
{ {
assert(th->state == TH_ST_RUNNING); if(th->state != TH_ST_RUNNING)
assert(th->cpu); die("pre_thread_end: thread %d not running\n",
th->tid);
if(th->cpu == NULL)
die("pre_thread_end: thread %d doesn't have a CPU\n",
th->tid);
/* First update the thread state */ /* First update the thread state */
thread_set_state(th, TH_ST_DEAD); thread_set_state(th, TH_ST_DEAD);
@ -340,8 +354,13 @@ pre_thread_end(struct ovni_ethread *th)
static void static void
pre_thread_pause(struct ovni_ethread *th) pre_thread_pause(struct ovni_ethread *th)
{ {
assert(th->state == TH_ST_RUNNING || th->state == TH_ST_COOLING); if(th->state != TH_ST_RUNNING && th->state != TH_ST_COOLING)
assert(th->cpu); die("pre_thread_pause: thread %d not running or cooling\n",
th->tid);
if(th->cpu == NULL)
die("pre_thread_pause: thread %d doesn't have a CPU\n",
th->tid);
thread_set_state(th, TH_ST_PAUSED); thread_set_state(th, TH_ST_PAUSED);
update_cpu(th->cpu); update_cpu(th->cpu);
@ -350,8 +369,13 @@ pre_thread_pause(struct ovni_ethread *th)
static void static void
pre_thread_resume(struct ovni_ethread *th) pre_thread_resume(struct ovni_ethread *th)
{ {
assert(th->state == TH_ST_PAUSED || th->state == TH_ST_WARMING); if(th->state != TH_ST_PAUSED && th->state != TH_ST_WARMING)
assert(th->cpu); die("pre_thread_resume: thread %d not paused or warming\n",
th->tid);
if(th->cpu == NULL)
die("pre_thread_resume: thread %d doesn't have a CPU\n",
th->tid);
thread_set_state(th, TH_ST_RUNNING); thread_set_state(th, TH_ST_RUNNING);
update_cpu(th->cpu); update_cpu(th->cpu);
@ -360,8 +384,13 @@ pre_thread_resume(struct ovni_ethread *th)
static void static void
pre_thread_cool(struct ovni_ethread *th) pre_thread_cool(struct ovni_ethread *th)
{ {
assert(th->state == TH_ST_RUNNING); if(th->state != TH_ST_RUNNING)
assert(th->cpu); die("pre_thread_cool: thread %d not running\n",
th->tid);
if(th->cpu == NULL)
die("pre_thread_cool: thread %d doesn't have a CPU\n",
th->tid);
thread_set_state(th, TH_ST_COOLING); thread_set_state(th, TH_ST_COOLING);
update_cpu(th->cpu); update_cpu(th->cpu);
@ -370,8 +399,13 @@ pre_thread_cool(struct ovni_ethread *th)
static void static void
pre_thread_warm(struct ovni_ethread *th) pre_thread_warm(struct ovni_ethread *th)
{ {
assert(th->state == TH_ST_PAUSED); if(th->state != TH_ST_PAUSED)
assert(th->cpu); die("pre_thread_warm: thread %d not paused\n",
th->tid);
if(th->cpu == NULL)
die("pre_thread_warm: thread %d doesn't have a CPU\n",
th->tid);
thread_set_state(th, TH_ST_WARMING); thread_set_state(th, TH_ST_WARMING);
update_cpu(th->cpu); update_cpu(th->cpu);
@ -421,10 +455,13 @@ pre_affinity_set(struct ovni_emu *emu)
th = emu->cur_thread; th = emu->cur_thread;
cpuid = emu->cur_ev->payload.i32[0]; cpuid = emu->cur_ev->payload.i32[0];
assert(th->cpu); if(th->cpu == NULL)
assert(th->state == TH_ST_RUNNING die("pre_affinity_set: thread %d doesn't have a CPU\n",
|| th->state == TH_ST_COOLING th->tid);
|| th->state == TH_ST_WARMING);
if(!th->is_active)
die("pre_affinity_set: thread %d is not active\n",
th->tid);
/* Migrate current cpu to the one at cpuid */ /* Migrate current cpu to the one at cpuid */
newcpu = emu_get_cpu(emu->cur_loom, cpuid); newcpu = emu_get_cpu(emu->cur_loom, cpuid);
@ -483,11 +520,18 @@ pre_affinity_remote(struct ovni_emu *emu)
} }
/* The remote_th cannot be in states dead or unknown */ /* The remote_th cannot be in states dead or unknown */
assert(remote_th->state != TH_ST_DEAD if(remote_th->state == TH_ST_DEAD)
&& remote_th->state != TH_ST_UNKNOWN); die("pre_affinity_remote: remote thread %d in state DEAD\n",
remote_th->tid);
if(remote_th->state == TH_ST_UNKNOWN)
die("pre_affinity_remote: remote thread %d in state UNKNOWN\n",
remote_th->tid);
/* It must have an assigned CPU */ /* It must have an assigned CPU */
assert(remote_th->cpu); if(remote_th->cpu == NULL)
die("pre_affinity_remote: remote thread %d has no CPU\n",
remote_th->tid);
/* Migrate current cpu to the one at cpuid */ /* Migrate current cpu to the one at cpuid */
newcpu = emu_get_cpu(emu->cur_loom, cpuid); newcpu = emu_get_cpu(emu->cur_loom, cpuid);

View File

@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <assert.h>
#include "uthash.h" #include "uthash.h"
#include "ovni.h" #include "ovni.h"
@ -86,7 +85,9 @@ pre_tampi_mode(struct ovni_emu *emu, int state)
void void
hook_pre_tampi(struct ovni_emu *emu) hook_pre_tampi(struct ovni_emu *emu)
{ {
assert(emu->cur_ev->header.model == 'T'); if(emu->cur_ev->header.model != 'T')
die("hook_pre_tampi: unexpected event with model %c\n",
emu->cur_ev->header.model);
switch(emu->cur_ev->header.category) switch(emu->cur_ev->header.category)
{ {

1
ovni.c
View File

@ -43,7 +43,6 @@
# define gettid() ((pid_t)syscall(SYS_gettid)) # define gettid() ((pid_t)syscall(SYS_gettid))
#endif #endif
/* Prevent usage of assert() */
#pragma GCC poison assert #pragma GCC poison assert
/* Data per process */ /* Data per process */

View File

@ -24,7 +24,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h>
#include <time.h> #include <time.h>
#include "ovni.h" #include "ovni.h"

17
prv.c
View File

@ -16,7 +16,6 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include "ovni.h" #include "ovni.h"
#include "emu.h" #include "emu.h"
@ -56,18 +55,20 @@ prv_ev_cpu(struct ovni_emu *emu, int row, int type, int val)
void void
prv_ev_autocpu_raw(struct ovni_emu *emu, int64_t time, int type, int val) prv_ev_autocpu_raw(struct ovni_emu *emu, int64_t time, int type, int val)
{ {
int row; if(emu->cur_thread == NULL)
struct ovni_cpu *cpu; die("prv_ev_autocpu_raw: current thread is NULL\n");
assert(emu->cur_thread); struct ovni_cpu *cpu = emu->cur_thread->cpu;
cpu = emu->cur_thread->cpu; if(cpu == NULL)
die("prv_ev_autocpu_raw: current thread CPU is NULL\n");
assert(cpu); /* FIXME: Use the global index of the CPUs */
assert(cpu->i >= 0); if(cpu->i < 0)
die("prv_ev_autocpu_raw: CPU index is negative\n");
/* Begin at 1 */ /* Begin at 1 */
row = emu->cur_loom->offset_ncpus + cpu->i + 1; int row = emu->cur_loom->offset_ncpus + cpu->i + 1;
prv_ev_cpu_raw(emu, row, time, type, val); prv_ev_cpu_raw(emu, row, time, type, val);
} }

20
sort.c
View File

@ -162,16 +162,19 @@ sort_buf(uint8_t *src, uint8_t *buf, int64_t bufsize,
if((uint8_t *) ev == srcnext) if((uint8_t *) ev == srcnext)
break; break;
assert((uint8_t *) ev < srcnext); if((uint8_t *) ev > srcnext)
die("exceeded srcnext while sorting\n");
if(bufsize < evsize)
die("no space left in the sort buffer\n");
assert(bufsize >= evsize);
memcpy(buf, ev, evsize); memcpy(buf, ev, evsize);
buf += evsize; buf += evsize;
bufsize -= evsize; bufsize -= evsize;
injected++; injected++;
} }
err("injected %ld events in the past\n", injected); dbg("injected %ld events in the past\n", injected);
} }
static int static int
@ -193,14 +196,12 @@ execute_sort_plan(struct sortplan *sp)
/* Allocate a working buffer */ /* Allocate a working buffer */
bufsize = ((int64_t) sp->next) - ((int64_t) sp->first); bufsize = ((int64_t) sp->next) - ((int64_t) sp->first);
assert(bufsize > 0); if(bufsize <= 0)
die("bufsize is non-positive\n");
buf = malloc(bufsize); buf = malloc(bufsize);
if(!buf) if(!buf)
{ die("malloc failed: %s\n", strerror(errno));
perror("malloc failed");
abort();
}
sort_buf((uint8_t *) sp->first, buf, bufsize, sort_buf((uint8_t *) sp->first, buf, bufsize,
(uint8_t *) sp->bad0, (uint8_t *) sp->next); (uint8_t *) sp->bad0, (uint8_t *) sp->next);
@ -308,7 +309,8 @@ process_trace(struct ovni_trace *trace)
ring.size = max_look_back; ring.size = max_look_back;
ring.ev = malloc(ring.size * sizeof(struct ovni_ev *)); ring.ev = malloc(ring.size * sizeof(struct ovni_ev *));
assert(ring.ev); if(ring.ev == NULL)
die("malloc failed: %s\n", strerror(errno));
for(i=0; i<trace->nstreams; i++) for(i=0; i<trace->nstreams; i++)
{ {

11
trace.c
View File

@ -13,7 +13,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <stdatomic.h> #include <stdatomic.h>
#include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
@ -103,7 +102,8 @@ load_proc_metadata(struct ovni_eproc *proc)
JSON_Object *meta; JSON_Object *meta;
meta = json_value_get_object(proc->meta); meta = json_value_get_object(proc->meta);
assert(meta); if(meta == NULL)
die("load_proc_metadata: json_value_get_object() failed\n");
proc->appid = (int) json_object_get_number(meta, "app_id"); proc->appid = (int) json_object_get_number(meta, "app_id");
} }
@ -551,6 +551,10 @@ ovni_load_next_event(struct ovni_stream *stream)
size = ovni_ev_size(stream->cur_ev); size = ovni_ev_size(stream->cur_ev);
stream->offset += size; stream->offset += size;
/* It cannot overflow, otherwise we are reading garbage */
if(stream->offset > stream->size)
die("ovni_load_next_event: stream offset exceeds size\n");
/* We have reached the end */ /* We have reached the end */
if(stream->offset == stream->size) if(stream->offset == stream->size)
{ {
@ -559,9 +563,6 @@ ovni_load_next_event(struct ovni_stream *stream)
return -1; return -1;
} }
/* It cannot overflow, otherwise we are reading garbage */
assert(stream->offset < stream->size);
stream->cur_ev = (struct ovni_ev *) &stream->buf[stream->offset]; stream->cur_ev = (struct ovni_ev *) &stream->buf[stream->offset];
out: out: