Commit 4f82c32b authored by Philippe Gerum's avatar Philippe Gerum
Browse files

evl/thread: allow passing user-defined arg to kthread



We need more flexibility in the argument passed to the thread
function. Change for an opaque pointer passed to evl_run_kthread() and
variants instead of the current kthread descriptor.
Signed-off-by: default avatarPhilippe Gerum <rpm@xenomai.org>
parent 5d0d91c3
......@@ -394,13 +394,12 @@ static int rtswitch_register_task(struct rtswitch_context *ctx,
return 0;
}
static void rtswitch_kthread(struct evl_kthread *kthread)
static void rtswitch_kthread(void *arg)
{
struct rtswitch_task *task = arg;
struct rtswitch_context *ctx;
struct rtswitch_task *task;
unsigned int to, i = 0;
task = container_of(kthread, struct rtswitch_task, kthread);
ctx = task->ctx;
to = task->base.index;
......@@ -443,7 +442,7 @@ static int rtswitch_create_kthread(struct rtswitch_context *ctx,
task = &ctx->tasks[ptask->index];
task->ctx = ctx;
err = evl_run_kthread_on_cpu(&task->kthread, ctx->cpu,
rtswitch_kthread, 1,
rtswitch_kthread, task, 1,
EVL_CLONE_PUBLIC,
"rtk%d@%u:%d",
ptask->index, ctx->cpu,
......
......@@ -439,14 +439,12 @@ static struct latmus_runner *create_sirq_runner(int cpu)
return &sirq_runner->runner;
}
void kthread_handler(struct evl_kthread *kthread)
void kthread_handler(void *arg)
{
struct kthread_runner *k_runner;
struct kthread_runner *k_runner = arg;
ktime_t now;
int ret = 0;
k_runner = container_of(kthread, struct kthread_runner, kthread);
for (;;) {
if (evl_kthread_should_stop())
break;
......@@ -542,7 +540,7 @@ create_kthread_runner(int priority, int cpu)
evl_init_flag(&k_runner->barrier);
ret = evl_run_kthread_on_cpu(&k_runner->kthread, cpu,
kthread_handler,
kthread_handler, k_runner,
priority,
EVL_CLONE_PUBLIC,
"latmus-klat:%d",
......
......@@ -329,15 +329,16 @@ int activate_oob_mm_state(struct oob_mm_state *p);
struct evl_kthread {
struct evl_thread thread;
struct completion done;
void (*threadfn)(struct evl_kthread *kthread);
void (*threadfn)(void *arg);
int status;
void *arg;
struct irq_work irq_work;
};
int __evl_run_kthread(struct evl_kthread *kthread, int clone_flags);
#define _evl_run_kthread(__kthread, __affinity, __fn, __priority, \
__clone_flags, __fmt, __args...) \
#define _evl_run_kthread(__kthread, __affinity, __fn, __arg, \
__priority, __clone_flags, __fmt, __args...) \
({ \
int __ret; \
struct evl_init_thread_attr __iattr = { \
......@@ -348,6 +349,7 @@ int __evl_run_kthread(struct evl_kthread *kthread, int clone_flags);
.sched_param.fifo.prio = __priority, \
}; \
(__kthread)->threadfn = __fn; \
(__kthread)->arg = __arg; \
(__kthread)->status = 0; \
init_completion(&(__kthread)->done); \
__ret = evl_init_thread(&(__kthread)->thread, &__iattr, \
......@@ -357,15 +359,15 @@ int __evl_run_kthread(struct evl_kthread *kthread, int clone_flags);
__ret; \
})
#define evl_run_kthread(__kthread, __fn, __priority, \
#define evl_run_kthread(__kthread, __fn, __arg, __priority, \
__clone_flags, __fmt, __args...) \
_evl_run_kthread(__kthread, &evl_oob_cpus, __fn, __priority, \
__clone_flags, __fmt, ##__args)
_evl_run_kthread(__kthread, &evl_oob_cpus, __fn, __arg, \
__priority, __clone_flags, __fmt, ##__args)
#define evl_run_kthread_on_cpu(__kthread, __cpu, __fn, __priority, \
__clone_flags, __fmt, __args...) \
_evl_run_kthread(__kthread, cpumask_of(__cpu), __fn, __priority, \
__clone_flags, __fmt, ##__args)
#define evl_run_kthread_on_cpu(__kthread, __cpu, __fn, __arg, \
__priority, __clone_flags, __fmt, __args...) \
_evl_run_kthread(__kthread, cpumask_of(__cpu), __fn, __arg, \
__priority, __clone_flags, __fmt, ##__args)
void evl_set_kthread_priority(struct evl_kthread *kthread,
int priority);
......
......@@ -428,7 +428,7 @@ static int kthread_trampoline(void *arg)
ret = map_kthread_self(kthread);
if (!ret) {
trace_evl_kthread_entry(curr);
kthread->threadfn(kthread);
kthread->threadfn(kthread->arg);
}
/* Handles nitty-gritty details like in-band switch. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment