[PATCH 1/2] kernel:async function call:introduce async_run_inatomic(v3)

From: tom . leiming
Date: Sat May 16 2009 - 09:54:39 EST


From: Ming Lei <tom.leiming@xxxxxxxxx>

The purpose of this function is to offer a simple way to schedule an
asynchronous thread from an atomic context, because there are not any
functions which can create and start a kernel thread in atomic contexts.
Now async_run_inatomic() uses a distinct running list in order to avoid
slowing down synchronization within the general domain.

The comment for async_run_inatomic is under guideline from Cornelia Huck.

Signed-off-by: Ming Lei <tom.leiming@xxxxxxxxx>
Signed-off-by: Cornelia Huck <cornelia.huck@xxxxxxxxxx>
---
include/linux/async.h | 2 ++
kernel/async.c | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/include/linux/async.h b/include/linux/async.h
index 18ce92b..9ff62af 100644
--- a/include/linux/async.h
+++ b/include/linux/async.h
@@ -16,6 +16,8 @@
typedef u64 async_cookie_t;
typedef void (async_func_ptr) (void *data, async_cookie_t cookie);

+extern int async_run_inatomic(async_func_ptr *ptr, void *data);
+
extern async_cookie_t async_schedule(async_func_ptr *ptr, void *data);
extern async_cookie_t async_schedule_domain(async_func_ptr *ptr, void *data,
struct list_head *list);
diff --git a/kernel/async.c b/kernel/async.c
index 8663f5b..adc0455 100644
--- a/kernel/async.c
+++ b/kernel/async.c
@@ -65,6 +65,7 @@ static async_cookie_t next_cookie = 1;

static LIST_HEAD(async_pending);
static LIST_HEAD(async_running);
+static LIST_HEAD(async_running_no_sync);
static DEFINE_SPINLOCK(async_lock);

static int async_enabled = 0;
@@ -222,6 +223,28 @@ static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data,
return newcookie;
}

+ /**
+ * async_run_inatomic - in atomic contexts schedule a function for
+ * asynchronous execution
+ *
+ * @ptr: function to execute asynchronously
+ * @data: data pointer to pass to the function
+ *
+ * The purpose of this function is to offer a simple way to schedule an
+ * asynchronous thread from an atomic context.
+ *
+ * Return zero one success, !zero on failured
+ * Note: async_run_inatomic() uses a distinct running list in order
+ * to avoid slowing down synchronization within the general domain.
+ * Since it does not return a cookie for checkpointing, it is for callers
+ * that don't need later synchronization.
+ */
+int async_run_inatomic(async_func_ptr *ptr, void *data)
+{
+ return !__async_schedule(ptr, data, &async_running_no_sync, 1);
+}
+EXPORT_SYMBOL_GPL(async_run_inatomic);
+
/**
* async_schedule - schedule a function for asynchronous execution
* @ptr: function to execute asynchronously
--
1.6.0.GIT

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/