From patchwork Fri Dec 13 22:24:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22416 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D453D23FBA for ; Fri, 13 Dec 2013 22:27:29 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id e14sf8989548iej.0 for ; Fri, 13 Dec 2013 14:27:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=8qWQIxdAjT/JCfWsEWFObNBcs9j+8tzE5ECpagKiG2w=; b=HMZg3vdQnn+ILW8HO+aTWVvKMkRTchAH2sGfr2kyrcl9V6/PEL+YHUloAC0sn2CPiW zLLbd2Z1MVov+QS/T0Kd6Ckg0iXGGOCf5oj3UzKvwso61tehHNCFwwleO2eKY2QesjDh w8IZc+oZo64TXOyeq2Vnmv1zxLM11pghDoM1XZueKQ8bpzp+MYnV7RwqwOs3035TaXdE COh7m2EuMcOh+F4IHd5C5OSjpV7/QLf+B0H2sKNNcSpH8pjEQQzYJGol8ZbrCms9f8WS osETlCUDz/tfVvw8UYgBLAAxdFHwchs3HsZ0aNwBPxNHwDgF66v4csNOfW3UV5JyflNS HKew== X-Gm-Message-State: ALoCoQkH2KpdC4XqMmIVrw5QxQ6oZwdooaAotV/gTSh3JZ9wYV9Li858Aw4WJ4XztNmDnJRtHqpw X-Received: by 10.42.136.136 with SMTP id u8mr1552573ict.16.1386973649571; Fri, 13 Dec 2013 14:27:29 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.4.105 with SMTP id j9ls1281984qej.94.gmail; Fri, 13 Dec 2013 14:27:29 -0800 (PST) X-Received: by 10.220.74.69 with SMTP id t5mr2249719vcj.18.1386973649135; Fri, 13 Dec 2013 14:27:29 -0800 (PST) Received: from mail-vb0-f48.google.com (mail-vb0-f48.google.com [209.85.212.48]) by mx.google.com with ESMTPS id tj7si1187865vdc.124.2013.12.13.14.27.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:27:29 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.48 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.48; Received: by mail-vb0-f48.google.com with SMTP id f13so1703722vbg.7 for ; Fri, 13 Dec 2013 14:27:29 -0800 (PST) X-Received: by 10.52.103.35 with SMTP id ft3mr1866395vdb.5.1386973649017; Fri, 13 Dec 2013 14:27:29 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp73546vcz; Fri, 13 Dec 2013 14:27:28 -0800 (PST) X-Received: by 10.66.145.166 with SMTP id sv6mr6116719pab.31.1386973648228; Fri, 13 Dec 2013 14:27:28 -0800 (PST) Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com [209.85.192.169]) by mx.google.com with ESMTPS id e8si2483148pac.285.2013.12.13.14.27.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:27:28 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.169 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.169; Received: by mail-pd0-f169.google.com with SMTP id v10so2096718pde.0 for ; Fri, 13 Dec 2013 14:27:27 -0800 (PST) X-Received: by 10.66.146.133 with SMTP id tc5mr6043876pab.58.1386973647792; Fri, 13 Dec 2013 14:27:27 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id qz9sm7457908pbc.3.2013.12.13.14.27.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:27:27 -0800 (PST) From: John Stultz To: LKML Cc: Greg KH , Android Kernel Team , Sumit Semwal , Jesse Barker , Colin Cross , Rebecca Schultz Zavin , John Stultz Subject: [PATCH 051/115] gpu: ion: Switch heap rbtree to a prio list Date: Fri, 13 Dec 2013 14:24:25 -0800 Message-Id: <1386973529-4884-52-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> References: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.48 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Rebecca Schultz Zavin Switches the rbtree tree of heaps for a plist. This significantly simplifies the code and the list is small and is modified only at first boot so the rbtree is unnecessary. This also switches the traversal of the heap list to traverse from highest to lowest id's. This allows allocations to pass a heap mask that falls back on the system heap -- typically id 0, which is the common case. Signed-off-by: Rebecca Schultz Zavin [jstultz: modified patch to apply to staging directory] Signed-off-by: John Stultz --- drivers/staging/android/ion/ion.c | 35 ++++++++-------------------------- drivers/staging/android/ion/ion_priv.h | 4 ++-- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 3f22f88..8cc0489 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -49,7 +49,7 @@ struct ion_device { struct rb_root buffers; struct mutex buffer_lock; struct rw_semaphore lock; - struct rb_root heaps; + struct plist_head heaps; long (*custom_ioctl) (struct ion_client *client, unsigned int cmd, unsigned long arg); struct rb_root clients; @@ -389,10 +389,10 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len, size_t align, unsigned int heap_mask, unsigned int flags) { - struct rb_node *n; struct ion_handle *handle; struct ion_device *dev = client->dev; struct ion_buffer *buffer = NULL; + struct ion_heap *heap; pr_debug("%s: len %d align %d heap_mask %u flags %x\n", __func__, len, align, heap_mask, flags); @@ -408,8 +408,7 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len, len = PAGE_ALIGN(len); down_read(&dev->lock); - for (n = rb_first(&dev->heaps); n != NULL; n = rb_next(n)) { - struct ion_heap *heap = rb_entry(n, struct ion_heap, node); + plist_for_each_entry(heap, &dev->heaps, node) { /* if the client doesn't support this heap type */ if (!((1 << heap->type) & client->heap_mask)) continue; @@ -1266,10 +1265,6 @@ static const struct file_operations debug_heap_fops = { void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap) { - struct rb_node **p = &dev->heaps.rb_node; - struct rb_node *parent = NULL; - struct ion_heap *entry; - if (!heap->ops->allocate || !heap->ops->free || !heap->ops->map_dma || !heap->ops->unmap_dma) pr_err("%s: can not add heap with invalid ops struct.\n", @@ -1277,26 +1272,12 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap) heap->dev = dev; down_write(&dev->lock); - while (*p) { - parent = *p; - entry = rb_entry(parent, struct ion_heap, node); - - if (heap->id < entry->id) { - p = &(*p)->rb_left; - } else if (heap->id > entry->id ) { - p = &(*p)->rb_right; - } else { - pr_err("%s: can not insert multiple heaps with " - "id %d\n", __func__, heap->id); - goto end; - } - } - - rb_link_node(&heap->node, parent, p); - rb_insert_color(&heap->node, &dev->heaps); + /* use negative heap->id to reverse the priority -- when traversing + the list later attempt higher id numbers first */ + plist_node_init(&heap->node, -heap->id); + plist_add(&heap->node, &dev->heaps); debugfs_create_file(heap->name, 0664, dev->debug_root, heap, &debug_heap_fops); -end: up_write(&dev->lock); } @@ -1330,7 +1311,7 @@ struct ion_device *ion_device_create(long (*custom_ioctl) idev->buffers = RB_ROOT; mutex_init(&idev->buffer_lock); init_rwsem(&idev->lock); - idev->heaps = RB_ROOT; + plist_head_init(&idev->heaps); idev->clients = RB_ROOT; return idev; } diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 77e2ac0..57dbf6a 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -127,11 +127,11 @@ struct ion_heap_ops { * that are allocated from a specially reserved heap. */ struct ion_heap { - struct rb_node node; + struct plist_node node; struct ion_device *dev; enum ion_heap_type type; struct ion_heap_ops *ops; - int id; + unsigned int id; const char *name; int (*debug_show)(struct ion_heap *heap, struct seq_file *, void *); };