DPDK patches and discussions
 help / color / mirror / Atom feed
From: Cyril Chemparathy <cchemparathy@ezchip.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v4 3/9] ethdev: silence -Wcast-align on pointer arithmetic
Date: Mon, 22 Jun 2015 11:34:17 -0700	[thread overview]
Message-ID: <1434998063-15739-4-git-send-email-cchemparathy@ezchip.com> (raw)
In-Reply-To: <1434998063-15739-1-git-send-email-cchemparathy@ezchip.com>

Statistics offsets in the rte_stats_strings[] array are always 64-bit aligned.
However, the compiler is unaware of this fact and complains on -Wcast-align.
This patch modifies the code to use RTE_PTR_ADD(), thereby silencing the
compiler by casting through (void *).

Change-Id: I6460b4b84b89dce6ac0b7b20e7002d53bcbd22db
Signed-off-by: Cyril Chemparathy <cchemparathy@ezchip.com>
---
 lib/librte_ether/rte_ethdev.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index e13fde5..02cd07f 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1742,8 +1742,7 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
 	struct rte_eth_stats eth_stats;
 	struct rte_eth_dev *dev;
 	unsigned count, i, q;
-	uint64_t val;
-	char *stats_ptr;
+	uint64_t val, *stats_ptr;
 
 	if (!rte_eth_dev_is_valid_port(port_id)) {
 		PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
@@ -1770,8 +1769,9 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
 
 	/* global stats */
 	for (i = 0; i < RTE_NB_STATS; i++) {
-		stats_ptr = (char *)&eth_stats + rte_stats_strings[i].offset;
-		val = *(uint64_t *)stats_ptr;
+		stats_ptr = RTE_PTR_ADD(&eth_stats,
+					rte_stats_strings[i].offset);
+		val = *stats_ptr;
 		snprintf(xstats[count].name, sizeof(xstats[count].name),
 			"%s", rte_stats_strings[i].name);
 		xstats[count++].value = val;
@@ -1780,10 +1780,10 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
 	/* per-rxq stats */
 	for (q = 0; q < dev->data->nb_rx_queues; q++) {
 		for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
-			stats_ptr = (char *)&eth_stats;
-			stats_ptr += rte_rxq_stats_strings[i].offset;
-			stats_ptr += q * sizeof(uint64_t);
-			val = *(uint64_t *)stats_ptr;
+			stats_ptr = RTE_PTR_ADD(&eth_stats,
+					rte_rxq_stats_strings[i].offset +
+					q * sizeof(uint64_t));
+			val = *stats_ptr;
 			snprintf(xstats[count].name, sizeof(xstats[count].name),
 				"rx_queue_%u_%s", q,
 				rte_rxq_stats_strings[i].name);
@@ -1794,10 +1794,10 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
 	/* per-txq stats */
 	for (q = 0; q < dev->data->nb_tx_queues; q++) {
 		for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
-			stats_ptr = (char *)&eth_stats;
-			stats_ptr += rte_txq_stats_strings[i].offset;
-			stats_ptr += q * sizeof(uint64_t);
-			val = *(uint64_t *)stats_ptr;
+			stats_ptr = RTE_PTR_ADD(&eth_stats,
+					rte_txq_stats_strings[i].offset +
+					q * sizeof(uint64_t));
+			val = *stats_ptr;
 			snprintf(xstats[count].name, sizeof(xstats[count].name),
 				"tx_queue_%u_%s", q,
 				rte_txq_stats_strings[i].name);
-- 
2.1.2

  parent reply	other threads:[~2015-06-22 18:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-22 18:34 [dpdk-dev] [PATCH v4 0/9] Improve cast alignment for strict aligned machines Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 1/9] mempool: silence -Wcast-align on pointer arithmetic Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 2/9] mbuf: " Cyril Chemparathy
2015-06-22 18:34 ` Cyril Chemparathy [this message]
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 4/9] hash: " Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 5/9] eal: add and use unaligned integer types Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 6/9] app/test-pmd: pack simple_gre_hdr Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 7/9] librte_mbuf: Add rte_pktmbuf_mtod_offset() Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 8/9] librte_mbuf: Add transform for rte_pktmbuf_mtod_offset() Cyril Chemparathy
2015-06-22 18:34 ` [dpdk-dev] [PATCH v4 9/9] librte_mbuf: Apply mtod-offset.cocci transform Cyril Chemparathy
2015-06-23 15:36 ` [dpdk-dev] [PATCH v4 0/9] Improve cast alignment for strict aligned machines Olivier MATZ
2015-06-23 17:36   ` Cyril Chemparathy
2015-06-24 10:04   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434998063-15739-4-git-send-email-cchemparathy@ezchip.com \
    --to=cchemparathy@ezchip.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).