dev.c (68d268d089314b7c9c9754388a9a301175287b1a) | dev.c (6c1c5097781f563b70a81683ea6fdac21637573b) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * NET3 Protocol independent device support routines. 4 * 5 * Derived from the non IP parts of dev.c 1.0.19 6 * Authors: Ross Biro 7 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 8 * Mark Evans, <evansmp@uhura.aston.ac.uk> --- 10355 unchanged lines hidden (view full) --- 10364/* Convert net_device_stats to rtnl_link_stats64. rtnl_link_stats64 has 10365 * all the same fields in the same order as net_device_stats, with only 10366 * the type differing, but rtnl_link_stats64 may have additional fields 10367 * at the end for newer counters. 10368 */ 10369void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64, 10370 const struct net_device_stats *netdev_stats) 10371{ | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * NET3 Protocol independent device support routines. 4 * 5 * Derived from the non IP parts of dev.c 1.0.19 6 * Authors: Ross Biro 7 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 8 * Mark Evans, <evansmp@uhura.aston.ac.uk> --- 10355 unchanged lines hidden (view full) --- 10364/* Convert net_device_stats to rtnl_link_stats64. rtnl_link_stats64 has 10365 * all the same fields in the same order as net_device_stats, with only 10366 * the type differing, but rtnl_link_stats64 may have additional fields 10367 * at the end for newer counters. 10368 */ 10369void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64, 10370 const struct net_device_stats *netdev_stats) 10371{ |
10372#if BITS_PER_LONG == 64 10373 BUILD_BUG_ON(sizeof(*stats64) < sizeof(*netdev_stats)); 10374 memcpy(stats64, netdev_stats, sizeof(*netdev_stats)); 10375 /* zero out counters that only exist in rtnl_link_stats64 */ 10376 memset((char *)stats64 + sizeof(*netdev_stats), 0, 10377 sizeof(*stats64) - sizeof(*netdev_stats)); 10378#else 10379 size_t i, n = sizeof(*netdev_stats) / sizeof(unsigned long); 10380 const unsigned long *src = (const unsigned long *)netdev_stats; | 10372 size_t i, n = sizeof(*netdev_stats) / sizeof(atomic_long_t); 10373 const atomic_long_t *src = (atomic_long_t *)netdev_stats; |
10381 u64 *dst = (u64 *)stats64; 10382 10383 BUILD_BUG_ON(n > sizeof(*stats64) / sizeof(u64)); 10384 for (i = 0; i < n; i++) | 10374 u64 *dst = (u64 *)stats64; 10375 10376 BUILD_BUG_ON(n > sizeof(*stats64) / sizeof(u64)); 10377 for (i = 0; i < n; i++) |
10385 dst[i] = src[i]; | 10378 dst[i] = atomic_long_read(&src[i]); |
10386 /* zero out counters that only exist in rtnl_link_stats64 */ 10387 memset((char *)stats64 + n * sizeof(u64), 0, 10388 sizeof(*stats64) - n * sizeof(u64)); | 10379 /* zero out counters that only exist in rtnl_link_stats64 */ 10380 memset((char *)stats64 + n * sizeof(u64), 0, 10381 sizeof(*stats64) - n * sizeof(u64)); |
10389#endif | |
10390} 10391EXPORT_SYMBOL(netdev_stats_to_stats64); 10392 10393struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device *dev) 10394{ 10395 struct net_device_core_stats __percpu *p; 10396 10397 p = alloc_percpu_gfp(struct net_device_core_stats, --- 1038 unchanged lines hidden --- | 10382} 10383EXPORT_SYMBOL(netdev_stats_to_stats64); 10384 10385struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device *dev) 10386{ 10387 struct net_device_core_stats __percpu *p; 10388 10389 p = alloc_percpu_gfp(struct net_device_core_stats, --- 1038 unchanged lines hidden --- |