Commit e9d4da6a authored by Michael Quigley's avatar Michael Quigley
Browse files

Updated tests

parent 363c77d3
......@@ -40,6 +40,7 @@
*/
static unsigned long initialized_marker = 0xDeadBeef;
awe_table_t* global_awe_map;
/*
* Initilaizes awe mapper.
......@@ -67,6 +68,7 @@ void
LIBASYNC_FUNC_ATTR
awe_mapper_uninit(void)
{
printk(KERN_ERR "in awe_mapper_uninit\n");
awe_table_t *awe_map = get_awe_map();
kfree(awe_map);
}
......@@ -88,7 +90,9 @@ int
LIBASYNC_FUNC_ATTR
awe_mapper_create_id(uint32_t *new_id)
{
printk(KERN_ERR "before awe_map\n");
awe_table_t *awe_map = get_awe_map();
printk(KERN_ERR "after awe_map = %lx\n", (unsigned long)awe_map);
if (unlikely(awe_map->used_slots >= AWE_TABLE_COUNT))
{
......@@ -112,52 +116,3 @@ awe_mapper_create_id(uint32_t *new_id)
}
EXPORT_SYMBOL(awe_mapper_create_id);
/*
* Marks provided id as available
*/
void
LIBASYNC_FUNC_ATTR
awe_mapper_remove_id(uint32_t id)
{
awe_table_t *awe_map = get_awe_map();
BUG_ON(unlikely(id >= AWE_TABLE_COUNT));
if( awe_map->used_slots > 0 )
{
awe_map->used_slots--;
}
(awe_map->awe_list)[id] = NULL;
}
EXPORT_SYMBOL(awe_mapper_remove_id);
/*
* Links awe_ptr with id.
*/
void
LIBASYNC_FUNC_ATTR
awe_mapper_set_id(uint32_t id, void* awe_ptr)
{
awe_table_t *awe_map = get_awe_map();
BUG_ON(unlikely(id >= AWE_TABLE_COUNT));
(awe_map->awe_list)[id] = awe_ptr;
}
/*
* Returns awe_ptr that corresponds to id.
*/
void*
LIBASYNC_FUNC_ATTR
awe_mapper_get_awe_ptr(uint32_t id)
{
awe_table_t *awe_map = get_awe_map();
if (id >= AWE_TABLE_COUNT)
return NULL;
return awe_map->awe_list[id];
}
......@@ -19,6 +19,7 @@
#undef linux
#endif
#ifndef LINUX_KERNEL
#include <stdlib.h>
#include <stdio.h>
......@@ -136,7 +137,7 @@ static void thc_dump_stack_0(void);
// Per-thread state
PTState_t *
TEMP_INLINE PTState_t *
LIBASYNC_FUNC_ATTR
PTS(void) {
PTState_t *pts = thc_get_pts_0();
......@@ -149,7 +150,7 @@ PTS(void) {
}
EXPORT_SYMBOL(PTS);
static void InitPTS(void) {
static TEMP_INLINE void InitPTS(void) {
#ifdef LINUX_KERNEL
PTState_t *pts = kzalloc(sizeof(PTState_t), GFP_KERNEL);
#else
......@@ -161,14 +162,14 @@ static void InitPTS(void) {
thc_set_pts_0(pts);
}
static void thc_pts_lock(PTState_t *t) {
static TEMP_INLINE void thc_pts_lock(PTState_t *t) {
#ifndef NDEBUG
t->lock++;
#endif
thc_latch_acquire(&t->latch);
}
static void thc_pts_unlock(PTState_t *t) {
static TEMP_INLINE void thc_pts_unlock(PTState_t *t) {
thc_latch_release(&t->latch);
}
......@@ -265,7 +266,7 @@ static void thc_print_pts_stats(PTState_t *t, int clear)
//
// There is currently no support for extending a stack, or allowing it
// to be discontiguous
void *
TEMP_INLINE void *
LIBASYNC_FUNC_ATTR
_thc_allocstack(void) {
PTState_t *pts = PTS();
......@@ -292,7 +293,7 @@ _thc_allocstack(void) {
// De-allocate a stack back to THC's pool of free stacks
void
TEMP_INLINE void
LIBASYNC_FUNC_ATTR
_thc_freestack(void *s) {
PTState_t *pts = PTS();
......@@ -306,7 +307,7 @@ _thc_freestack(void *s) {
#endif
}
static void thc_pendingfree(PTState_t * pts) {
static TEMP_INLINE void thc_pendingfree(PTState_t * pts) {
if (pts->pendingFree) {
DEBUG_DISPATCH(DEBUGPRINTF(DEBUG_DISPATCH_PREFIX
" pending free of stack %p\n",
......@@ -316,7 +317,7 @@ static void thc_pendingfree(PTState_t * pts) {
}
}
void
TEMP_INLINE void
LIBASYNC_FUNC_ATTR
_thc_pendingfree(void) {
thc_pendingfree(PTS());
......@@ -328,7 +329,7 @@ EXPORT_SYMBOL(_thc_pendingfree);
// This checks whether the awe's lazy stack is finished with (according to
// the provided esp, and puts it on pending free list if so.
static void check_lazy_stack_finished (PTState_t *pts, void *esp) {
static TEMP_INLINE void check_lazy_stack_finished (PTState_t *pts, void *esp) {
assert(pts->curr_lazy_stack);
DEBUG_STACK(DEBUGPRINTF(DEBUG_STACK_PREFIX
"> CheckLazyStackFinished(s=%p,esp+buf=%p)\n",
......@@ -345,7 +346,7 @@ static void check_lazy_stack_finished (PTState_t *pts, void *esp) {
// Allocate a lazy stack for this awe's continuation to execute on.
static void alloc_lazy_stack (awe_t *awe) {
static TEMP_INLINE void alloc_lazy_stack (awe_t *awe) {
void * new_esp;
DEBUG_STACK(DEBUGPRINTF(DEBUG_STACK_PREFIX "> AllocLazyStack(awe=%p)\n",
awe));
......@@ -441,6 +442,7 @@ static void thc_dispatch_loop(void) {
thc_pendingfree(pts);
// Pick up work passed to us from other threads
/*
if (pts->aweRemoteHead.next != &pts->aweRemoteTail) {
awe_t *tmp = pts->aweHead.next;
thc_pts_lock(pts);
......@@ -453,7 +455,7 @@ static void thc_dispatch_loop(void) {
pts->aweRemoteHead.next = &pts->aweRemoteTail;
pts->aweRemoteTail.prev = &pts->aweRemoteHead;
thc_pts_unlock(pts);
}
} */
if (pts->aweHead.next == &pts->aweTail) {
awe_t idle_awe;
......@@ -539,7 +541,7 @@ static void thc_exit_dispatch_loop(void) {
// the caller's)
static void thc_dispatch(PTState_t *pts) {
assert(pts && pts->doneInit && "Not initialized RTS");
//assert(pts && pts->doneInit && "Not initialized RTS");
thc_awe_execute_0(&pts->dispatch_awe);
}
......@@ -579,7 +581,7 @@ static void thc_end_rts(void) {
#endif
}
// Done
thc_print_pts_stats(PTS(), 0);
//thc_print_pts_stats(PTS(), 0);
PTS()->doneInit = 0;
DEBUG_INIT(DEBUGPRINTF(DEBUG_INIT_PREFIX "< Ending\n"));
}
......@@ -588,7 +590,7 @@ static void thc_end_rts(void) {
// AWE management
static void thc_awe_init(awe_t *awe, void *eip, void *ebp, void *esp) {
static TEMP_INLINE void thc_awe_init(awe_t *awe, void *eip, void *ebp, void *esp) {
PTState_t *pts = PTS();
DEBUG_AWE(DEBUGPRINTF(DEBUG_AWE_PREFIX "> AWEInit(%p, %p, %p, %p)\n",
awe, eip, ebp, esp));
......@@ -699,7 +701,7 @@ static inline void check_for_lazy_awe (void * ebp) { }
// fb->finish_awe which will be resumed when the final async
// call finsihes. _thc_endasync picks this up.
void
void TEMP_INLINE
LIBASYNC_FUNC_ATTR
_thc_startfinishblock(finish_t *fb, int fb_kind) {
PTState_t *pts = PTS();
......@@ -771,7 +773,7 @@ _thc_startfinishblock(finish_t *fb, int fb_kind) {
EXPORT_SYMBOL(_thc_startfinishblock);
__attribute__ ((unused))
static void _thc_endfinishblock0(void *a, void *f) {
static TEMP_INLINE void _thc_endfinishblock0(void *a, void *f) {
finish_t *fb = (finish_t*)f;
awe_t *awe = (awe_t*)a;
......@@ -847,7 +849,7 @@ _thc_do_cancel_request(finish_t *fb) {
}
EXPORT_SYMBOL(_thc_do_cancel_request);
void
void TEMP_INLINE
LIBASYNC_FUNC_ATTR
_thc_endfinishblock(finish_t *fb, void *stack) {
PTState_t *pts = PTS();
......@@ -897,7 +899,7 @@ _thc_endfinishblock(finish_t *fb, void *stack) {
EXPORT_SYMBOL(_thc_endfinishblock);
void
void TEMP_INLINE
LIBASYNC_FUNC_ATTR
_thc_startasync(void *f, void *stack) {
finish_t *fb = (finish_t*)f;
......@@ -912,7 +914,7 @@ _thc_startasync(void *f, void *stack) {
}
EXPORT_SYMBOL(_thc_startasync);
void
TEMP_INLINE void
LIBASYNC_FUNC_ATTR
_thc_endasync(void *f, void *s) {
finish_t *fb = (finish_t*)f;
......@@ -1112,9 +1114,10 @@ THCYieldToId(uint32_t id_to)
return -EINVAL;
}
CALL_CONT_LAZY((void*)&thc_yieldto_with_cont, (void*)awe_ptr);
if ( likely(PTS() == awe_ptr->pts) ) {
// Switch to target awe
CALL_CONT_LAZY((void*)&thc_yieldto_with_cont, (void*)awe_ptr);
// We were woken up
return 0;
}
......@@ -1291,21 +1294,22 @@ THCSchedule(awe_t *awe) {
DEBUG_AWE(DEBUGPRINTF(DEBUG_AWE_PREFIX "> THCSchedule(%p)\n",
awe));
awe_pts = awe->pts;
if (awe_pts == PTS()) {
//if (awe_pts == PTS()) {
// Work is for us
awe->prev = &(awe_pts->aweHead);
awe->next = awe_pts->aweHead.next;
awe_pts->aweHead.next->prev = awe;
awe_pts->aweHead.next = awe;
} else {
//} else {
// Work is remote
/*
thc_pts_lock(awe_pts);
awe->prev = &(awe_pts->aweRemoteHead);
awe->next = awe_pts->aweRemoteHead.next;
awe_pts->aweRemoteHead.next->prev = awe;
awe_pts->aweRemoteHead.next = awe;
thc_pts_unlock(awe_pts);
}
}*/
DEBUG_AWE(DEBUGPRINTF(DEBUG_AWE_PREFIX " added AWE between %p %p\n",
awe->prev, awe->next));
DEBUG_AWE(DEBUGPRINTF(DEBUG_AWE_PREFIX "< THCSchedule\n"));
......
......@@ -45,38 +45,71 @@ void awe_mapper_uninit(void);
*/
int awe_mapper_create_id(uint32_t *new_id);
extern awe_table_t* global_awe_map;
static inline awe_table_t* get_awe_map(void)
{
//return PTS()->awe_map;
return global_awe_map;
}
/*
* Marks provided id as available
* Called in awe_mapper_init.
* Sets awe_map struct of the current PTS to a specific awe_table.
*/
void awe_mapper_remove_id(uint32_t id);
static inline void set_awe_map(awe_table_t * map_ptr)
{
printk(KERN_ERR "in set_awe_map with ptr: %p\n", map_ptr);
//PTS()->awe_map = map_ptr;
global_awe_map = map_ptr;
}
/*
* Links awe_ptr with id.
* Marks provided id as available
*/
void awe_mapper_set_id(uint32_t id, void* awe_ptr);
static inline void
LIBASYNC_FUNC_ATTR
awe_mapper_remove_id(uint32_t id)
{
awe_table_t *awe_map = get_awe_map();
BUG_ON(unlikely(id >= AWE_TABLE_COUNT));
if( awe_map->used_slots > 0 )
{
awe_map->used_slots--;
}
(awe_map->awe_list)[id] = NULL;
}
/*
* Returns awe_ptr that corresponds to id.
*
* If there is no awe associated with id, returns
* NULL.
* Links awe_ptr with id.
*/
void* awe_mapper_get_awe_ptr(uint32_t id);
static inline awe_table_t* get_awe_map(void)
static inline void
LIBASYNC_FUNC_ATTR
awe_mapper_set_id(uint32_t id, void* awe_ptr)
{
return PTS()->awe_map;
awe_table_t *awe_map = get_awe_map();
BUG_ON(unlikely(id >= AWE_TABLE_COUNT));
(awe_map->awe_list)[id] = awe_ptr;
}
/*
* Called in awe_mapper_init.
* Sets awe_map struct of the current PTS to a specific awe_table.
* Returns awe_ptr that corresponds to id.
*/
static inline void set_awe_map(awe_table_t * map_ptr)
static inline void*
LIBASYNC_FUNC_ATTR
awe_mapper_get_awe_ptr(uint32_t id)
{
PTS()->awe_map = map_ptr;
awe_table_t *awe_map = get_awe_map();
if (id >= AWE_TABLE_COUNT)
return NULL;
return awe_map->awe_list[id];
}
#endif /* LINUX_KERNEL */
#endif
......@@ -10,12 +10,16 @@
#ifdef LINUX_KERNEL
#include <linux/types.h>
#include <linux/printk.h>
#define assert(XX) do { \
if (!(XX)) { \
printk("assertion failure at %s:%d\n", \
__FILE__, __LINE__); \
} \
} while(0)
#ifdef USE_ASSERT
#define assert(XX) do { \
if (!(XX)) { \
printk("assertion failure at %s:%d\n", \
__FILE__, __LINE__); \
} \
} while(0)
#else
#define assert(XX) do {} while(0)
#endif
#else
#include <stdint.h>
#include <stdlib.h>
......@@ -203,7 +207,8 @@ typedef int errval_t;
awe_t _awe; \
void *_new_stack = _thc_allocstack(); \
/* Define nested function containing the body */ \
auto void _thc_nested_async(void) __asm__(NESTED_FN_STRING(_C)); \
auto void noinline \
__attribute__((used)) _thc_nested_async(void) __asm__(NESTED_FN_STRING(_C)); \
__attribute__((used)) void noinline _thc_nested_async(void) { \
void *_my_fb = _fb_info; \
void *_my_stack = _new_stack; \
......
......@@ -3,6 +3,8 @@
#ifndef _THC_INTERNAL_H_
#define _THC_INTERNAL_H_
#define TEMP_INLINE
/***********************************************************************/
typedef struct ptstate_t PTState_t;
typedef struct thcstack_t thcstack_t;
......@@ -168,22 +170,22 @@ struct ptstate_t {
int awes_should_stop;
};
PTState_t *PTS(void);
PTState_t TEMP_INLINE *PTS(void);
typedef void (*THCContFn_t)(void *cont, void *args);
void *_thc_allocstack(void);
void _thc_freestack(void *s);
TEMP_INLINE void *_thc_allocstack(void);
TEMP_INLINE void _thc_freestack(void *s);
void _thc_onaltstack(void *s, void *fn, void *args);
void _thc_startasync(void *f, void *stack);
void _thc_endasync(void *f, void *s);
void _thc_startfinishblock(finish_t *fb, int fb_kind);
void _thc_endfinishblock(finish_t *fb, void *stack);
TEMP_INLINE void _thc_endasync(void *f, void *s);
TEMP_INLINE void _thc_startfinishblock(finish_t *fb, int fb_kind);
TEMP_INLINE void _thc_endfinishblock(finish_t *fb, void *stack);
void _thc_do_cancel_request(finish_t *fb);
void _thc_callcont(struct awe_t *awe, THCContFn_t fn, void *args) __attribute__((returns_twice));
int _thc_schedulecont(struct awe_t *awe) __attribute__((returns_twice));
void _thc_lazy_awe_marker(void);
void _thc_pendingfree(void);
TEMP_INLINE void _thc_pendingfree(void);
/***********************************************************************/
......@@ -482,6 +484,7 @@ extern int _end_text_nx;
#define CALL_CONT(_FN,_ARG) \
do { \
awe_t _awe; \
_awe.status = EAGER_AWE; \
KILL_CALLEE_SAVES(); \
_thc_callcont(&_awe, (THCContFn_t)(_FN), (_ARG)); \
} while (0)
......@@ -492,6 +495,7 @@ extern int _end_text_nx;
#define CALL_CONT_AND_SAVE(_FN,_IDNUM,_ARG) \
do { \
awe_t _awe; \
_awe.status = EAGER_AWE; \
awe_mapper_set_id((_IDNUM), &_awe); \
KILL_CALLEE_SAVES(); \
_thc_callcont(&_awe, (THCContFn_t)(_FN), (_ARG)); \
......
......@@ -19,11 +19,11 @@
MODULE_LICENSE("GPL");
#define NUM_SWITCH_MEASUREMENTS 100000
#define NUM_SWITCH_MEASUREMENTS 14
#define CPU_NUM 2
static unsigned long ctx_measurements_arr[NUM_SWITCH_MEASUREMENTS];
static unsigned long thd_measurements_arr[NUM_SWITCH_MEASUREMENTS];
//static unsigned long ctx_measurements_arr[NUM_SWITCH_MEASUREMENTS];
//static unsigned long thd_measurements_arr[NUM_SWITCH_MEASUREMENTS];
static const int USE_OTHER_CORE = 0;
......@@ -31,32 +31,56 @@ static int test_ctx_switch_and_thd_creation(void)
{
unsigned long t1, t2, t3;
uint32_t msg_id;
int i;
int ret;
int i = 0;
thc_init();
for( i = 0; i < NUM_SWITCH_MEASUREMENTS; i++ )
{
DO_FINISH_(ctx_switch,{
t1 = test_fipc_start_stopwatch();
// t1 = test_fipc_start_stopwatch();
ASYNC({
t2 = test_fipc_stop_stopwatch();
thd_measurements_arr[i] = t2 - t1;
// t2 = test_fipc_stop_stopwatch();
// thd_measurements_arr[i] = t2 - t1;
ret = awe_mapper_create_id(&msg_id);
// THCYieldAndSave
BUG_ON(ret);
THCYieldAndSave(msg_id);
//THCYield();
t3 = test_fipc_stop_stopwatch();
// t3 = test_fipc_stop_stopwatch();
awe_mapper_remove_id(msg_id);
printk(KERN_ERR "async 1 done\n");
});
ASYNC({
t2 = test_fipc_start_stopwatch();
BUG_ON(THCYieldToId(msg_id));
// t2 = test_fipc_start_stopwatch();
//BUG_ON(THCYieldToId(msg_id));
THCYieldToId(msg_id);
//THCYield();//To(awe_pointer);
printk(KERN_ERR "async 2 done\n");
});
});
ctx_measurements_arr[i] = t3 - t2;
printk(KERN_ERR "outside of DO_FINISH\n");
// ctx_measurements_arr[i] = t3 - t2;
}
printk(KERN_ERR "outside of loop \n");
#if 0
DO_FINISH_(ctx_switch,{
ASYNC({
int i;
for (i = 0; i < NUM_SWITCH_MEASUREMENTS; i++)
THCYield();
});
ASYNC({
int i;
for (i = 0; i < NUM_SWITCH_MEASUREMENTS; i++)
THCYield();
});
});
#endif
thc_done();
return 0;
......@@ -77,7 +101,7 @@ static int thread_fn(void* data)
return ret;
}
#if 0
static void print_max(unsigned long* arr)
{
int max_iter = 0;
......@@ -94,7 +118,7 @@ static void print_max(unsigned long* arr)
printk(KERN_ERR "\nmax_num = %lu, max iter = %d\n\n", max_num, max_iter);
}
#endif
static int run_test_fn_thread(int (*fn)(void))
......@@ -120,13 +144,13 @@ static int run_test_fn_thread(int (*fn)(void))
printk(KERN_ERR "Error waiting for thread.\n");
}
printk(KERN_ERR "\nTiming results for context switches:\n");
/* printk(KERN_ERR "\nTiming results for context switches:\n");
print_max(ctx_measurements_arr);
test_fipc_dump_time(ctx_measurements_arr, NUM_SWITCH_MEASUREMENTS);
print_max(thd_measurements_arr);
printk(KERN_ERR "\nTiming results for thread creation:\n");
test_fipc_dump_time(thd_measurements_arr, NUM_SWITCH_MEASUREMENTS);
printk(KERN_ERR "\n\n");
printk(KERN_ERR "\n\n");*/
return 0;
fail:
......@@ -148,7 +172,7 @@ static int run_test_fn_nothread(int (*fn)(void))
printk(KERN_ERR "Error running test.\n");
goto fail1;
}
/*
printk(KERN_ERR "\nTiming results for context switches:\n");
print_max(ctx_measurements_arr);
test_fipc_dump_time(ctx_measurements_arr, NUM_SWITCH_MEASUREMENTS);
......@@ -156,7 +180,7 @@ static int run_test_fn_nothread(int (*fn)(void))
print_max(thd_measurements_arr);
test_fipc_dump_time(thd_measurements_arr, NUM_SWITCH_MEASUREMENTS);
printk(KERN_ERR "\n\n");
*/
return 0;
fail1:
return ret;
......@@ -169,7 +193,7 @@ static int test_fn(void)
{
int ret;
printk(KERN_ERR "Starting tests. Using %d samples per test.\n\n", NUM_SWITCH_MEASUREMENTS);
// printk(KERN_ERR "Starting tests. Using %d samples per test.\n\n", NUM_SWITCH_MEASUREMENTS);
if( USE_OTHER_CORE )
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment