async: Handle kthread_run() return codes.
PATCH 1/2 async: Handle kthread_run() return codes.
If we fail to create the manager thread, fall back to non-fastboot. If we fail to create an async thread, try again when the manager thread runs again.
--- kernel/async.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/async.c +8 -3
@@ -315,11 +315,14 @@ static int async_manager_thread(void *un ec =atomic_read (&entry_count);while (tc < ec && tc <MAX_THREADS ) { -kthread_run (async_thread,NULL ,"async/%i" , tc); +if (IS_ERR (kthread_run (async_thread,NULL ,"async/%i" , + tc))) +/* Try again later. */ + goto schedule;atomic_inc (&thread_count); tc++; } - +schedule:schedule (); }remove_wait_queue (&async_new, &wq);
@@ -330,7 +333,9 @@ static int async_manager_thread(void *unstatic int __init async_init (void ) {if (async_enabled) -kthread_run (async_manager_thread,NULL ,"async/mgr" ); +if (IS_ERR (kthread_run (async_manager_thread,NULL , +"async/mgr" ))) + async_enabled =0 ;return 0 ; }
Quoted 13 lines · Cornelia Huck
If we fail to create the manager thread, fall back to non-fastboot. If we fail to create an async thread, try again when the manager thread runs again.
Signed-off-by Cornelia Huck <[email protected]>--- kernel/async.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/async.c static int async_manager_thread(void *un · line 317
Quoted 3 lines
kernel/async.c +0
-0@@ -315,11 +315,14 @@ static int async_manager_thread(void *un ec =atomic_read (&entry_count);while (tc < ec && tc <MAX_THREADS ) {
why not add the following to stop the wrapping of kthread_run:
+ struct task_struct *kt; kt = kthread_run(async_thread, NULL, "async/%i", tc); if (IS_ERR(kt)) goto schedule;
also, I belive the goto isn't necessary, just break out of the while
if (IS_ERR(kt)) break;
Quoted 29 lines
kernel/async.c +8
-4-kthread_run (async_thread,NULL ,"async/%i" , tc); +if (IS_ERR (kthread_run (async_thread,NULL ,"async/%i" , + tc))) +/* Try again later. */ + goto schedule;atomic_inc (&thread_count); tc++; } - +schedule:schedule (); }remove_wait_queue (&async_new, &wq);@@ -330,7 +333,9 @@ static int async_manager_thread(void *unstatic int __init async_init (void ) {if (async_enabled) -kthread_run (async_manager_thread,NULL ,"async/mgr" ); +if (IS_ERR (kthread_run (async_manager_thread,NULL , +"async/mgr" ))) + async_enabled =0 ;return 0 ; } --To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
Quoted 9 lines · Ben Dooks
Review static int async_manager_thread(void *un · line 317
Quoted 4 lines
(quoted diff) +0
-0@@ -315,11 +315,14 @@ static int async_manager_thread(void *un ec = atomic_read(&entry_count); while (tc < ec && tc < MAX_THREADS) {why not add the following to stop the wrapping of
kthread_run:+ struct task_struct *kt; kt = kthread_run(async_thread, NULL, "async/%i", tc);
Hm, I don't think avoiding wrapping is worth adding another variable.
Quoted 7 lines
if (IS_ERR(kt)) goto schedule;also, I belive the goto isn't necessary, just break out of the while
if (IS_ERR(kt)) break;
OK, that's a bit nicer. Updated patch follows.
If we fail to create the manager thread, fall back to non-fastboot. If we fail to create an async thread, try again when the manager thread runs again.
--- kernel/async.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/async.c +7 -2
@@ -315,7 +315,10 @@ static int async_manager_thread(void *un ec =atomic_read (&entry_count);while (tc < ec && tc <MAX_THREADS ) { -kthread_run (async_thread,NULL ,"async/%i" , tc); +if (IS_ERR (kthread_run (async_thread,NULL ,"async/%i" , + tc))) +/* Try again later. */ +break ;atomic_inc (&thread_count); tc++; }
@@ -330,7 +333,9 @@ static int async_manager_thread(void *unstatic int __init async_init (void ) {if (async_enabled) -kthread_run (async_manager_thread,NULL ,"async/mgr" ); +if (IS_ERR (kthread_run (async_manager_thread,NULL , +"async/mgr" ))) + async_enabled =0 ;return 0 ; }
kernel/async.c static int async_manager_thread(void *un · line 321
Quoted 10 lines
kernel/async.c +0
-1ec =atomic_read (&entry_count);while (tc < ec && tc <MAX_THREADS ) { - kthread_run(async_thread, NULL, "async/%i",tc);
(quoted diff) +1
-0+ if (IS_ERR(kthread_run(async_thread, NULL,"async/%i",
kernel/async.c +3
-0+ tc))) +/* Try again later. */ + goto schedule;
I do not like this recovery to be honest. an msleep() followed by a "continue" is probably much better.
kernel/async.c static int async_manager_thread(void *un · line 338
Quoted 8 lines
kernel/async.c +3
-1@@ -330,7 +333,9 @@ static int async_manager_thread(void *unstatic int __init async_init (void ) {if (async_enabled) -kthread_run (async_manager_thread,NULL ,"async/mgr" ); +if (IS_ERR (kthread_run (async_manager_thread,NULL , +"async/mgr" ))) + async_enabled =0 ;
hmm maybe; it might make more sense to set it to 0 here, and have the thread itself set the variable to 1..... that way we KNOW the thread is running for sure..
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
Quoted 13 lines · Arjan van de Ven
kernel/async.c static int async_manager_thread(void *un · line 321
Quoted 10 lines
kernel/async.c +0
-1ec =atomic_read (&entry_count);while (tc < ec && tc <MAX_THREADS ) { - kthread_run(async_thread, NULL, "async/%i",tc);
(quoted diff) +1
-0+ if (IS_ERR(kthread_run(async_thread, NULL,"async/%i",
kernel/async.c +3
-0+ tc))) +/* Try again later. */ + goto schedule;I do not like this recovery to be honest. an
msleep()followed by a "continue" is probably much better.
Will change.
Quoted 14 lines
kernel/async.c static int async_manager_thread(void *un · line 338
Quoted 10 lines
kernel/async.c +3
-1@@ -330,7 +333,9 @@ static int async_manager_thread(void *unstatic int __init async_init (void ) {if (async_enabled) -kthread_run (async_manager_thread,NULL ,"async/mgr" ); +if (IS_ERR (kthread_run (async_manager_thread,NULL , +"async/mgr" ))) + async_enabled =0 ;hmm maybe; it might make more sense to set it to 0 here, and have the thread itself set the variable to 1..... that way we KNOW the thread is running for sure..
That would look a bit strange to me.
setup_async sets async_enabled -> async_init unsets it again -> async_manager_thread sets it again
If anything, we could use two variables (use_async and async_enabled), but that smells of overengeneering to me...