diff mbox

[ovs-dev,2/2] netdev-dpdk: Fix coding style

Message ID 1475144823-209138-3-git-send-email-mark.b.kavanagh@intel.com
State Accepted
Delegated to: Daniele Di Proietto
Headers show

Commit Message

Mark Kavanagh Sept. 29, 2016, 10:27 a.m. UTC
Coding style violations of the following conventions are present in netdev-dpdk.c:
    - limit lines to 79 characters
    - put a space after (but not before) the "sizeof" keyword.
    - put a space between the () used in a cast and the
      expression whose type is cast: (void *) 0.

Resolve occurrences of each, and any other minor style infractions.

Signed-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com>
---
 lib/netdev-dpdk.c | 81 ++++++++++++++++++++++++++++++-------------------------
 1 file changed, 44 insertions(+), 37 deletions(-)

Comments

Daniele Di Proietto Sept. 29, 2016, 6:42 p.m. UTC | #1
2016-09-29 3:27 GMT-07:00 Mark Kavanagh <mark.b.kavanagh@intel.com>:

> Coding style violations of the following conventions are present in
> netdev-dpdk.c:
>     - limit lines to 79 characters
>     - put a space after (but not before) the "sizeof" keyword.
>     - put a space between the () used in a cast and the
>       expression whose type is cast: (void *) 0.
>
> Resolve occurrences of each, and any other minor style infractions.
>
> Signed-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com>
> ---
>  lib/netdev-dpdk.c | 81 ++++++++++++++++++++++++++++++
> -------------------------
>  1 file changed, 44 insertions(+), 37 deletions(-)
>
>
Thanks for taking the time to fix all these!

I believe that the space after "sizeof" should only be there when the
operand is not parenthesized.  A quick grep in the tree shows that "sizeof
(" is not very popular, at least in userspace code.  Perhaps we should fix
this in CodingStyle.md? Anyway, I removed the space before the parenthesis.

I fixed a couple of more whitespaces around and applied this and the
previous patch to master

Thanks!

Daniele
diff mbox

Patch

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index 819a842..dbf72ed 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -76,12 +76,14 @@  static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
  * The minimum mbuf size is limited to avoid scatter behaviour and drop in
  * performance for standard Ethernet MTU.
  */
-#define ETHER_HDR_MAX_LEN           (ETHER_HDR_LEN + ETHER_CRC_LEN + (2 * VLAN_HEADER_LEN))
+#define ETHER_HDR_MAX_LEN           (ETHER_HDR_LEN + ETHER_CRC_LEN \
+                                    + (2 * VLAN_HEADER_LEN))
 #define MTU_TO_FRAME_LEN(mtu)       ((mtu) + ETHER_HDR_LEN + ETHER_CRC_LEN)
 #define MTU_TO_MAX_FRAME_LEN(mtu)   ((mtu) + ETHER_HDR_MAX_LEN)
-#define FRAME_LEN_TO_MTU(frame_len) ((frame_len)- ETHER_HDR_LEN - ETHER_CRC_LEN)
-#define MBUF_SIZE(mtu)              ( MTU_TO_MAX_FRAME_LEN(mtu)   \
-                                    + sizeof(struct dp_packet)    \
+#define FRAME_LEN_TO_MTU(frame_len) ((frame_len)                    \
+                                    - ETHER_HDR_LEN - ETHER_CRC_LEN)
+#define MBUF_SIZE(mtu)              ( MTU_TO_MAX_FRAME_LEN(mtu)     \
+                                    + sizeof (struct dp_packet)     \
                                     + RTE_PKTMBUF_HEADROOM)
 #define NETDEV_DPDK_MBUF_ALIGN      1024
 #define NETDEV_DPDK_MAX_PKT_LEN     9728
