From patchwork Thu May 17 08:08:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael, Alice" X-Patchwork-Id: 915568 X-Patchwork-Delegate: jeffrey.t.kirsher@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=osuosl.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mxL00k1pz9s3X for ; Fri, 18 May 2018 02:18:00 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id B24FE88269; Thu, 17 May 2018 16:17:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dj-o7fXrDm5N; Thu, 17 May 2018 16:17:56 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id E6B26882A7; Thu, 17 May 2018 16:17:55 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 50D211C2C4E for ; Thu, 17 May 2018 16:17:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 473B588217 for ; Thu, 17 May 2018 16:17:52 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id E-a8J-+C4bI2 for ; Thu, 17 May 2018 16:17:49 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by whitealder.osuosl.org (Postfix) with ESMTPS id 9BCCB88273 for ; Thu, 17 May 2018 16:17:48 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 May 2018 09:17:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,411,1520924400"; d="scan'208";a="42632764" Received: from alicemic-2.jf.intel.com ([10.166.16.121]) by orsmga006.jf.intel.com with ESMTP; 17 May 2018 09:17:47 -0700 From: Alice Michael To: alice.michael@intel.com, intel-wired-lan@lists.osuosl.org Date: Thu, 17 May 2018 01:08:38 -0700 Message-Id: <20180517080840.30192-7-alice.michael@intel.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180517080840.30192-1-alice.michael@intel.com> References: <20180517080840.30192-1-alice.michael@intel.com> Subject: [Intel-wired-lan] [next PATCH S92 7/9] i40e: update data pointer directly when copying to the buffer X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" From: Jacob Keller A future patch is going to add a helper function i40e_add_ethtool_stats that will help lower the amount of boiler plate code in the i40e_get_ethtool_stats function. This conversion will take place over many patches, and the helper function will work by directly updating a reference to the data pointer. Since this would not work combined with the current method of accessing data like an array, update all the code that copies stats into the data buffer to use direct updates to the pointer instead of array accesses. This will prevent incorrect stat updates for patches in between the conversion. Similarly, when copying strings, we used a separate char *p pointer. Instead, use the data pointer directly as it's already a (u8 *) type which is the same size. Signed-off-by: Jacob Keller Tested-by: Andrew Bowers --- drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 117 ++++++++++++------------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c index 2498d19..94e1995 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c +++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c @@ -1579,7 +1579,6 @@ static void i40e_get_ethtool_stats(struct net_device *netdev, struct i40e_vsi *vsi = np->vsi; struct i40e_pf *pf = vsi->back; unsigned int j; - int i = 0; char *p; struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi); unsigned int start; @@ -1588,12 +1587,12 @@ static void i40e_get_ethtool_stats(struct net_device *netdev, for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) { p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset; - data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat == + *(data++) = (i40e_gstrings_net_stats[j].sizeof_stat == sizeof(u64)) ? *(u64 *)p : *(u32 *)p; } for (j = 0; j < I40E_MISC_STATS_LEN; j++) { p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset; - data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat == + *(data++) = (i40e_gstrings_misc_stats[j].sizeof_stat == sizeof(u64)) ? *(u64 *)p : *(u32 *)p; } rcu_read_lock(); @@ -1604,29 +1603,29 @@ static void i40e_get_ethtool_stats(struct net_device *netdev, /* Bump the stat counter to skip these stats, and make * sure the memory is zero'd */ - data[i++] = 0; - data[i++] = 0; - data[i++] = 0; - data[i++] = 0; + *(data++) = 0; + *(data++) = 0; + *(data++) = 0; + *(data++) = 0; continue; } /* process Tx ring statistics */ do { start = u64_stats_fetch_begin_irq(&tx_ring->syncp); - data[i] = tx_ring->stats.packets; - data[i + 1] = tx_ring->stats.bytes; + data[0] = tx_ring->stats.packets; + data[1] = tx_ring->stats.bytes; } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); - i += 2; + data += 2; /* Rx ring is the 2nd half of the queue pair */ rx_ring = &tx_ring[1]; do { start = u64_stats_fetch_begin_irq(&rx_ring->syncp); - data[i] = rx_ring->stats.packets; - data[i + 1] = rx_ring->stats.bytes; + data[0] = rx_ring->stats.packets; + data[1] = rx_ring->stats.bytes; } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); - i += 2; + data += 2; } rcu_read_unlock(); if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1) @@ -1639,33 +1638,33 @@ static void i40e_get_ethtool_stats(struct net_device *netdev, for (j = 0; j < I40E_VEB_STATS_LEN; j++) { p = (char *)veb; p += i40e_gstrings_veb_stats[j].stat_offset; - data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat == + *(data++) = (i40e_gstrings_veb_stats[j].sizeof_stat == sizeof(u64)) ? *(u64 *)p : *(u32 *)p; } for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) { - data[i++] = veb->tc_stats.tc_tx_packets[j]; - data[i++] = veb->tc_stats.tc_tx_bytes[j]; - data[i++] = veb->tc_stats.tc_rx_packets[j]; - data[i++] = veb->tc_stats.tc_rx_bytes[j]; + *(data++) = veb->tc_stats.tc_tx_packets[j]; + *(data++) = veb->tc_stats.tc_tx_bytes[j]; + *(data++) = veb->tc_stats.tc_rx_packets[j]; + *(data++) = veb->tc_stats.tc_rx_bytes[j]; } } else { - i += I40E_VEB_STATS_TOTAL; + data += I40E_VEB_STATS_TOTAL; } for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) { p = (char *)pf + i40e_gstrings_stats[j].stat_offset; - data[i++] = (i40e_gstrings_stats[j].sizeof_stat == + *(data++) = (i40e_gstrings_stats[j].sizeof_stat == sizeof(u64)) ? *(u64 *)p : *(u32 *)p; } for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { - data[i++] = pf->stats.priority_xon_tx[j]; - data[i++] = pf->stats.priority_xoff_tx[j]; + *(data++) = pf->stats.priority_xon_tx[j]; + *(data++) = pf->stats.priority_xoff_tx[j]; } for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { - data[i++] = pf->stats.priority_xon_rx[j]; - data[i++] = pf->stats.priority_xoff_rx[j]; + *(data++) = pf->stats.priority_xon_rx[j]; + *(data++) = pf->stats.priority_xoff_rx[j]; } for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) - data[i++] = pf->stats.priority_xon_2_xoff[j]; + *(data++) = pf->stats.priority_xon_2_xoff[j]; } static void i40e_get_stat_strings(struct net_device *netdev, u8 *data) @@ -1677,73 +1676,73 @@ static void i40e_get_stat_strings(struct net_device *netdev, u8 *data) u8 *p = data; for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) { - snprintf(p, ETH_GSTRING_LEN, "%s", + snprintf(data, ETH_GSTRING_LEN, "%s", i40e_gstrings_net_stats[i].stat_string); - p += ETH_GSTRING_LEN; + data += ETH_GSTRING_LEN; } for (i = 0; i < I40E_MISC_STATS_LEN; i++) { - snprintf(p, ETH_GSTRING_LEN, "%s", + snprintf(data, ETH_GSTRING_LEN, "%s", i40e_gstrings_misc_stats[i].stat_string); - p += ETH_GSTRING_LEN; + data += ETH_GSTRING_LEN; } for (i = 0; i < I40E_MAX_NUM_QUEUES(netdev); i++) { - snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i); - p += ETH_GSTRING_LEN; - snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i); - p += ETH_GSTRING_LEN; - snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i); - p += ETH_GSTRING_LEN; - snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i); - p += ETH_GSTRING_LEN; + snprintf(data, ETH_GSTRING_LEN, "tx-%u.tx_packets", i); + data += ETH_GSTRING_LEN; + snprintf(data, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i); + data += ETH_GSTRING_LEN; + snprintf(data, ETH_GSTRING_LEN, "rx-%u.rx_packets", i); + data += ETH_GSTRING_LEN; + snprintf(data, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i); + data += ETH_GSTRING_LEN; } if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1) return; for (i = 0; i < I40E_VEB_STATS_LEN; i++) { - snprintf(p, ETH_GSTRING_LEN, "%s", + snprintf(data, ETH_GSTRING_LEN, "%s", i40e_gstrings_veb_stats[i].stat_string); - p += ETH_GSTRING_LEN; + data += ETH_GSTRING_LEN; } for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { - snprintf(p, ETH_GSTRING_LEN, + snprintf(data, ETH_GSTRING_LEN, "veb.tc_%u_tx_packets", i); - p += ETH_GSTRING_LEN; - snprintf(p, ETH_GSTRING_LEN, + data += ETH_GSTRING_LEN; + snprintf(data, ETH_GSTRING_LEN, "veb.tc_%u_tx_bytes", i); - p += ETH_GSTRING_LEN; - snprintf(p, ETH_GSTRING_LEN, + data += ETH_GSTRING_LEN; + snprintf(data, ETH_GSTRING_LEN, "veb.tc_%u_rx_packets", i); - p += ETH_GSTRING_LEN; - snprintf(p, ETH_GSTRING_LEN, + data += ETH_GSTRING_LEN; + snprintf(data, ETH_GSTRING_LEN, "veb.tc_%u_rx_bytes", i); - p += ETH_GSTRING_LEN; + data += ETH_GSTRING_LEN; } for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) { - snprintf(p, ETH_GSTRING_LEN, "%s", + snprintf(data, ETH_GSTRING_LEN, "%s", i40e_gstrings_stats[i].stat_string); - p += ETH_GSTRING_LEN; + data += ETH_GSTRING_LEN; } for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { - snprintf(p, ETH_GSTRING_LEN, + snprintf(data, ETH_GSTRING_LEN, "port.tx_priority_%u_xon", i); - p += ETH_GSTRING_LEN; - snprintf(p, ETH_GSTRING_LEN, + data += ETH_GSTRING_LEN; + snprintf(data, ETH_GSTRING_LEN, "port.tx_priority_%u_xoff", i); - p += ETH_GSTRING_LEN; + data += ETH_GSTRING_LEN; } for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { - snprintf(p, ETH_GSTRING_LEN, + snprintf(data, ETH_GSTRING_LEN, "port.rx_priority_%u_xon", i); - p += ETH_GSTRING_LEN; - snprintf(p, ETH_GSTRING_LEN, + data += ETH_GSTRING_LEN; + snprintf(data, ETH_GSTRING_LEN, "port.rx_priority_%u_xoff", i); - p += ETH_GSTRING_LEN; + data += ETH_GSTRING_LEN; } for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { - snprintf(p, ETH_GSTRING_LEN, + snprintf(data, ETH_GSTRING_LEN, "port.rx_priority_%u_xon_2_xoff", i); - p += ETH_GSTRING_LEN; + data += ETH_GSTRING_LEN; } WARN_ONCE(p - data != i40e_get_stats_count(netdev) * ETH_GSTRING_LEN,