net/iavf: fix old GCC compilation warnings

Message ID 20230609054156.605581-1-zhichaox.zeng@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series net/iavf: fix old GCC compilation warnings |

Checks

Context Check Description
ci/loongarch-compilation warning apply patch failure
ci/checkpatch success coding style OK
ci/Intel-compilation warning apply issues

Commit Message

Zeng, ZhichaoX June 9, 2023, 5:41 a.m. UTC
The code uses the Wimplicit-fallthrough compile option to ignore
falls through warnings in switch case, but this option was introduced
by GCC 7 and old GCC do not recognize the option.

Add judgment to avoid warnings about unrecognized options in old GCC.

Fixes: 95a1b0b23140 ("net/iavf: support Rx timestamp offload on SSE")
Fixes: 4f58266da4d3 ("net/iavf: support Rx timestamp offload on AVX2")
Fixes: d65eadb9e178 ("net/iavf: support Rx timestamp offload on AVX512")
Signed-off-by: Zhichao Zeng <zhichaox.zeng@intel.com>
---
 drivers/net/iavf/iavf_rxtx_vec_avx2.c   | 10 +++++++---
 drivers/net/iavf/iavf_rxtx_vec_avx512.c | 10 +++++++---
 drivers/net/iavf/iavf_rxtx_vec_sse.c    | 10 +++++++---
 3 files changed, 21 insertions(+), 9 deletions(-)
  

Comments

David Marchand June 9, 2023, 6:58 a.m. UTC | #1
On Fri, Jun 9, 2023 at 7:35 AM Zhichao Zeng <zhichaox.zeng@intel.com> wrote:
>
> The code uses the Wimplicit-fallthrough compile option to ignore
> falls through warnings in switch case, but this option was introduced
> by GCC 7 and old GCC do not recognize the option.
>
> Add judgment to avoid warnings about unrecognized options in old GCC.
>
> Fixes: 95a1b0b23140 ("net/iavf: support Rx timestamp offload on SSE")
> Fixes: 4f58266da4d3 ("net/iavf: support Rx timestamp offload on AVX2")
> Fixes: d65eadb9e178 ("net/iavf: support Rx timestamp offload on AVX512")
> Signed-off-by: Zhichao Zeng <zhichaox.zeng@intel.com>

This is ugly.

I don't think we introduced a marker for this in EAL, but at least I
see other drivers use /* fallthrough */.
Prefer this form, please.

IOW:

