From owner-freebsd-hackers@FreeBSD.ORG Fri Mar 15 17:19:20 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 89C222FD for ; Fri, 15 Mar 2013 17:19:20 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-ob0-x234.google.com (mail-ob0-x234.google.com [IPv6:2607:f8b0:4003:c01::234]) by mx1.freebsd.org (Postfix) with ESMTP id 57E3CEC5 for ; Fri, 15 Mar 2013 17:19:20 +0000 (UTC) Received: by mail-ob0-f180.google.com with SMTP id ef5so3520289obb.11 for ; Fri, 15 Mar 2013 10:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=lK0UgRVdGi37kItSCzFul2d9b5jxgmyU2QenhEo0Y2c=; b=eNTrN8Bz9KujqKpVeO3Ia7Zjnk9aN684HayUSMpMxyBXmNSPd2iKgouh24UdYyaLlG 4Tbshy0DgFN+5VrIvTNSwLktLJaIXHyEfVf/CABajrVTcLeyS7RnoMVS/pMEt+ZYu84Z 6IDssKzURLCiTAOYWSnuAOV3VUtwMaxG0hiMJPS8g6Y8ALNT4K1YJaM/0GfzyGxmBX5z W3djx46IVf/RW5VZhEIU27iaKEJoIPf91D2Lluuko14xHkmATObPBhJajZ9vjVl09pd5 e2RG84zLEacAruI/vdF73yNed9FDvgTBUuZP6NPU8xfuwiB09WDTh+yc+KEdNRrA6AfJ AVGw== MIME-Version: 1.0 X-Received: by 10.60.172.237 with SMTP id bf13mr3389030oec.83.1363367959940; Fri, 15 Mar 2013 10:19:19 -0700 (PDT) Received: by 10.76.109.236 with HTTP; Fri, 15 Mar 2013 10:19:19 -0700 (PDT) In-Reply-To: <51435063.7050907@embedded-brains.de> References: <51435063.7050907@embedded-brains.de> Date: Fri, 15 Mar 2013 13:19:19 -0400 Message-ID: Subject: Re: Purpose of kqueue_task? From: Ryan Stone To: Sebastian Huber Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: FreeBSD Hackers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Mar 2013 17:19:20 -0000 On Fri, Mar 15, 2013 at 12:46 PM, Sebastian Huber < sebastian.huber@embedded-brains.de> wrote: > Hello, > > I want to port the FreeBSD kqueue implementation to another operating > system (RTEMS in this case) to improve the Erlang support. > > I have difficulties to understand the purpose of the kqueue_task. This > function runs asynchronously. It obtains some locks and wakes up the > normal kqueue channel if (kq->kq_state & KQ_TASKDRAIN) == KQ_TASKDRAIN. > This state is only set in kqueue_close(). So most of the time the > kqueue_task only obtains some locks, clears a flag (KQ_TASKSCHED) and > releases the locks? > You missed the most important thing that it does: it calls KNOTE_LOCKED to wake up any waiters sleeping on this event. I suspect that it had to be done in a separate task due to lock ordering problems with the kq_global lock. The call to wakeup() is used to synchronize with kqueue_close to ensure that kqueue_close will not free the kqueue while the task is pending. Otherwise the task could run after kq was freed and crash the system.