From owner-freebsd-hackers@FreeBSD.ORG Mon Apr 10 14:09:07 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E001B16A400 for ; Mon, 10 Apr 2006 14:09:07 +0000 (UTC) (envelope-from scottl@samsco.org) Received: from pooker.samsco.org (pooker.samsco.org [168.103.85.57]) by mx1.FreeBSD.org (Postfix) with ESMTP id 44B3F43D6B for ; Mon, 10 Apr 2006 14:09:03 +0000 (GMT) (envelope-from scottl@samsco.org) Received: from [192.168.254.11] (junior.samsco.home [192.168.254.11]) (authenticated bits=0) by pooker.samsco.org (8.13.4/8.13.4) with ESMTP id k3AE8v3L030707; Mon, 10 Apr 2006 08:08:57 -0600 (MDT) (envelope-from scottl@samsco.org) Message-ID: <443A66F0.7050802@samsco.org> Date: Mon, 10 Apr 2006 08:08:48 -0600 From: Scott Long User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.12) Gecko/20051230 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Nickolas References: <1879959918.20060410165511@atlas.ua> In-Reply-To: <1879959918.20060410165511@atlas.ua> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.4 required=3.8 tests=ALL_TRUSTED autolearn=failed version=3.1.1 X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on pooker.samsco.org Cc: freebsd-hackers@freebsd.org Subject: Re: Context switching X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Apr 2006 14:09:08 -0000 Nickolas wrote: > 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? > > OS version: FreeBSD 5.4 > tsleep and msleep are the appropriate ways to context switch. mi_switch is an implementation detail of the scheduler. Scott