From owner-freebsd-hackers@FreeBSD.ORG Fri Sep 16 14:41:28 2011 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 16B7F106564A for ; Fri, 16 Sep 2011 14:41:28 +0000 (UTC) (envelope-from kmacybsd@gmail.com) Received: from mail-qy0-f182.google.com (mail-qy0-f182.google.com [209.85.216.182]) by mx1.freebsd.org (Postfix) with ESMTP id C51D58FC17 for ; Fri, 16 Sep 2011 14:41:27 +0000 (UTC) Received: by qyk4 with SMTP id 4so4436218qyk.13 for ; Fri, 16 Sep 2011 07:41:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=fPC6KmtjV+jEaaEaC6YygDNQdI6GcF6RbBnZHt4M3SU=; b=YYBKkYxEmNu12VxZclxzO7/YVcYHUWl7n5z+sGUw2XI68ialW+0wGPdXK0jgYcM9yI EaE3Bs4OLWrDQ3nrkVrxQWdk2tXz7aaUr3nq0jJ0TflT8frK8rBgok/1pVYwkMLsbavy 3ihAKfqYotL7RoPWMTvm6CEnxmTQH2zz61tUc= MIME-Version: 1.0 Received: by 10.52.36.101 with SMTP id p5mr1180175vdj.278.1316184086918; Fri, 16 Sep 2011 07:41:26 -0700 (PDT) Sender: kmacybsd@gmail.com Received: by 10.52.113.225 with HTTP; Fri, 16 Sep 2011 07:41:26 -0700 (PDT) In-Reply-To: References: Date: Fri, 16 Sep 2011 16:41:26 +0200 X-Google-Sender-Auth: XptWsiEi-wAvlk9GSILZsr3iTEQ Message-ID: From: "K. Macy" To: Arnaud Lacombe Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: FreeBSD Hackers Subject: Re: buf_ring(9) API precisions 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: Fri, 16 Sep 2011 14:41:28 -0000 On Fri, Sep 16, 2011 at 3:02 AM, Arnaud Lacombe wrote: > Hi, > > On Wed, Sep 14, 2011 at 10:53 PM, Arnaud Lacombe wro= te: >> Hi Kip, >> >> I've got a few question about the buf_ring(9) API. >> >> 1) what means the 'drbr_' prefix. I can guess the two last letter, 'b' >> and 'r', for Buffer Ring, but what about 'd' and 'r' ? >> >> 2) in `sys/sys/buf_ring.h', you defined 'struct buf_ring' as: >> >> struct buf_ring { >> =A0 =A0 =A0 =A0volatile uint32_t =A0 =A0 =A0 br_prod_head; >> =A0 =A0 =A0 =A0volatile uint32_t =A0 =A0 =A0 br_prod_tail; >> =A0 =A0 =A0 =A0int =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 br_prod_size; >> =A0 =A0 =A0 =A0int =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 br_prod_mask; >> =A0 =A0 =A0 =A0uint64_t =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0br_drops; >> =A0 =A0 =A0 =A0uint64_t =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0br_prod_bufs; >> =A0 =A0 =A0 =A0uint64_t =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0br_prod_bytes; > shouldn't those 3 fields be updated atomically, especially on 32bits > platforms ? That might pose a problem as, AFAIK, FreeBSD do not have > MI 64bits atomics operations... Between the point at which br_prod_tail =3D=3D prod_head and when we update br_prod_tail to point to prod_next we are the exclusive owners of the fields in buf_ring. That is why we wait for any other enqueueing threads to update br_prod_tail to point to prod_head before continuing. Cheers /* * If there are other enqueues in progress * that preceeded us, we need to wait for them * to complete */ while (br->br_prod_tail !=3D prod_head) cpu_spinwait(); br->br_prod_bufs++; br->br_prod_bytes +=3D nbytes; br->br_prod_tail =3D prod_next; critical_exit();