kthread: saa7134-tvaudio.c
PATCH 1/1 kthread: saa7134-tvaudio.c
Replace kernel_thread() with kthread_run() since kernel_thread() is deprecated in drivers/modules.
Note that this driver, like a few others, allows SIGTERM. Not sure if that is affected by conversion to kthread. Appreciate any comments on that.
drivers/media/video/saa7134/saa7134-tvaudio.c | 33 ++++++++++++-------------- drivers/media/video/saa7134/saa7134.h | 4 --- 2 files changed, 17 insertions(+), 20 deletions(-)
drivers/media/video/saa7134/saa7134.h +1 -3
@@ -311,10 +311,8 @@ struct saa7134_pgtable {/* tvaudio thread status */ struct saa7134_thread { -pid_t pid; -struct completion exit; +struct task_struct * task;wait_queue_head_t wq; -unsigned int shutdown;unsigned int scan1;unsigned int scan2;unsigned int mode;
drivers/media/video/saa7134/saa7134-tvaudio.c +16 -17
@@ -28,6 +28,7 @@#include <linux/slab.h> #include <linux/delay.h> #include <linux/smp_lock.h> +#include <linux/kthread.h> #include <asm/div64.h> #include "saa7134-reg.h"
@@ -357,7 +358,7 @@ static int tvaudio_sleep(struct saa7134_DECLARE_WAITQUEUE (wait, current);add_wait_queue (&dev->thread.wq, &wait); -if (dev->thread.scan1 == dev->thread.scan2 && !dev->thread.shutdown) { +if (dev->thread.scan1 == dev->thread.scan2 && !kthread_should_stop ()) {if (timeout <0 ) {set_current_state (TASK_INTERRUPTIBLE );schedule ();
@@ -525,7 +526,7 @@ static int tvaudio_thread(void *data)allow_signal (SIGTERM );for (;;) {tvaudio_sleep (dev,-1 ); -if (dev->thread.shutdown ||signal_pending (current)) +if (kthread_should_stop () ||signal_pending (current)) goto done; restart:
@@ -633,7 +634,7 @@ static int tvaudio_thread(void *data)for (;;) {if (tvaudio_sleep (dev,5000 )) goto restart; -if (dev->thread.shutdown ||signal_pending (current)) +if (kthread_should_stop () ||signal_pending (current))break ;if (UNSET == dev->thread.mode) { rx =tvaudio_getstereo (dev,&tvaudio[i]);
@@ -649,7 +650,6 @@ static int tvaudio_thread(void *data) } done: -complete_and_exit (&dev->thread.exit,0 );return 0 ; }
@@ -798,7 +798,6 @@ static int tvaudio_thread_ddep(void *datstruct saa7134_dev *dev = data;u32 value, norms, clock; -daemonize ("%s" , dev->name);allow_signal (SIGTERM ); clock = saa7134_boards[dev->board].audio_clock;
@@ -812,7 +811,7 @@ static int tvaudio_thread_ddep(void *datfor (;;) {tvaudio_sleep (dev,-1 ); -if (dev->thread.shutdown ||signal_pending (current)) +if (kthread_should_stop () ||signal_pending (current)) goto done; restart:
@@ -894,7 +893,6 @@ static int tvaudio_thread_ddep(void *dat } done: -complete_and_exit (&dev->thread.exit,0 );return 0 ; }
@@ -1004,15 +1002,16 @@ int saa7134_tvaudio_init2(struct saa7134break ; } - dev->thread.pid =-1 ; + dev->thread.task =NULL ;if (my_thread) {/* start tvaudio thread */ init_waitqueue_head (&dev->thread.wq); -init_completion (&dev->thread.exit); - dev->thread.pid =kernel_thread (my_thread,dev,0 ); -if (dev->thread.pid <0 ) + dev->thread.task =kthread_run (my_thread,dev,dev->name); +if (IS_ERR (dev->thread.task)) {printk (KERN_WARNING "%s: kernel_thread() failed\n" , - dev->name); + dev->name); + dev->thread.task =NULL ; + }saa7134_tvaudio_do_scan (dev); }
@@ -1023,10 +1022,10 @@ int saa7134_tvaudio_init2(struct saa7134int saa7134_tvaudio_fini (struct saa7134_dev *dev) {/* shutdown tvaudio thread */ -if (dev->thread.pid >=0 ) { - dev->thread.shutdown =1 ; -wake_up_interruptible (&dev->thread.wq); -wait_for_completion (&dev->thread.exit); +if (dev->thread.task) { +/* kthread_stop() wakes up the thread */ +kthread_stop (dev->thread.task); + dev->thread.task =NULL ; }saa_andorb (SAA7134_ANALOG_IO_SELECT ,0x07 ,0x00 );/* LINE1 */ return 0 ;
@@ -1034,7 +1033,7 @@ int saa7134_tvaudio_fini(struct saa7134_int saa7134_tvaudio_do_scan (struct saa7134_dev *dev) { -if (dev->thread.pid >=0 ) { +if (dev->thread.task) { dev->thread.mode =UNSET ; dev->thread.scan2++;wake_up_interruptible (&dev->thread.wq);
drivers/media/video/saa7134/saa7134-tvaudio.c int saa7134_tvaudio_init2(struct saa7134 · line 1006
Quoted 7 lines · Sukadev Bhattiprolu
drivers/media/video/saa7134/saa7134-tvaudio.c +1
-1@@ -1004,15 +1002,16 @@ int saa7134_tvaudio_init2(struct saa7134break ; } - dev->thread.pid =-1 ; + dev->thread.task =NULL ;if (my_thread) {
...
This is _really_ minor, but I think dev is kzmalloc()'d. I haven't examined it closely enough to tell if these devices get reused, but this one _might_ be unnecessary. Certainly no big deal either way, and it certainly doesn't make anything worse.
-- Dave
Quoted 8 lines · On Tue, 29 Aug 2006 14:15:55 -0700 Sukadev Bhattiprolu <[email protected]>…
Replace
kernel_thread()withkthread_run()sincekernel_thread()is deprecated indrivers/modules.Note that this driver, like a few others, allows SIGTERM. Not sure if that is affected by conversion to kthread. Appreciate any comments on that.
hm, I think this driver needs more help.
- It shouldn't be using signals at all, really. Signals are for userspace IPC. The kernel internally has better/richer/faster/tighter ways of inter-thread communication.
- saa7134_tvaudio_fini()-versus-tvaudio_sleep() looks racy:
if (dev->thread.scan1 == dev->thread.scan2 && !dev->thread.shutdown) {
if (timeout < 0) {
set_current_state(TASK_INTERRUPTIBLE);
schedule(); If the wakeup happens after the test of dev->thread.shutdown, that sleep will be permanent.
So in general, yes, the driver should be converted to the kthread API - this is a requirement for virtualisation, but I forget why, and that's the "standard" way of doing it.
- The signal stuff should go away if at all possible.
- the thread.shutdown field should go away and be replaced by kthread_should_stop().
- the tvaudio_sleep() race might need some attention (simply moving the set_current_state() to before the add_wait_queue() will suffice).
- the complete_and_exit() stuff might (should) no longer be needed - kthread_stop() does that.
Sorry ;)
Quoted 136 lines
2 files changed, 17 insertions(+), 20 deletions(-)Index:
lx26-18-rc5/drivers/media/video/saa7134/saa7134.h
===================================================================drivers/media/video/saa7134/saa7134.h +1
-3@@ -311,10 +311,8 @@ struct saa7134_pgtable {/* tvaudio thread status */ struct saa7134_thread { -pid_t pid; -struct completion exit; +struct task_struct * task;wait_queue_head_t wq; -unsigned int shutdown;unsigned int scan1;unsigned int scan2;unsigned int mode;Index:
lx26-18-rc5/drivers/media/video/saa7134/saa7134-tvaudio.c
===================================================================drivers/media/video/saa7134/saa7134-tvaudio.c +16
-17@@ -28,6 +28,7 @@#include <linux/slab.h> #include <linux/delay.h> #include <linux/smp_lock.h> +#include <linux/kthread.h> #include <asm/div64.h> #include "saa7134-reg.h" @@ -357,7 +358,7 @@ static int tvaudio_sleep(struct saa7134_DECLARE_WAITQUEUE (wait, current);add_wait_queue (&dev->thread.wq, &wait); -if (dev->thread.scan1 == dev->thread.scan2 && !dev->thread.shutdown) { +if (dev->thread.scan1 == dev->thread.scan2 && !kthread_should_stop ()) {if (timeout <0 ) {set_current_state (TASK_INTERRUPTIBLE );schedule ();@@ -525,7 +526,7 @@ static int tvaudio_thread(void *data)allow_signal (SIGTERM );for (;;) {tvaudio_sleep (dev,-1 ); -if (dev->thread.shutdown ||signal_pending (current)) +if (kthread_should_stop () ||signal_pending (current)) goto done; restart:@@ -633,7 +634,7 @@ static int tvaudio_thread(void *data)for (;;) {if (tvaudio_sleep (dev,5000 )) goto restart; -if (dev->thread.shutdown ||signal_pending (current)) +if (kthread_should_stop () ||signal_pending (current))break ;if (UNSET == dev->thread.mode) { rx =tvaudio_getstereo (dev,&tvaudio[i]);@@ -649,7 +650,6 @@ static int tvaudio_thread(void *data) } done: -complete_and_exit (&dev->thread.exit,0 );return 0 ; }@@ -798,7 +798,6 @@ static int tvaudio_thread_ddep(void *datstruct saa7134_dev *dev = data;u32 value, norms, clock; -daemonize ("%s" , dev->name);allow_signal (SIGTERM ); clock = saa7134_boards[dev->board].audio_clock;@@ -812,7 +811,7 @@ static int tvaudio_thread_ddep(void *datfor (;;) {tvaudio_sleep (dev,-1 ); -if (dev->thread.shutdown ||signal_pending (current)) +if (kthread_should_stop () ||signal_pending (current)) goto done; restart:@@ -894,7 +893,6 @@ static int tvaudio_thread_ddep(void *dat } done: -complete_and_exit (&dev->thread.exit,0 );return 0 ; }@@ -1004,15 +1002,16 @@ int saa7134_tvaudio_init2(struct saa7134break ; } - dev->thread.pid =-1 ; + dev->thread.task =NULL ;if (my_thread) {/* start tvaudio thread */ init_waitqueue_head (&dev->thread.wq); -init_completion (&dev->thread.exit); - dev->thread.pid =kernel_thread (my_thread,dev,0 ); -if (dev->thread.pid <0 ) + dev->thread.task =kthread_run (my_thread,dev,dev->name); +if (IS_ERR (dev->thread.task)) {printk (KERN_WARNING "%s: kernel_thread() failed\n" , - dev->name); + dev->name); + dev->thread.task =NULL ; + }saa7134_tvaudio_do_scan (dev); }@@ -1023,10 +1022,10 @@ int saa7134_tvaudio_init2(struct saa7134int saa7134_tvaudio_fini (struct saa7134_dev *dev) {/* shutdown tvaudio thread */ -if (dev->thread.pid >=0 ) { - dev->thread.shutdown =1 ; -wake_up_interruptible (&dev->thread.wq); -wait_for_completion (&dev->thread.exit); +if (dev->thread.task) { +/* kthread_stop() wakes up the thread */ +kthread_stop (dev->thread.task); + dev->thread.task =NULL ; }saa_andorb (SAA7134_ANALOG_IO_SELECT ,0x07 ,0x00 );/* LINE1 */ return 0 ;@@ -1034,7 +1033,7 @@ int saa7134_tvaudio_fini(struct saa7134_int saa7134_tvaudio_do_scan (struct saa7134_dev *dev) { -if (dev->thread.pid >=0 ) { +if (dev->thread.task) { dev->thread.mode =UNSET ; dev->thread.scan2++;wake_up_interruptible (&dev->thread.wq);
Quoted 3 lines · Andrew Morton
So in general, yes, the driver should be converted to the kthread API - this is a requirement for virtualisation, but I forget why, and that's the "standard" way of doing it.
With the kthread api new kernel threads are started as children of keventd in well defined circumstances. If you don't do this kernel threads can wind up sharing weird parts of a parent process's resources and locking resources in the kernel long past the time when they are actually used by anything a user space process can kill.
We have actually witnessed this problem with the kernels filesystem mount namespace. Mostly daemonize in the kernel unshares everything that could be a problem but the problem is sufficiently subtle it makes more sense to the change kernel threads. So these weird and subtle dependencies go away.
So in essence the container work needs the new kthread api for the same reasons everyone else does it is just more pronounced in that case.
Eric
Quoted 18 lines · [email protected] (Eric W. Biederman) writes:
Quoted 3 lines · Andrew Morton
So in general, yes, the driver should be converted to the kthread API - this is a requirement for virtualisation, but I forget why, and that's the "standard" way of doing it.
With the kthread api new kernel threads are started as children of keventd in well defined circumstances. If you don't do this kernel threads can wind up sharing weird parts of a parent process's resources and locking resources in the kernel long past the time when they are actually used by anything a user space process can kill.
We have actually witnessed this problem with the kernels filesystem mount namespace. Mostly daemonize in the kernel unshares everything that could be a problem but the problem is sufficiently subtle it makes more sense to the change kernel threads. So these weird and subtle dependencies go away.
Quoted 3 lines
So in essence the container work needs the new kthread api for the same reasons everyone else does it is just more pronounced in that case.
That plus the obvious bit. For the pid namespace we have to declare war on people storing a pid_t values. Either converting them to struct pid * or removing them entirely. Doing the kernel_thread to kthread conversion removes them entirely.
Eric
Quoted 13 lines
Quoted 13 lines
With the kthread api new kernel threads are started as children of keventd in well defined circumstances. If you don't do this kernel threads can wind up sharing weird parts of a parent process's resources and locking resources in the kernel long past the time when they are actually used by anything a user space process can kill.
We have actually witnessed this problem with the kernels filesystem mount namespace. Mostly daemonize in the kernel unshares everything that could be a problem but the problem is sufficiently subtle it makes more sense to the change kernel threads. So these weird and subtle dependencies go away.
Quoted 8 lines
Quoted 3 lines
So in essence the container work needs the new kthread api for the same reasons everyone else does it is just more pronounced in that case.
That plus the obvious bit. For the pid namespace we have to declare war on people storing a
pid_tvalues. Either converting them to struct pid * or removing them entirely. Doing thekernel_threadto kthread conversion removes them entirely.
we've started that war, won a few battles but some drivers need more work that a simple replace. If we could give some priorities, it would help to focus on the most important ones. check out the list bellow.
thanks,
C.
arch/arm/kernel/ecard.carch/i386/kernel/apm.carch/i386/kernel/io_apic.carch/i386/mach-voyager/voyager_thread.carch/ia64/sn/kernel/xpc_main.carch/mips/au1000/db1x00/mirage_ts.carch/mips/kernel/apm.carch/parisc/kernel/process.carch/powerpc/platforms/pseries/eeh_event.carch/powerpc/platforms/pseries/rtasd.carch/s390/mm/cmm.carch/sparc64/kernel/power.c
drivers/base/firmware_class.cdrivers/block/loop.cdrivers/ieee1394/nodemgr.cdrivers/macintosh/adb.cdrivers/macintosh/mediabay.cdrivers/macintosh/therm_pm72.cdrivers/macintosh/therm_windtunnel.cdrivers/media/dvb/dvb-core/dvb_ca_en50221.cdrivers/media/dvb/dvb-core/dvb_frontend.cdrivers/media/dvb/ttpci/av7110.cdrivers/media/video/saa7134/saa7134-tvaudio.cdrivers/media/video/tvaudio.cdrivers/mmc/mmc_queue.cdrivers/mtd/mtd_blkdevs.cdrivers/net/wireless/airo.cdrivers/pci/hotplug/cpci_hotplug_core.cdrivers/pci/hotplug/cpqphp_ctrl.cdrivers/pci/hotplug/ibmphp_hpc.cdrivers/pci/hotplug/pciehp_ctrl.cdrivers/pnp/pnpbios/core.cdrivers/s390/net/lcs.cdrivers/s390/net/qeth_main.cdrivers/s390/scsi/zfcp_erp.cdrivers/usb/atm/usbatm.cdrivers/usb/storage/libusual.c
fs/afs/cmservice.cfs/afs/kafsasyncd.cfs/afs/kafstimod.cfs/cifs/connect.cfs/jffs2/background.cfs/jffs/inode-v23.cfs/lockd/clntlock.cfs/nfs/delegation.c
init/do_mounts_initrd.ckernel/kmod.ckernel/stop_machine.c
net/bluetooth/bnep/core.cnet/bluetooth/cmtp/core.cnet/bluetooth/hidp/core.cnet/bluetooth/rfcomm/core.cnet/core/pktgen.cnet/ipv4/ipvs/ip_vs_sync.cnet/rxrpc/krxiod.cnet/rxrpc/krxsecd.cnet/rxrpc/krxtimod.cnet/sunrpc/svc.c
Quoted 16 lines · Cedric Le Goater
Quoted 16 lines
Quoted 15 lines
With the kthread api new kernel threads are started as children of keventd in well defined circumstances. If you don't do this kernel threads can wind up sharing weird parts of a parent process's resources and locking resources in the kernel long past the time when they are actually used by anything a user space process can kill.
We have actually witnessed this problem with the kernels filesystem mount namespace. Mostly daemonize in the kernel unshares everything that could be a problem but the problem is sufficiently subtle it makes more sense to the change kernel threads. So these weird and subtle dependencies go away.
So in essence the container work needs the new kthread api for the same reasons everyone else does it is just more pronounced in that case.
Quoted 8 lines
Quoted 4 lines
That plus the obvious bit. For the pid namespace we have to declare war on people storing a
pid_tvalues. Either converting them to struct pid * or removing them entirely. Doing thekernel_threadto kthread conversion removes them entirely.we've started that war, won a few battles but some drivers need more work that a simple replace. If we could give some priorities, it would help to focus on the most important ones. check out the list bellow.
Sure, I think I can help.
There are a couple of test I can think of that should help.
1) Is the pid value stored. If not a pid namespace won't affect it's normal operation.
2) Is this thread started during kernel boot before this thread could have a user space parent. If it can't have a user space parent then it can't take a reference to user space resources.
3) Can the code be compiled modular and will it break when we stop exporting kernel_thread.
4) How frequently is this thing used. The more common code is probably in better shape and more likely to get a good maintainer response, and we care more :)
irqbalanced from arch/i386/kernel/io_apic.c should be safe to leave alone because it doesn't store a pid_t, it is started during boot, and it can't be compiled modular.
Quoted 1 line
From what I have seen you can shorten the list by several entries by removing
code like irqbalanced that can't possibly cause us any problems. kvoyagerd from arch/i386/mach-voyager/voyager_thread.c is another one.
The first on my personal hit list is nfs.
Quoted 3 lines
fs/lockd/clntlock.cfs/nfs/delegation.cnet/sunrpc/svc.c
Because it does store pid_t values, it isn't started during kernel boot, it can be compiled modular, and people use it all of the time.
I do agree from what I have seen, that changing idioms to the kthread way of doing things isn't simply a matter of substitute and replace which is unfortunate. Although the biggest hurdle seems to be to teach kernel threads to communicate with something besides signals. Which is a general help anyway.
Unfortunately I'm distracted at the moment so I haven't gone through the entire list but I hope this helps.
Eric
Quoted 66 lines
arch/arm/kernel/ecard.carch/i386/kernel/apm.carch/i386/kernel/io_apic.carch/i386/mach-voyager/voyager_thread.carch/ia64/sn/kernel/xpc_main.carch/mips/au1000/db1x00/mirage_ts.carch/mips/kernel/apm.carch/parisc/kernel/process.carch/powerpc/platforms/pseries/eeh_event.carch/powerpc/platforms/pseries/rtasd.carch/s390/mm/cmm.carch/sparc64/kernel/power.c
drivers/base/firmware_class.cdrivers/block/loop.cdrivers/ieee1394/nodemgr.cdrivers/macintosh/adb.cdrivers/macintosh/mediabay.cdrivers/macintosh/therm_pm72.cdrivers/macintosh/therm_windtunnel.cdrivers/media/dvb/dvb-core/dvb_ca_en50221.cdrivers/media/dvb/dvb-core/dvb_frontend.cdrivers/media/dvb/ttpci/av7110.cdrivers/media/video/saa7134/saa7134-tvaudio.cdrivers/media/video/tvaudio.cdrivers/mmc/mmc_queue.cdrivers/mtd/mtd_blkdevs.cdrivers/net/wireless/airo.cdrivers/pci/hotplug/cpci_hotplug_core.cdrivers/pci/hotplug/cpqphp_ctrl.cdrivers/pci/hotplug/ibmphp_hpc.cdrivers/pci/hotplug/pciehp_ctrl.cdrivers/pnp/pnpbios/core.cdrivers/s390/net/lcs.cdrivers/s390/net/qeth_main.cdrivers/s390/scsi/zfcp_erp.cdrivers/usb/atm/usbatm.cdrivers/usb/storage/libusual.c
fs/afs/cmservice.cfs/afs/kafsasyncd.cfs/afs/kafstimod.cfs/cifs/connect.cfs/jffs2/background.cfs/jffs/inode-v23.cfs/lockd/clntlock.cfs/nfs/delegation.c
init/do_mounts_initrd.ckernel/kmod.ckernel/stop_machine.c
net/bluetooth/bnep/core.cnet/bluetooth/cmtp/core.cnet/bluetooth/hidp/core.cnet/bluetooth/rfcomm/core.cnet/core/pktgen.cnet/ipv4/ipvs/ip_vs_sync.cnet/rxrpc/krxiod.cnet/rxrpc/krxsecd.cnet/rxrpc/krxtimod.cnet/sunrpc/svc.c
_______________________________________________
Containers mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/containers
Eric W. Biederman wrote:
[ ... ]
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
That plus the obvious bit. For the pid namespace we have to declare war on people storing a
pid_tvalues. Either converting them to struct pid * or removing them entirely. Doing thekernel_threadto kthread conversion removes them entirely.we've started that war, won a few battles but some drivers need more work that a simple replace. If we could give some priorities, it would help to focus on the most important ones. check out the list bellow.
Quoted 5 lines
Sure, I think I can help.
There are a couple of test I can think of that should help.
1) Is the pid value stored. If not a pid namespace won't affect it's normal operation.
I've extracted this list from a table which includes a pid cache column. this pid cache column is not complete yet. I'd be nice if we could use a wiki to maintain this table, the existing openvz or vserver wiki ?
Quoted 3 lines
2) Is this thread started during kernel boot before this thread could have a user space parent. If it can't have a user space parent then it can't take a reference to user space resources.
ok we need to add this one.
Quoted 2 lines
3) Can the code be compiled modular and will it break when we stop exporting
kernel_thread.
got that also.
Quoted 3 lines
4) How frequently is this thing used. The more common code is probably in better shape and more likely to get a good maintainer response, and we care more :)
sure :) some drivers are for some exotic piece of hardware that are not currently found on a standard server.
Quoted 7 lines
irqbalanced from
arch/i386/kernel/io_apic.cshould be safe to leave alone because it doesn't store apid_t, it is started during boot, and it can't be compiled modular.Quoted 1 line
From what I have seen you can shorten the list by several entries by removing
code like irqbalanced that can't possibly cause us any problems. kvoyagerd from
arch/i386/mach-voyager/voyager_thread.cis another one.
ok thanks, will update.
Quoted 7 lines
The first on my personal hit list is nfs.
Quoted 3 lines
fs/lockd/clntlock.cfs/nfs/delegation.cnet/sunrpc/svc.cBecause it does store
pid_tvalues, it isn't started during kernel boot, it can be compiled modular, and people use it all of the time.
yes yes. hard stuff though which requires time.
Quoted 7 lines
I do agree from what I have seen, that changing idioms to the kthread way of doing things isn't simply a matter of substitute and replace which is unfortunate. Although the biggest hurdle seems to be to teach kernel threads to communicate with something besides signals. Which is a general help anyway.
Unfortunately I'm distracted at the moment so I haven't gone through the entire list but I hope this helps.
we would need a wiki to maintain the work in progress on that topic while we work on the pidspace.
another list to maintain would be the pid_t to struct pid replacement.
C.
Quoted 16 lines · Cedric Le Goater
Eric W. Biederman wrote:
[ ... ]
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
That plus the obvious bit. For the pid namespace we have to declare war on people storing a
pid_tvalues. Either converting them to struct pid * or removing them entirely. Doing thekernel_threadto kthread conversion removes them entirely.we've started that war, won a few battles but some drivers need more work that a simple replace. If we could give some priorities, it would help to focus on the most important ones. check out the list bellow.
Sure, I think I can help.
Quoted 8 lines
Quoted 3 lines
There are a couple of test I can think of that should help.
1) Is the pid value stored. If not a pid namespace won't affect it's normal operation.I've extracted this list from a table which includes a pid cache column. this pid cache column is not complete yet. I'd be nice if we could use a wiki to maintain this table, the existing openvz or vserver wiki ?
feel free to use http://wiki.openvz.org
we will create a 'Developement' category then for such pages. I think we can help with the patches soon as well.
[...]
Quoted 7 lines
Quoted 7 lines
I do agree from what I have seen, that changing idioms to the kthread way of doing things isn't simply a matter of substitute and replace which is unfortunate. Although the biggest hurdle seems to be to teach kernel threads to communicate with something besides signals. Which is a general help anyway.
Unfortunately I'm distracted at the moment so I haven't gone through the entire list but I hope this helps.
If we have some list on the wiki, people could assign the issues to themself and prepare the patches. Thus work could be paralleled a bit.
Thanks,
Kirill
Quoted 4 lines · Cedric Le Goater
I've extracted this list from a table which includes a pid cache column. this pid cache column is not complete yet. I'd be nice if we could use a wiki to maintain this table, the existing openvz or vserver wiki ?
Feel free to use http://wiki.openvz.org/ for that. I can also create/host a separate one in case you want it that way.
Quoted 28 lines · Andrew Morton
Quoted 7 lines · On Tue, 29 Aug 2006 14:15:55 -0700 Sukadev Bhattiprolu <[email protected]>…
Replace
kernel_thread()withkthread_run()sincekernel_thread()is deprecated indrivers/modules.Note that this driver, like a few others, allows SIGTERM. Not sure if that is affected by conversion to kthread. Appreciate any comments on that.
hm, I think this driver needs more help.
- It shouldn't be using signals at all, really. Signals are for userspace IPC. The kernel internally has better/richer/faster/tighter ways of inter-thread communication.
- saa7134_tvaudio_fini()-versus-tvaudio_sleep() looks racy:
if (dev->thread.scan1 == dev->thread.scan2 && !dev->thread.shutdown) { if (timeout < 0) { set_current_state(TASK_INTERRUPTIBLE); schedule();If the wakeup happens after the test of
dev->thread.shutdown, that sleep will be permanent.
Quoted 5 lines
So in general, yes, the driver should be converted to the kthread API - this is a requirement for virtualisation, but I forget why, and that's the "standard" way of doing it.
- The signal stuff should go away if at all possible.
The thread of this driver allows SIGTERM for some obscure reason. Not sure why, I didn't find anything relying on it.
could we just remove the allow_signal() ?
C.
Quoted 33 lines · On Wed, 30 Aug 2006 18:30:27 +0200 Cedric Le Goater <[email protected]> wrote:
Quoted 32 lines · Andrew Morton
Quoted 7 lines · On Tue, 29 Aug 2006 14:15:55 -0700 Sukadev Bhattiprolu <[email protected]>…
Replace
kernel_thread()withkthread_run()sincekernel_thread()is deprecated indrivers/modules.Note that this driver, like a few others, allows SIGTERM. Not sure if that is affected by conversion to kthread. Appreciate any comments on that.
hm, I think this driver needs more help.
- It shouldn't be using signals at all, really. Signals are for userspace IPC. The kernel internally has better/richer/faster/tighter ways of inter-thread communication.
- saa7134_tvaudio_fini()-versus-tvaudio_sleep() looks racy:
if (dev->thread.scan1 == dev->thread.scan2 && !dev->thread.shutdown) { if (timeout < 0) { set_current_state(TASK_INTERRUPTIBLE); schedule();If the wakeup happens after the test of
dev->thread.shutdown, that sleep will be permanent.So in general, yes, the driver should be converted to the kthread API - this is a requirement for virtualisation, but I forget why, and that's the "standard" way of doing it.
Quoted 7 lines
Quoted 1 line
- The signal stuff should go away if at all possible.
The thread of this driver allows SIGTERM for some obscure reason. Not sure why, I didn't find anything relying on it.
could we just remove the
allow_signal()?
I hope so. However I have a bad feeling that the driver wants to accept signals from userspace. Hopefully Mauro & co will be able to clue us in.
Em Qua, 2006-08-30 às 09:49 -0700, Andrew Morton escreveu:
Quoted 4 lines
On Wed, 30 Aug 2006 18:30:27 +0200
Cedric Le Goater <[email protected]> wrote:
Quoted 8 lines
Quoted 5 lines
The thread of this driver allows SIGTERM for some obscure reason. Not sure why, I didn't find anything relying on it.
could we just remove the
allow_signal()?I hope so. However I have a bad feeling that the driver wants to accept signals from userspace. Hopefully Mauro & co will be able to clue us in.
The history we have on our development tree goes only until Feb, 2004. This line were added before it.
I've looked briefly the driver. The same allow_signal is also present on tvaudio (part of bttv driver). BTTV were written to kernel 2.1, so, this piece seems to be an inheritance from 2.1 time.
No other V4L drivers have this one, although cx88-tvaudio (written on 2.6 series) have a similar kthread to check if audio status changed.
On cx88-tvaudio, it does:
if (kthread_should_stop())
break;instead of:
if (dev->thread.shutdown || signal_pending(current))
goto done;It is likely to work if we remove allow_signal and replacing the signal_pending() by kthread_should_stop() as above.
The better is to check the real patch on a saa7134 hardware before submiting to mainstream. You may submit the final patch for us to test at the proper hardware.
Cheers,
Mauro.
Mauro Carvalho Chehab [[email protected]] wrote:
| Em Qua, 2006-08-30 às 09:49 -0700, Andrew Morton escreveu: | > On Wed, 30 Aug 2006 18:30:27 +0200 | > Cedric Le Goater <[email protected]> wrote: | > | | It is likely to work if we remove allow_signal and replacing the | signal_pending() by kthread_should_stop() as above. | | The better is to check the real patch on a saa7134 hardware before | submiting to mainstream. You may submit the final patch for us to test | at the proper hardware. |
Thanks for all the input. Mauro, thanks for help with testing. Here is an updated patch that removes the signal code and the race.
---
Replace kernel_thread() with kthread_run() since kernel_thread() is deprecated in drivers/modules. Also remove signalling code as it is not needed in the driver.
drivers/media/video/saa7134/saa7134-tvaudio.c | 45 +++++++++++++------------- drivers/media/video/saa7134/saa7134.h | 4 -- 2 files changed, 24 insertions(+), 25 deletions(-)
drivers/media/video/saa7134/saa7134.h +1 -3
@@ -311,10 +311,8 @@ struct saa7134_pgtable {/* tvaudio thread status */ struct saa7134_thread { -pid_t pid; -struct completion exit; +struct task_struct * task;wait_queue_head_t wq; -unsigned int shutdown;unsigned int scan1;unsigned int scan2;unsigned int mode;
drivers/media/video/saa7134/saa7134-tvaudio.c +23 -22
125 lines not on this page · raw message
PATCH 1/1 kthread: tvaudio.c
In reply to Mauro Carvalho ChehabReplaced kernel_thread() with kthread_run() since kernel_thread() is deprecated in drivers/modules.
Removed the completion and the wait queue which are now useless with kthread. Also removed the allow_signal() call as signals don't apply to kernel threads.
Fixed a small race condition when thread is stopped.
Please check if the timer vs. thread still works fine without the wait queue.
drivers/media/video/tvaudio.c | 42 ++++++++++++++++-------------------------- 1 files changed, 16 insertions(+), 26 deletions(-)
drivers/media/video/tvaudio.c +16 -26
@@ -28,6 +28,7 @@#include <linux/i2c-algo-bit.h> #include <linux/init.h> #include <linux/smp_lock.h> +#include <linux/kthread.h> #include <media/tvaudio.h> #include <media/v4l2-common.h>
@@ -124,11 +125,8 @@ struct CHIPSTATE {int input;/* thread */ -pid_t tpid; -struct completion texit; -wait_queue_head_t wq; +struct task_struct *thread;struct timer_list wt; -int done;int watch_stereo;int audmode; };
@@ -264,28 +262,23 @@ static int chip_cmd(struct CHIPSTATE *chstatic void chip_thread_wake (unsigned long data) {struct CHIPSTATE *chip = (struct CHIPSTATE *)data; -wake_up_interruptible (&chip->wq); +wake_up_process (chip->thread); }static int chip_thread (void *data) { -DECLARE_WAITQUEUE (wait, current);struct CHIPSTATE *chip = data;struct CHIPDESC *desc = chiplist + chip->type; -daemonize ("%s" , chip->c.name); -allow_signal (SIGTERM );v4l_dbg (1 , debug, &chip->c,"%s: thread started\n" , chip->c.name);for (;;) { -add_wait_queue (&chip->wq, &wait); -if (!chip->done) { -set_current_state (TASK_INTERRUPTIBLE ); +set_current_state (TASK_INTERRUPTIBLE ); +if (!kthread_should_stop ())schedule (); - } -remove_wait_queue (&chip->wq, &wait); +set_current_state (TASK_RUNNING );try_to_freeze (); -if (chip->done ||signal_pending (current)) +if (kthread_should_stop ())break ;v4l_dbg (1 , debug, &chip->c,"%s: thread wakeup\n" , chip->c.name);
@@ -301,7 +294,6 @@ static int chip_thread(void *data) }v4l_dbg (1 , debug, &chip->c,"%s: thread exiting\n" , chip->c.name); -complete_and_exit (&chip->texit,0 );return 0 ; }
@@ -1536,19 +1528,18 @@ static int chip_attach(struct i2c_adaptechip_write (chip,desc->treblereg,desc->treblefunc (chip->treble)); } - chip->tpid =-1 ; + chip->thread =NULL ;if (desc->checkmode) {/* start async thread */ init_timer (&chip->wt); chip->wt.function = chip_thread_wake; chip->wt.data = (unsigned long )chip; -init_waitqueue_head (&chip->wq); -init_completion (&chip->texit); - chip->tpid =kernel_thread (chip_thread,(void *)chip,0 ); -if (chip->tpid <0 ) -v4l_warn (&chip->c,"%s: kernel_thread() failed\n" , + chip->thread =kthread_run (chip_thread, chip, chip->c.name); +if (IS_ERR (chip->thread)) { +v4l_warn (&chip->c,"%s: failed to create kthread\n" , chip->c.name); -wake_up_interruptible (&chip->wq); + chip->thread =NULL ; + } }return 0 ; }
@@ -1569,11 +1560,10 @@ static int chip_detach(struct i2c_clientstruct CHIPSTATE *chip =i2c_get_clientdata (client);del_timer_sync (&chip->wt); -if (chip->tpid >=0 ) { +if (chip->thread) {/* shutdown async thread */ - chip->done =1 ; -wake_up_interruptible (&chip->wq); -wait_for_completion (&chip->texit); +kthread_stop (chip->thread); + chip->thread =NULL ; }i2c_detach_client (&chip->c);