Skip to contentSkip to conversation

lib/librte_vhost: code style fixes

PATCH In review Huawei Xie 2 participants 6 messages Nov 5, 2014 3 messages not in the archive

lore
Share & tools
lore

Huawei Xie

author
#0 lore raw

PATCH 1/1 lib/librte_vhost: code style fixes

This patch fixes code style issues and refines some comments in vhost library.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 244 ++++++++++-----------
 lib/librte_vhost/eventfd_link/eventfd_link.h | 127 ++++++-----
 lib/librte_vhost/rte_virtio_net.h            |   3 +-
 lib/librte_vhost/vhost-net-cdev.c            | 187 +++++++++-------
 lib/librte_vhost/vhost_rxtx.c                |  13 +-
 lib/librte_vhost/virtio-net.c                | 317 +++++++++++++++++----------
 6 files changed, 494 insertions(+), 397 deletions(-)
lib/librte_vhost/eventfd_link/eventfd_link.c +117 -127
index fc0653a..542ec2c 100644
@@ -1,26 +1,26 @@
 /*-
- *  * GPL LICENSE SUMMARY
- *  *
- *  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *  *
- *  *   This program is free software; you can redistribute it and/or modify
- *  *   it under the terms of version 2 of the GNU General Public License as
- *  *   published by the Free Software Foundation.
- *  *
- *  *   This program is distributed in the hope that it will be useful, but
- *  *   WITHOUT ANY WARRANTY; without even the implied warranty of
- *  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  *   General Public License for more details.
- *  *
- *  *   You should have received a copy of the GNU General Public License
- *  *   along with this program; if not, write to the Free Software
- *  *   Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *  *   The full GNU General Public License is included in this distribution
- *  *   in the file called LICENSE.GPL.
- *  *
- *  *   Contact Information:
- *  *   Intel Corporation
- *   */
+ * GPL LICENSE SUMMARY
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of version 2 of the GNU General Public License as
+ *   published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *   The full GNU General Public License is included in this distribution
+ *   in the file called LICENSE.GPL.
+ *
+ *   Contact Information:
+ *   Intel Corporation
+ */
 
 #include <linux/eventfd.h>
 #include <linux/miscdevice.h>
@@ -42,15 +42,15 @@
  * get_files_struct is copied from fs/file.c
  */
 struct files_struct *
-get_files_struct (struct task_struct *task)
+get_files_struct(struct task_struct *task)
 {
 	struct files_struct *files;
 
-	task_lock (task);
+	task_lock(task);
 	files = task->files;
 	if (files)
-		atomic_inc (&files->count);
-	task_unlock (task);
+		atomic_inc(&files->count);
+	task_unlock(task);
 
 	return files;
 }
@@ -59,17 +59,15 @@ get_files_struct (struct task_struct *task)
  * put_files_struct is extracted from fs/file.c
  */
 void
-put_files_struct (struct files_struct *files)
+put_files_struct(struct files_struct *files)
 {
-	if (atomic_dec_and_test (&files->count))
-	{
-		BUG ();
-	}
+	if (atomic_dec_and_test(&files->count))
+		BUG();
 }
 
 
 static long