@@ -132,8 +134,10 @@  BUILD_ASSERT_DECL((MAX_NB_MBUF / ROUND_DOWN_POW2(MAX_NB_MBUF/MIN_NB_MBUF))
 
 #define SOCKET0              0
 
-#define NIC_PORT_RX_Q_SIZE 2048  /* Size of Physical NIC RX Queue, Max (n+32<=4096)*/
-#define NIC_PORT_TX_Q_SIZE 2048  /* Size of Physical NIC TX Queue, Max (n+32<=4096)*/
+/* Size of Physical NIC RX Queue, Max (n + 32 <= 4096) */
+#define NIC_PORT_RX_Q_SIZE 2048
+/* Size of Physical NIC TX Queue, Max (n + 32 <= 4096) */
+#define NIC_PORT_TX_Q_SIZE 2048
 
 #define OVS_VHOST_MAX_QUEUE_NUM 1024  /* Maximum number of vHost TX queues. */
 #define OVS_VHOST_QUEUE_MAP_UNKNOWN (-1) /* Mapping not initialized. */
@@ -414,8 +418,8 @@  is_dpdk_class(const struct netdev_class *class)
  * entirety. Furthermore, certain drivers need to ensure that there is also
  * sufficient space in the Rx buffer to accommodate two VLAN tags (for QinQ
  * frames). If the RX buffer is too small, then the driver enables scatter RX
- * behaviour, which reduces performance. To prevent this, use a buffer size that
- * is closest to 'mtu', but which satisfies the aforementioned criteria.
+ * behaviour, which reduces performance. To prevent this, use a buffer size
+ * that is closest to 'mtu', but which satisfies the aforementioned criteria.
  */
 static uint32_t
 dpdk_buf_size(int mtu)
@@ -481,13 +485,13 @@  dpdk_mp_get(int socket_id, int mtu) OVS_REQUIRES(dpdk_mutex)
     dmp->socket_id = socket_id;
     dmp->mtu = mtu;
     dmp->refcount = 1;
-    mbp_priv.mbuf_data_room_size = MBUF_SIZE(mtu) - sizeof(struct dp_packet);
+    mbp_priv.mbuf_data_room_size = MBUF_SIZE(mtu) - sizeof (struct dp_packet);
     mbp_priv.mbuf_priv_size = sizeof (struct dp_packet)
                               - sizeof (struct rte_mbuf);
     /* XXX: this is a really rough method of provisioning memory.
      * It's impossible to determine what the exact memory requirements are when
-     * the number of ports and rxqs that utilize a particular mempool can change
-     * dynamically at runtime. For the moment, use this rough heurisitic.
+     * when the number of ports and rxqs that utilize a particular mempool can
+     * change dynamically at runtime. For now, use this rough heurisitic.
      */
     if (mtu >= ETHER_MTU) {
         mp_size = MAX_NB_MBUF;
@@ -582,7 +586,7 @@  check_link_status(struct netdev_dpdk *dev)
         dev->link = link;
         if (dev->link.link_status) {
             VLOG_DBG_RL(&rl, "Port %d Link Up - speed %u Mbps - %s",
-                        dev->port_id, (unsigned)dev->link.link_speed,
+                        dev->port_id, (unsigned) dev->link.link_speed,
                         (dev->link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
                          ("full-duplex") : ("half-duplex"));
         } else {
@@ -730,7 +734,7 @@  dpdk_eth_dev_init(struct netdev_dpdk *dev) OVS_REQUIRES(dpdk_mutex)
     rte_eth_promiscuous_enable(dev->port_id);
     rte_eth_allmulticast_enable(dev->port_id);
 
-    memset(&eth_addr, 0x0, sizeof(eth_addr));
+    memset(&eth_addr, 0x0, sizeof (eth_addr));
     rte_eth_macaddr_get(dev->port_id, &eth_addr);
     VLOG_INFO_RL(&rl, "Port %d: "ETH_ADDR_FMT"",
                     dev->port_id, ETH_ADDR_BYTES_ARGS(eth_addr.addr_bytes));
@@ -1007,8 +1011,8 @@  netdev_dpdk_vhost_destruct(struct netdev *netdev)
         && !(dev->vhost_driver_flags & RTE_VHOST_USER_CLIENT)) {
         VLOG_ERR("Removing port '%s' while vhost device still attached.",
                  netdev->name);
-        VLOG_ERR("To restore connectivity after re-adding of port, VM on socket"
-                 " '%s' must be restarted.", dev->vhost_id);
+        VLOG_ERR("To restore connectivity after re-adding of port, VM on "
+                 "socket  '%s' must be restarted.", dev->vhost_id);
     }
 
     free(ovsrcu_get_protected(struct ingress_policer *,
@@ -1233,7 +1237,7 @@  static inline bool
 netdev_dpdk_policer_pkt_handle(struct rte_meter_srtcm *meter,
                                struct rte_mbuf *pkt, uint64_t time)
 {
-    uint32_t pkt_len = rte_pktmbuf_pkt_len(pkt) - sizeof(struct ether_hdr);
+    uint32_t pkt_len = rte_pktmbuf_pkt_len(pkt) - sizeof (struct ether_hdr);
 
     return rte_meter_srtcm_color_blind_check(meter, time, pkt_len) ==
                                                 e_RTE_METER_GREEN;
@@ -1407,7 +1411,7 @@  netdev_dpdk_rxq_recv(struct netdev_rxq *rxq, struct dp_packet_batch *batch)
     if (policer) {
         dropped = nb_rx;
         nb_rx = ingress_policer_run(policer,
-                                    (struct rte_mbuf **)batch->packets,
+                                    (struct rte_mbuf **) batch->packets,
                                     nb_rx);
         dropped -= nb_rx;
     }
@@ -1572,7 +1576,7 @@  dpdk_do_tx_copy(struct netdev *netdev, int qid, struct dp_packet_batch *batch)
 
         if (OVS_UNLIKELY(size > dev->max_packet_len)) {
             VLOG_WARN_RL(&rl, "Too big size %d max_packet_len %d",
-                         (int)size , dev->max_packet_len);
+                         (int) size , dev->max_packet_len);
 
             dropped++;
             continue;
@@ -1978,7 +1982,7 @@  netdev_dpdk_policer_construct(uint32_t rate, uint32_t burst)
     policer->app_srtcm_params.ebs = 0;
     err = rte_meter_srtcm_config(&policer->in_policer,
                                     &policer->app_srtcm_params);
-    if(err) {
+    if (err) {
         VLOG_ERR("Could not create rte meter for ingress policer");
         return NULL;
     }
@@ -2142,7 +2146,7 @@  netdev_dpdk_update_flags__(struct netdev_dpdk *dev,
             /* Clear statistics if device is getting up. */
             if (NETDEV_UP & on) {
                 rte_spinlock_lock(&dev->stats_lock);
-                memset(&dev->stats, 0, sizeof(dev->stats));
+                memset(&dev->stats, 0, sizeof (dev->stats));
                 rte_spinlock_unlock(&dev->stats_lock);
             }
         }
@@ -2181,14 +2185,16 @@  netdev_dpdk_get_status(const struct netdev *netdev, struct smap *args)
     ovs_mutex_unlock(&dev->mutex);
 
     smap_add_format(args, "port_no", "%d", dev->port_id);
-    smap_add_format(args, "numa_id", "%d", rte_eth_dev_socket_id(dev->port_id));
+    smap_add_format(args, "numa_id", "%d",
+                           rte_eth_dev_socket_id(dev->port_id));
     smap_add_format(args, "driver_name", "%s", dev_info.driver_name);
     smap_add_format(args, "min_rx_bufsize", "%u", dev_info.min_rx_bufsize);
     smap_add_format(args, "max_rx_pktlen", "%u", dev->max_packet_len);
     smap_add_format(args, "max_rx_queues", "%u", dev_info.max_rx_queues);
     smap_add_format(args, "max_tx_queues", "%u", dev_info.max_tx_queues);
     smap_add_format(args, "max_mac_addrs", "%u", dev_info.max_mac_addrs);
-    smap_add_format(args, "max_hash_mac_addrs", "%u", dev_info.max_hash_mac_addrs);
+    smap_add_format(args, "max_hash_mac_addrs", "%u",
+                           dev_info.max_hash_mac_addrs);
     smap_add_format(args, "max_vfs", "%u", dev_info.max_vfs);
     smap_add_format(args, "max_vmdq_pools", "%u", dev_info.max_vmdq_pools);
 
@@ -2327,7 +2333,7 @@  new_device(int vid)
     int newnode = 0;
     char ifname[IF_NAME_SZ];
 
-    rte_vhost_get_ifname(vid, ifname, sizeof(ifname));
+    rte_vhost_get_ifname(vid, ifname, sizeof (ifname));
 
     ovs_mutex_lock(&dpdk_mutex);
     /* Add device to the vhost port with the same name as that passed down. */
@@ -2408,7 +2414,7 @@  destroy_device(int vid)
     bool exists = false;
     char ifname[IF_NAME_SZ];
 
-    rte_vhost_get_ifname(vid, ifname, sizeof(ifname));
+    rte_vhost_get_ifname(vid, ifname, sizeof (ifname));
 
     ovs_mutex_lock(&dpdk_mutex);
     LIST_FOR_EACH (dev, list_node, &dpdk_list) {
@@ -2453,7 +2459,7 @@  vring_state_changed(int vid, uint16_t queue_id, int enable)
     int qid = queue_id / VIRTIO_QNUM;
     char ifname[IF_NAME_SZ];
 
-    rte_vhost_get_ifname(vid, ifname, sizeof(ifname));
+    rte_vhost_get_ifname(vid, ifname, sizeof (ifname));
 
     if (queue_id % VIRTIO_QNUM == VIRTIO_TXQ) {
         return 0;
@@ -2559,7 +2565,7 @@  dpdk_ring_create(const char dev_name[], unsigned int port_no,
     }
 
     /* XXX: Add support for multiquque ring. */
-    err = snprintf(ring_name, sizeof(ring_name), "%s_tx", dev_name);
+    err = snprintf(ring_name, sizeof (ring_name), "%s_tx", dev_name);
     if (err < 0) {
         return -err;
     }
@@ -2572,7 +2578,7 @@  dpdk_ring_create(const char dev_name[], unsigned int port_no,
         return ENOMEM;
     }
 
-    err = snprintf(ring_name, sizeof(ring_name), "%s_rx", dev_name);
+    err = snprintf(ring_name, sizeof (ring_name), "%s_rx", dev_name);
     if (err < 0) {
         return -err;
     }
@@ -2615,11 +2621,12 @@  dpdk_ring_open(const char dev_name[], unsigned int *eth_port_id)
         return err;
     }
 
-    /* look through our list to find the device */
+    /* Look through our list to find the device */
     LIST_FOR_EACH (ivshmem, list_node, &dpdk_ring_list) {
          if (ivshmem->user_port_id == port_no) {
             VLOG_INFO("Found dpdk ring device %s:", dev_name);
-            *eth_port_id = ivshmem->eth_port_id; /* really all that is needed */
+            /* Really all that is needed */
+            *eth_port_id = ivshmem->eth_port_id;
             return 0;
          }
     }
@@ -2635,10 +2642,10 @@  netdev_dpdk_ring_send(struct netdev *netdev, int qid,
     struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
     unsigned i;
 
-    /* When using 'dpdkr' and sending to a DPDK ring, we want to ensure that the
-     * rss hash field is clear. This is because the same mbuf may be modified by
-     * the consumer of the ring and return into the datapath without recalculating
-     * the RSS hash. */
+    /* When using 'dpdkr' and sending to a DPDK ring, we want to ensure that
+     * the rss hash field is clear. This is because the same mbuf may be
+     * modified by the consumer of the ring and return into the datapath
+     * without recalculating the RSS hash. */
     for (i = 0; i < batch->count; i++) {
         dp_packet_rss_invalidate(batch->packets[i]);
     }
@@ -2743,7 +2750,7 @@  netdev_dpdk_get_qos(const struct netdev *netdev,
     int error = 0;
 
     ovs_mutex_lock(&dev->mutex);
-    if(dev->qos_conf) {
+    if (dev->qos_conf) {
         *typep = dev->qos_conf->ops->qos_name;
         error = (dev->qos_conf->ops->qos_get
                  ? dev->qos_conf->ops->qos_get(netdev, details): 0);
@@ -3138,7 +3145,7 @@  process_vhost_flags(char *flag, char *default_val, int size,
 static char **
 grow_argv(char ***argv, size_t cur_siz, size_t grow_by)
 {
-    return xrealloc(*argv, sizeof(char *) * (cur_siz + grow_by));
+    return xrealloc(*argv, sizeof (char *) * (cur_siz + grow_by));
 }
 
 static void
@@ -3399,7 +3406,7 @@  dpdk_init__(const struct smap *ovs_other_config)
         int i;
         /* Get the main thread affinity */
         CPU_ZERO(&cpuset);
-        err = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t),
+        err = pthread_getaffinity_np(pthread_self(), sizeof (cpu_set_t),
                                      &cpuset);
         if (!err) {
             for (i = 0; i < CPU_SETSIZE; i++) {
@@ -3446,7 +3453,7 @@  dpdk_init__(const struct smap *ovs_other_config)
 
     /* Set the main thread affinity back to pre rte_eal_init() value */
     if (auto_determine && !err) {
-        err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t),
+        err = pthread_setaffinity_np(pthread_self(), sizeof (cpu_set_t),
                                      &cpuset);
         if (err) {
             VLOG_ERR("Thread setaffinity error %d", err);