diff --git a/drivers/net/iavf/iavf_rxtx_vec_sse.c
b/drivers/net/iavf/iavf_rxtx_vec_sse.c
index b754122c51..81ea154519 100644
--- a/drivers/net/iavf/iavf_rxtx_vec_sse.c
+++ b/drivers/net/iavf/iavf_rxtx_vec_sse.c
@@ -1126,24 +1126,26 @@ _recv_raw_pkts_vec_flex_rxd(struct iavf_rx_queue *rxq,
                nb_pkts_recd += var;

 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
                if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
                        inflection_point = (inflection_point <= var) ?
inflection_point : 0;
                        switch (inflection_point) {
                        case 1:
                                *RTE_MBUF_DYNFIELD(rx_pkts[pos + 0],
                                        iavf_timestamp_dynfield_offset
+ 4, uint32_t *) += 1;
+                               /* fallthrough */
                        case 2:

etc...
  
Zeng, ZhichaoX June 9, 2023, 7:19 a.m. UTC | #2
Hi David, 

> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: Friday, June 9, 2023 2:58 PM
> To: Zeng, ZhichaoX <zhichaox.zeng@intel.com>
> Cc: dev@dpdk.org; Zhang, Qi Z <qi.z.zhang@intel.com>; Gao, DaxueX
> <daxuex.gao@intel.com>; Richardson, Bruce <bruce.richardson@intel.com>;
> Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>; Wu, Jingjing
> <jingjing.wu@intel.com>; Xing, Beilei <beilei.xing@intel.com>; Wu, Wenjun1
> <wenjun1.wu@intel.com>
> Subject: Re: [PATCH] net/iavf: fix old GCC compilation warnings
> 
> On Fri, Jun 9, 2023 at 7:35 AM Zhichao Zeng <zhichaox.zeng@intel.com>
> wrote:
> >
> > The code uses the Wimplicit-fallthrough compile option to ignore falls
> > through warnings in switch case, but this option was introduced by GCC
> > 7 and old GCC do not recognize the option.
> >
> > Add judgment to avoid warnings about unrecognized options in old GCC.
> >
> > Fixes: 95a1b0b23140 ("net/iavf: support Rx timestamp offload on SSE")
> > Fixes: 4f58266da4d3 ("net/iavf: support Rx timestamp offload on AVX2")
> > Fixes: d65eadb9e178 ("net/iavf: support Rx timestamp offload on
> > AVX512")
> > Signed-off-by: Zhichao Zeng <zhichaox.zeng@intel.com>
> 
> This is ugly.
> 
> I don't think we introduced a marker for this in EAL, but at least I see other
> drivers use /* fallthrough */.
> Prefer this form, please.

Thanks for your advice, I will change to this form and submit v2.

Best Regards
Zhichao

> IOW:
> 
> diff --git a/drivers/net/iavf/iavf_rxtx_vec_sse.c
> b/drivers/net/iavf/iavf_rxtx_vec_sse.c
> index b754122c51..81ea154519 100644
> --- a/drivers/net/iavf/iavf_rxtx_vec_sse.c
> +++ b/drivers/net/iavf/iavf_rxtx_vec_sse.c
> @@ -1126,24 +1126,26 @@ _recv_raw_pkts_vec_flex_rxd(struct
> iavf_rx_queue *rxq,
>                 nb_pkts_recd += var;
> 
>  #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
> -#pragma GCC diagnostic push
> -#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
>                 if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
>                         inflection_point = (inflection_point <= var) ?
> inflection_point : 0;
>                         switch (inflection_point) {
>                         case 1:
>                                 *RTE_MBUF_DYNFIELD(rx_pkts[pos + 0],
>                                         iavf_timestamp_dynfield_offset
> + 4, uint32_t *) += 1;
> +                               /* fallthrough */
>                         case 2:
> 
> etc...
> 
> 
> --
> David Marchand
  
Stephen Hemminger June 9, 2023, 2:38 p.m. UTC | #3
On Fri,  9 Jun 2023 13:41:56 +0800
Zhichao Zeng <zhichaox.zeng@intel.com> wrote:

> The code uses the Wimplicit-fallthrough compile option to ignore
> falls through warnings in switch case, but this option was introduced
> by GCC 7 and old GCC do not recognize the option.
> 
> Add judgment to avoid warnings about unrecognized options in old GCC.
> 
> Fixes: 95a1b0b23140 ("net/iavf: support Rx timestamp offload on SSE")
> Fixes: 4f58266da4d3 ("net/iavf: support Rx timestamp offload on AVX2")
> Fixes: d65eadb9e178 ("net/iavf: support Rx timestamp offload on AVX512")
> Signed-off-by: Zhichao Zeng <zhichaox.zeng@intel.com>
> ---

RHEL 7 becomes end of life this month.
That makes the oldest version of Gcc that DPDK is required to support
is gcc 8.X in RHEL 8.
  

Patch

diff --git a/drivers/net/iavf/iavf_rxtx_vec_avx2.c b/drivers/net/iavf/iavf_rxtx_vec_avx2.c
index 86290c4bbb..25094d5958 100644
--- a/drivers/net/iavf/iavf_rxtx_vec_avx2.c
+++ b/drivers/net/iavf/iavf_rxtx_vec_avx2.c
@@ -1397,8 +1397,10 @@  _iavf_recv_raw_pkts_vec_avx2_flex_rxd(struct iavf_rx_queue *rxq,
 					(_mm256_castsi256_si128(status0_7)));
 		received += burst;
 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#if __GNUC__ >= 7
+	#pragma GCC diagnostic push
+	#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#endif
 		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
 			inflection_point = (inflection_point <= burst) ? inflection_point : 0;
 			switch (inflection_point) {
@@ -1436,7 +1438,9 @@  _iavf_recv_raw_pkts_vec_avx2_flex_rxd(struct iavf_rx_queue *rxq,
 
 			rxq->hw_time_update = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
 		}
-#pragma GCC diagnostic pop
+#if __GNUC__ >= 7
+	#pragma GCC diagnostic pop
+#endif
 #endif
 		if (burst != IAVF_DESCS_PER_LOOP_AVX)
 			break;
diff --git a/drivers/net/iavf/iavf_rxtx_vec_avx512.c b/drivers/net/iavf/iavf_rxtx_vec_avx512.c
index f9961e53b8..b74a6443b3 100644
--- a/drivers/net/iavf/iavf_rxtx_vec_avx512.c
+++ b/drivers/net/iavf/iavf_rxtx_vec_avx512.c
@@ -1551,8 +1551,10 @@  _iavf_recv_raw_pkts_vec_avx512_flex_rxd(struct iavf_rx_queue *rxq,
 		received += burst;
 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
 #ifdef IAVF_RX_TS_OFFLOAD
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#if __GNUC__ >= 7
+	#pragma GCC diagnostic push
+	#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#endif
 		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
 			inflection_point = (inflection_point <= burst) ? inflection_point : 0;
 			switch (inflection_point) {
@@ -1590,7 +1592,9 @@  _iavf_recv_raw_pkts_vec_avx512_flex_rxd(struct iavf_rx_queue *rxq,
 
 			rxq->hw_time_update = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
 		}
-#pragma GCC diagnostic pop
+#if __GNUC__ >= 7
+	#pragma GCC diagnostic pop
+#endif
 #endif
 #endif
 		if (burst != IAVF_DESCS_PER_LOOP_AVX)
diff --git a/drivers/net/iavf/iavf_rxtx_vec_sse.c b/drivers/net/iavf/iavf_rxtx_vec_sse.c
index b754122c51..ff364d4fe5 100644
--- a/drivers/net/iavf/iavf_rxtx_vec_sse.c
+++ b/drivers/net/iavf/iavf_rxtx_vec_sse.c
@@ -1126,8 +1126,10 @@  _recv_raw_pkts_vec_flex_rxd(struct iavf_rx_queue *rxq,
 		nb_pkts_recd += var;
 
 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#if __GNUC__ >= 7
+	#pragma GCC diagnostic push
+	#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#endif
 		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
 			inflection_point = (inflection_point <= var) ? inflection_point : 0;
 			switch (inflection_point) {
@@ -1153,7 +1155,9 @@  _recv_raw_pkts_vec_flex_rxd(struct iavf_rx_queue *rxq,
 
 			rxq->hw_time_update = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
 		}
-#pragma GCC diagnostic pop
+#if __GNUC__ >= 7
+	#pragma GCC diagnostic pop
+#endif
 #endif
 
 		if (likely(var != IAVF_VPMD_DESCS_PER_LOOP))