From ddff7757d64688a978e581b005d50db9248d6741 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Fri, 22 Nov 2019 10:00:15 +0100 Subject: [PATCH] infra: restart failed kthread creation --- kernel/brick.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/kernel/brick.h b/kernel/brick.h index 767c5859..c8b0b9ac 100644 --- a/kernel/brick.h +++ b/kernel/brick.h @@ -656,15 +656,24 @@ typedef enum { #define brick_thread_create(_thread_fn, _data, _fmt, _args...) \ ({ \ - brick_thread_t *_thr; \ + brick_thread_t *_thr = NULL; \ + int _max_retry = 3; \ \ - flush_signals(current); \ - _thr = kthread_create(_thread_fn, _data, _fmt, ##_args); \ - if (unlikely(IS_ERR(_thr))) { \ - int _err = PTR_ERR(_thr); \ + while (_max_retry-- > 0) { \ + int _err; \ + \ + flush_signals(current); \ + _thr = kthread_create(_thread_fn, _data, _fmt, ##_args); \ + if (likely(!IS_ERR(_thr))) \ + break; \ + _err = PTR_ERR(_thr); \ + if (_err == -EAGAIN || _err == -EINTR) \ + continue; \ BRICK_ERR("cannot create thread '%s', status = %d\n", _fmt, _err); \ _thr = NULL; \ - } else { \ + break; \ + } \ + if (_thr) { \ struct say_channel *ch = get_binding(current); \ if (ch) \ bind_to_channel(ch, _thr); \