-eventfd_link_ioctl (struct file *f, unsigned int ioctl, unsigned long arg)
+eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
 {
 	void __user *argp = (void __user *) arg;
 	struct task_struct *task_target = NULL;
@@ -78,96 +76,88 @@ eventfd_link_ioctl (struct file *f, unsigned int ioctl, unsigned long arg)
 	struct fdtable *fdt;
 	struct eventfd_copy eventfd_copy;
 
-	switch (ioctl)
-	{
-		case EVENTFD_COPY:
-			if (copy_from_user (&eventfd_copy, argp, sizeof (struct eventfd_copy)))
-				return -EFAULT;
-
-			/*
-			 * Find the task struct for the target pid
-			 */
-			task_target =
-				pid_task (find_vpid (eventfd_copy.target_pid), PIDTYPE_PID);
-			if (task_target == NULL)
-			{
-				printk (KERN_DEBUG "Failed to get mem ctx for target pid\n");
-				return -EFAULT;
-			}
-
-			files = get_files_struct (current);
-			if (files == NULL)
-			{
-				printk (KERN_DEBUG "Failed to get files struct\n");
-				return -EFAULT;
-			}
-
-			rcu_read_lock ();
-			file = fcheck_files (files, eventfd_copy.source_fd);
-			if (file)
-			{
-				if (file->f_mode & FMODE_PATH
-						|| !atomic_long_inc_not_zero (&file->f_count))
-					file = NULL;
-			}
-			rcu_read_unlock ();
-			put_files_struct (files);
-
-			if (file == NULL)
-			{
-				printk (KERN_DEBUG "Failed to get file from source pid\n");
-				return 0;
-			}
-
-			/*
-			 * Release the existing eventfd in the source process
-			 */
-			spin_lock (&files->file_lock);
-			filp_close (file, files);
-			fdt = files_fdtable (files);
-			fdt->fd[eventfd_copy.source_fd] = NULL;
-			spin_unlock (&files->file_lock);
-
-			/*
-			 * Find the file struct associated with the target fd.
-			 */
-
-			files = get_files_struct (task_target);
-			if (files == NULL)
-			{
-				printk (KERN_DEBUG "Failed to get files struct\n");
-				return -EFAULT;
-			}
-
-			rcu_read_lock ();
-			file = fcheck_files (files, eventfd_copy.target_fd);
-			if (file)
-			{
-				if (file->f_mode & FMODE_PATH
-						|| !atomic_long_inc_not_zero (&file->f_count))
+	switch (ioctl) {
+	case EVENTFD_COPY:
+		if (copy_from_user(&eventfd_copy, argp,
+			sizeof(struct eventfd_copy)))
+			return -EFAULT;
+
+		/*
+		 * Find the task struct for the target pid
+		 */
+		task_target =
+			pid_task(find_vpid(eventfd_copy.target_pid), PIDTYPE_PID);
+		if (task_target == NULL) {
+			printk(KERN_DEBUG "Failed to get mem ctx for target pid\n");
+			return -EFAULT;
+		}
+
+		files = get_files_struct(current);
+		if (files == NULL) {
+			printk(KERN_DEBUG "Failed to get files struct\n");
+			return -EFAULT;
+		}
+
+		rcu_read_lock();
+		file = fcheck_files(files, eventfd_copy.source_fd);
+		if (file) {
+			if (file->f_mode & FMODE_PATH ||
+				!atomic_long_inc_not_zero(&file->f_count))
+				file = NULL;
+		}
+		rcu_read_unlock();
+		put_files_struct(files);
+
+		if (file == NULL) {
+			printk(KERN_DEBUG "Failed to get file from source pid\n");
+			return 0;
+		}
+
+		/*
+		 * Release the existing eventfd in the source process
+		 */
+		spin_lock(&files->file_lock);
+		filp_close(file, files);
+		fdt = files_fdtable(files);
+		fdt->fd[eventfd_copy.source_fd] = NULL;
+		spin_unlock(&files->file_lock);
+
+		/*
+		 * Find the file struct associated with the target fd.
+		 */
+
+		files = get_files_struct(task_target);
+		if (files == NULL) {
+			printk(KERN_DEBUG "Failed to get files struct\n");
+			return -EFAULT;
+		}
+
+		rcu_read_lock();
+		file = fcheck_files(files, eventfd_copy.target_fd);
+		if (file) {
+			if (file->f_mode & FMODE_PATH ||
+				!atomic_long_inc_not_zero(&file->f_count))
 					file = NULL;
-			}
-			rcu_read_unlock ();
-			put_files_struct (files);
-
-			if (file == NULL)
-			{
-				printk (KERN_DEBUG "Failed to get file from target pid\n");
-				return 0;
-			}
+		}
+		rcu_read_unlock();
+		put_files_struct(files);
 
+		if (file == NULL) {
+			printk(KERN_DEBUG "Failed to get file from target pid\n");
+			return 0;
+		}
 
-			/*
-			 * Install the file struct from the target process into the
-			 * file desciptor of the source process,
-			 */
+		/*
+		 * Install the file struct from the target process into the
+		 * file desciptor of the source process,
+		 */
 
-			fd_install (eventfd_copy.source_fd, file);
+		fd_install(eventfd_copy.source_fd, file);
 
-			return 0;
+		return 0;
 
-		default:
-			return -ENOIOCTLCMD;
+	default:
+		return -ENOIOCTLCMD;
 	}
 }
 
@@ -183,23 +173,23 @@ static struct miscdevice eventfd_link_misc = {
 };
 
 static int __init
-eventfd_link_init (void)
+eventfd_link_init(void)
 {
-	return misc_register (&eventfd_link_misc);
+	return misc_register(&eventfd_link_misc);
 }
 
-module_init (eventfd_link_init);
+module_init(eventfd_link_init);
 
 static void __exit
-eventfd_link_exit (void)
+eventfd_link_exit(void)
 {
-	misc_deregister (&eventfd_link_misc);
+	misc_deregister(&eventfd_link_misc);
 }
 
-module_exit (eventfd_link_exit);
+module_exit(eventfd_link_exit);
 
-MODULE_VERSION ("0.0.1");
-MODULE_LICENSE ("GPL v2");
-MODULE_AUTHOR ("Anthony Fee");
-MODULE_DESCRIPTION ("Link eventfd");
-MODULE_ALIAS ("devname:eventfd-link");
+MODULE_VERSION("0.0.1");
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Anthony Fee");
+MODULE_DESCRIPTION("Link eventfd");
+MODULE_ALIAS("devname:eventfd-link");
lib/librte_vhost/eventfd_link/eventfd_link.h +62 -65

141 lines not on this page · raw message

lib/librte_vhost/rte_virtio_net.h +1 -2
index b6548a1..00b1328 100644
@@ -90,8 +90,7 @@ struct vhost_virtqueue {
 /**
  * Device structure contains all configuration information relating to the device.
  */
-struct virtio_net
-{
+struct virtio_net {
 	struct vhost_virtqueue	*virtqueue[VIRTIO_QNUM];	/**< Contains all virtqueue information. */
 	struct virtio_memory	*mem;		/**< QEMU memory and memory region information. */
 	uint64_t		features;	/**< Negotiated feature set. */
lib/librte_vhost/vhost-net-cdev.c +108 -79

346 lines not on this page · raw message

lib/librte_vhost/vhost_rxtx.c +5 -8
index 84ec0e8..ccfd82f 100644
@@ -45,7 +45,7 @@
 /**
  * This function adds buffers to the virtio devices RX virtqueue. Buffers can
  * be received from the physical port or from another virtio device. A packet
- * count is returned to indicate the number of packets that were succesfully
+ * count is returned to indicate the number of packets that are succesfully
  * added to the RX queue. This function works when mergeable is disabled.
  */
 static inline uint32_t __attribute__((always_inline))
@@ -76,7 +76,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	count = (count > MAX_PKT_BURST) ? MAX_PKT_BURST : count;
 
 	/*
-	 * As many data cores may want access to available buffers, 
+	 * As many data cores may want access to available buffers,
 	 * they need to be reserved.
 	 */
 	do {
@@ -143,7 +143,8 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 		}
 
 		/* Update used ring with desc information */
-		vq->used->ring[res_cur_idx & (vq->size - 1)].id = head[packet_success];
+		vq->used->ring[res_cur_idx & (vq->size - 1)].id =
+							head[packet_success];
 		vq->used->ring[res_cur_idx & (vq->size - 1)].len = packet_len;
 
 		/* Copy mbuf data to buffer */
@@ -389,10 +390,7 @@ copy_from_mbuf_to_vring(struct virtio_net *dev, uint16_t res_base_idx,
 }
 
 /*
- * This function adds buffers to the virtio devices RX virtqueue. Buffers can
- * be received from the physical port or from another virtio device. A packet
- * count is returned to indicate the number of packets that were succesfully
- * added to the RX queue. This function works for mergeable RX.
+ * This function works for mergeable RX.
  */
 static inline uint32_t __attribute__((always_inline))
 virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
@@ -729,5 +727,4 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT))
 		eventfd_write((int)vq->kickfd, 1);
 	return entry_success;
-
 }
lib/librte_vhost/virtio-net.c +201 -116

687 lines not on this page · raw message

Signature · 1 line
1.8.1.4

A message that is not in the archive (sent off-list or not yet received): 1415206995-1086-1-git-send-email-huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

#2 lore raw

Hi Huawei,

checkpatch.pl reports some errors of types PREFER_PR_LEVEL and MISORDERED_TYPE.

Signature · 1 line
Thomas
#3 lore raw

Thomas:
I checked before. checkpatch reports 9 warnings, "over 80 characters" and "prefer pr_deubg". This code style fixes code style issue only, not the pr_debug/printk issue. Thoughts? Besides, I don't understand the MISORDERED_TYPE.

Quoted 14 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, November 05, 2014 1:42 PM
To: Xie, Huawei
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] lib/librte_vhost: code style fixes

