kernel:async function call:introduce async_run
PATCH 1/1 kernel:async function call:introduce async_run
From: Ming Lei <[email protected]>
In fact, some async function call does not need to check, async_run is right for this kind of function call. Also, async_run is very suitable to used to start a thread in atomic context to do somthing, for now there is no such kind of kernel api, eg. kthread_run can not be started in atomic context.
This patch is againt my another patch:
kernel/async.c:introduce async_schedule*_atomic
please review.
--- include/linux/async.h | 1 + kernel/async.c | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletions(-)
include/linux/async.h +1 -0
@@ -16,6 +16,7 @@typedef u64 async_cookie_t ;typedef void (async_func_ptr ) (void *data,async_cookie_t cookie); +extern void async_run (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);
kernel/async.c +23 -1
@@ -60,6 +60,7 @@ asynchronous and synchronous parts of the kernel.static async_cookie_t next_cookie =1 ; +#define MAX_COOKIE (~0)#define MAX_THREADS 256#define MAX_WORK 32768
@@ -207,7 +208,10 @@ static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, \ entry->running = running;spin_lock_irqsave (&async_lock, flags); - newcookie = entry->cookie = next_cookie++; +if (atomic ==1 ) + newcookie = entry->cookie = next_cookie++; +else + newcookie = entry->cookie =MAX_COOKIE ;list_add_tail (&entry->list, &async_pending);atomic_inc (&entry_count);spin_unlock_irqrestore (&async_lock, flags);
@@ -216,6 +220,24 @@ static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, \ }/** +* async_run - schedule a function for asynchronous execution +* @ptr: function to execute asynchronously +* @data: data pointer to pass to the function +* +* Note:we do not allocate a cookie for this kind of aysnchronous +* function to decrease the wait time of async_synchronize_full(). +* In fact, some function does not need to check, async_run is right +* for this kind of function call. Also, async_run is very suitable to +* start a thread to do somthing in atomic context,for now there is no such +* kind of kernel api, eg. kthread_run can not be run in atomic context. +*/ +void async_run (async_func_ptr *ptr,void *data) +{ +__async_schedule (ptr, data, &async_running,2 ); +} +EXPORT_SYMBOL_GPL (async_run); + +/** * async_schedule - schedule a function for asynchronous execution * @ptr: function to execute asynchronously * @data: data pointer to pass to the function
Signature · 1 line
1.6.0.GIT
Quoted 7 lines · On Wed, 13 May 2009 08:33:49 +0800, [email protected] wrote:
From: Ming Lei <[email protected]>
In fact, some async function call does not need to check,
async_runis right for this kind of function call. Also,async_runis very suitable to used to start a thread in atomic context to do somthing, for now there is no such kind of kernel api, eg.kthread_runcan not be started in atomic context.
Could you rework your explanation a bit? If I understand correctly, you want to introduce a way to queue an async thread for those callers that don't want to synchronize on cookies.
Quoted 36 lines
This patch is againt my another patch:
kernel/async.c:introduce async_schedule*_atomic
please review.Signed-off-by Ming Lei <[email protected]>--- include/linux/async.h | 1 + kernel/async.c | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletions(-)include/linux/async.h +1
-0@@ -16,6 +16,7 @@typedef u64 async_cookie_t ;typedef void (async_func_ptr ) (void *data,async_cookie_t cookie); +extern void async_run (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);kernel/async.c +1
-0@@ -60,6 +60,7 @@ asynchronous and synchronous parts of the kernel.static async_cookie_t next_cookie =1 ; +#define MAX_COOKIE (~0)#define MAX_THREADS 256#define MAX_WORK 32768
kernel/async.c static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, \ · line 214
Quoted 8 lines
kernel/async.c +4
-1@@ -207,7 +208,10 @@ static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, \ entry->running = running;spin_lock_irqsave (&async_lock, flags); - newcookie = entry->cookie = next_cookie++; +if (atomic ==1 ) + newcookie = entry->cookie = next_cookie++; +else + newcookie = entry->cookie =MAX_COOKIE ;
This confuses me. Why do you change the behaviour for atomic == 0?
kernel/async.c static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, \ · line 228
Quoted 13 lines
kernel/async.c +6
-0list_add_tail (&entry->list, &async_pending);atomic_inc (&entry_count);spin_unlock_irqrestore (&async_lock, flags);@@ -216,6 +220,24 @@ static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, \ }/** +* async_run - schedule a function for asynchronous execution +* @ptr: function to execute asynchronously +* @data: data pointer to pass to the function +* +* Note:we do not allocate a cookie for this kind of aysnchronous +* function to decrease the wait time of async_synchronize_full().
But async_synchronize_full() still waits for list_empty(&async_running)
- so what does this buy us?
kernel/async.c static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, \ · line 232
Quoted 4 lines
kernel/async.c +4
-0+* In fact, some function does not need to check, async_run is right +* for this kind of function call. Also, async_run is very suitable to +* start a thread to do somthing in atomic context,for now there is no such +* kind of kernel api, eg. kthread_run can not be run in atomic context.
Hm...
"The purpose of this function is to offer a simple way to schedule an asynchronous thread, especially from an atomic context." Would that describe async_run() better?
Doesn't this function need a return code since queueing the async work can fail?
kernel/async.c static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, \ · line 236
Quoted 4 lines
kernel/async.c +4
-0+*/ +void async_run (async_func_ptr *ptr,void *data) +{ +__async_schedule (ptr, data, &async_running,2 );
I don't like the overloading of the "atomic" value - if I causually looked at the declaration of __async_schedule(), I'd think it would be a kind of boolean value...
Quoted 7 lines
kernel/async.c +4
-0+} +EXPORT_SYMBOL_GPL (async_run); + +/** * async_schedule - schedule a function for asynchronous execution * @ptr: function to execute asynchronously * @data: data pointer to pass to the function
2009/5/13 Cornelia Huck <[email protected]>:
Quoted 53 lines
Quoted 7 lines · On Wed, 13 May 2009 08:33:49 +0800, [email protected] wrote:
From: Ming Lei <[email protected]>
In fact, some async function call does not need to check,
async_runis right for this kind of function call. Also,async_runis very suitable to used to start a thread in atomic context to do somthing, for now there is no such kind of kernel api, eg.kthread_runcan not be started in atomic context.Could you rework your explanation a bit? If I understand correctly, you want to introduce a way to queue an async thread for those callers that don't want to synchronize on cookies.
Quoted 38 lines
This patch is againt my another patch:
kernel/async.c:introduce async_schedule*_atomic please review.Signed-off-by Ming Lei <[email protected]>---
include/linux/async.h | 1 +kernel/async.c| 24 +++++++++++++++++++++++-2 files changed, 24 insertions(+), 1 deletions(-)include/linux/async.h +1
-0@@ -16,6 +16,7 @@ typedef u64 async_cookie_t; typedef void (async_func_ptr) (void *data, async_cookie_t cookie); +extern void async_run (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);kernel/async.c +1
-0@@ -60,6 +60,7 @@ asynchronous and synchronous parts of the kernel. static async_cookie_t next_cookie = 1; +#define MAX_COOKIE (~0) #define MAX_THREADS 256 #define MAX_WORK 32768@@ -207,7 +208,10 @@ static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, \ entry->running = running;
Quoted 8 lines
kernel/async.c static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, \ · line 214
Quoted 6 lines
kernel/async.c +4
-1spin_lock_irqsave(&async_lock, flags); - newcookie = entry->cookie = next_cookie++; + if (atomic == 1) + newcookie = entry->cookie = next_cookie++; + else + newcookie = entry->cookie = MAX_COOKIE;This confuses me. Why do you change the behaviour for atomic == 0?
Yes, it needs to be fixed.
Quoted 7 lines
Quoted 7 lines
kernel/async.c +0
-0list_add_tail(&entry->list, &async_pending); atomic_inc(&entry_count); spin_unlock_irqrestore(&async_lock, flags);@@ -216,6 +220,24 @@ static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, \ }
Quoted 10 lines
kernel/async.c static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, \ · line 228
Quoted 7 lines
kernel/async.c +6
-0/** +* async_run - schedule a function for asynchronous execution +* @ptr: function to execute asynchronously +* @data: data pointer to pass to the function +* +* Note:we do not allocate a cookie for this kind of aysnchronous +* function to decrease the wait time of async_synchronize_full(). But
async_synchronize_full()still waits forlist_empty(&async_running)
- so what does this buy us?
I mean it can decrease the wait time for other async function. async_schedule() still can be used to do such thing, but may lead to a slower boot. It is the main
purpose of the patch.
Quoted 10 lines
kernel/async.c static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, \ · line 232
Quoted 5 lines
kernel/async.c +4
-0+* In fact, some function does not need to check, async_run is right +* for this kind of function call. Also, async_run is very suitable to +* start a thread to do somthing in atomic context,for now there is no such +* kind of kernel api, eg. kthread_run can not be run in atomic context. Hm...
"The purpose of this function is to offer a simple way to schedule an asynchronous thread, especially from an atomic context." Would that describeasync_run()better?
Yes, very good, please forgive my poor english.
Thanks!
Signature · 1 line
Lei Ming
Quoted 12 lines · Ming Lei
2009/5/13 Cornelia Huck <[email protected]>:
Quoted 11 lines
Quoted 7 lines · On Wed, 13 May 2009 08:33:49 +0800, [email protected] wrote:
/**
+ *async_run- schedule a function for asynchronous execution
+ * @ptr: function to execute asynchronously
+ * @data: data pointer to pass to the function
+ *
+ * Note:we do not allocate a cookie for this kind of aysnchronous
+ * function to decrease the wait time ofasync_synchronize_full().
Quoted 7 lines
Quoted 2 lines
But
async_synchronize_full()still waits forlist_empty(&async_running)
- so what does this buy us?I mean it can decrease the wait time for other async function.
async_schedule()still can be used to do such thing, but may lead to a slower boot. It is the main
purpose of the patch.
I see how this can affect places calling async_synchronize_cookie(), but the function will still end up on async_running. If you don't want async_synchronize_full() waiting for these functions, couldn't you use your own running list?
(Oh, and I just thought about it a bit further:
- somebody calls async_run() -> function with cookie = MAX_COOKIE will be lowest_in_progress at some point in time
- somebody else calls async_schedule() -> cookie = n
- we wait with async_synchronize_cookie(n) - which returns since MAX_COOKIE >= n, which is probably not what we want)
2009/5/13 Cornelia Huck <[email protected]>:
Quoted 28 lines
Quoted 12 lines · Ming Lei
2009/5/13 Cornelia Huck <[email protected]>:
Quoted 11 lines
Quoted 7 lines · On Wed, 13 May 2009 08:33:49 +0800, [email protected] wrote:
/**
+ *async_run- schedule a function for asynchronous execution
+ * @ptr: function to execute asynchronously
+ * @data: data pointer to pass to the function
+ *
+ * Note:we do not allocate a cookie for this kind of aysnchronous
+ * function to decrease the wait time ofasync_synchronize_full().Quoted 7 lines
Quoted 2 lines
But
async_synchronize_full()still waits forlist_empty(&async_running)
- so what does this buy us?I mean it can decrease the wait time for other async function.
async_schedule()still can be used to do such thing, but may lead to a slower boot. It is the main
purpose of the patch.I see how this can affect places calling
async_synchronize_cookie(), but the function will still end up onasync_running. If you don't wantasync_synchronize_full()waiting for these functions, couldn't you use your own running list?
Quoted 7 lines
(Oh, and I just thought about it a bit further:
- somebody callsasync_run()-> function with cookie =MAX_COOKIEwill belowest_in_progressat some point in time
- somebody else callsasync_schedule()-> cookie = n
- we wait withasync_synchronize_cookie(n)- which returns sinceMAX_COOKIE>= n, which is probably not what we want)
yes , you are right, I'll think about it.
Signature · 1 line
Lei Ming
Quoted 7 lines · On Wed, 13 May 2009 08:33:49 +0800 [email protected] wrote:
From: Ming Lei <[email protected]>
In fact, some async function call does not need to check,
async_runis right for this kind of function call. Also,async_runis very suitable to used to start a thread in atomic context to do somthing, for now there is no such kind of kernel api, eg.kthread_runcan not be started in atomic context.
I don't think it's worth complicating the cookie allocation; I don't assume that what you're scheduling is going to take a really long time...
if it does it's better to make a private domain for it.
Signature · 3 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org