From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751757AbcERW5x (ORCPT ); Wed, 18 May 2016 18:57:53 -0400 Received: from mail.fireflyinternet.com ([87.106.93.118]:65237 "EHLO fireflyinternet.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751332AbcERW5w (ORCPT ); Wed, 18 May 2016 18:57:52 -0400 X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Date: Wed, 18 May 2016 23:57:10 +0100 From: Chris Wilson To: Gustavo Padovan Cc: dri-devel@lists.freedesktop.org, marcheu@google.com, Daniel Stone , seanpaul@google.com, Daniel Vetter , linux-kernel@vger.kernel.org, Christian =?iso-8859-1?Q?K=F6nig?= , laurent.pinchart@ideasonboard.com, Alex Deucher , Gustavo Padovan , John Harrison , m.chehab@samsung.com Subject: Re: [PATCH 1/2] dma-buf/fence: add fence_collection fences Message-ID: <20160518225710.GA32627@nuc-i3427.alporthouse.com> Mail-Followup-To: Chris Wilson , Gustavo Padovan , dri-devel@lists.freedesktop.org, marcheu@google.com, Daniel Stone , seanpaul@google.com, Daniel Vetter , linux-kernel@vger.kernel.org, Christian =?iso-8859-1?Q?K=F6nig?= , laurent.pinchart@ideasonboard.com, Alex Deucher , Gustavo Padovan , John Harrison , m.chehab@samsung.com References: <1463605193-18040-1-git-send-email-gustavo@padovan.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1463605193-18040-1-git-send-email-gustavo@padovan.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 18, 2016 at 05:59:52PM -0300, Gustavo Padovan wrote: > +static void collection_check_cb_func(struct fence *fence, struct fence_cb *cb) > +{ > + struct fence_collection_cb *f_cb; > + struct fence_collection *collection; > + > + f_cb = container_of(cb, struct fence_collection_cb, cb); > + collection = f_cb->collection; > + > + if (atomic_dec_and_test(&collection->num_pending_fences)) > + fence_signal(&collection->base); > +} > + > +static bool fence_collection_enable_signaling(struct fence *fence) > +{ > + struct fence_collection *collection = to_fence_collection(fence); > + int i; > + > + for (i = 0 ; i < collection->num_fences ; i++) { > + if (fence_add_callback(collection->fences[i].fence, > + &collection->fences[i].cb, > + collection_check_cb_func)) { > + atomic_dec(&collection->num_pending_fences); > + } > + } We don't always have a convenient means to preallocate an array of fences to use. Keeping a list of fences in addition to the array would be easier to user in many circumstances. Just means we need a struct fence_collection_entry { struct fence *fence; struct list_head link; }; int fence_collection_add(struct fence *_collection, struct fence *fence) { struct fence_collection *collection = to_fence_collection(_collection); struct fence_collection_entry *entry; entry = kmalloc(sizeof(*entry), GFP_KERNEL); if (!entry) return -ENOMEM; entry->fence = fence_get(fence); list_add_tail(&entry->link, &collection->fence_list); atomic_inc(&collection->num_pending_fences); return 0; } and a couple of list iterations as well as walking the arrays. (This fence_collection_add() needs to be documented to only be valid from the constructing thread before the fence is sealed for export/use.) -Chris -- Chris Wilson, Intel Open Source Technology Centre