Hi Huawei,

checkpatch.pl reports some errors of types PREFER_PR_LEVEL and MISORDERED_TYPE.

--
Thomas

A message that is not in the archive (sent off-list or not yet received): C37D651A908B024F974696C65296B57B0F2E23EB-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org

#5 lore raw

2014-11-05 21:21, Xie, Huawei:

Quoted 3 lines

Thomas:
I checked before. checkpatch reports 9 warnings, "over 80 characters" and "prefer pr_deubg". This code style fixes code style issue only, not the pr_debug/printk issue. Thoughts?

Using pr_debug is a code style fix.

Quoted 1 line

Besides, I don't understand the MISORDERED_TYPE.

You should replace (long long unsigned) by (unsigned long long).

Quoted 14 lines
Quoted 14 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, November 05, 2014 1:42 PM
To: Xie, Huawei
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] lib/librte_vhost: code style fixes

Hi Huawei,

checkpatch.pl reports some errors of types PREFER_PR_LEVEL and MISORDERED_TYPE.

--
Thomas

#6 lore raw
Quoted 7 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, November 05, 2014 2:25 PM
To: Xie, Huawei
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] lib/librte_vhost: code style fixes

Quoted 9 lines

2014-11-05 21:21, Xie, Huawei:

Quoted 2 lines

