mirror of
https://github.com/schoebel/mars
synced 2025-03-25 04:26:49 +00:00
all: replace kthread by brick_thread wrapper
This commit is contained in:
parent
47040b5798
commit
fdd3b251c0
51
brick.c
51
brick.c
@ -31,6 +31,57 @@ int _brick_msleep(int msecs, bool shorten)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(_brick_msleep);
|
||||
|
||||
#if 1
|
||||
/* The following _could_ go to kernel/kthread.c.
|
||||
* However, we need it only for a workaround here.
|
||||
* This has some conceptual shortcomings, so I will not
|
||||
* force that.
|
||||
*/
|
||||
#if 1 // remove this for migration to kernel/kthread.c
|
||||
struct kthread {
|
||||
int should_stop;
|
||||
#ifdef KTHREAD_WORKER_INIT
|
||||
void *data;
|
||||
#endif
|
||||
struct completion exited;
|
||||
};
|
||||
#define to_kthread(tsk) \
|
||||
container_of((tsk)->vfork_done, struct kthread, exited)
|
||||
#endif
|
||||
/**
|
||||
* kthread_stop_nowait - like kthread_stop(), but don't wait for termination.
|
||||
* @k: thread created by kthread_create().
|
||||
*
|
||||
* If threadfn() may call do_exit() itself, the caller must ensure
|
||||
* task_struct can't go away.
|
||||
*
|
||||
* Therefore, you must not call this twice (or after kthread_stop()), at least
|
||||
* if you don't get_task_struct() yourself.
|
||||
*/
|
||||
void kthread_stop_nowait(struct task_struct *k)
|
||||
{
|
||||
struct kthread *kthread;
|
||||
|
||||
#if 0 // enable this after migration to kernel/kthread.c
|
||||
trace_sched_kthread_stop(k);
|
||||
#endif
|
||||
|
||||
kthread = to_kthread(k);
|
||||
barrier(); /* it might have exited */
|
||||
if (k->vfork_done != NULL) {
|
||||
kthread->should_stop = 1;
|
||||
wake_up_process(k);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(kthread_stop_nowait);
|
||||
#endif
|
||||
|
||||
void brick_thread_stop_nowait(struct task_struct *k)
|
||||
{
|
||||
kthread_stop_nowait(k);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(brick_thread_stop_nowait);
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// number management
|
||||
|
9
brick.h
9
brick.h
@ -5,6 +5,7 @@
|
||||
#include <linux/list.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/wait.h>
|
||||
#include <linux/kthread.h>
|
||||
|
||||
#include <asm/atomic.h>
|
||||
|
||||
@ -598,23 +599,31 @@ extern int set_recursive_button(struct generic_brick *brick, brick_switch_t mode
|
||||
BRICK_ERR("cannot create thread '%s', status = %d\n", _fmt, _err); \
|
||||
_thr = NULL; \
|
||||
} else { \
|
||||
struct say_channel *ch = get_binding(current); \
|
||||
if (ch) \
|
||||
bind_to_channel(ch, _thr); \
|
||||
get_task_struct(_thr); \
|
||||
wake_up_process(_thr); \
|
||||
} \
|
||||
_thr; \
|
||||
})
|
||||
|
||||
extern void brick_thread_stop_nowait(struct task_struct *k);
|
||||
|
||||
#define brick_thread_stop(_thread) \
|
||||
do { \
|
||||
if (likely(_thread)) { \
|
||||
BRICK_INF("stopping thread '%s'\n", (_thread)->comm); \
|
||||
kthread_stop(_thread); \
|
||||
BRICK_INF("thread '%s' finished.\n", (_thread)->comm); \
|
||||
remove_binding(_thread); \
|
||||
put_task_struct(_thread); \
|
||||
_thread = NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define brick_thread_should_stop kthread_should_stop
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// init
|
||||
|
82
mars_aio.c
82
mars_aio.c
@ -10,7 +10,6 @@
|
||||
#include <linux/list.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/blkdev.h>
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/wait.h>
|
||||
#include <linux/file.h>
|
||||
@ -353,63 +352,14 @@ int aio_start_thread(
|
||||
init_waitqueue_head(&tinfo->event);
|
||||
init_waitqueue_head(&tinfo->terminate_event);
|
||||
tinfo->terminated = false;
|
||||
tinfo->thread = kthread_create(fn, tinfo, "mars_aio_%c%d", class, output->index);
|
||||
if (IS_ERR(tinfo->thread)) {
|
||||
int err = PTR_ERR(tinfo->thread);
|
||||
tinfo->thread = brick_thread_create(fn, tinfo, "mars_aio_%c%d", class, output->index);
|
||||
if (unlikely(!tinfo->thread)) {
|
||||
MARS_ERR("cannot create thread\n");
|
||||
tinfo->thread = NULL;
|
||||
return err;
|
||||
return -ENOENT;
|
||||
}
|
||||
get_task_struct(tinfo->thread);
|
||||
wake_up_process(tinfo->thread);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 1
|
||||
/* The following _could_ go to kernel/kthread.c.
|
||||
* However, we need it only for a workaround here.
|
||||
* This has some conceptual shortcomings, so I will not
|
||||
* force that.
|
||||
*/
|
||||
#if 1 // remove this for migration to kernel/kthread.c
|
||||
struct kthread {
|
||||
int should_stop;
|
||||
#ifdef KTHREAD_WORKER_INIT
|
||||
void *data;
|
||||
#endif
|
||||
struct completion exited;
|
||||
};
|
||||
#define to_kthread(tsk) \
|
||||
container_of((tsk)->vfork_done, struct kthread, exited)
|
||||
#endif
|
||||
/**
|
||||
* kthread_stop_nowait - like kthread_stop(), but don't wait for termination.
|
||||
* @k: thread created by kthread_create().
|
||||
*
|
||||
* If threadfn() may call do_exit() itself, the caller must ensure
|
||||
* task_struct can't go away.
|
||||
*
|
||||
* Therefore, you must not call this twice (or after kthread_stop()), at least
|
||||
* if you don't get_task_struct() yourself.
|
||||
*/
|
||||
void kthread_stop_nowait(struct task_struct *k)
|
||||
{
|
||||
struct kthread *kthread;
|
||||
|
||||
#if 0 // enable this after migration to kernel/kthread.c
|
||||
trace_sched_kthread_stop(k);
|
||||
#endif
|
||||
|
||||
kthread = to_kthread(k);
|
||||
barrier(); /* it might have exited */
|
||||
if (k->vfork_done != NULL) {
|
||||
kthread->should_stop = 1;
|
||||
wake_up_process(k);
|
||||
}
|
||||
}
|
||||
//EXPORT_SYMBOL(kthread_stop_nowait);
|
||||
#endif
|
||||
|
||||
static
|
||||
void aio_stop_thread(struct aio_output *output, int i, bool do_submit_dummy)
|
||||
{
|
||||
@ -417,7 +367,7 @@ void aio_stop_thread(struct aio_output *output, int i, bool do_submit_dummy)
|
||||
|
||||
if (tinfo->thread) {
|
||||
MARS_INF("stopping thread %d ...\n", i);
|
||||
kthread_stop_nowait(tinfo->thread);
|
||||
brick_thread_stop_nowait(tinfo->thread);
|
||||
|
||||
// workaround for waking up the receiver thread. TODO: check whether signal handlong could do better.
|
||||
if (do_submit_dummy) {
|
||||
@ -432,11 +382,7 @@ void aio_stop_thread(struct aio_output *output, int i, bool do_submit_dummy)
|
||||
tinfo->terminated,
|
||||
(60 - i * 2) * HZ);
|
||||
if (likely(tinfo->terminated)) {
|
||||
//MARS_INF("finalizing thread %d ...\n", i);
|
||||
//kthread_stop(tinfo->thread);
|
||||
MARS_INF("thread %d finished.\n", i);
|
||||
put_task_struct(tinfo->thread);
|
||||
tinfo->thread = NULL;
|
||||
brick_thread_stop(tinfo->thread);
|
||||
} else {
|
||||
MARS_ERR("thread %d did not terminate - leaving a zombie\n", i);
|
||||
}
|
||||
@ -538,10 +484,10 @@ int aio_sync_thread(void *data)
|
||||
struct q_sync q_sync = {};
|
||||
#endif
|
||||
|
||||
MARS_INF("kthread has started on '%s'.\n", output->brick->brick_path);
|
||||
MARS_INF("sync thread has started on '%s'.\n", output->brick->brick_path);
|
||||
//set_user_nice(current, -20);
|
||||
|
||||
while (!kthread_should_stop() || tinfo->queued_sum > 0) {
|
||||
while (!brick_thread_should_stop() || tinfo->queued_sum > 0) {
|
||||
LIST_HEAD(tmp_list);
|
||||
unsigned long flags;
|
||||
int i;
|
||||
@ -579,7 +525,7 @@ int aio_sync_thread(void *data)
|
||||
#endif
|
||||
}
|
||||
|
||||
MARS_INF("kthread has stopped.\n");
|
||||
MARS_INF("sync thread has stopped.\n");
|
||||
tinfo->terminated = true;
|
||||
wake_up_interruptible_all(&tinfo->terminate_event);
|
||||
return 0;
|
||||
@ -592,7 +538,7 @@ static int aio_event_thread(void *data)
|
||||
struct aio_threadinfo *other = &output->tinfo[2];
|
||||
int err = -ENOMEM;
|
||||
|
||||
MARS_INF("kthread has started.\n");
|
||||
MARS_INF("event thread has started.\n");
|
||||
//set_user_nice(current, -20);
|
||||
|
||||
use_fake_mm();
|
||||
@ -603,7 +549,7 @@ static int aio_event_thread(void *data)
|
||||
if (unlikely(err < 0))
|
||||
goto err;
|
||||
|
||||
while (!kthread_should_stop() || tinfo->queued_sum > 0) {
|
||||
while (!brick_thread_should_stop() || tinfo->queued_sum > 0) {
|
||||
mm_segment_t oldfs;
|
||||
int count;
|
||||
int i;
|
||||
@ -656,7 +602,7 @@ static int aio_event_thread(void *data)
|
||||
err = 0;
|
||||
|
||||
err:
|
||||
MARS_INF("kthread has stopped, err = %d\n", err);
|
||||
MARS_INF("event thread has stopped, err = %d\n", err);
|
||||
|
||||
aio_stop_thread(output, 2, false);
|
||||
|
||||
@ -751,7 +697,7 @@ static int aio_submit_thread(void *data)
|
||||
output->fd = err;
|
||||
fd_install(err, file);
|
||||
|
||||
MARS_INF("kthread has started.\n");
|
||||
MARS_INF("submit thread has started.\n");
|
||||
//set_user_nice(current, -20);
|
||||
|
||||
use_fake_mm();
|
||||
@ -771,7 +717,7 @@ static int aio_submit_thread(void *data)
|
||||
if (unlikely(err < 0))
|
||||
goto cleanup_ctxp;
|
||||
|
||||
while (!kthread_should_stop() || atomic_read(&output->read_count) + atomic_read(&output->write_count) + tinfo->queued_sum > 0) {
|
||||
while (!brick_thread_should_stop() || atomic_read(&output->read_count) + atomic_read(&output->write_count) + tinfo->queued_sum > 0) {
|
||||
struct aio_mref_aspect *mref_a;
|
||||
struct mref_object *mref;
|
||||
int sleeptime;
|
||||
@ -858,7 +804,7 @@ static int aio_submit_thread(void *data)
|
||||
}
|
||||
}
|
||||
|
||||
MARS_INF("kthread has stopped.\n");
|
||||
MARS_INF("submit thread has stopped.\n");
|
||||
|
||||
aio_stop_thread(output, 1, true);
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/bio.h>
|
||||
#include <linux/kthread.h>
|
||||
|
||||
#include "mars.h"
|
||||
#include "lib_timing.h"
|
||||
@ -481,7 +480,7 @@ int bio_response_thread(void *data)
|
||||
int code;
|
||||
|
||||
if (list_empty(&tmp_list)) {
|
||||
if (kthread_should_stop())
|
||||
if (brick_thread_should_stop())
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
@ -575,7 +574,7 @@ int bio_submit_thread(void *data)
|
||||
|
||||
MARS_INF("bio submit thread has started on '%s'.\n", brick->brick_path);
|
||||
|
||||
while (!kthread_should_stop()) {
|
||||
while (!brick_thread_should_stop()) {
|
||||
int prio;
|
||||
#ifdef IO_DEBUGGING
|
||||
round++;
|
||||
|
10
mars_check.c
10
mars_check.c
@ -21,7 +21,6 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/kthread.h>
|
||||
|
||||
#include "mars.h"
|
||||
|
||||
@ -127,7 +126,7 @@ static int check_watchdog(void *data)
|
||||
{
|
||||
struct check_output *output = data;
|
||||
MARS_INF("watchdog has started.\n");
|
||||
while (!kthread_should_stop()) {
|
||||
while (!brick_thread_should_stop()) {
|
||||
struct list_head *h;
|
||||
unsigned long flags;
|
||||
unsigned long now;
|
||||
@ -270,15 +269,10 @@ static int check_output_construct(struct check_output *output)
|
||||
{
|
||||
static int count = 0;
|
||||
#ifdef CHECK_LOCK
|
||||
struct task_struct *watchdog;
|
||||
|
||||
spin_lock_init(&output->check_lock);
|
||||
INIT_LIST_HEAD(&output->mref_anchor);
|
||||
watchdog = kthread_create(check_watchdog, output, "check_watchdog%d", output->instance_nr);
|
||||
if (!IS_ERR(watchdog)) {
|
||||
output->watchdog = watchdog;
|
||||
wake_up_process(watchdog);
|
||||
}
|
||||
output->watchdog = brick_thread_create(check_watchdog, output, "check_watchdog%d", output->instance_nr);
|
||||
#endif
|
||||
output->instance_nr = ++count;
|
||||
return 0;
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/kthread.h>
|
||||
|
||||
#include "mars.h"
|
||||
|
||||
@ -24,10 +23,7 @@ static int thread_count = 0;
|
||||
static void _kill_thread(struct client_threadinfo *ti)
|
||||
{
|
||||
if (ti->thread) {
|
||||
MARS_INF("stopping thread...\n");
|
||||
kthread_stop(ti->thread);
|
||||
put_task_struct(ti->thread);
|
||||
ti->thread = NULL;
|
||||
brick_thread_stop(ti->thread);
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,16 +91,13 @@ static int _connect(struct client_output *output, const char *str)
|
||||
}
|
||||
output->socket.s_shutdown_on_err = true;
|
||||
|
||||
output->receiver.thread = kthread_create(receiver_thread, output, "mars_receiver%d", thread_count++);
|
||||
if (unlikely(IS_ERR(output->receiver.thread))) {
|
||||
status = PTR_ERR(output->receiver.thread);
|
||||
output->receiver.thread = brick_thread_create(receiver_thread, output, "mars_receiver%d", thread_count++);
|
||||
if (unlikely(!output->receiver.thread)) {
|
||||
MARS_ERR("cannot start receiver thread, status = %d\n", status);
|
||||
output->receiver.thread = NULL;
|
||||
status = -ENOENT;
|
||||
output->receiver.terminated = true;
|
||||
goto done;
|
||||
}
|
||||
get_task_struct(output->receiver.thread);
|
||||
wake_up_process(output->receiver.thread);
|
||||
|
||||
|
||||
{
|
||||
@ -250,7 +243,7 @@ int receiver_thread(void *data)
|
||||
struct client_output *output = data;
|
||||
int status = 0;
|
||||
|
||||
while (status >= 0 && mars_socket_is_alive(&output->socket) && !kthread_should_stop()) {
|
||||
while (status >= 0 && mars_socket_is_alive(&output->socket) && !brick_thread_should_stop()) {
|
||||
struct mars_cmd cmd = {};
|
||||
struct list_head *tmp;
|
||||
struct client_mref_aspect *mref_a = NULL;
|
||||
@ -429,7 +422,7 @@ static int sender_thread(void *data)
|
||||
|
||||
output->receiver.restart_count = 0;
|
||||
|
||||
while (!kthread_should_stop()) {
|
||||
while (!brick_thread_should_stop()) {
|
||||
struct list_head *tmp = NULL;
|
||||
struct client_mref_aspect *mref_a;
|
||||
struct mref_object *mref;
|
||||
@ -464,7 +457,7 @@ static int sender_thread(void *data)
|
||||
_do_timeout(output, &output->mref_list, false);
|
||||
}
|
||||
|
||||
wait_event_interruptible_timeout(output->event, !list_empty(&output->mref_list) || output->get_info || kthread_should_stop(), 1 * HZ);
|
||||
wait_event_interruptible_timeout(output->event, !list_empty(&output->mref_list) || output->get_info || brick_thread_should_stop(), 1 * HZ);
|
||||
|
||||
if (output->get_info) {
|
||||
status = _request_info(output);
|
||||
@ -547,17 +540,14 @@ static int client_switch(struct client_brick *brick)
|
||||
mars_power_led_off((void*)brick, false);
|
||||
if (output->sender.terminated) {
|
||||
output->sender.terminated = false;
|
||||
output->sender.thread = kthread_create(sender_thread, output, "mars_sender%d", thread_count++);
|
||||
if (unlikely(IS_ERR(output->sender.thread))) {
|
||||
status = PTR_ERR(output->sender.thread);
|
||||
MARS_ERR("cannot start sender thread, status = %d\n", status);
|
||||
output->sender.thread = NULL;
|
||||
output->sender.thread = brick_thread_create(sender_thread, output, "mars_sender%d", thread_count++);
|
||||
if (unlikely(!output->sender.thread)) {
|
||||
MARS_ERR("cannot start sender thread\n");
|
||||
output->sender.terminated = true;
|
||||
status = -ENOENT;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
get_task_struct(output->sender.thread);
|
||||
wake_up_process(output->sender.thread);
|
||||
if (!output->sender.terminated) {
|
||||
mars_power_led_on((void*)brick, true);
|
||||
}
|
||||
|
11
mars_copy.c
11
mars_copy.c
@ -9,7 +9,6 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/kthread.h>
|
||||
|
||||
#include "mars.h"
|
||||
#include "lib_limiter.h"
|
||||
@ -582,7 +581,7 @@ int _run_copy(struct copy_brick *brick)
|
||||
static
|
||||
bool _is_done(struct copy_brick *brick)
|
||||
{
|
||||
if (kthread_should_stop())
|
||||
if (brick_thread_should_stop())
|
||||
brick->is_aborting = true;
|
||||
return brick->is_aborting &&
|
||||
atomic_read(&brick->copy_flight) <= 0;
|
||||
@ -684,11 +683,9 @@ static int copy_switch(struct copy_brick *brick)
|
||||
brick->is_aborting = false;
|
||||
if (!brick->thread) {
|
||||
brick->copy_last = brick->copy_start;
|
||||
brick->thread = kthread_create(_copy_thread, brick, "mars_copy%d", version++);
|
||||
brick->thread = brick_thread_create(_copy_thread, brick, "mars_copy%d", version++);
|
||||
if (brick->thread) {
|
||||
get_task_struct(brick->thread);
|
||||
brick->trigger = true;
|
||||
wake_up_process(brick->thread);
|
||||
} else {
|
||||
mars_power_led_off((void*)brick, true);
|
||||
MARS_ERR("could not start copy thread\n");
|
||||
@ -698,9 +695,7 @@ static int copy_switch(struct copy_brick *brick)
|
||||
mars_power_led_on((void*)brick, false);
|
||||
if (brick->thread) {
|
||||
MARS_INF("stopping thread...\n");
|
||||
kthread_stop(brick->thread);
|
||||
put_task_struct(brick->thread);
|
||||
brick->thread = NULL;
|
||||
brick_thread_stop(brick->thread);
|
||||
wake_up_interruptible(&brick->event);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/kthread.h>
|
||||
|
||||
#include "mars.h"
|
||||
#include "mars_net.h"
|
||||
@ -314,7 +313,7 @@ int _mars_send_raw(struct mars_socket *msock, void *buf, int len)
|
||||
while (len > 0) {
|
||||
int this_len = len;
|
||||
|
||||
if (!mars_net_is_alive || kthread_should_stop()) {
|
||||
if (!mars_net_is_alive || brick_thread_should_stop()) {
|
||||
MARS_WRN("interrupting, sent = %d\n", sent);
|
||||
status = -EIDRM;
|
||||
break;
|
||||
@ -487,7 +486,7 @@ int mars_recv_raw(struct mars_socket *msock, void *buf, int minlen, int maxlen)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!mars_net_is_alive || kthread_should_stop()) {
|
||||
if (!mars_net_is_alive || brick_thread_should_stop()) {
|
||||
MARS_WRN("#%d interrupting, done = %d\n", msock->s_debug_nr, done);
|
||||
if (done > 0)
|
||||
status = -EIDRM;
|
||||
@ -500,7 +499,7 @@ int mars_recv_raw(struct mars_socket *msock, void *buf, int minlen, int maxlen)
|
||||
|
||||
MARS_IO("#%d status = %d\n", msock->s_debug_nr, status);
|
||||
|
||||
if (!mars_net_is_alive || kthread_should_stop()) {
|
||||
if (!mars_net_is_alive || brick_thread_should_stop()) {
|
||||
MARS_WRN("#%d interrupting, done = %d\n", msock->s_debug_nr, done);
|
||||
if (done > 0)
|
||||
status = -EIDRM;
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/kthread.h>
|
||||
|
||||
#define _STRATEGY
|
||||
#include "mars.h"
|
||||
@ -45,7 +44,7 @@ int cb_thread(void *data)
|
||||
if (!ok)
|
||||
goto done;
|
||||
|
||||
while (!kthread_should_stop() || !list_empty(&brick->cb_read_list) || !list_empty(&brick->cb_write_list) || atomic_read(&brick->in_flight) > 0) {
|
||||
while (!brick_thread_should_stop() || !list_empty(&brick->cb_read_list) || !list_empty(&brick->cb_write_list) || atomic_read(&brick->in_flight) > 0) {
|
||||
struct server_mref_aspect *mref_a;
|
||||
struct mref_object *mref;
|
||||
struct list_head *tmp;
|
||||
@ -293,7 +292,7 @@ int handler_thread(void *data)
|
||||
wake_up_interruptible(&brick->startup_event);
|
||||
|
||||
MARS_DBG("--------------- handler_thread starting on socket %p\n", sock);
|
||||
while (brick->cb_running && !sock->s_dead && !kthread_should_stop()) {
|
||||
while (brick->cb_running && !sock->s_dead && !brick_thread_should_stop()) {
|
||||
struct mars_cmd cmd = {};
|
||||
|
||||
status = mars_recv_struct(sock, &cmd, mars_cmd_meta);
|
||||
@ -418,12 +417,7 @@ int handler_thread(void *data)
|
||||
MARS_DBG("handler_thread terminating, status = %d\n", status);
|
||||
if (cb_thread) {
|
||||
MARS_INF("stopping cb thread...\n");
|
||||
kthread_stop(cb_thread);
|
||||
wait_event_interruptible_timeout(
|
||||
brick->startup_event,
|
||||
!brick->cb_running,
|
||||
10 * HZ);
|
||||
put_task_struct(cb_thread);
|
||||
brick_thread_stop(cb_thread);
|
||||
}
|
||||
|
||||
_clean_list(brick, &brick->cb_read_list);
|
||||
@ -488,7 +482,6 @@ static int server_switch(struct server_brick *brick)
|
||||
int status = 0;
|
||||
if (brick->power.button) {
|
||||
static int version = 0;
|
||||
struct task_struct *thread;
|
||||
|
||||
mars_power_led_off((void*)brick, false);
|
||||
|
||||
@ -498,26 +491,20 @@ static int server_switch(struct server_brick *brick)
|
||||
list_add(&brick->server_link, &server_list);
|
||||
spin_unlock(&server_lock);
|
||||
|
||||
thread = kthread_create(cb_thread, brick, "mars_cb%d", version);
|
||||
if (IS_ERR(thread)) {
|
||||
status = PTR_ERR(thread);
|
||||
MARS_ERR("cannot create cb thread, status = %d\n", status);
|
||||
brick->cb_thread = brick_thread_create(cb_thread, brick, "mars_cb%d", version);
|
||||
if (unlikely(!brick->cb_thread)) {
|
||||
MARS_ERR("cannot create cb thread\n");
|
||||
status = -ENOENT;
|
||||
goto err;
|
||||
}
|
||||
get_task_struct(thread);
|
||||
brick->cb_thread = thread;
|
||||
wake_up_process(thread);
|
||||
|
||||
thread = kthread_create(handler_thread, brick, "mars_handler%d", version++);
|
||||
if (IS_ERR(thread)) {
|
||||
status = PTR_ERR(thread);
|
||||
MARS_ERR("cannot create handler thread, status = %d\n", status);
|
||||
kthread_stop(brick->cb_thread);
|
||||
brick->handler_thread = brick_thread_create(handler_thread, brick, "mars_handler%d", version++);
|
||||
if (unlikely(!brick->handler_thread)) {
|
||||
MARS_ERR("cannot create handler thread\n");
|
||||
brick_thread_stop(brick->cb_thread);
|
||||
status = -ENOENT;
|
||||
goto err;
|
||||
}
|
||||
get_task_struct(thread);
|
||||
brick->handler_thread = thread;
|
||||
wake_up_process(thread);
|
||||
|
||||
wait_event_interruptible(brick->startup_event, brick->cb_thread == NULL);
|
||||
|
||||
@ -534,10 +521,9 @@ static int server_switch(struct server_brick *brick)
|
||||
if (thread) {
|
||||
brick->handler_thread = NULL;
|
||||
MARS_INF("stopping handler thread....\n");
|
||||
kthread_stop(thread);
|
||||
brick_thread_stop(thread);
|
||||
if (sock->s_socket)
|
||||
mars_put_socket(sock);
|
||||
put_task_struct(thread);
|
||||
} else {
|
||||
MARS_WRN("handler thread does not exist\n");
|
||||
}
|
||||
@ -667,7 +653,7 @@ static int _server_thread(void *data)
|
||||
|
||||
MARS_INF("-------- server starting on host '%s' ----------\n", id);
|
||||
|
||||
while (!kthread_should_stop() &&
|
||||
while (!brick_thread_should_stop() &&
|
||||
(!mars_global || !mars_global->global_power.button)) {
|
||||
MARS_DBG("system did not start up\n");
|
||||
brick_msleep(5000);
|
||||
@ -675,7 +661,7 @@ static int _server_thread(void *data)
|
||||
|
||||
MARS_INF("-------- server now working on host '%s' ----------\n", id);
|
||||
|
||||
while (!kthread_should_stop() && mars_global && mars_global->global_power.button) {
|
||||
while (!brick_thread_should_stop() && mars_global && mars_global->global_power.button) {
|
||||
|
||||
if (!brick) {
|
||||
brick = (void*)mars_make_brick(mars_global, NULL, true, &server_brick_type, "server", "server");
|
||||
@ -702,7 +688,7 @@ static int _server_thread(void *data)
|
||||
/* TODO: check authorization.
|
||||
*/
|
||||
|
||||
if (!mars_global || !mars_global->global_power.button || kthread_should_stop()) {
|
||||
if (!mars_global || !mars_global->global_power.button || brick_thread_should_stop()) {
|
||||
MARS_WRN("system is not alive\n");
|
||||
goto err;
|
||||
}
|
||||
@ -782,12 +768,10 @@ EXPORT_SYMBOL_GPL(server_limiter);
|
||||
int __init init_mars_server(void)
|
||||
{
|
||||
struct sockaddr_storage sockaddr = {};
|
||||
struct task_struct *thread;
|
||||
int status;
|
||||
|
||||
MARS_INF("init_server()\n");
|
||||
|
||||
#if 1
|
||||
status = mars_create_sockaddr(&sockaddr, "");
|
||||
if (status < 0)
|
||||
return status;
|
||||
@ -798,18 +782,12 @@ int __init init_mars_server(void)
|
||||
return status;
|
||||
}
|
||||
|
||||
thread = kthread_create(_server_thread, NULL, "mars_server");
|
||||
if (IS_ERR(thread)) {
|
||||
status = PTR_ERR(thread);
|
||||
server_thread = brick_thread_create(_server_thread, NULL, "mars_server");
|
||||
if (unlikely(!server_thread)) {
|
||||
mars_put_socket(&server_socket);
|
||||
return status;
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
get_task_struct(thread);
|
||||
server_thread = thread;
|
||||
wake_up_process(thread);
|
||||
#endif
|
||||
|
||||
return server_register_brick_type();
|
||||
}
|
||||
|
||||
@ -819,9 +797,7 @@ void __exit exit_mars_server(void)
|
||||
server_unregister_brick_type();
|
||||
if (server_thread) {
|
||||
MARS_INF("stopping server thread...\n");
|
||||
kthread_stop(server_thread);
|
||||
put_task_struct(server_thread);
|
||||
server_thread = NULL;
|
||||
brick_thread_stop(server_thread);
|
||||
mars_put_socket(&server_socket);
|
||||
}
|
||||
}
|
||||
|
26
mars_sio.c
26
mars_sio.c
@ -14,7 +14,6 @@
|
||||
#include <linux/types.h>
|
||||
#include <linux/blkdev.h>
|
||||
#include <linux/highmem.h>
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/wait.h>
|
||||
#include <linux/splice.h>
|
||||
@ -427,10 +426,10 @@ static int sio_thread(void *data)
|
||||
{
|
||||
struct sio_threadinfo *tinfo = data;
|
||||
|
||||
MARS_INF("kthread has started.\n");
|
||||
MARS_INF("sio thread has started.\n");
|
||||
//set_user_nice(current, -20);
|
||||
|
||||
while (!kthread_should_stop()) {
|
||||
while (!brick_thread_should_stop()) {
|
||||
struct list_head *tmp = NULL;
|
||||
struct mref_object *mref;
|
||||
struct sio_mref_aspect *mref_a;
|
||||
@ -438,7 +437,7 @@ static int sio_thread(void *data)
|
||||
|
||||
wait_event_interruptible_timeout(
|
||||
tinfo->event,
|
||||
!list_empty(&tinfo->mref_list) || kthread_should_stop(),
|
||||
!list_empty(&tinfo->mref_list) || brick_thread_should_stop(),
|
||||
HZ);
|
||||
|
||||
tinfo->last_jiffies = jiffies;
|
||||
@ -462,7 +461,7 @@ static int sio_thread(void *data)
|
||||
_sio_ref_io(tinfo, mref);
|
||||
}
|
||||
|
||||
MARS_INF("kthread has stopped.\n");
|
||||
MARS_INF("sio thread has stopped.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -595,16 +594,11 @@ static int sio_switch(struct sio_brick *brick)
|
||||
struct sio_threadinfo *tinfo = &output->tinfo[index];
|
||||
|
||||
tinfo->last_jiffies = jiffies;
|
||||
tinfo->thread = kthread_create(sio_thread, tinfo, "mars_sio%d", sio_nr++);
|
||||
if (IS_ERR(tinfo->thread)) {
|
||||
int error = PTR_ERR(tinfo->thread);
|
||||
MARS_ERR("cannot create thread, status=%d\n", error);
|
||||
filp_close(output->filp, NULL);
|
||||
output->filp = NULL;
|
||||
return error;
|
||||
tinfo->thread = brick_thread_create(sio_thread, tinfo, "mars_sio%d", sio_nr++);
|
||||
if (unlikely(!tinfo->thread)) {
|
||||
MARS_ERR("cannot create thread\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
get_task_struct(tinfo->thread);
|
||||
wake_up_process(tinfo->thread);
|
||||
}
|
||||
mars_power_led_on((void*)brick, true);
|
||||
} else {
|
||||
@ -614,9 +608,7 @@ static int sio_switch(struct sio_brick *brick)
|
||||
for (index = 0; index <= WITH_THREAD; index++) {
|
||||
struct sio_threadinfo *tinfo = &output->tinfo[index];
|
||||
MARS_DBG("stopping thread %d\n", index);
|
||||
kthread_stop(tinfo->thread);
|
||||
put_task_struct(tinfo->thread);
|
||||
tinfo->thread = NULL;
|
||||
brick_thread_stop(tinfo->thread);
|
||||
}
|
||||
MARS_DBG("closing file\n");
|
||||
filp_close(output->filp, NULL);
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/bio.h>
|
||||
#include <linux/kthread.h>
|
||||
|
||||
#include "mars.h"
|
||||
#include "lib_rank.h"
|
||||
@ -2274,7 +2273,7 @@ void trans_logger_log(struct trans_logger_brick *brick)
|
||||
|
||||
mars_power_led_on((void*)brick, true);
|
||||
|
||||
while (!kthread_should_stop() || _congested(brick)) {
|
||||
while (!brick_thread_should_stop() || _congested(brick)) {
|
||||
int winner;
|
||||
int nr;
|
||||
|
||||
@ -2526,7 +2525,7 @@ void trans_logger_replay(struct trans_logger_brick *brick)
|
||||
int len = 0;
|
||||
|
||||
finished_pos = input->logst.log_pos + input->logst.offset;
|
||||
if (kthread_should_stop() ||
|
||||
if (brick_thread_should_stop() ||
|
||||
(!brick->continuous_replay_mode && finished_pos >= brick->replay_end_pos)) {
|
||||
status = 0; // treat as EOF
|
||||
break;
|
||||
@ -2553,7 +2552,7 @@ void trans_logger_replay(struct trans_logger_brick *brick)
|
||||
MARS_RPL("read %lld %lld\n", finished_pos, new_finished_pos);
|
||||
|
||||
if ((!status && len <= 0) ||
|
||||
new_finished_pos > brick->replay_end_pos) { // EOF -> wait until kthread_should_stop()
|
||||
new_finished_pos > brick->replay_end_pos) { // EOF -> wait until brick_thread_should_stop()
|
||||
MARS_DBG("EOF at %lld (old = %lld, end_pos = %lld)\n", new_finished_pos, finished_pos, brick->replay_end_pos);
|
||||
if (!brick->continuous_replay_mode) {
|
||||
// notice: finished_pos remains at old value here!
|
||||
@ -2615,7 +2614,7 @@ void trans_logger_replay(struct trans_logger_brick *brick)
|
||||
|
||||
mars_trigger();
|
||||
|
||||
while (!kthread_should_stop()) {
|
||||
while (!brick_thread_should_stop()) {
|
||||
brick_msleep(500);
|
||||
}
|
||||
}
|
||||
@ -2652,23 +2651,17 @@ int trans_logger_switch(struct trans_logger_brick *brick)
|
||||
if (!brick->thread && brick->power.led_off) {
|
||||
mars_power_led_off((void*)brick, false);
|
||||
|
||||
brick->thread = kthread_create(trans_logger_thread, output, "mars_logger%d", index++);
|
||||
if (IS_ERR(brick->thread)) {
|
||||
int error = PTR_ERR(brick->thread);
|
||||
MARS_ERR("cannot create thread, status=%d\n", error);
|
||||
brick->thread = NULL;
|
||||
return error;
|
||||
brick->thread = brick_thread_create(trans_logger_thread, output, "mars_logger%d", index++);
|
||||
if (unlikely(!brick->thread)) {
|
||||
MARS_ERR("cannot create logger thread\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
get_task_struct(brick->thread);
|
||||
wake_up_process(brick->thread);
|
||||
}
|
||||
} else {
|
||||
mars_power_led_on((void*)brick, false);
|
||||
if (brick->thread) {
|
||||
MARS_INF("stopping thread...\n");
|
||||
kthread_stop(brick->thread);
|
||||
put_task_struct(brick->thread);
|
||||
brick->thread = NULL;
|
||||
brick_thread_stop(brick->thread);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "strategy.h"
|
||||
#include "../buildtag.h"
|
||||
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/wait.h>
|
||||
|
||||
// used brick types
|
||||
@ -1044,7 +1043,7 @@ int peer_thread(void *data)
|
||||
|
||||
atomic_inc(&peer_thread_count);
|
||||
|
||||
while (!kthread_should_stop()) {
|
||||
while (!brick_thread_should_stop()) {
|
||||
LIST_HEAD(tmp_list);
|
||||
LIST_HEAD(old_list);
|
||||
unsigned long flags;
|
||||
@ -1125,7 +1124,7 @@ int peer_thread(void *data)
|
||||
}
|
||||
|
||||
brick_msleep(1000);
|
||||
if (!kthread_should_stop()) {
|
||||
if (!brick_thread_should_stop()) {
|
||||
if (pause_time < CONFIG_MARS_PROPAGATE_INTERVAL)
|
||||
pause_time++;
|
||||
wait_event_interruptible_timeout(remote_event,
|
||||
@ -1173,9 +1172,7 @@ static int _kill_peer(void *buf, struct mars_dent *dent)
|
||||
|
||||
MARS_INF("stopping peer thread...\n");
|
||||
if (peer->peer_thread) {
|
||||
kthread_stop(peer->peer_thread);
|
||||
put_task_struct(peer->peer_thread);
|
||||
peer->peer_thread = NULL;
|
||||
brick_thread_stop(peer->peer_thread);
|
||||
}
|
||||
traced_lock(&peer->lock, flags);
|
||||
list_replace_init(&peer->remote_dent_list, &tmp_list);
|
||||
@ -1227,15 +1224,12 @@ static int _make_peer(struct mars_global *global, struct mars_dent *dent, char *
|
||||
|
||||
peer = dent->d_private;
|
||||
if (!peer->peer_thread) {
|
||||
peer->peer_thread = kthread_create(peer_thread, peer, "mars_peer%d", serial++);
|
||||
if (unlikely(IS_ERR(peer->peer_thread))) {
|
||||
MARS_ERR("cannot start peer thread, status = %d\n", (int)PTR_ERR(peer->peer_thread));
|
||||
peer->peer_thread = NULL;
|
||||
peer->peer_thread = brick_thread_create(peer_thread, peer, "mars_peer%d", serial++);
|
||||
if (unlikely(!peer->peer_thread)) {
|
||||
MARS_ERR("cannot start peer thread\n");
|
||||
return -1;
|
||||
}
|
||||
MARS_DBG("starting peer thread\n");
|
||||
get_task_struct(peer->peer_thread);
|
||||
wake_up_process(peer->peer_thread);
|
||||
MARS_DBG("started peer thread\n");
|
||||
}
|
||||
|
||||
/* This must be called by the main thread in order to
|
||||
@ -3854,7 +3848,7 @@ static int light_thread(void *data)
|
||||
|
||||
brick_msleep(100);
|
||||
|
||||
if (kthread_should_stop()) {
|
||||
if (brick_thread_should_stop()) {
|
||||
_global.global_power.button = false;
|
||||
mars_net_is_alive = false;
|
||||
}
|
||||
@ -3938,7 +3932,6 @@ done:
|
||||
#endif
|
||||
|
||||
mars_global = NULL;
|
||||
main_thread = NULL;
|
||||
|
||||
MARS_INF("-------- done status = %d ----------\n", status);
|
||||
//cleanup_mm();
|
||||
@ -3982,18 +3975,13 @@ EXPORT_SYMBOL_GPL(_mars_remote_trigger);
|
||||
|
||||
static void __exit exit_light(void)
|
||||
{
|
||||
struct task_struct *thread;
|
||||
|
||||
MARS_DBG("====================== stopping everything...\n");
|
||||
// TODO: make this thread-safe.
|
||||
thread = main_thread;
|
||||
if (thread) {
|
||||
main_thread = NULL;
|
||||
if (main_thread) {
|
||||
MARS_DBG("=== stopping light thread...\n");
|
||||
MARS_INF("stopping thread...\n");
|
||||
mars_trigger();
|
||||
kthread_stop(thread);
|
||||
put_task_struct(thread);
|
||||
MARS_INF("stopping main thread...\n");
|
||||
brick_thread_stop(main_thread);
|
||||
}
|
||||
|
||||
_mars_remote_trigger = NULL;
|
||||
@ -4021,7 +4009,6 @@ EXPORT_SYMBOL_GPL(global_free_space);
|
||||
static int __init init_light(void)
|
||||
{
|
||||
int status = 0;
|
||||
struct task_struct *thread;
|
||||
|
||||
init_say(); // this must come first
|
||||
|
||||
@ -4055,14 +4042,11 @@ static int __init init_light(void)
|
||||
|
||||
brick_mem_reserve(&global_reserve);
|
||||
|
||||
thread = kthread_create(light_thread, NULL, "mars_light");
|
||||
if (IS_ERR(thread)) {
|
||||
status = PTR_ERR(thread);
|
||||
main_thread = brick_thread_create(light_thread, NULL, "mars_light");
|
||||
if (unlikely(!main_thread)) {
|
||||
status = -ENOENT;
|
||||
goto done;
|
||||
}
|
||||
get_task_struct(thread);
|
||||
main_thread = thread;
|
||||
wake_up_process(thread);
|
||||
|
||||
done:
|
||||
if (status < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user