From patchwork Mon Apr 29 22:08:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chia-I Wu X-Patchwork-Id: 10922555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1AAF81390 for ; Mon, 29 Apr 2019 22:08:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08D2E289EA for ; Mon, 29 Apr 2019 22:08:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0DA5289ED; Mon, 29 Apr 2019 22:08:32 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 8C4C2289EA for ; Mon, 29 Apr 2019 22:08:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 259D9892E4; Mon, 29 Apr 2019 22:08:30 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id 15852892E4 for ; Mon, 29 Apr 2019 22:08:29 +0000 (UTC) Received: by mail-pg1-x543.google.com with SMTP id t22so2811680pgi.10 for ; Mon, 29 Apr 2019 15:08:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=neudzHMjG+trVVVGpjV7l9fWvO6StovsfoKxdSU/ZIA=; b=AWROIKbWyc/45g3jZvRmQ3Otr9vyWxDqWjESTprBAmW9ctuAApY549KXp1D3F7hRdn 7k3uwKG7fNAwvGVgeQA+NTRtXVTuOCCYvAjh5EeOsLtlYSN9qNP0OngpLj+iq1V4l/eE iKK4+94jBXqaNZqce0cKvV0/elQQ6zYSQVoBOWxoCMxBmxlQqXTLgqgNc7Ttw1ppJxTx EiBmft+KHWUDupemlCP6b+snw5Y0w9Y8MT70HnKy1EAR8bK0n93v4TS7iLAPpFtnyBoa VfjfeH4kMKKKBOR9QndM043e7IHOq93ugUB943gKppULHWwPjJ3W8MYD3f2HBDOUdLFf IZGA== X-Gm-Message-State: APjAAAXLPKeC/SvYQnt/t6H1kuBYRr+yX2UTaImCLJLLfLMJ2EGjTG9W RpkvuB8kSGBQSj35JcaEUzUfXr1b X-Google-Smtp-Source: APXvYqzbmnrjBmExhJ3it6/PaKTv8B/fYuVhR6UQOeIjQCeR9sWjd3dhQpfWgu915YZNl9vHK4DrUA== X-Received: by 2002:a65:4907:: with SMTP id p7mr12744067pgs.288.1556575708070; Mon, 29 Apr 2019 15:08:28 -0700 (PDT) Received: from olv0.mtv.corp.google.com ([2620:15c:202:201:9649:82d6:f889:b307]) by smtp.gmail.com with ESMTPSA id g3sm14828635pfm.167.2019.04.29.15.08.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Apr 2019 15:08:27 -0700 (PDT) From: Chia-I Wu To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/3] drm/virtio: set seqno for dma-fence Date: Mon, 29 Apr 2019 15:08:23 -0700 Message-Id: <20190429220825.156644-1-olvaffe@gmail.com> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=neudzHMjG+trVVVGpjV7l9fWvO6StovsfoKxdSU/ZIA=; b=EAG9jofuxrKzhgGJAiMmQYJxKdNBHe+HxBCZAFLhQmKo2VKtiX9sMaudaEVVUuJbU0 cGC7Ab55v91eh/WpQXQP/QMKb4uO+dR/NWLibN1iZeQHgLKuHp+jFGKw9ggyJk5rUXMe I83gbSA0b3tt2c+6a/Ok29TWlIPt3Gr911IW7DOgI6+ojW9S9+BMiDFHoPvAWqkevuBw gQIWN2Pjh1IFtY3GfpjnZ4beEaLbQNpzWsokrpIqyqlDkF4XZzfVFEo5KDfi9tmG8L8j unJgJUJrQ2Z5usush4n5xFDE8FdYnIFan5DIACzR3fJHm1mF6qCFcZZW9jQmVjYVb1uH 5Jsg== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is motivated by having meaningful ftrace events, but it also fixes use cases where dma_fence_is_later is called, such as in sync_file_merge. In other drivers, fence creation and cmdbuf submission normally happen atomically, mutex_lock(); fence = dma_fence_create(..., ++timeline->seqno); submit_cmdbuf(); mutex_unlock(); and have no such issue. But in our driver, because most ioctls queue commands into ctrlq, we do not want to grab a lock. Instead, we set seqno to 0 when a fence is created, and update it when the command is finally queued and the seqno is known. Signed-off-by: Chia-I Wu Reviewed-by: Emil Velikov --- drivers/gpu/drm/virtio/virtgpu_drv.h | 1 - drivers/gpu/drm/virtio/virtgpu_fence.c | 17 ++++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index 491dec0712b3..90461feeafdb 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -102,7 +102,6 @@ struct virtio_gpu_fence { struct dma_fence f; struct virtio_gpu_fence_driver *drv; struct list_head node; - uint64_t seq; }; #define to_virtio_fence(x) \ container_of(x, struct virtio_gpu_fence, f) diff --git a/drivers/gpu/drm/virtio/virtgpu_fence.c b/drivers/gpu/drm/virtio/virtgpu_fence.c index 87d1966192f4..72b4f7561432 100644 --- a/drivers/gpu/drm/virtio/virtgpu_fence.c +++ b/drivers/gpu/drm/virtio/virtgpu_fence.c @@ -40,16 +40,14 @@ bool virtio_fence_signaled(struct dma_fence *f) { struct virtio_gpu_fence *fence = to_virtio_fence(f); - if (atomic64_read(&fence->drv->last_seq) >= fence->seq) + if (atomic64_read(&fence->drv->last_seq) >= fence->f.seqno) return true; return false; } static void virtio_fence_value_str(struct dma_fence *f, char *str, int size) { - struct virtio_gpu_fence *fence = to_virtio_fence(f); - - snprintf(str, size, "%llu", fence->seq); + snprintf(str, size, "%llu", f->seqno); } static void virtio_timeline_value_str(struct dma_fence *f, char *str, int size) @@ -76,6 +74,11 @@ struct virtio_gpu_fence *virtio_gpu_fence_alloc(struct virtio_gpu_device *vgdev) return fence; fence->drv = drv; + + /* This only partially initializes the fence because the seqno is + * unknown yet. The fence must not be used outside of the driver + * until virtio_gpu_fence_emit is called. + */ dma_fence_init(&fence->f, &virtio_fence_ops, &drv->lock, drv->context, 0); return fence; @@ -89,13 +92,13 @@ int virtio_gpu_fence_emit(struct virtio_gpu_device *vgdev, unsigned long irq_flags; spin_lock_irqsave(&drv->lock, irq_flags); - fence->seq = ++drv->sync_seq; + fence->f.seqno = ++drv->sync_seq; dma_fence_get(&fence->f); list_add_tail(&fence->node, &drv->fences); spin_unlock_irqrestore(&drv->lock, irq_flags); cmd_hdr->flags |= cpu_to_le32(VIRTIO_GPU_FLAG_FENCE); - cmd_hdr->fence_id = cpu_to_le64(fence->seq); + cmd_hdr->fence_id = cpu_to_le64(fence->f.seqno); return 0; } @@ -109,7 +112,7 @@ void virtio_gpu_fence_event_process(struct virtio_gpu_device *vgdev, spin_lock_irqsave(&drv->lock, irq_flags); atomic64_set(&vgdev->fence_drv.last_seq, last_seq); list_for_each_entry_safe(fence, tmp, &drv->fences, node) { - if (last_seq < fence->seq) + if (last_seq < fence->f.seqno) continue; dma_fence_signal_locked(&fence->f); list_del(&fence->node);