From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 80BD88D3C for ; Thu, 17 Dec 2015 04:11:56 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 16 Dec 2015 19:11:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,439,1444719600"; d="scan'208";a="873183519" Received: from yliu-dev.sh.intel.com ([10.239.66.49]) by orsmga002.jf.intel.com with ESMTP; 16 Dec 2015 19:11:46 -0800 From: Yuanhan Liu To: dev@dpdk.org Date: Thu, 17 Dec 2015 11:11:57 +0800 Message-Id: <1450321921-27799-3-git-send-email-yuanhan.liu@linux.intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1450321921-27799-1-git-send-email-yuanhan.liu@linux.intel.com> References: <1449027793-30975-1-git-send-email-yuanhan.liu@linux.intel.com> <1450321921-27799-1-git-send-email-yuanhan.liu@linux.intel.com> Cc: "Michael S. Tsirkin" , Victor Kaplansky Subject: [dpdk-dev] [PATCH v2 2/6] vhost: introduce vhost_log_write X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Dec 2015 03:11:57 -0000 Introduce vhost_log_write() helper function to log the dirty pages we touched. Page size is harded code to 4096 (VHOST_LOG_PAGE), and each log is presented by 1 bit. Therefore, vhost_log_write() simply finds the right bit for related page we are gonna change, and set it to 1. dev->log_base denotes the start of the dirty page bitmap. Signed-off-by: Yuanhan Liu Signed-off-by: Victor Kaplansky +#include #include #include #include @@ -59,6 +60,8 @@ struct rte_mbuf; /* Backend value set by guest. */ #define VIRTIO_DEV_STOPPED -1 +#define VHOST_LOG_PAGE 4096 + /* Enum for virtqueue management. */ enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM}; @@ -205,6 +208,32 @@ gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa) return vhost_va; } +static inline void __attribute__((always_inline)) +vhost_log_page(uint8_t *log_base, uint64_t page) +{ + log_base[page / 8] |= 1 << (page % 8); +} + +static inline void __attribute__((always_inline)) +vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len) +{ + uint64_t page; + + if (likely(((dev->features & (1ULL << VHOST_F_LOG_ALL)) == 0) || + !dev->log_base || !len)) + return; + + if (unlikely(dev->log_size < ((addr + len - 1) / VHOST_LOG_PAGE / 8))) + return; + + page = addr / VHOST_LOG_PAGE; + while (page * VHOST_LOG_PAGE < addr + len) { + vhost_log_page((uint8_t *)(uintptr_t)dev->log_base, page); + page += VHOST_LOG_PAGE; + } +} + + /** * Disable features in feature_mask. Returns 0 on success. */ -- 1.9.0