Date: Tue, 4 Aug 2015 18:27:46 +0200 From: Luigi Rizzo <rizzo@iet.unipi.it> To: Konstantin Belousov <kostikbel@gmail.com> Cc: freebsd-current <freebsd-current@freebsd.org>, Stefano Garzarella <stefanogarzarella@gmail.com>, Giuseppe Lettieri <g.lettieri@iet.unipi.it> Subject: Re: proper way to terminate a kthread when the parent process dies ? Message-ID: <CA%2BhQ2%2BikWxJ-rdj7F74xPfsP2Sdf56zq41fBEMA2aCKGd8O6XQ@mail.gmail.com> In-Reply-To: <20150804160211.GO2072@kib.kiev.ua> References: <CA%2BhQ2%2Bg8zSSHrLFiuD3-oZ1D0F9BsnJKVwc0hSDowr4gaX6eYw@mail.gmail.com> <20150804145311.GN2072@kib.kiev.ua> <CA%2BhQ2%2BiUpK9Z_bV9TYpWQEd0mi=PKtcwNThqg_WYVrka1reBHg@mail.gmail.com> <20150804160211.GO2072@kib.kiev.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Aug 4, 2015 at 6:02 PM, Konstantin Belousov <kostikbel@gmail.com> wrote: > On Tue, Aug 04, 2015 at 05:32:28PM +0200, Luigi Rizzo wrote: >> On Tue, Aug 4, 2015 at 4:53 PM, Konstantin Belousov <kostikbel@gmail.com> wrote: >> > If this is a thread of the normal user process, then it is not a kernel >> > thread, even if it never leaves the kernel mode. >> >> thanks for the answer. >> >> i do not really know what is the difference between a "kernel thread" >> and a "thread". >> Could you clarify what is the distinctive feature between the two ? >> Perhaps being owned by pid 0 ? > No. I probably having troubles answering this exact question. TDP_KTHREAD > is used as a shortcut in several places, mostly to avoid some specific > actions that are useless for the real kernel process. E.g. the amd64 > context switch code avoids setting some CPU registers when switching to > the kernel thread. Hacks to not switch address spaces when switching > to the kthread were already removed. > > Overall, claiming that a thread of the normal user process (i.e. process > which executes in userspace) is kernel thread is fragile and, if not > breaking in your tests, could break later. >> >> This specific thread is created within a system call by invoking kthread_add() >> and associated with the user process. > Did you tried the other approach, by creating the thread from userspace, > and then executing the syscall which would loop ? This is how things are > done by e.g. nfsd. ok will look at the alternative you suggest. Specifically, our two threads implement the host part of a virtualized network interface and operate in a way that is very similar to an interrupt handler, or vhost-net in KVM. In principle, the user process that issues the system call could be unaware of the existence and number of those threads; that is why we went for a "kernel thread" created within the kernel. thanks again for the explanation cheers luigi > > Still, if you looping in the kernel, you must call thread_suspend_check() > periodically. >> >> > >> > You must call thread_suspend_check() in any in-kernel loop to allow the >> > stops and process exit to work. >> >> so does it mean that the kthread_suspend_check() is incorrect and we should >> use thread_suspend_check() instead ? > Most likely yes. -- -----------------------------------------+------------------------------- Prof. Luigi RIZZO, rizzo@iet.unipi.it . Dip. di Ing. dell'Informazione http://www.iet.unipi.it/~luigi/ . Universita` di Pisa TEL +39-050-2217533 . via Diotisalvi 2 Mobile +39-338-6809875 . 56122 PISA (Italy) -----------------------------------------+-------------------------------
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CA%2BhQ2%2BikWxJ-rdj7F74xPfsP2Sdf56zq41fBEMA2aCKGd8O6XQ>