From owner-freebsd-multimedia@FreeBSD.ORG Thu Jul 18 21:22:42 2013 Return-Path: Delivered-To: freebsd-multimedia@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 20B085C3; Thu, 18 Jul 2013 21:22:42 +0000 (UTC) (envelope-from hps@bitfrost.no) Received: from mta.bitpro.no (mta.bitpro.no [92.42.64.202]) by mx1.freebsd.org (Postfix) with ESMTP id A4AC39E3; Thu, 18 Jul 2013 21:22:41 +0000 (UTC) Received: from mail.lockless.no (mail.lockless.no [46.29.221.38]) by mta.bitpro.no (Postfix) with ESMTP id 6C0B37A19B; Thu, 18 Jul 2013 23:22:39 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.lockless.no (Postfix) with ESMTP id 249878EF20E; Thu, 18 Jul 2013 23:22:42 +0200 (CEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at lockless.no Received: from mail.lockless.no ([127.0.0.1]) by localhost (mail.lockless.no [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tNuvJkXgLIE1; Thu, 18 Jul 2013 23:22:41 +0200 (CEST) Received: from laptop015.hselasky.homeunix.org (cm-176.74.213.204.customer.telag.net [176.74.213.204]) by mail.lockless.no (Postfix) with ESMTPSA id DDD8A8EF20D; Thu, 18 Jul 2013 23:22:40 +0200 (CEST) Message-ID: <51E85CFC.3060305@bitfrost.no> Date: Thu, 18 Jul 2013 23:24:12 +0200 From: Hans Petter Selasky Organization: Bitfrost A/S User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/20130522 Thunderbird/17.0.6 MIME-Version: 1.0 To: =?ISO-8859-1?Q?Bernhard_Fr=F6hlich?= Subject: Re: kqueue(2) vs. cuse4bsd? References: <201307181834.r6IIY35e055755@triton8.kn-bremen.de> <51E844C9.4060106@bitfrost.no> In-Reply-To: Content-Type: multipart/mixed; boundary="------------080807080100070207040400" Cc: freebsd-multimedia@freebsd.org, Juergen Lock X-BeenThere: freebsd-multimedia@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Multimedia discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jul 2013 21:22:42 -0000 This is a multi-part message in MIME format. --------------080807080100070207040400 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, >> >> kevent() support is not implemented for cuse4bsd. The devfs callback is > NULL. Possibly could add that, but have to read up on kqueue first. > > Oh what a bummer. It would definitely be good to add that callback but is > this everything that is needed or should we expect more problems? > Hi, Can you try the attached patch for cuse4bsd. Note sure if it works. Check the CPU usage if it is spinning 100% or not. I had to fake some kqueue events. Also need to know if this code compiles with 8-stable. --HPS --------------080807080100070207040400 Content-Type: text/x-patch; name="kqfilter.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kqfilter.diff" Index: cuse4bsd_kmod.c =================================================================== --- cuse4bsd_kmod.c (revision 2614) +++ cuse4bsd_kmod.c (working copy) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2010-2012 Hans Petter Selasky. All rights reserved. + * Copyright (c) 2010-2013 Hans Petter Selasky. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -134,6 +134,15 @@ static int cuse_alloc_unit_id[CUSE_DEVICES_MAX]; static struct cuse_memory cuse_mem[CUSE_ALLOC_UNIT_MAX]; +static void cuse_client_kqfilter_detach(struct knote *kn); +static int cuse_client_kqfilter_event(struct knote *kn, long hint); + +static struct filterops cuse_client_kqfilter_ops = { + .f_isfd = 1, + .f_detach = cuse_client_kqfilter_detach, + .f_event = cuse_client_kqfilter_event, +}; + static d_open_t cuse_client_open; static d_close_t cuse_client_close; static d_ioctl_t cuse_client_ioctl; @@ -141,6 +150,7 @@ static d_write_t cuse_client_write; static d_poll_t cuse_client_poll; static d_mmap_t cuse_client_mmap; +static d_kqfilter_t cuse_client_kqfilter; static struct cdevsw cuse_client_devsw = { .d_version = D_VERSION, @@ -153,6 +163,7 @@ .d_write = cuse_client_write, .d_poll = cuse_client_poll, .d_mmap = cuse_client_mmap, + .d_kqfilter = cuse_client_kqfilter, }; static d_open_t cuse_server_open; @@ -635,6 +646,10 @@ cuse_server_free_memory(pcs); + seldrain(&pcs->selinfo); + + knlist_destroy(&pcs->selinfo.si_note); + cuse_unlock(); cv_destroy(&pcs->cv); @@ -662,6 +677,8 @@ cv_init(&pcs->cv, "cuse-server-cv"); + knlist_init_mtx(&pcs->selinfo.si_note, &cuse_mtx); + cuse_lock(); pcs->refs++; TAILQ_INSERT_TAIL(&cuse_server_head, pcs, entry); @@ -1698,3 +1715,38 @@ return (0); } + +static void +cuse_client_kqfilter_detach(struct knote *kn) +{ + struct cuse_server *pcs; + + cuse_lock(); + pcs = kn->kn_hook; + knlist_remove(&pcs->selinfo.si_note, kn, 0); + cuse_unlock(); +} + +static int +cuse_client_kqfilter_event(struct knote *kn, long hint) +{ + return (1); +} + +static int +cuse_client_kqfilter(struct cdev *dev, struct knote *kn) +{ + struct cuse_client *pcc; + int error; + + error = cuse_client_get(&pcc); + if (error != 0) + return (error); + + cuse_lock(); + kn->kn_hook = pcc->server; + kn->kn_fop = &cuse_client_kqfilter_ops; + knlist_add(&pcc->server->selinfo.si_note, kn, 0); + cuse_unlock(); + return (0); +} --------------080807080100070207040400--