Commit 5f36629f authored by Charles Jacobsen's avatar Charles Jacobsen
Browse files

Simple example and abort example working for lazy.

Phew ... Lots of debugging. This is the commit in which I
discovered AC/THC fails when it uses %rsp offsets instead of
%rbp offsets. And that we need to be careful with local variables
inside ASYNCs.

Anyway, this commit does the following:

    -- You can build for LAZY/EAGER using a configure flag:

            --enable-eager

       By default, it builds for lazy.

    -- Fix abort example to yield async 0. The print out result
       is quite interesting.

    -- Fix caller to use alloca, just to be paranoid about passing
       the local variable transaction_id. This is probably not
       necessary in this example, but it demonstrates the care
       required to pass locals in async's.
parent a72792f9
Pipeline #658 skipped
......@@ -26,6 +26,23 @@ AM_COND_IF([ENABLE_KERNEL_TESTS_BUILD],
[AC_MSG_NOTICE([Building kernel tests.])],
[AC_MSG_NOTICE([Not building kernel tests.])])
# Lazy or Eager?
AC_ARG_ENABLE([eager],
[AS_HELP_STRING([--enable-eager]),
[Enable building libasync for eager stack allocation])],
[],
[enable_eager="no"])
AS_IF([test "x$enable_eager" = "xyes"],
[
EAGER_OR_LAZY=""
AC_MSG_NOTICE([Building for EAGER stack allocation.])
],
[
EAGER_OR_LAZY="-DCONFIG_LAZY_THC"
AC_MSG_NOTICE([Building for LAZY stack allocation.])
])
AC_SUBST(EAGER_OR_LAZY)
# --------------------------------------------------
# Checks for programs.
# --------------------------------------------------
......@@ -116,6 +133,7 @@ AC_CONFIG_FILES(
src/tests/dispatch/Kbuild
src/tests/ctx-switch/Kbuild
src/tests/async-msg-benchmarks/Kbuild
src/tests/abort/Kbuild
)
AC_OUTPUT
......@@ -15,8 +15,7 @@ AM_CPPFLAGS = \
-I$(abs_top_builddir)/src/include \
-I$(LIBFIPC_DIR)/include
AM_CFLAGS = -DLINUX_KERNEL
#-DCONFIG_LAZY_THC
AM_CFLAGS = -DLINUX_KERNEL $(EAGER_OR_LAZY)
COMMON_SRCS= \
common/thc.c \
......
......@@ -1173,7 +1173,7 @@ THCAbort(void) {
pts->asyncCallsEnded ++;
#endif
DEBUGPRINTF("Aborting awe in finish block %p\n", fb);
DEBUG_CANCEL(DEBUGPRINTF("Aborting awe in finish block %p\n", fb));
assert(fb->count > 0);
fb->count --;
......@@ -1182,8 +1182,8 @@ THCAbort(void) {
// and if someone was waiting for us to finish.
if (fb->count == 0) {
if (fb->finish_awe) {
DEBUGPRINTF("Enclosing finish block reached zero awes; scheduling finish awe %p\n",
fb->finish_awe);
DEBUG_CANCEL(DEBUGPRINTF("Enclosing finish block reached zero awes; scheduling finish awe %p\n",
fb->finish_awe));
thc_schedule_local(fb->finish_awe);
fb->finish_awe = NULL;
}
......
......@@ -28,9 +28,9 @@ typedef int errval_t;
#endif
#if (defined(linux) || defined(BARRELFISH))
#ifndef noinline
#define noinline __attribute__((noinline))
#endif
// #ifndef noinline
// #define noinline __attribute__((noinline))
// #endif
#endif
// The implementation of do..finish relies on shadowing so that
......@@ -129,8 +129,9 @@ typedef int errval_t;
_thc_nested_async(FORCE_ARGS_STACK awe_t *awe) \
__asm__(NESTED_FN_STRING(_C)); \
\
noinline \
void _thc_nested_async(FORCE_ARGS_STACK awe_t *awe) { \
void \
noinline \
_thc_nested_async(FORCE_ARGS_STACK awe_t *awe) { \
void *_my_fb = _fb_info; \
_awe.current_fb = _my_fb; \
INIT_LAZY_AWE(awe, &_thc_lazy_awe_marker); \
......
......@@ -6,10 +6,11 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <thc.h>
#include "../test_helpers.h"
MODULE_LICENSE("GPL");
static int __init abort_example_init(void)
static void abort_example_init(void)
{
DO_FINISH(
......@@ -17,6 +18,7 @@ static int __init abort_example_init(void)
int i;
printk(KERN_ERR "ASYNC 0 started\n");
for (i = 0; i < 4; i++) {
THCYield();
printk(KERN_ERR "ASYNC 0 scheduled\n");
}
......@@ -29,8 +31,10 @@ static int __init abort_example_init(void)
ASYNC(
printk(KERN_ERR "ASYNC 1 started\n");
while(!THCShouldStop())
while(!THCShouldStop()) {
THCYield();
printk(KERN_ERR "ASYNC 1 Scheduled\n");
}
printk(KERN_ERR "ASYNC 1 aborting\n");
THCAbort();
......@@ -39,8 +43,10 @@ static int __init abort_example_init(void)
ASYNC(
printk(KERN_ERR "ASYNC 2 started\n");
while(!THCShouldStop())
while(!THCShouldStop()) {
THCYield();
printk(KERN_ERR "Async 2 Scheduled\n");
}
printk(KERN_ERR "ASYNC 2 aborting\n");
THCAbort();
......@@ -61,12 +67,23 @@ static int __init abort_example_init(void)
printk(KERN_ERR "Exited do finish\n");
return 0;
}
static int __abort_example_init(void)
{
thc_init();
LCD_MAIN( abort_example_init(); );
thc_done();
return 0;
}
static void __exit abort_example_rmmod(void)
{
return;
}
module_init(abort_example_init);
module_init(__abort_example_init);
module_exit(abort_example_rmmod);
......@@ -99,15 +99,6 @@ static inline int send_response(struct thc_channel *chnl,
return ret;
}
/*
* Mark recvd msg slot as available
*/
ret = fipc_recv_msg_end(thc_channel_to_fipc(chnl), recvd_msg);
if (ret) {
pr_err("Error marking msg as recvd");
return ret;
}
return 0;
}
......
......@@ -106,36 +106,55 @@ fail:
int __caller(void *_caller_channel_header)
{
struct fipc_ring_channel *fchan = _caller_channel_header;
struct thc_channel chan;
unsigned long transaction_id = 0;
int ret = 0;
thc_channel_init(&chan, fchan);
thc_init();
struct fipc_ring_channel *fchan = _caller_channel_header;
struct thc_channel *chan;
unsigned long transaction_id;
chan = kmalloc(sizeof(*chan), GFP_KERNEL);
if (!chan) {
pr_err("thc channel alloc failed\n");
return -ENOMEM;
}
thc_channel_init(chan, fchan);
thc_init();
/*
* Add nums
*/
DO_FINISH({
while(transaction_id < TRANSACTIONS)
{
ASYNC({
transaction_id++;
ret = async_add_nums(&chan, transaction_id, 1000);
if (ret) {
pr_err("error doing null invocation, ret = %d, exiting...\n",
ret);
}
});
}
});
DO_FINISH(
for (transaction_id = 0;
transaction_id < TRANSACTIONS;
transaction_id++) {
ASYNC(
int ret;
void *tid = __builtin_alloca(
sizeof(transaction_id));
memcpy(tid, (void *)&transaction_id,
sizeof(transaction_id));
ret = async_add_nums(chan,
*(unsigned long *)tid,
1000);
if (ret)
pr_err("error doing add nums, ret = %d\n", ret);
);
}
);
pr_err("Complete\n");
thc_done();
return ret;
kfree(chan);
thc_done();
return 0;
}
int caller(void *_caller_channel_header)
......
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