Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1804939imu; Wed, 21 Nov 2018 02:09:25 -0800 (PST) X-Google-Smtp-Source: AFSGD/W49p6cUyAJRwmMfa2aWSQ70VjSZkmp+hHXE0A5XfaAaIyGEV8dmajRZIwcmkYjGcE+L7im X-Received: by 2002:a63:f901:: with SMTP id h1mr5413608pgi.154.1542794965133; Wed, 21 Nov 2018 02:09:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542794965; cv=none; d=google.com; s=arc-20160816; b=QCjM2AUO/xvhXTLKeZQZb11Jk3LmvG28Xn3TlDCieRM9EkZB25Zubefi8EDMjAfPuV oeMf6h9/3AERErgSf8n7OD5rDygJj8LdBWPEboY6YQf2F0EDR3sLkHA11M5G3zQAee7B uvX9TvjFZAt5Tz4cAbZD+/575cdD1Rl7M2mqcnKa0e67RHGFKLdUVXLsX8XPb39Fes0m lHciRgDVQFWe+ffIWXNF+LB8KwjEXZ/l4mkBeMvzh+T+ZzhGyYLUjuL3cZQrpcUrmia5 V6J3beTAGafE/xYcxnKwJQ+ap3GgPeDCmXhmyqwDahz2QnmceswIBguxq8XmOixSDtNC 4Wyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=2qxWy+Y6Yh/+zvin5x6lJk/8B+6CDIKt4dGYq7F9x4g=; b=aueLWcZQqGtFrnwYmhTNb+8ZHNenSmYcskrNamn3r7LnpnpmvQkm1XzhBEG1CGtOhK AqC+40n04pHD9k0T+vom4gJzNWOIBOc+732uPpkOSyOJ56fVUrva79K8O7ENFlF8KpiW gYNICK/zPEd0+KwSNsrCzvSSIj7iW8OxEgQGYDA5ZbCE3xOmQnALJ/tYfLjXe2PhlWns cK393CE5n1imdkM/vUvMx2L6DUx8jbCUmTvp+qExJUfOezamCPSXgRvsIj59sT7AfoWp y8lEPmxvnOsPJ2XQtwCBUTSjz86lIRduc7Sgc75us0JvfWbV6B+qNkNm8mVGwlXHOpnC oYow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p9-v6si53830217pfe.76.2018.11.21.02.09.09; Wed, 21 Nov 2018 02:09:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729609AbeKUUjZ (ORCPT + 99 others); Wed, 21 Nov 2018 15:39:25 -0500 Received: from mga18.intel.com ([134.134.136.126]:14789 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729526AbeKUUjY (ORCPT ); Wed, 21 Nov 2018 15:39:24 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2018 02:05:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,260,1539673200"; d="scan'208";a="275727057" Received: from btwcube1.sh.intel.com ([10.67.104.173]) by orsmga005.jf.intel.com with ESMTP; 21 Nov 2018 02:05:32 -0800 From: Tiwei Bie To: mst@redhat.com, jasowang@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, virtio-dev@lists.oasis-open.org Cc: wexu@redhat.com, jfreimann@redhat.com, maxime.coquelin@redhat.com, tiwei.bie@intel.com Subject: [PATCH net-next v3 05/13] virtio_ring: introduce debug helpers Date: Wed, 21 Nov 2018 18:03:22 +0800 Message-Id: <20181121100330.24846-6-tiwei.bie@intel.com> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20181121100330.24846-1-tiwei.bie@intel.com> References: <20181121100330.24846-1-tiwei.bie@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce debug helpers for last_add_time update, check and invalid. They will be used by packed ring too. Signed-off-by: Tiwei Bie --- drivers/virtio/virtio_ring.c | 49 ++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 0b97e5c79654..10d407910aa2 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -44,6 +44,26 @@ } while (0) #define END_USE(_vq) \ do { BUG_ON(!(_vq)->in_use); (_vq)->in_use = 0; } while(0) +#define LAST_ADD_TIME_UPDATE(_vq) \ + do { \ + ktime_t now = ktime_get(); \ + \ + /* No kick or get, with .1 second between? Warn. */ \ + if ((_vq)->last_add_time_valid) \ + WARN_ON(ktime_to_ms(ktime_sub(now, \ + (_vq)->last_add_time)) > 100); \ + (_vq)->last_add_time = now; \ + (_vq)->last_add_time_valid = true; \ + } while (0) +#define LAST_ADD_TIME_CHECK(_vq) \ + do { \ + if ((_vq)->last_add_time_valid) { \ + WARN_ON(ktime_to_ms(ktime_sub(ktime_get(), \ + (_vq)->last_add_time)) > 100); \ + } \ + } while (0) +#define LAST_ADD_TIME_INVALID(_vq) \ + ((_vq)->last_add_time_valid = false) #else #define BAD_RING(_vq, fmt, args...) \ do { \ @@ -53,6 +73,9 @@ } while (0) #define START_USE(vq) #define END_USE(vq) +#define LAST_ADD_TIME_UPDATE(vq) +#define LAST_ADD_TIME_CHECK(vq) +#define LAST_ADD_TIME_INVALID(vq) #endif struct vring_desc_state { @@ -295,18 +318,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq, return -EIO; } -#ifdef DEBUG - { - ktime_t now = ktime_get(); - - /* No kick or get, with .1 second between? Warn. */ - if (vq->last_add_time_valid) - WARN_ON(ktime_to_ms(ktime_sub(now, vq->last_add_time)) - > 100); - vq->last_add_time = now; - vq->last_add_time_valid = true; - } -#endif + LAST_ADD_TIME_UPDATE(vq); BUG_ON(total_sg == 0); @@ -467,13 +479,8 @@ static bool virtqueue_kick_prepare_split(struct virtqueue *_vq) new = vq->split.avail_idx_shadow; vq->num_added = 0; -#ifdef DEBUG - if (vq->last_add_time_valid) { - WARN_ON(ktime_to_ms(ktime_sub(ktime_get(), - vq->last_add_time)) > 100); - } - vq->last_add_time_valid = false; -#endif + LAST_ADD_TIME_CHECK(vq); + LAST_ADD_TIME_INVALID(vq); if (vq->event) { needs_kick = vring_need_event(virtio16_to_cpu(_vq->vdev, @@ -597,9 +604,7 @@ static void *virtqueue_get_buf_ctx_split(struct virtqueue *_vq, &vring_used_event(&vq->split.vring), cpu_to_virtio16(_vq->vdev, vq->last_used_idx)); -#ifdef DEBUG - vq->last_add_time_valid = false; -#endif + LAST_ADD_TIME_INVALID(vq); END_USE(vq); return ret; -- 2.14.5