Date: Mon, 10 Apr 2006 09:30:15 -0600 (MDT) From: "M. Warner Losh" <imp@bsdimp.com> To: nickolas@atlas.ua Cc: freebsd-drivers@freebsd.org Subject: Re: Context switching Message-ID: <20060410.093015.34601940.imp@bsdimp.com> In-Reply-To: <637898557.20060410154542@atlas.ua> References: <637898557.20060410154542@atlas.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
In message: <637898557.20060410154542@atlas.ua> Nickolas <nickolas@atlas.ua> writes: : Hello All! : : I'm porting a CPI card driver from linux to FreeBSD. : Some initialization routines require much time (~1-2 seconds). : Initialization of hardware should be done during opening device : special file. So, I need to switch thread context. : : I'm doing it in such way: : : mi_switch(SW_VOL, choosethread()); : : Main trouble: system panic after program exit. : : dmesg output: : -------------------------- : Fatal trap 12: page fault while in user mode : fault virtual address = 0xbfbfe5bc : fault code = user write, protection violation : instruction pointer = 0x1f:0x8074604 : stack pointer = 0x2f:0xbfbfe5c0 : frame pointer = 0x2f:0xbfbfe5f8 : code segment = base 0xc090f8c0, limit 0x0, type 0x13 : = DPL 0, pres 1, def32 1, gran 1 : processor eflags = interrupt enabled, resume, IOPL = 0 : current process = 472 (bash) : trap number = 12 : panic: page fault : -------------------------- : : Please, tell how correct context switching should be implemented? Create a thread on attach. Have it msleep. Use wakeup from open and have open msleep. The thread then runs, does its init and wakes up the open thread to continue. Of course, you could likely do all that in the open thread... Warner
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060410.093015.34601940.imp>