Changes in 4.9.264 net: fec: ptp: avoid register access when ipg clock is disabled powerpc/4xx: Fix build errors from mfdcr() atm: eni: dont release is never initialized atm: lanai: dont run lanai_dev_close if not open ixgbe: Fix memleak in ixgbe_configure_clsu32 net: tehuti: fix error return code in bdx_probe() sun/niu: fix wrong RXMAC_BC_FRM_CNT_COUNT count nfs: fix PNFS_FLEXFILE_LAYOUT Kconfig default NFS: Correct size calculation for create reply length net: wan: fix error return code of uhdlc_init() atm: uPD98402: fix incorrect allocation atm: idt77252: fix null-ptr-dereference u64_stats,lockdep: Fix u64_stats_init() vs lockdep nfs: we don't support removing system.nfs4_acl ia64: fix ia64_syscall_get_set_arguments() for break-based syscalls ia64: fix ptrace(PTRACE_SYSCALL_INFO_EXIT) sign x86/tlb: Flush global mappings when KAISER is disabled squashfs: fix inode lookup sanity checks squashfs: fix xattr id and id lookup sanity checks arm64: dts: ls1043a: mark crypto engine dma coherent bus: omap_l3_noc: mark l3 irqs as IRQF_NO_THREAD macvlan: macvlan_count_rx() needs to be aware of preemption net: dsa: bcm_sf2: Qualify phydev->dev_flags based on port e1000e: add rtnl_lock() to e1000_reset_task e1000e: Fix error handling in e1000_set_d0_lplu_state_82571 net/qlcnic: Fix a use after free in qlcnic_83xx_get_minidump_template can: c_can_pci: c_can_pci_remove(): fix use-after-free can: c_can: move runtime PM enable/disable to c_can_platform can: m_can: m_can_do_rx_poll(): fix extraneous msg loss warning mac80211: fix rate mask reset net: cdc-phonet: fix data-interface release on probe failure RDMA/cxgb4: Fix adapter LE hash errors while destroying ipv6 listening server ACPI: scan: Rearrange memory allocation in acpi_device_add() ACPI: scan: Use unique number for instance_no perf auxtrace: Fix auxtrace queue conflict idr: add ida_is_empty futex: Use smp_store_release() in mark_wake_futex() futex,rt_mutex: Introduce rt_mutex_init_waiter() futex: Rework futex_lock_pi() to use rt_mutex_*_proxy_lock() futex: Drop hb->lock before enqueueing on the rtmutex futex: Avoid freeing an active timer futex,rt_mutex: Fix rt_mutex_cleanup_proxy_lock() futex: Handle early deadlock return correctly futex: Fix (possible) missed wakeup locking/futex: Allow low-level atomic operations to return -EAGAIN arm64: futex: Bound number of LDXR/STXR loops in FUTEX_WAKE_OP futex: Prevent robust futex exit race futex: Fix incorrect should_fail_futex() handling futex: Handle transient "ownerless" rtmutex state correctly can: dev: Move device back to init netns on owning netns delete net: sched: validate stab values net: qrtr: fix a kernel-infoleak in qrtr_recvmsg() mac80211: fix double free in ibss_leave xen-blkback: don't leak persistent grants from xen_blkbk_map() Linux 4.9.264 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I8c5617c1f82aa378e3ba19d43879065e15457edd
189 lines
5.4 KiB
C
189 lines
5.4 KiB
C
#ifndef _LINUX_U64_STATS_SYNC_H
|
|
#define _LINUX_U64_STATS_SYNC_H
|
|
|
|
/*
|
|
* To properly implement 64bits network statistics on 32bit and 64bit hosts,
|
|
* we provide a synchronization point, that is a noop on 64bit or UP kernels.
|
|
*
|
|
* Key points :
|
|
* 1) Use a seqcount on SMP 32bits, with low overhead.
|
|
* 2) Whole thing is a noop on 64bit arches or UP kernels.
|
|
* 3) Write side must ensure mutual exclusion or one seqcount update could
|
|
* be lost, thus blocking readers forever.
|
|
* If this synchronization point is not a mutex, but a spinlock or
|
|
* spinlock_bh() or disable_bh() :
|
|
* 3.1) Write side should not sleep.
|
|
* 3.2) Write side should not allow preemption.
|
|
* 3.3) If applicable, interrupts should be disabled.
|
|
*
|
|
* 4) If reader fetches several counters, there is no guarantee the whole values
|
|
* are consistent (remember point 1) : this is a noop on 64bit arches anyway)
|
|
*
|
|
* 5) readers are allowed to sleep or be preempted/interrupted : They perform
|
|
* pure reads. But if they have to fetch many values, it's better to not allow
|
|
* preemptions/interruptions to avoid many retries.
|
|
*
|
|
* 6) If counter might be written by an interrupt, readers should block interrupts.
|
|
* (On UP, there is no seqcount_t protection, a reader allowing interrupts could
|
|
* read partial values)
|
|
*
|
|
* 7) For irq and softirq uses, readers can use u64_stats_fetch_begin_irq() and
|
|
* u64_stats_fetch_retry_irq() helpers
|
|
*
|
|
* Usage :
|
|
*
|
|
* Stats producer (writer) should use following template granted it already got
|
|
* an exclusive access to counters (a lock is already taken, or per cpu
|
|
* data is used [in a non preemptable context])
|
|
*
|
|
* spin_lock_bh(...) or other synchronization to get exclusive access
|
|
* ...
|
|
* u64_stats_update_begin(&stats->syncp);
|
|
* stats->bytes64 += len; // non atomic operation
|
|
* stats->packets64++; // non atomic operation
|
|
* u64_stats_update_end(&stats->syncp);
|
|
*
|
|
* While a consumer (reader) should use following template to get consistent
|
|
* snapshot for each variable (but no guarantee on several ones)
|
|
*
|
|
* u64 tbytes, tpackets;
|
|
* unsigned int start;
|
|
*
|
|
* do {
|
|
* start = u64_stats_fetch_begin(&stats->syncp);
|
|
* tbytes = stats->bytes64; // non atomic operation
|
|
* tpackets = stats->packets64; // non atomic operation
|
|
* } while (u64_stats_fetch_retry(&stats->syncp, start));
|
|
*
|
|
*
|
|
* Example of use in drivers/net/loopback.c, using per_cpu containers,
|
|
* in BH disabled context.
|
|
*/
|
|
#include <linux/seqlock.h>
|
|
|
|
struct u64_stats_sync {
|
|
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
|
|
seqcount_t seq;
|
|
#endif
|
|
};
|
|
|
|
|
|
#if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
|
|
#define u64_stats_init(syncp) seqcount_init(&(syncp)->seq)
|
|
#else
|
|
static inline void u64_stats_init(struct u64_stats_sync *syncp)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
static inline void u64_stats_update_begin(struct u64_stats_sync *syncp)
|
|
{
|
|
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
|
|
write_seqcount_begin(&syncp->seq);
|
|
#endif
|
|
}
|
|
|
|
static inline void u64_stats_update_end(struct u64_stats_sync *syncp)
|
|
{
|
|
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
|
|
write_seqcount_end(&syncp->seq);
|
|
#endif
|
|
}
|
|
|
|
static inline unsigned long
|
|
u64_stats_update_begin_irqsave(struct u64_stats_sync *syncp)
|
|
{
|
|
unsigned long flags = 0;
|
|
|
|
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
|
|
local_irq_save(flags);
|
|
write_seqcount_begin(&syncp->seq);
|
|
#endif
|
|
return flags;
|
|
}
|
|
|
|
static inline void
|
|
u64_stats_update_end_irqrestore(struct u64_stats_sync *syncp,
|
|
unsigned long flags)
|
|
{
|
|
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
|
|
write_seqcount_end(&syncp->seq);
|
|
local_irq_restore(flags);
|
|
#endif
|
|
}
|
|
|
|
static inline void u64_stats_update_begin_raw(struct u64_stats_sync *syncp)
|
|
{
|
|
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
|
|
raw_write_seqcount_begin(&syncp->seq);
|
|
#endif
|
|
}
|
|
|
|
static inline void u64_stats_update_end_raw(struct u64_stats_sync *syncp)
|
|
{
|
|
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
|
|
raw_write_seqcount_end(&syncp->seq);
|
|
#endif
|
|
}
|
|
|
|
static inline unsigned int __u64_stats_fetch_begin(const struct u64_stats_sync *syncp)
|
|
{
|
|
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
|
|
return read_seqcount_begin(&syncp->seq);
|
|
#else
|
|
return 0;
|
|
#endif
|
|
}
|
|
|
|
static inline unsigned int u64_stats_fetch_begin(const struct u64_stats_sync *syncp)
|
|
{
|
|
#if BITS_PER_LONG==32 && !defined(CONFIG_SMP)
|
|
preempt_disable();
|
|
#endif
|
|
return __u64_stats_fetch_begin(syncp);
|
|
}
|
|
|
|
static inline bool __u64_stats_fetch_retry(const struct u64_stats_sync *syncp,
|
|
unsigned int start)
|
|
{
|
|
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
|
|
return read_seqcount_retry(&syncp->seq, start);
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
static inline bool u64_stats_fetch_retry(const struct u64_stats_sync *syncp,
|
|
unsigned int start)
|
|
{
|
|
#if BITS_PER_LONG==32 && !defined(CONFIG_SMP)
|
|
preempt_enable();
|
|
#endif
|
|
return __u64_stats_fetch_retry(syncp, start);
|
|
}
|
|
|
|
/*
|
|
* In case irq handlers can update u64 counters, readers can use following helpers
|
|
* - SMP 32bit arches use seqcount protection, irq safe.
|
|
* - UP 32bit must disable irqs.
|
|
* - 64bit have no problem atomically reading u64 values, irq safe.
|
|
*/
|
|
static inline unsigned int u64_stats_fetch_begin_irq(const struct u64_stats_sync *syncp)
|
|
{
|
|
#if BITS_PER_LONG==32 && !defined(CONFIG_SMP)
|
|
local_irq_disable();
|
|
#endif
|
|
return __u64_stats_fetch_begin(syncp);
|
|
}
|
|
|
|
static inline bool u64_stats_fetch_retry_irq(const struct u64_stats_sync *syncp,
|
|
unsigned int start)
|
|
{
|
|
#if BITS_PER_LONG==32 && !defined(CONFIG_SMP)
|
|
local_irq_enable();
|
|
#endif
|
|
return __u64_stats_fetch_retry(syncp, start);
|
|
}
|
|
|
|
#endif /* _LINUX_U64_STATS_SYNC_H */
|