From owner-freebsd-drivers@FreeBSD.ORG Thu Dec 11 06:38:07 2014 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 441ADB6A for ; Thu, 11 Dec 2014 06:38:07 +0000 (UTC) Received: from mail-oi0-x235.google.com (mail-oi0-x235.google.com [IPv6:2607:f8b0:4003:c06::235]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0AC4D28C for ; Thu, 11 Dec 2014 06:38:07 +0000 (UTC) Received: by mail-oi0-f53.google.com with SMTP id x69so3248961oia.40 for ; Wed, 10 Dec 2014 22:38:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=g4sGRa7KDUCcVbsHIz4hc68VR3z20T+VLrf5BSWB8dU=; b=rCIeEOEdDg+w/X3jWULR+eKmaxV+ruN9f6ru9b7unePrrPCGnQXGeqEKUQKtxLkfsP Z4jG/tjmb71mPX9TouffIWMdGlgYogCoEnNtRVF5U8hs1HR1V4CnJenhF/ue8fCBzI5c 6OJwWXL/wrT5cy49wqtO9DCkCfPocyfdA2jnUou1eSdAYbJfNz6baIODT/DA/jb+YDnh dm8bypNcEMeDrZDcPz2VmahoefAQfxPMCLl7Fd3hlOz1MIaMkiQJScLtJ2qE8SvU76Cf JzLgdv9gzi2FWwSglBiRYG4VN459pHEBILvemeaEeK8iVfEY2zabFOtSoIoyU5HjiEXa dbxg== MIME-Version: 1.0 X-Received: by 10.202.98.10 with SMTP id w10mr5001609oib.104.1418279886379; Wed, 10 Dec 2014 22:38:06 -0800 (PST) Received: by 10.60.25.106 with HTTP; Wed, 10 Dec 2014 22:38:06 -0800 (PST) Date: Thu, 11 Dec 2014 03:38:06 -0300 Message-ID: Subject: Locking a MTX_DEF inside an interrupt thread From: Martin Galvan To: freebsd-drivers@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Dec 2014 06:38:07 -0000 Hi everyone! I was reading the man page on bus_setup_intr() and noticed it warned against sleeping inside an ithread routine. However, I saw a few drivers that start their ithread routines by locking a MTX_DEF mutex, which I understand will make a thread sleep if the mutex is already being held by another thread. Based on that, I'd like to ask you guys a few questions: 1) Why can't we sleep inside an ithread? Isn't being able to context-switch (and thus avoiding using spinlocks) the whole point of using a separate thread for an interrupt handler? 2) What would be the 'correct' way to write an ithread routine which uses shared resources (such as a softc)? 3) Should we fix the drivers that use MTX_DEF mutexes inside their ithreads? Thanks a lot! From owner-freebsd-drivers@FreeBSD.ORG Thu Dec 11 19:58:41 2014 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 32F20D82 for ; Thu, 11 Dec 2014 19:58:41 +0000 (UTC) Received: from mail-pd0-x231.google.com (mail-pd0-x231.google.com [IPv6:2607:f8b0:400e:c02::231]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F1A0B998 for ; Thu, 11 Dec 2014 19:58:40 +0000 (UTC) Received: by mail-pd0-f177.google.com with SMTP id ft15so5529879pdb.8 for ; Thu, 11 Dec 2014 11:58:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=lj0WQFcvgt3yICYFfLw5VDQLVW9VBkSfmcASVdUUEBM=; b=Cam15oGAJ+qAcLkvgaUdkZ/zna7aglFh0tSbG8vy0jG+q3im/VCsA7z7dJyq4AbRHo zUx9CBm26wiTialDr1OCT15W5Z36KvI/mcGwsZvBgXYTR4M7pTNDrOWOLfDZJYQrHbBh eBa3KfAZ+26xpUK5zLvp/Ljc5NDpXX0wXK3QhK5vE2gOIHSkskUfDAcw5Pm4F7PO32VE ZePtDVRnC/xAmSNMyUr+wWyoagxGgV8ikBpHlzeBcjE9phi1vItZBXqKZrgn0kETiqn9 3fYfieyFwFb8Vb5XJoHj5UfND3Niob81cPH8fWm1S5r9KsdMenzImg18KZmPsm0hb1uY DXLQ== X-Received: by 10.68.204.8 with SMTP id ku8mr19975230pbc.103.1418327920486; Thu, 11 Dec 2014 11:58:40 -0800 (PST) Received: from ox ([24.6.44.228]) by mx.google.com with ESMTPSA id bu4sm2062457pdb.80.2014.12.11.11.58.38 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 11 Dec 2014 11:58:39 -0800 (PST) Date: Thu, 11 Dec 2014 11:58:21 -0800 From: Navdeep Parhar To: Martin Galvan Subject: Re: Locking a MTX_DEF inside an interrupt thread Message-ID: <20141211195821.GA3827@ox> Mail-Followup-To: Martin Galvan , freebsd-drivers@freebsd.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-drivers@freebsd.org X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Dec 2014 19:58:41 -0000 MTX_DEF mutexes can block but never sleep, and it is perfectly safe to acquire them in an ithread. On Thu, Dec 11, 2014 at 03:38:06AM -0300, Martin Galvan wrote: > Hi everyone! I was reading the man page on bus_setup_intr() and > noticed it warned against sleeping inside an ithread routine. However, > I saw a few drivers that start their ithread routines by locking a > MTX_DEF mutex, which I understand will make a thread sleep if the > mutex is already being held by another thread. Based on that, I'd like > to ask you guys a few questions: > > 1) Why can't we sleep inside an ithread? Isn't being able to > context-switch (and thus avoiding using spinlocks) the whole point of > using a separate thread for an interrupt handler? > 2) What would be the 'correct' way to write an ithread routine which > uses shared resources (such as a softc)? > 3) Should we fix the drivers that use MTX_DEF mutexes inside their ithreads? > > Thanks a lot! > _______________________________________________ > freebsd-drivers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-drivers > To unsubscribe, send any mail to "freebsd-drivers-unsubscribe@freebsd.org" From owner-freebsd-drivers@FreeBSD.ORG Fri Dec 12 01:59:40 2014 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id CC55BDBA for ; Fri, 12 Dec 2014 01:59:40 +0000 (UTC) Received: from mail-la0-x233.google.com (mail-la0-x233.google.com [IPv6:2a00:1450:4010:c03::233]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6BD447DF for ; Fri, 12 Dec 2014 01:59:40 +0000 (UTC) Received: by mail-la0-f51.google.com with SMTP id ms9so5328993lab.38 for ; Thu, 11 Dec 2014 17:59:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=vASR1cqaxMGMdyZ6VFxvqaif1SzqoVznLMshdO3N2mk=; b=PVrwwsbUEpKzUuEJasOUr5/hgAzeLbv/fXl9/7cECn10LN8b5AR0OIiiBgF4/8IoEG tArNcp+0NqK8wMeIknSF9aet2UlOcztOAMwgHu48hiunNVUPLfTMUuNMVsXhRYgkZ2kE rEJi1X3fcZS6MFE472OqVoYAr4fX2Ea7H1iMOZfBTVPEb4uCYkA5eY0YAF9RLoyk1LNv xKwpwefT026GM6Qa7ZX6GmQp0kw4vLnAbSYnDOGRPv21RS1TRGuNngbTjNIJzS0YfJb6 1kN63R7xPgJRIy2bWw1rog3z0ly2QWuotPSmSrN5QG3GYg0BVtnTG7jrbcfNSEKPw37Q +BBQ== MIME-Version: 1.0 X-Received: by 10.152.5.198 with SMTP id u6mr13221921lau.42.1418349578452; Thu, 11 Dec 2014 17:59:38 -0800 (PST) Received: by 10.114.184.115 with HTTP; Thu, 11 Dec 2014 17:59:38 -0800 (PST) Date: Thu, 11 Dec 2014 18:59:38 -0700 Message-ID: Subject: Reading kernel input events From: Ales Katona To: freebsd-drivers@freebsd.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Dec 2014 01:59:40 -0000 Hello, I'm trying to help port wayland's libinput library to FreeBSD and I'm currently trying to figure out how to get input device events from the kernel. Basically, what interface/api would I need to use to read events similar to evdev? Thanks, Ales Katona -- Feel the power of Opensource. Feel the power of Free Pascal. From owner-freebsd-drivers@FreeBSD.ORG Fri Dec 12 07:34:11 2014 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9502DF58 for ; Fri, 12 Dec 2014 07:34:11 +0000 (UTC) Received: from mail-ob0-x235.google.com (mail-ob0-x235.google.com [IPv6:2607:f8b0:4003:c01::235]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 589D3D87 for ; Fri, 12 Dec 2014 07:34:11 +0000 (UTC) Received: by mail-ob0-f181.google.com with SMTP id gq1so6943977obb.12 for ; Thu, 11 Dec 2014 23:34:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=rr1AoY5Vzq1xCzwT1l1g1hJVB0cJQphacuTL0bpWLAM=; b=pR3janIzfo1LASwsT7XbH5rNfRW42HGWdb1Bo/4X5dnHqze2t7ddw3kKtUc/qQb/bZ D8p1vPrPv6Br8rjV73PjKCxCIvApkGg8ppgdF6I2zO+TJyPlP/7vZuRJ8OT5N740D4So d6/bHvWrsJ73L9v4yvsDAMsFek5Qg7OCAqtnHcvIMDv3/EH9lDby4xhi19nSXRRs2NgF 2FDyBxtz9ay0Je8gezxWFOHdCUGdi07OISDUGpP47v7m1gKyAFl5fBSYS+KAEb3MrlUo pRLB9fcF6cQ7/7Sd6k83ipAtbYlU39VNgY3TM/Rthzj1YeHACE9is2o01vglHxfozTd/ za/w== MIME-Version: 1.0 X-Received: by 10.202.3.3 with SMTP id 3mr8655617oid.11.1418369650683; Thu, 11 Dec 2014 23:34:10 -0800 (PST) Received: by 10.60.25.106 with HTTP; Thu, 11 Dec 2014 23:34:10 -0800 (PST) In-Reply-To: <20141211195821.GA3827@ox> References: <20141211195821.GA3827@ox> Date: Fri, 12 Dec 2014 04:34:10 -0300 Message-ID: Subject: Re: Locking a MTX_DEF inside an interrupt thread From: Martin Galvan To: freebsd-drivers@freebsd.org, nparhar@gmail.com Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Dec 2014 07:34:11 -0000 2014-12-11 16:58 GMT-03:00 Navdeep Parhar : > MTX_DEF mutexes can block but never sleep, and it is perfectly safe to acquire > them in an ithread. Thanks a lot for your answer. At first I was a bit confused on what the actual difference between "blocking" and "sleeping" was, but then I read the "Bounded vs Unbounded Sleep" section from locking(9) and it cleared things out a bit. I still don't understand why can't we sleep (i.e. do an 'unbounded sleep') inside an ithread. What would be the problem, exactly?