Skip to contentSkip to conversation

gcc compiler option -Og warnings fix

PATCH In review Keith Wiles 3 participants 5 messages Apr 1, 2016 – Apr 5, 2016 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gcc compiler option -Og warnings fix

The new compiler option -Og causes a few warning on variables being used before being set warnings. The new option allows better debugging then -O0 without losing a lot of performance. This option does not include -g debug symbol option.

---
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 2 +-
 lib/librte_lpm/rte_lpm6.c                 | 1 +
 lib/librte_vhost/vhost_rxtx.c             | 4 ++--
 3 files changed, 4 insertions(+), 3 deletions(-)
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +1 -1
index 068694d..89709f8 100644
@@ -152,7 +152,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 			   unsigned int buflen, int create)
 {
 	struct rte_pci_addr *loc = &dev->addr;
-	unsigned int uio_num;
+	unsigned int uio_num = 0;
 	struct dirent *e;
 	DIR *dir;
 	char dirname[PATH_MAX];
lib/librte_lpm/rte_lpm6.c +1 -0
index 4c44cd7..36565da 100644
@@ -381,6 +381,7 @@ add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl,
 	int8_t bitshift;
 	uint8_t bits_covered;
 
+	*tbl_next = NULL;
 	/*
 	 * Calculate index to the table based on the number and position
 	 * of the bytes being inspected in this step.
lib/librte_vhost/vhost_rxtx.c +2 -2
index 750821a..acf3632 100644
@@ -295,7 +295,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	for (i = 0; i < count; i++) {
 		uint16_t desc_idx = desc_indexes[i];
 		uint16_t used_idx = (res_start_idx + i) & (vq->size - 1);
-		uint32_t copied;
+		uint32_t copied = 0;
 		int err;
 
 		err = copy_mbuf_to_desc(dev, vq, pkts[i], desc_idx, &copied);
@@ -531,7 +531,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 {
 	struct vhost_virtqueue *vq;
 	uint32_t pkt_idx = 0, nr_used = 0;
-	uint16_t start, end;
+	uint16_t start = 0, end = 0;
 
 	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") virtio_dev_merge_rx()\n",
 		dev->device_fh);
Signature · 1 line
2.5.0
#1 lore raw

2016-04-01 14:20, Keith Wiles:

Quoted 2 lines

The new compiler option -Og causes a few warning on variables being used before being set warnings.

Sometimes the compiler is wrong. It seems this option makes it even wronger. Why not use -Wno-error with -Og?

More details below:

Quoted 3 lines
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 2 +-
 lib/librte_lpm/rte_lpm6.c                 | 1 +
 lib/librte_vhost/vhost_rxtx.c             | 4 ++--

There are also some warnings in mlx drivers, solved with patch below:

drivers/net/mlx4/mlx4.c +1 -1
@@ -5415,7 +5415,7 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
        int err = 0;
        struct ibv_context *attr_ctx = NULL;
        struct ibv_device_attr device_attr;
-       unsigned int vf;
+       unsigned int vf = 0;
        int idx;
        int i;
 
drivers/net/mlx5/mlx5.c +2 -2
@@ -260,8 +260,8 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
        int err = 0;
        struct ibv_context *attr_ctx = NULL;
        struct ibv_device_attr device_attr;
-       unsigned int vf;
-       unsigned int mps;
+       unsigned int vf = 0;
+       unsigned int mps = 0;
        int idx;
        int i;
 

lib/librte_eal/linuxapp/eal/eal_pci_uio.c pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf, · line 155

Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +1 -1
@@ -152,7 +152,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 			   unsigned int buflen, int create)
 {
 	struct rte_pci_addr *loc = &dev->addr;
-	unsigned int uio_num;
+	unsigned int uio_num = 0;

This one is OK to fix.

lib/librte_lpm/rte_lpm6.c add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl, · line 387

Quoted 10 lines
lib/librte_lpm/rte_lpm6.c +1 -0
@@ -381,6 +381,7 @@ add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl,
 	int8_t bitshift;
 	uint8_t bits_covered;
 
+	*tbl_next = NULL;
 	/*
 	 * Calculate index to the table based on the number and position
 	 * of the bytes being inspected in this step.

It would be more logical to set this variable in the right condition branch:

lib/librte_lpm/rte_lpm6.c +1 -0
@@ -429,6 +429,7 @@ add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl,
                        }
                }
 
+               *tbl_next = NULL;
                return 0;
        }
 

lib/librte_vhost/vhost_rxtx.c virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id, · line 298

Quoted 8 lines
lib/librte_vhost/vhost_rxtx.c +1 -1
@@ -295,7 +295,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	for (i = 0; i < count; i++) {
 		uint16_t desc_idx = desc_indexes[i];
 		uint16_t used_idx = (res_start_idx + i) & (vq->size - 1);
-		uint32_t copied;
+		uint32_t copied = 0;

This variable is not used if copy_mbuf_to_desc fails, so it is always initialised before being used.
We can workaround the silly compiler while avoiding a performance hit by resetting the variable only in the error case of copy_mbuf_to_desc:

lib/librte_vhost/vhost_rxtx.c +3 -1
@@ -147,8 +147,10 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
        struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0, 0, 0, 0, 0, 0}, 0};
 
        desc = &vq->desc[desc_idx];
-       if (unlikely(desc->len < vq->vhost_hlen))
+       if (unlikely(desc->len < vq->vhost_hlen)) {
+               *copied = 0;
                return -1;
+       }
 

lib/librte_vhost/vhost_rxtx.c virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, · line 534

Quoted 7 lines
lib/librte_vhost/vhost_rxtx.c +1 -1
 		err = copy_mbuf_to_desc(dev, vq, pkts[i], desc_idx, &copied);
@@ -531,7 +531,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 {
 	struct vhost_virtqueue *vq;
 	uint32_t pkt_idx = 0, nr_used = 0;
-	uint16_t start, end;
+	uint16_t start = 0, end = 0;

I don't understand this one because the variables are not used if reserve_avail_buf_mergeable fails.
I don't see any smart workaround.
Huawei, Yuanhan, can we expect a little slowdown with this change?

#2 lore raw
Quoted 16 lines · Thomas Monjalon
lib/librte_vhost/vhost_rxtx.c +3 -1
@@ -147,8 +147,10 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
        struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0, 0, 0, 0, 0, 0}, 0};
 
        desc = &vq->desc[desc_idx];
-       if (unlikely(desc->len < vq->vhost_hlen))
+       if (unlikely(desc->len < vq->vhost_hlen)) {
+               *copied = 0;
                return -1;
+       }
 
 >  		err = copy_mbuf_to_desc(dev, vq, pkts[i], desc_idx, &copied);
 > @@ -531,7 +531,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
Quoted 2 lines

{
struct vhost_virtqueue *vq;

Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +1 -1
 	uint32_t pkt_idx = 0, nr_used = 0;
-	uint16_t start, end;
+	uint16_t start = 0, end = 0;

I don't understand this one because the variables are not used if reserve_avail_buf_mergeable fails.
I don't see any smart workaround.
Huawei, Yuanhan, can we expect a little slowdown with this change?

I agree with you that the compiler seems buggy here, I'm okay with the fix though: it should not introduce slowdown, IMO. However, I'd ask the opinion from Huawei: he knows this better than me.

	--yliu
#3 lore raw
In reply to Thomas Monjalon
Quoted 6 lines

2016-04-01 14:20, Keith Wiles:

Quoted 2 lines

The new compiler option -Og causes a few warning on variables being used before being set warnings.

Sometimes the compiler is wrong. It seems this option makes it even wronger. Why not use -Wno-error with -Og?

Did you want me to make these changes or just request everyone to use -Wno-error with -Og?

If you want a new patch from me on these changes it will be toward the weekend after I get back home from traveling.

Quoted 96 lines

More details below:

Quoted 3 lines
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 2 +-
 lib/librte_lpm/rte_lpm6.c                 | 1 +
 lib/librte_vhost/vhost_rxtx.c             | 4 ++--

There are also some warnings in mlx drivers, solved with patch below:

drivers/net/mlx4/mlx4.c +1 -1
@@ -5415,7 +5415,7 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
       int err = 0;
       struct ibv_context *attr_ctx = NULL;
       struct ibv_device_attr device_attr;
-       unsigned int vf;
+       unsigned int vf = 0;
       int idx;
       int i;
 
drivers/net/mlx5/mlx5.c +2 -2
@@ -260,8 +260,8 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
       int err = 0;
       struct ibv_context *attr_ctx = NULL;
       struct ibv_device_attr device_attr;
-       unsigned int vf;
-       unsigned int mps;
+       unsigned int vf = 0;
+       unsigned int mps = 0;
       int idx;
       int i;
 

lib/librte_eal/linuxapp/eal/eal_pci_uio.c pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf, · line 155

Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +1 -1
@@ -152,7 +152,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 			   unsigned int buflen, int create)
 {
 	struct rte_pci_addr *loc = &dev->addr;
-	unsigned int uio_num;
+	unsigned int uio_num = 0;

This one is OK to fix.

lib/librte_lpm/rte_lpm6.c add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl, · line 387

Quoted 10 lines
lib/librte_lpm/rte_lpm6.c +1 -0
@@ -381,6 +381,7 @@ add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl,
 	int8_t bitshift;
 	uint8_t bits_covered;
 
+	*tbl_next = NULL;
 	/*
 	 * Calculate index to the table based on the number and position
 	 * of the bytes being inspected in this step.

It would be more logical to set this variable in the right condition branch:

lib/librte_lpm/rte_lpm6.c +1 -0
@@ -429,6 +429,7 @@ add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl,
                       }
               }
 
+               *tbl_next = NULL;
               return 0;
       }
 

lib/librte_vhost/vhost_rxtx.c virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id, · line 298

Quoted 8 lines
lib/librte_vhost/vhost_rxtx.c +1 -1
@@ -295,7 +295,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	for (i = 0; i < count; i++) {
 		uint16_t desc_idx = desc_indexes[i];
 		uint16_t used_idx = (res_start_idx + i) & (vq->size - 1);
-		uint32_t copied;
+		uint32_t copied = 0;

This variable is not used if copy_mbuf_to_desc fails, so it is always initialised before being used.
We can workaround the silly compiler while avoiding a performance hit by resetting the variable only in the error case of copy_mbuf_to_desc:

lib/librte_vhost/vhost_rxtx.c +3 -1
@@ -147,8 +147,10 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
       struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0, 0, 0, 0, 0, 0}, 0};
 
       desc = &vq->desc[desc_idx];
-       if (unlikely(desc->len < vq->vhost_hlen))
+       if (unlikely(desc->len < vq->vhost_hlen)) {
+               *copied = 0;
               return -1;
+       }
 
 >  		err = copy_mbuf_to_desc(dev, vq, pkts[i], desc_idx, &copied);
 > @@ -531,7 +531,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
Quoted 2 lines
lib/librte_vhost/vhost_rxtx.c +0 -0
 {
 	struct vhost_virtqueue *vq;
Quoted 10 lines

lib/librte_vhost/vhost_rxtx.c virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,

Quoted 3 lines
lib/librte_vhost/vhost_rxtx.c +1 -1
 	uint32_t pkt_idx = 0, nr_used = 0;
-	uint16_t start, end;
+	uint16_t start = 0, end = 0;

I don't understand this one because the variables are not used if reserve_avail_buf_mergeable fails.
I don't see any smart workaround.
Huawei, Yuanhan, can we expect a little slowdown with this change?

Regards,
Keith

#4 lore raw

2016-04-04 23:03, Wiles, Keith:

Quoted 8 lines
Quoted 6 lines

2016-04-01 14:20, Keith Wiles:

Quoted 2 lines

The new compiler option -Og causes a few warning on variables being used before being set warnings.

Sometimes the compiler is wrong. It seems this option makes it even wronger. Why not use -Wno-error with -Og?

Did you want me to make these changes or just request everyone to use -Wno-error with -Og?

I was suggesting that everyone can use -Wno-error when using -Og.

Quoted 2 lines

If you want a new patch from me on these changes it will be toward the weekend after I get back home from traveling.

If some driver maintainers think there are some things to fix, they are free to send a patch by themselves before the end of the week.

Quoted 113 lines
Quoted 95 lines

More details below:

Quoted 3 lines
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 2 +-
 lib/librte_lpm/rte_lpm6.c                 | 1 +
 lib/librte_vhost/vhost_rxtx.c             | 4 ++--

There are also some warnings in mlx drivers, solved with patch below:

drivers/net/mlx4/mlx4.c +1 -1
@@ -5415,7 +5415,7 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
       int err = 0;
       struct ibv_context *attr_ctx = NULL;
       struct ibv_device_attr device_attr;
-       unsigned int vf;
+       unsigned int vf = 0;
       int idx;
       int i;
 
drivers/net/mlx5/mlx5.c +2 -2
@@ -260,8 +260,8 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
       int err = 0;
       struct ibv_context *attr_ctx = NULL;
       struct ibv_device_attr device_attr;
-       unsigned int vf;
-       unsigned int mps;
+       unsigned int vf = 0;
+       unsigned int mps = 0;
       int idx;
       int i;
 

lib/librte_eal/linuxapp/eal/eal_pci_uio.c pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf, · line 155

Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +1 -1
@@ -152,7 +152,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 			   unsigned int buflen, int create)
 {
 	struct rte_pci_addr *loc = &dev->addr;
-	unsigned int uio_num;
+	unsigned int uio_num = 0;

This one is OK to fix.

lib/librte_lpm/rte_lpm6.c add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl, · line 387

Quoted 10 lines
lib/librte_lpm/rte_lpm6.c +1 -0
@@ -381,6 +381,7 @@ add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl,
 	int8_t bitshift;
 	uint8_t bits_covered;
 
+	*tbl_next = NULL;
 	/*
 	 * Calculate index to the table based on the number and position
 	 * of the bytes being inspected in this step.

It would be more logical to set this variable in the right condition branch:

lib/librte_lpm/rte_lpm6.c +1 -0
@@ -429,6 +429,7 @@ add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl,
                       }
               }
 
+               *tbl_next = NULL;
               return 0;
       }
 

lib/librte_vhost/vhost_rxtx.c virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id, · line 298

Quoted 8 lines
lib/librte_vhost/vhost_rxtx.c +1 -1
@@ -295,7 +295,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	for (i = 0; i < count; i++) {
 		uint16_t desc_idx = desc_indexes[i];
 		uint16_t used_idx = (res_start_idx + i) & (vq->size - 1);
-		uint32_t copied;
+		uint32_t copied = 0;

This variable is not used if copy_mbuf_to_desc fails, so it is always initialised before being used.
We can workaround the silly compiler while avoiding a performance hit by resetting the variable only in the error case of copy_mbuf_to_desc:

lib/librte_vhost/vhost_rxtx.c +3 -1
@@ -147,8 +147,10 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
       struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0, 0, 0, 0, 0, 0}, 0};
 
       desc = &vq->desc[desc_idx];
-       if (unlikely(desc->len < vq->vhost_hlen))
+       if (unlikely(desc->len < vq->vhost_hlen)) {
+               *copied = 0;
               return -1;
+       }
 
 >  		err = copy_mbuf_to_desc(dev, vq, pkts[i], desc_idx, &copied);
 > @@ -531,7 +531,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
Quoted 2 lines
lib/librte_vhost/vhost_rxtx.c +0 -0
 {
 	struct vhost_virtqueue *vq;
Quoted 10 lines

lib/librte_vhost/vhost_rxtx.c virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,

Quoted 3 lines
lib/librte_vhost/vhost_rxtx.c +1 -1
 	uint32_t pkt_idx = 0, nr_used = 0;
-	uint16_t start, end;
+	uint16_t start = 0, end = 0;

I don't understand this one because the variables are not used if reserve_avail_buf_mergeable fails.
I don't see any smart workaround.
Huawei, Yuanhan, can we expect a little slowdown with this change?

Regards,
Keith