From patchwork Sat Jul 22 09:53:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Gmeiner X-Patchwork-Id: 9858037 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 20F4F600F5 for ; Sat, 22 Jul 2017 09:55:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B9B6285ED for ; Sat, 22 Jul 2017 09:55:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00A99285F5; Sat, 22 Jul 2017 09:55:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A3A34285ED for ; Sat, 22 Jul 2017 09:55:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6DDBD6E0A9; Sat, 22 Jul 2017 09:55:08 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8E1CB6E0A9; Sat, 22 Jul 2017 09:55:06 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id c24so10220022wra.2; Sat, 22 Jul 2017 02:55:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xuI0ZVa910xBQhWuITOGrEBkMsJkM9UVLMgDM74ZqRo=; b=c7axeAUH6Vc5pONEll6wue+2vTFv29wmWmVIEMNq78SMTlzkJM2+aDUz259ORsyqtU J6idZC/SJZsG60D0kyuE5sl7Pa7jlyZ2jmsI2iMoAOskdYqCU2Yd6Kzls9G/Oi4xjGUc 0X8Zrxam8TLt3nBb0yJdc1jcT3LmqtQv1wvGlPs09QtZ3zbpwwtSv/XH3IeT9u10nyuw s8YpAeDG+4bX/OoiMfq6awdSTIKfrZu7ZeZumyCupMwF4HnQBniM7t2cH0/AbBpSDwOO m93EXE4g78ZnUrDxOlo7IAeC9456MWyjqlEzA1dcnUAKOM0QYQXcJ9kVtO5ZDp2FnDOU Yjng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xuI0ZVa910xBQhWuITOGrEBkMsJkM9UVLMgDM74ZqRo=; b=jXC86ivtYV8sgtm/GoYPl9mYY1/OvZBkVF5Hxsvzsn3wYjjx29w0EZPiCNLjfr+/C2 AQpqqpIyCK6p4Sd/YKO5H/5kkoTshZgWzaqCgLST6LKti6bKBUKZuR5F4IXOZgmMTxgq yqn2R+WTjVa6zgotE2UZUQ7dbBIAQX7ILEj8xkR6USw1/wYJKMz51SXBEJ1To5sCBeig +qX3oaqVNZDsOHl7khUVkcVN2RXIYTDuoL0xVO3CNjkRHfZhA0b8DgLn7P0Cimf3xF6C EsBkDGjhKqfAKMgdRQD2wiCd52PG/M4X6DqDO2H/XlHgG2uo7ls8AbcSAa+ggYkjvwRE jJOQ== X-Gm-Message-State: AIVw111SeAT0A9az84HWoMOQgGJSxEELAqHJYAsaT2Slu2selJbEEopM ts6UxlK+dclerTNx X-Received: by 10.223.153.70 with SMTP id x64mr11329264wrb.18.1500717304892; Sat, 22 Jul 2017 02:55:04 -0700 (PDT) Received: from cp720.fritz.box (91-114-193-248.adsl.highway.telekom.at. [91.114.193.248]) by smtp.gmail.com with ESMTPSA id z192sm2544673wmz.44.2017.07.22.02.55.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Jul 2017 02:55:04 -0700 (PDT) From: Christian Gmeiner To: dri-devel@lists.freedesktop.org Subject: [PATCH V2 01/23] drm/etnaviv: use bitmap to keep track of events Date: Sat, 22 Jul 2017 11:53:01 +0200 Message-Id: <20170722095323.9964-2-christian.gmeiner@gmail.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170722095323.9964-1-christian.gmeiner@gmail.com> References: <20170722095323.9964-1-christian.gmeiner@gmail.com> Cc: linux+etnaviv@armlinux.org.uk, etnaviv@lists.freedesktop.org, cphealy@gmail.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is prep work to be able to allocate multiple events in one go. Signed-off-by: Christian Gmeiner --- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 31 +++++++++++++------------------ drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 6 ++++-- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index ada45fdd0eae..fa9c7bd98e9c 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -739,10 +739,9 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu) /* Setup event management */ spin_lock_init(&gpu->event_spinlock); init_completion(&gpu->event_free); - for (i = 0; i < ARRAY_SIZE(gpu->event); i++) { - gpu->event[i].used = false; + bitmap_zero(gpu->event_bitmap, ETNA_NR_EVENTS); + for (i = 0; i < ARRAY_SIZE(gpu->event); i++) complete(&gpu->event_free); - } /* Now program the hardware */ mutex_lock(&gpu->lock); @@ -926,7 +925,7 @@ static void recover_worker(struct work_struct *work) struct etnaviv_gpu *gpu = container_of(work, struct etnaviv_gpu, recover_work); unsigned long flags; - unsigned int i; + unsigned int i = 0; dev_err(gpu->dev, "hangcheck recover!\n"); @@ -945,14 +944,12 @@ static void recover_worker(struct work_struct *work) /* complete all events, the GPU won't do it after the reset */ spin_lock_irqsave(&gpu->event_spinlock, flags); - for (i = 0; i < ARRAY_SIZE(gpu->event); i++) { - if (!gpu->event[i].used) - continue; + for_each_set_bit_from(i, gpu->event_bitmap, ETNA_NR_EVENTS) { dma_fence_signal(gpu->event[i].fence); gpu->event[i].fence = NULL; - gpu->event[i].used = false; complete(&gpu->event_free); } + bitmap_zero(gpu->event_bitmap, ETNA_NR_EVENTS); spin_unlock_irqrestore(&gpu->event_spinlock, flags); gpu->completed_fence = gpu->active_fence; @@ -1143,7 +1140,7 @@ int etnaviv_gpu_fence_sync_obj(struct etnaviv_gem_object *etnaviv_obj, static unsigned int event_alloc(struct etnaviv_gpu *gpu) { unsigned long ret, flags; - unsigned int i, event = ~0U; + unsigned int event; ret = wait_for_completion_timeout(&gpu->event_free, msecs_to_jiffies(10 * 10000)); @@ -1153,13 +1150,11 @@ static unsigned int event_alloc(struct etnaviv_gpu *gpu) spin_lock_irqsave(&gpu->event_spinlock, flags); /* find first free event */ - for (i = 0; i < ARRAY_SIZE(gpu->event); i++) { - if (gpu->event[i].used == false) { - gpu->event[i].used = true; - event = i; - break; - } - } + event = find_first_zero_bit(gpu->event_bitmap, ETNA_NR_EVENTS); + if (event < ETNA_NR_EVENTS) + set_bit(event, gpu->event_bitmap); + else + event = ~0U; spin_unlock_irqrestore(&gpu->event_spinlock, flags); @@ -1172,12 +1167,12 @@ static void event_free(struct etnaviv_gpu *gpu, unsigned int event) spin_lock_irqsave(&gpu->event_spinlock, flags); - if (gpu->event[event].used == false) { + if (!test_bit(event, gpu->event_bitmap)) { dev_warn(gpu->dev, "event %u is already marked as free", event); spin_unlock_irqrestore(&gpu->event_spinlock, flags); } else { - gpu->event[event].used = false; + clear_bit(event, gpu->event_bitmap); spin_unlock_irqrestore(&gpu->event_spinlock, flags); complete(&gpu->event_free); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h index 689cb8f3680c..70e6590aacdf 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h @@ -88,13 +88,14 @@ struct etnaviv_chip_identity { }; struct etnaviv_event { - bool used; struct dma_fence *fence; }; struct etnaviv_cmdbuf_suballoc; struct etnaviv_cmdbuf; +#define ETNA_NR_EVENTS 30 + struct etnaviv_gpu { struct drm_device *drm; struct thermal_cooling_device *cooling; @@ -112,7 +113,8 @@ struct etnaviv_gpu { u32 memory_base; /* event management: */ - struct etnaviv_event event[30]; + DECLARE_BITMAP(event_bitmap, ETNA_NR_EVENTS); + struct etnaviv_event event[ETNA_NR_EVENTS]; struct completion event_free; spinlock_t event_spinlock;