Thomas:
I checked before. checkpatch reports 9 warnings, "over 80 characters" and

"prefer pr_deubg".

Quoted 1 line

This code style fixes code style issue only, not the pr_debug/printk issue.

Thoughts?

Using pr_debug is a code style fix.

Ok, will also fix this.
If there are other code style issue you want to be fixed in this patch, please let me know.
Btw, for alignment in structure, I see different projects use different way, some use tab, and some use space(between type and var), do we have rules for this? {
Type var1
Type var2
}

Quoted 3 lines
Quoted 1 line

Besides, I don't understand the MISORDERED_TYPE.

You should replace (long long unsigned) by (unsigned long long).

Check patch at my side doesn't report warnings about the patch. I remember I have also check against the source file. Will double check and fix those.

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, November 05, 2014 1:42 PM
To: Xie, Huawei
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] lib/librte_vhost: code style fixes

Hi Huawei,

checkpatch.pl reports some errors of types PREFER_PR_LEVEL and MISORDERED_TYPE.

--
Thomas

A message that is not in the archive (sent off-list or not yet received): C37D651A908B024F974696C65296B57B0F2E2498-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org

#8 lore raw

2014-11-05 21:55, Xie, Huawei:

Quoted 7 lines
Quoted 1 line

2014-11-05 21:21, Xie, Huawei:

Btw, for alignment in structure, I see different projects use different way, some use tab, and some use space(between type and var), do we have rules for this? {
Type var1
Type var2
}

I prefer using spaces for such alignments. But Linux style is to use a mix of tab and space with tab being equivalent to 8 spaces.
We have to write clear rules about such things and have our own checkpatch. For release 1.8, we still don't care about this level of details. Please let's re-open this topic after the release.

Signature · 1 line
Thomas