From owner-freebsd-hackers@FreeBSD.ORG Mon Apr 21 21:46:12 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4B1C6106566B for ; Mon, 21 Apr 2008 21:46:12 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.156]) by mx1.freebsd.org (Postfix) with ESMTP id CDF488FC13 for ; Mon, 21 Apr 2008 21:46:11 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: by fg-out-1718.google.com with SMTP id 16so2082720fgg.35 for ; Mon, 21 Apr 2008 14:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=uJyFTgJNiwcyiUjvW9ovy97tpltPWtHu3brBtHVFd/s=; b=TaZLWY7/PG2U3E+1jnDN6rI97QublqOrZh/iCmB8tgrbio7RLd8LHnZ5QoJ4bdGPDJI6JiDYLO4JDNGVNafzB+NcCX5fsWA10yZLN1ed4N8y/lPm4u3arOaKi0Pm/p7O4Sn3jSI9VuoQJkBi3kdTFcso39a5C768Dh6hCTZ10LY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=N4zCyZ6SPqHTE2/5ewiY/Xr+ktpRBKcD1SRNmqR4PlWen9w4ExBVuxFbNJNto6+w7tcBQKpL9OxLRLpnOsuq7tTsODvYvEO6IuOfkEnJZRhzXaoA9POvfTzyUEhan8ueEARUQS2meksz3Ofd6uA4GD1ekdPGqPP06ouKod1MAWY= Received: by 10.86.72.15 with SMTP id u15mr14170437fga.21.1208812796144; Mon, 21 Apr 2008 14:19:56 -0700 (PDT) Received: by 10.86.36.15 with HTTP; Mon, 21 Apr 2008 14:19:56 -0700 (PDT) Message-ID: <3bbf2fe10804211419r5a5178e1ndd2cdc65430b651c@mail.gmail.com> Date: Mon, 21 Apr 2008 23:19:56 +0200 From: "Attilio Rao" Sender: asmrookie@gmail.com To: "Murty, Ravi" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Google-Sender-Auth: 914533151dcce9ad Cc: freebsd-hackers@freebsd.org Subject: Re: Do you really "sleep" when blocked on a mutex? 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, 21 Apr 2008 21:46:12 -0000 2008/4/21, Murty, Ravi : > Hello, > > > > When a thread cannot get a mutex (default mutex) and needs to be > blocked, is it really put to sleep? From looking at the code it appears > that it is inhibited (TD_SET_LOCK) but isn't really put to sleep. > >From a scheduler perspective, sleeping and blocking are 2 different events but from a low level look-through there is not much difference. What happens is that the thread is maked as inhibited, moved into a different queue than runqueue and switched out. What really changes is upper level behaviour. TD_SET_LOCK is used in conjuction with turnstiles which basically operate priority propagation on the 'lock owner' and so the turnstile becames the recipient for blocked thread (in other word, the turnstile is the 'different queue than runqueue' where the thread lives). TD_SET_SLEEP, on the other side, is used in conjuction with sleepqueue which doesn't operate priority propagation to lock owner (as long as, often, this owner is not present -- just think to wait channels). In this case the recipient is the sleepqueue and there the thread lives. On a low level the paradigm is similar when a thread blocks using the turnstile or sleeps using the sleepqueue: - the thread is running so it is nomore present on any runqueue - the thread is marked as inhibited - the relevant event is signalled (lock / sleep) - the thread is assigned to the new recipient (turnstile / sleepqueue) - the thread is switched out Thanks, Attilio -- Peace can only be achieved by understanding - A. Einstein