Skip to contentSkip to conversation

make kthread_worker_fn to be freezable

RFC NAK yalin wang 2 participants 5 messages Jun 1, 2015 – Jun 4, 2015 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

yalin wang

author
#1 lore raw

RFC 1/1 make kthread_worker_fn to be freezable

I notice that kthread_worker_fn() call try_to_freeze() function, but it don't make itself to be a freezable kthread, kthread default behavior is not freezable, we should change it if want try_to_freeze() work correctly.

---
 kernel/kthread.c | 1 +
 1 file changed, 1 insertion(+)
kernel/kthread.c +1 -0
index 10e489c..b20a21d 100644
@@ -550,6 +550,7 @@ int kthread_worker_fn(void *worker_ptr)
 
        WARN_ON(worker->task);
        worker->task = current;
+       set_freezable();
 repeat:
        set_current_state(TASK_INTERRUPTIBLE);  /* mb paired w/ kthread_stop */
 

--
1.9.1

Nacked-by on v1 1/1 NAK
#2 lore raw

Hello,

Quoted 6 lines · yalin wang

I notice that kthread_worker_fn() call try_to_freeze() function, but it don't make itself to be a freezable kthread, kthread default behavior is not freezable, we should change it if want try_to_freeze() work correctly.

Whether a kthread worker should be able to freeze or not is to be determined by the owner of the specific kthread. If the kthread is marked freezable, kthread_worker will freeze. If not, it won't.

Thanks.

Signature · 1 line
tejun
author
#3 lore raw

2015-06-01 19:40 GMT+08:00 Tejun Heo <[email protected]>:

Quoted 8 lines

Hello,

Quoted 5 lines · yalin wang

I notice that kthread_worker_fn() call try_to_freeze() function, but it don't make itself to be a freezable kthread, kthread default behavior is not freezable, we should change it if want try_to_freeze() work correctly.

Quoted 6 lines
Quoted 1 line

Whether a kthread worker should be able to freeze or not is to be determined by the owner of the specific kthread. If the kthread is marked freezable, kthread_worker will freeze. If not, it won't.

this means i need create kthread like this :

struct task_struct *kworker_task = kthread_run(kthread_worker_fn, &worker, "nvme%d", dev->instance);
kworker_task->flags &= ~PF_NOFREEZE;
is it safe to do like this ?

i don't see an API to set other thread to be freezable . only set_freezable() , which set the current thread to be freezable .

am i missing something ?
Thanks

#4 lore raw
Quoted 6 lines · yalin wang

this means i need create kthread like this :

struct task_struct *kworker_task = kthread_run(kthread_worker_fn, &worker, "nvme%d", dev->instance);
kworker_task->flags &= ~PF_NOFREEZE;
is it safe to do like this ?

It's not.

Quoted 2 lines

i don't see an API to set other thread to be freezable . only set_freezable() , which set the current thread to be freezable .

But you can create a wrapper kthread function which sets freezable and calls kthread_worker_fn().

Thanks.

Signature · 1 line
tejun
author
#5 lore raw

2015-06-03 13:20 GMT+08:00 Tejun Heo <[email protected]>:

Quoted 8 lines · yalin wang
Quoted 6 lines

this means i need create kthread like this :

struct task_struct *kworker_task = kthread_run(kthread_worker_fn, &worker, "nvme%d", dev->instance);
kworker_task->flags &= ~PF_NOFREEZE;
is it safe to do like this ?

Quoted 8 lines

It's not.

Quoted 2 lines

i don't see an API to set other thread to be freezable . only set_freezable() , which set the current thread to be freezable .

But you can create a wrapper kthread function which sets freezable and calls kthread_worker_fn().

oh, got it, i see your meaning,
Thanks a lot !