From owner-freebsd-hackers@freebsd.org Sun Apr 9 18:02:08 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C43DCD3607A for ; Sun, 9 Apr 2017 18:02:08 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-io0-x230.google.com (mail-io0-x230.google.com [IPv6:2607:f8b0:4001:c06::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8ACAF895 for ; Sun, 9 Apr 2017 18:02:08 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: by mail-io0-x230.google.com with SMTP id r16so19129880ioi.2 for ; Sun, 09 Apr 2017 11:02:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=uuoVb0oAtQXZ/NyuchdxgsKc/vAdEk+3WWY3C6y6/HA=; b=TFzidzG5LLGHLFZBiHNcCZOSGvHzlkQPZ1GVbvaUnFH34Eddap/PZn9IedLvAhz32j 0/StQdzqEq8vTTtdeFFytHoFdqraWZ8Tb/bgyLAeYavygNlz9Ts2tbecgf7OnW4y79nY LwsbfSADRxJjaRhB8Qy8i7r5gaOburE0gR+CIxXLJggUQAMjL0NnqSq4ekQySJalSw7J qBrsch3TvqAgKx0H8GaT72mRQlPWnNetHVDRbxCFHChqpJUkqRlOD/lqja6h1Gras/+H skkttrOv9mnVdZgxfmHm0TK/voQ48q/HbQwCwJygZ/G5zokii4MPiom/jb9ztY9FRS9Q PjJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=uuoVb0oAtQXZ/NyuchdxgsKc/vAdEk+3WWY3C6y6/HA=; b=AZE9dH5+dtwJW8xLuxlh+9fSDh9DM32keOkF70MWLBwJuZBCR0FJMOkdarMpwSXTNz SVJhz4oUNWxTFGByxNnbeK8eVR3ZRmkE9zeXxPeXcFAXO7rHqFe1tC65scnS+rjdBd+V 1UlYCt8YH/GAtPFguepBI9IJkFcIySycvclWnAW28JDNgMC95vDQAeO1YEKrpwNQHUB2 TURhB74bwk1g75H3MSRs/0fPnlDw640MonFd13o7U/GPVH2cbpOs3telA9QrozRk5v7/ 2SeKU7MQ4Gtdv+cjYVLxuLsoRg/5BbpFFWG07WwjmsZnA4S1RqqBDdZPJtdUjhgFwCkp axXw== X-Gm-Message-State: AFeK/H12LNHWavsepZmXn3VRggpOU38TrpP75uVwqgMl+3AjJV1iyT2RArpq5TIbNs9ARJX06Ro9mjGmSVzSQQ== X-Received: by 10.107.164.36 with SMTP id n36mr46312095ioe.103.1491760927967; Sun, 09 Apr 2017 11:02:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.19.33 with HTTP; Sun, 9 Apr 2017 11:02:07 -0700 (PDT) In-Reply-To: References: From: Ryan Stone Date: Sun, 9 Apr 2017 14:02:07 -0400 Message-ID: Subject: Re: Understanding the FreeBSD locking mechanism To: vasanth sabavat Cc: Yubin Ruan , Ed Schouten , "freebsd-hackers@freebsd.org" Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Apr 2017 18:02:08 -0000 On Sun, Apr 9, 2017 at 12:48 PM, vasanth sabavat wrote: > Isn't it true that interrupt handlers instead of running on the current > thread stack now have their own thread? > It depend on what you mean by "interrupt handler" in this context,as that's ambiguous in FreeBSD. Most driver interrupt handling is done through an ithread, which does have its own thread context, and MTX_DEF mutexes are the appropriate locking primitive to use with them. However, it is possible to handle an interrupt through what FreeBSD calls an "interrupt filter", which runs on the kernel stack of whatever thread happened to be running on the CPU, and therefore you must use a spinlock to synchronize with an interrupt. FreeBSD prefers the use of ithreads and MTX_DEF mutexes over filters and spinlocks. Sorry for the use of confusing terminology. I considering referring interrupt filters in my last message, but I figured the term would be unfamiliar to someone not intimately familiar with FreeBSD internals so I decided to avoid it.