* aosp/android-4.14-stable:
Linux 4.14.216
net: drop bogus skb with CHECKSUM_PARTIAL and offset beyond end of trimmed packet
block: fix use-after-free in disk_part_iter_next
KVM: arm64: Don't access PMCR_EL0 when no PMU is available
wan: ds26522: select CONFIG_BITREVERSE
net/mlx5e: Fix two double free cases
net/mlx5e: Fix memleak in mlx5e_create_l2_table_groups
iommu/intel: Fix memleak in intel_irq_remapping_alloc
block: rsxx: select CONFIG_CRC32
wil6210: select CONFIG_CRC32
dmaengine: xilinx_dma: fix mixed_enum_type coverity warning
dmaengine: xilinx_dma: check dma_async_device_register return value
spi: stm32: FIFO threshold level - fix align packet size
cpufreq: powernow-k8: pass policy rather than use cpufreq_cpu_get()
i2c: sprd: use a specific timeout to avoid system hang up issue
ARM: OMAP2+: omap_device: fix idling of devices during probe
iio: imu: st_lsm6dsx: fix edge-trigger interrupts
iio: imu: st_lsm6dsx: flip irq return logic
spi: pxa2xx: Fix use-after-free on unbind
ubifs: wbuf: Don't leak kernel memory to flash
drm/i915: Fix mismatch between misplaced vma check and vma insert
vmlinux.lds.h: Add PGO and AutoFDO input sections
x86/resctrl: Don't move a task to the same resource group
x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR
net: fix pmtu check in nopmtudisc mode
net: ip: always refragment ip defragmented packets
net: vlan: avoid leaks on register_vlan_dev() failures
net: cdc_ncm: correct overhead in delayed_ndp_size
powerpc: Fix incorrect stw{, ux, u, x} instructions in __set_pte_at
Linux 4.14.215
scsi: target: Fix XCOPY NAA identifier lookup
KVM: x86: fix shift out of bounds reported by UBSAN
x86/mtrr: Correct the range check before performing MTRR type lookups
netfilter: xt_RATEEST: reject non-null terminated string from userspace
netfilter: ipset: fix shift-out-of-bounds in htable_bits()
Revert "device property: Keep secondary firmware node secondary by type"
ALSA: hda/realtek - Fix speaker volume control on Lenovo C940
ALSA: hda/conexant: add a new hda codec CX11970
x86/mm: Fix leak of pmd ptlock
USB: serial: keyspan_pda: remove unused variable
usb: gadget: configfs: Fix use-after-free issue with udc_name
usb: gadget: configfs: Preserve function ordering after bind failure
usb: gadget: Fix spinlock lockup on usb_function_deactivate
USB: gadget: legacy: fix return error code in acm_ms_bind()
usb: gadget: function: printer: Fix a memory leak for interface descriptor
usb: gadget: f_uac2: reset wMaxPacketSize
usb: gadget: select CONFIG_CRC32
ALSA: usb-audio: Fix UBSAN warnings for MIDI jacks
USB: usblp: fix DMA to stack
USB: yurex: fix control-URB timeout handling
USB: serial: option: add Quectel EM160R-GL
USB: serial: option: add LongSung M5710 module support
USB: serial: iuu_phoenix: fix DMA from stack
usb: uas: Add PNY USB Portable SSD to unusual_uas
usb: usbip: vhci_hcd: protect shift size
USB: xhci: fix U1/U2 handling for hardware with XHCI_INTEL_HOST quirk set
usb: chipidea: ci_hdrc_imx: add missing put_device() call in usbmisc_get_init_data()
usb: dwc3: ulpi: Use VStsDone to detect PHY regs access completion
USB: cdc-acm: blacklist another IR Droid device
usb: gadget: enable super speed plus
crypto: ecdh - avoid buffer overflow in ecdh_set_secret()
video: hyperv_fb: Fix the mmap() regression for v5.4.y and older
net: systemport: set dev->max_mtu to UMAC_MAX_MTU_SIZE
net: mvpp2: Fix GoP port 3 Networking Complex Control configurations
net-sysfs: take the rtnl lock when accessing xps_cpus_map and num_tc
net: sched: prevent invalid Scell_log shift count
vhost_net: fix ubuf refcount incorrectly when sendmsg fails
net: usb: qmi_wwan: add Quectel EM160R-GL
CDC-NCM: remove "connected" log message
net: hdlc_ppp: Fix issues when mod_timer is called while timer is running
net: hns: fix return value check in __lb_other_process()
ipv4: Ignore ECN bits for fib lookups in fib_compute_spec_dst()
net: ethernet: ti: cpts: fix ethtool output when no ptp_clock registered
net-sysfs: take the rtnl lock when storing xps_cpus
net: ethernet: Fix memleak in ethoc_probe
net/ncsi: Use real net-device for response handler
virtio_net: Fix recursive call to cpus_read_lock()
qede: fix offload for IPIP tunnel packets
atm: idt77252: call pci_disable_device() on error path
ethernet: ucc_geth: set dev->max_mtu to 1518
ethernet: ucc_geth: fix use-after-free in ucc_geth_remove()
depmod: handle the case of /sbin/depmod without /sbin in PATH
lib/genalloc: fix the overflow when size is too big
scsi: ide: Do not set the RQF_PREEMPT flag for sense requests
scsi: ufs-pci: Ensure UFS device is in PowerDown mode for suspend-to-disk ->poweroff()
workqueue: Kick a worker based on the actual activation of delayed works
kbuild: don't hardcode depmod path
Linux 4.14.214
mwifiex: Fix possible buffer overflows in mwifiex_cmd_802_11_ad_hoc_start
iio:magnetometer:mag3110: Fix alignment and data leak issues.
iio:imu:bmi160: Fix alignment and data leak issues
kdev_t: always inline major/minor helper functions
dm verity: skip verity work if I/O error when system is shutting down
ALSA: pcm: Clear the full allocated memory at hw_params
module: delay kobject uevent until after module init call
powerpc: sysdev: add missing iounmap() on error in mpic_msgr_probe()
quota: Don't overflow quota file offsets
module: set MODULE_STATE_GOING state when a module fails to load
rtc: sun6i: Fix memleak in sun6i_rtc_clk_init
ALSA: seq: Use bool for snd_seq_queue internal flags
media: gp8psk: initialize stats at power control logic
misc: vmw_vmci: fix kernel info-leak by initializing dbells in vmci_ctx_get_chkpt_doorbells()
reiserfs: add check for an invalid ih_entry_count
of: fix linker-section match-table corruption
uapi: move constants from <linux/kernel.h> to <linux/const.h>
powerpc/bitops: Fix possible undefined behaviour with fls() and fls64()
USB: serial: digi_acceleport: fix write-wakeup deadlocks
s390/dasd: fix hanging device offline processing
vfio/pci: Move dummy_resources_list init in vfio_pci_probe()
mm: memcontrol: fix excessive complexity in memory.stat reporting
mm: memcontrol: implement lruvec stat functions on top of each other
mm: memcontrol: eliminate raw access to stat and event counters
ALSA: usb-audio: fix sync-ep altsetting sanity check
ALSA: usb-audio: simplify set_sync_ep_implicit_fb_quirk
ALSA: hda/ca0132 - Fix work handling in delayed HP detection
md/raid10: initialize r10_bio->read_slot before use.
x86/entry/64: Add instruction suffix
ANDROID: usb: f_accessory: Don't drop NULL reference in acc_disconnect()
ANDROID: usb: f_accessory: Avoid bitfields for shared variables
ANDROID: usb: f_accessory: Cancel any pending work before teardown
ANDROID: usb: f_accessory: Don't corrupt global state on double registration
ANDROID: usb: f_accessory: Fix teardown ordering in acc_release()
ANDROID: usb: f_accessory: Add refcounting to global 'acc_dev'
ANDROID: usb: f_accessory: Wrap '_acc_dev' in get()/put() accessors
ANDROID: usb: f_accessory: Remove useless assignment
ANDROID: usb: f_accessory: Remove useless non-debug prints
ANDROID: usb: f_accessory: Remove stale comments
ANDROID: USB: f_accessory: Check dev pointer before decoding ctrl request
ANDROID: usb: gadget: f_accessory: fix CTS test stuck
Linux 4.14.213
PCI: Fix pci_slot_release() NULL pointer dereference
libnvdimm/namespace: Fix reaping of invalidated block-window-namespace labels
xenbus/xenbus_backend: Disallow pending watch messages
xen/xenbus: Count pending messages for each watch
xen/xenbus/xen_bus_type: Support will_handle watch callback
xen/xenbus: Add 'will_handle' callback support in xenbus_watch_path()
xen/xenbus: Allow watches discard events before queueing
xen-blkback: set ring->xenblkd to NULL after kthread_stop()
clk: mvebu: a3700: fix the XTAL MODE pin to MPP1_9
md/cluster: fix deadlock when node is doing resync job
iio:imu:bmi160: Fix too large a buffer.
iio:pressure:mpl3115: Force alignment of buffer
iio:light:rpr0521: Fix timestamp alignment and prevent data leak.
iio: adc: rockchip_saradc: fix missing clk_disable_unprepare() on error in rockchip_saradc_resume
iio: buffer: Fix demux update
mtd: parser: cmdline: Fix parsing of part-names with colons
soc: qcom: smp2p: Safely acquire spinlock without IRQs
spi: st-ssc4: Fix unbalanced pm_runtime_disable() in probe error path
spi: sc18is602: Don't leak SPI master in probe error path
spi: rb4xx: Don't leak SPI master in probe error path
spi: pic32: Don't leak DMA channels in probe error path
spi: davinci: Fix use-after-free on unbind
spi: spi-sh: Fix use-after-free on unbind
drm/dp_aux_dev: check aux_dev before use in drm_dp_aux_dev_get_by_minor()
jfs: Fix array index bounds check in dbAdjTree
jffs2: Fix GC exit abnormally
ceph: fix race in concurrent __ceph_remove_cap invocations
ima: Don't modify file descriptor mode on the fly
powerpc/powernv/memtrace: Don't leak kernel memory to user space
powerpc/xmon: Change printk() to pr_cont()
powerpc/rtas: Fix typo of ibm,open-errinjct in RTAS filter
ARM: dts: at91: sama5d2: fix CAN message ram offset and size
KVM: arm64: Introduce handling of AArch32 TTBCR2 traps
ext4: fix deadlock with fs freezing and EA inodes
ext4: fix a memory leak of ext4_free_data
btrfs: fix return value mixup in btrfs_get_extent
Btrfs: fix selftests failure due to uninitialized i_mode in test inodes
USB: serial: keyspan_pda: fix write unthrottling
USB: serial: keyspan_pda: fix tx-unthrottle use-after-free
USB: serial: keyspan_pda: fix write-wakeup use-after-free
USB: serial: keyspan_pda: fix stalled writes
USB: serial: keyspan_pda: fix write deadlock
USB: serial: keyspan_pda: fix dropped unthrottle interrupts
USB: serial: mos7720: fix parallel-port state restore
EDAC/amd64: Fix PCI component registration
crypto: ecdh - avoid unaligned accesses in ecdh_set_secret()
powerpc/perf: Exclude kernel samples while counting events in user space.
staging: comedi: mf6x4: Fix AI end-of-conversion detection
s390/dasd: fix list corruption of lcu list
s390/dasd: fix list corruption of pavgroup group list
s390/dasd: prevent inconsistent LCU device data
s390/smp: perform initial CPU reset also for SMT siblings
ALSA: usb-audio: Disable sample read check if firmware doesn't give back
ALSA: pcm: oss: Fix a few more UBSAN fixes
ALSA: hda/realtek - Enable headset mic of ASUS Q524UQK with ALC255
ACPI: PNP: compare the string length in the matching_id()
Revert "ACPI / resources: Use AE_CTRL_TERMINATE to terminate resources walks"
PM: ACPI: PCI: Drop acpi_pm_set_bridge_wakeup()
Input: cyapa_gen6 - fix out-of-bounds stack access
media: netup_unidvb: Don't leak SPI master in probe error path
media: sunxi-cir: ensure IR is handled when it is continuous
media: gspca: Fix memory leak in probe
Input: goodix - add upside-down quirk for Teclast X98 Pro tablet
Input: cros_ec_keyb - send 'scancodes' in addition to key events
fix namespaced fscaps when !CONFIG_SECURITY
cfg80211: initialize rekey_data
clk: sunxi-ng: Make sure divider tables have sentinel
clk: s2mps11: Fix a resource leak in error handling paths in the probe function
qlcnic: Fix error code in probe
perf record: Fix memory leak when using '--user-regs=?' to list registers
pwm: lp3943: Dynamically allocate PWM chip base
pwm: zx: Add missing cleanup in error path
clk: ti: Fix memleak in ti_fapll_synth_setup
watchdog: coh901327: add COMMON_CLK dependency
watchdog: qcom: Avoid context switch in restart handler
net: korina: fix return value
net: allwinner: Fix some resources leak in the error handling path of the probe and in the remove function
net: bcmgenet: Fix a resource leak in an error handling path in the probe functin
checkpatch: fix unescaped left brace
powerpc/ps3: use dma_mapping_error()
nfc: s3fwrn5: Release the nfc firmware
um: chan_xterm: Fix fd leak
watchdog: sirfsoc: Add missing dependency on HAS_IOMEM
irqchip/alpine-msi: Fix freeing of interrupts on allocation error path
ASoC: wm_adsp: remove "ctl" from list on error in wm_adsp_create_control()
extcon: max77693: Fix modalias string
clk: tegra: Fix duplicated SE clock entry
x86/kprobes: Restore BTF if the single-stepping is cancelled
nfs_common: need lock during iterate through the list
nfsd: Fix message level for normal termination
speakup: fix uninitialized flush_lock
usb: oxu210hp-hcd: Fix memory leak in oxu_create
usb: ehci-omap: Fix PM disable depth umbalance in ehci_hcd_omap_probe
powerpc/pseries/hibernation: remove redundant cacheinfo update
powerpc/pseries/hibernation: drop pseries_suspend_begin() from suspend ops
scsi: fnic: Fix error return code in fnic_probe()
seq_buf: Avoid type mismatch for seq_buf_init
scsi: pm80xx: Fix error return in pm8001_pci_probe()
scsi: qedi: Fix missing destroy_workqueue() on error in __qedi_probe
cpufreq: scpi: Add missing MODULE_ALIAS
cpufreq: loongson1: Add missing MODULE_ALIAS
cpufreq: st: Add missing MODULE_DEVICE_TABLE
cpufreq: mediatek: Add missing MODULE_DEVICE_TABLE
cpufreq: highbank: Add missing MODULE_DEVICE_TABLE
clocksource/drivers/arm_arch_timer: Correct fault programming of CNTKCTL_EL1.EVNTI
dm ioctl: fix error return code in target_message
ASoC: jz4740-i2s: add missed checks for clk_get()
net/mlx5: Properly convey driver version to firmware
memstick: r592: Fix error return in r592_probe()
arm64: dts: rockchip: Fix UART pull-ups on rk3328
pinctrl: falcon: add missing put_device() call in pinctrl_falcon_probe()
ARM: dts: at91: sama5d2: map securam as device
clocksource/drivers/cadence_ttc: Fix memory leak in ttc_setup_clockevent()
media: saa7146: fix array overflow in vidioc_s_audio()
vfio-pci: Use io_remap_pfn_range() for PCI IO memory
NFS: switch nfsiod to be an UNBOUND workqueue.
lockd: don't use interval-based rebinding over TCP
SUNRPC: xprt_load_transport() needs to support the netid "rdma6"
NFSv4.2: condition READDIR's mask for security label based on LSM state
ath10k: Release some resources in an error handling path
ath10k: Fix an error handling path
ARM: dts: at91: at91sam9rl: fix ADC triggers
PCI: iproc: Fix out-of-bound array accesses
genirq/irqdomain: Don't try to free an interrupt that has no mapping
power: supply: bq24190_charger: fix reference leak
ARM: dts: Remove non-existent i2c1 from 98dx3236
HSI: omap_ssi: Don't jump to free ID in ssi_add_controller()
media: max2175: fix max2175_set_csm_mode() error code
mips: cdmm: fix use-after-free in mips_cdmm_bus_discover
samples: bpf: Fix lwt_len_hist reusing previous BPF map
media: siano: fix memory leak of debugfs members in smsdvb_hotplug
cw1200: fix missing destroy_workqueue() on error in cw1200_init_common
orinoco: Move context allocation after processing the skb
ARM: dts: at91: sama5d3_xplained: add pincontrol for USB Host
ARM: dts: at91: sama5d4_xplained: add pincontrol for USB Host
memstick: fix a double-free bug in memstick_check
RDMA/cxgb4: Validate the number of CQEs
Input: omap4-keypad - fix runtime PM error handling
drivers: soc: ti: knav_qmss_queue: Fix error return code in knav_queue_probe
soc: ti: Fix reference imbalance in knav_dma_probe
soc: ti: knav_qmss: fix reference leak in knav_queue_probe
crypto: omap-aes - Fix PM disable depth imbalance in omap_aes_probe
powerpc/feature: Fix CPU_FTRS_ALWAYS by removing CPU_FTRS_GENERIC_32
Input: ads7846 - fix unaligned access on 7845
Input: ads7846 - fix integer overflow on Rt calculation
Input: ads7846 - fix race that causes missing releases
drm/omap: dmm_tiler: fix return error code in omap_dmm_probe()
media: solo6x10: fix missing snd_card_free in error handling case
scsi: core: Fix VPD LUN ID designator priorities
media: mtk-vcodec: add missing put_device() call in mtk_vcodec_release_dec_pm()
staging: greybus: codecs: Fix reference counter leak in error handling
MIPS: BCM47XX: fix kconfig dependency bug for BCM47XX_BCMA
RDMa/mthca: Work around -Wenum-conversion warning
ASoC: arizona: Fix a wrong free in wm8997_probe
ASoC: wm8998: Fix PM disable depth imbalance on error
mwifiex: fix mwifiex_shutdown_sw() causing sw reset failure
spi: tegra114: fix reference leak in tegra spi ops
spi: tegra20-sflash: fix reference leak in tegra_sflash_resume
spi: tegra20-slink: fix reference leak in slink ops of tegra20
spi: spi-ti-qspi: fix reference leak in ti_qspi_setup
Bluetooth: Fix null pointer dereference in hci_event_packet()
arm64: dts: exynos: Correct psci compatible used on Exynos7
selinux: fix inode_doinit_with_dentry() LABEL_INVALID error handling
ASoC: pcm: DRAIN support reactivation
spi: img-spfi: fix reference leak in img_spfi_resume
crypto: talitos - Fix return type of current_desc_hdr()
sched: Reenable interrupts in do_sched_yield()
sched/deadline: Fix sched_dl_global_validate()
ARM: p2v: fix handling of LPAE translation in BE mode
x86/mm/ident_map: Check for errors from ident_pud_init()
RDMA/rxe: Compute PSN windows correctly
selinux: fix error initialization in inode_doinit_with_dentry()
RDMA/bnxt_re: Set queue pair state when being queried
soc: mediatek: Check if power domains can be powered on at boot time
soc: renesas: rmobile-sysc: Fix some leaks in rmobile_init_pm_domains()
drm/gma500: fix double free of gma_connector
Bluetooth: Fix slab-out-of-bounds read in hci_le_direct_adv_report_evt()
md: fix a warning caused by a race between concurrent md_ioctl()s
crypto: af_alg - avoid undefined behavior accessing salg_name
media: msi2500: assign SPI bus number dynamically
quota: Sanity-check quota file headers on load
serial_core: Check for port state when tty is in error state
HID: i2c-hid: add Vero K147 to descriptor override
ARM: dts: exynos: fix USB 3.0 pins supply being turned off on Odroid XU
ARM: dts: exynos: fix USB 3.0 VBUS control and over-current pins on Exynos5410
ARM: dts: exynos: fix roles of USB 3.0 ports on Odroid XU
usb: chipidea: ci_hdrc_imx: Pass DISABLE_DEVICE_STREAMING flag to imx6ul
USB: gadget: f_rndis: fix bitrate for SuperSpeed and above
usb: gadget: f_fs: Re-use SS descriptors for SuperSpeedPlus
USB: gadget: f_midi: setup SuperSpeed Plus descriptors
USB: gadget: f_acm: add support for SuperSpeed Plus
USB: serial: option: add interface-number sanity check to flag handling
soc/tegra: fuse: Fix index bug in get_process_id
dm table: Remove BUG_ON(in_interrupt())
scsi: mpt3sas: Increase IOCInit request timeout to 30s
vxlan: Copy needed_tailroom from lowerdev
vxlan: Add needed_headroom for lower device
drm/tegra: sor: Disable clocks on error in tegra_sor_init()
kernel/cpu: add arch override for clear_tasks_mm_cpumask() mm handling
RDMA/cm: Fix an attempt to use non-valid pointer when cleaning timewait
can: softing: softing_netdev_open(): fix error handling
scsi: bnx2i: Requires MMU
gpio: mvebu: fix potential user-after-free on probe
ARM: dts: sun8i: v3s: fix GIC node memory range
pinctrl: baytrail: Avoid clearing debounce value when turning it off
pinctrl: merrifield: Set default bias in case no particular value given
drm: fix drm_dp_mst_port refcount leaks in drm_dp_mst_allocate_vcpi
serial: 8250_omap: Avoid FIFO corruption caused by MDR1 access
ALSA: pcm: oss: Fix potential out-of-bounds shift
USB: sisusbvga: Make console support depend on BROKEN
USB: UAS: introduce a quirk to set no_write_same
xhci: Give USB2 ports time to enter U3 in bus suspend
ALSA: usb-audio: Fix control 'access overflow' errors from chmap
ALSA: usb-audio: Fix potential out-of-bounds shift
USB: add RESET_RESUME quirk for Snapscan 1212
USB: dummy-hcd: Fix uninitialized array use in init()
mac80211: mesh: fix mesh_pathtbl_init() error path
net: bridge: vlan: fix error return code in __vlan_add()
net: stmmac: dwmac-meson8b: fix mask definition of the m250_sel mux
net: stmmac: delete the eee_ctrl_timer after napi disabled
net/mlx4_en: Handle TX error CQE
net/mlx4_en: Avoid scheduling restart task if it is already running
tcp: fix cwnd-limited bug for TSO deferral where we send nothing
net: stmmac: free tx skb buffer in stmmac_resume()
PCI: qcom: Add missing reset for ipq806x
x86/mm/mem_encrypt: Fix definition of PMD_FLAGS_DEC_WP
scsi: be2iscsi: Revert "Fix a theoretical leak in beiscsi_create_eqs()"
kbuild: avoid static_assert for genksyms
pinctrl: amd: remove debounce filter setting in IRQ type setting
Input: i8042 - add Acer laptops to the i8042 reset list
Input: cm109 - do not stomp on control URB
platform/x86: acer-wmi: add automatic keyboard background light toggle key as KEY_LIGHTS_TOGGLE
soc: fsl: dpio: Get the cpumask through cpumask_of(cpu)
scsi: ufs: Make sure clk scaling happens only when HBA is runtime ACTIVE
ARC: stack unwinding: don't assume non-current task is sleeping
iwlwifi: mvm: fix kernel panic in case of assert during CSA
arm64: dts: rockchip: Assign a fixed index to mmc devices on rk3399 boards.
iwlwifi: pcie: limit memory read spin time
spi: bcm2835aux: Restore err assignment in bcm2835aux_spi_probe
spi: bcm2835aux: Fix use-after-free on unbind
Linux 4.14.212
x86/uprobes: Do not use prefixes.nbytes when looping over prefixes.bytes
Input: i8042 - fix error return code in i8042_setup_aux()
i2c: qup: Fix error return code in qup_i2c_bam_schedule_desc()
gfs2: check for empty rgrp tree in gfs2_ri_update
tracing: Fix userstacktrace option for instances
spi: bcm2835: Release the DMA channel if probe fails after dma_init
spi: bcm2835: Fix use-after-free on unbind
spi: bcm-qspi: Fix use-after-free on unbind
spi: Introduce device-managed SPI controller allocation
iommu/amd: Set DTE[IntTabLen] to represent 512 IRTEs
speakup: Reject setting the speakup line discipline outside of speakup
i2c: imx: Check for I2SR_IAL after every byte
i2c: imx: Fix reset of I2SR_IAL flag
mm/swapfile: do not sleep with a spin lock held
cifs: fix potential use-after-free in cifs_echo_request()
ftrace: Fix updating FTRACE_FL_TRAMP
ALSA: hda/generic: Add option to enforce preferred_dacs pairs
ALSA: hda/realtek - Add new codec supported for ALC897
tty: Fix ->session locking
tty: Fix ->pgrp locking in tiocspgrp()
USB: serial: option: fix Quectel BG96 matching
USB: serial: option: add support for Thales Cinterion EXS82
USB: serial: option: add Fibocom NL668 variants
USB: serial: ch341: sort device-id entries
USB: serial: ch341: add new Product ID for CH341A
USB: serial: kl5kusb105: fix memleak on open
usb: gadget: f_fs: Use local copy of descriptors for userspace copy
vlan: consolidate VLAN parsing code and limit max parsing depth
pinctrl: baytrail: Fix pin being driven low for a while on gpiod_get(..., GPIOD_OUT_HIGH)
pinctrl: baytrail: Replace WARN with dev_info_once when setting direct-irq pin to output
ANDROID: Incremental fs: Set credentials before reading/writing
ANDROID: Incremental fs: Fix incfs_test use of atol, open
ANDROID: Incremental fs: Change per UID timeouts to microseconds
ANDROID: Incremental fs: Add v2 feature flag
ANDROID: Incremental fs: Add zstd feature flag
Linux 4.14.211
RDMA/i40iw: Address an mmap handler exploit in i40iw
Input: i8042 - add ByteSpeed touchpad to noloop table
Input: xpad - support Ardwiino Controllers
ALSA: usb-audio: US16x08: fix value count for level meters
dt-bindings: net: correct interrupt flags in examples
net/mlx5: Fix wrong address reclaim when command interface is down
net: pasemi: fix error return code in pasemi_mac_open()
cxgb3: fix error return code in t3_sge_alloc_qset()
net/x25: prevent a couple of overflows
ibmvnic: Fix TX completion error handling
ibmvnic: Ensure that SCRQ entry reads are correctly ordered
ipv4: Fix tos mask in inet_rtm_getroute()
netfilter: bridge: reset skb->pkt_type after NF_INET_POST_ROUTING traversal
bonding: wait for sysfs kobject destruction before freeing struct slave
usbnet: ipheth: fix connectivity with iOS 14
tun: honor IOCB_NOWAIT flag
tcp: Set INET_ECN_xmit configuration in tcp_reinit_congestion_control
sock: set sk_err to ee_errno on dequeue from errq
rose: Fix Null pointer dereference in rose_send_frame()
net/af_iucv: set correct sk_protocol for child sockets
ANDROID: Incremental fs: Fix 32-bit build
UPSTREAM: arm64: sysreg: Clean up instructions for modifying PSTATE fields
[CP] CHROMIUM: drm/virtio: rebase zero-copy patches to virgl/drm-misc-next
Linux 4.14.210
USB: core: Fix regression in Hercules audio card
USB: core: add endpoint-blacklist quirk
x86/resctrl: Add necessary kernfs_put() calls to prevent refcount leak
x86/resctrl: Remove superfluous kernfs_get() calls to prevent refcount leak
x86/speculation: Fix prctl() when spectre_v2_user={seccomp,prctl},ibpb
usb: gadget: Fix memleak in gadgetfs_fill_super
usb: gadget: f_midi: Fix memleak in f_midi_alloc
USB: core: Change %pK for __user pointers to %px
perf probe: Fix to die_entrypc() returns error correctly
can: m_can: fix nominal bitiming tseg2 min for version >= 3.1
platform/x86: toshiba_acpi: Fix the wrong variable assignment
can: gs_usb: fix endianess problem with candleLight firmware
efivarfs: revert "fix memory leak in efivarfs_create()"
ibmvnic: fix NULL pointer dereference in ibmvic_reset_crq
ibmvnic: fix NULL pointer dereference in reset_sub_crq_queues
net: ena: set initial DMA width to avoid intel iommu issue
nfc: s3fwrn5: use signed integer for parsing GPIO numbers
IB/mthca: fix return value of error branch in mthca_init_cq()
bnxt_en: Release PCI regions when DMA mask setup fails during probe.
video: hyperv_fb: Fix the cache type when mapping the VRAM
bnxt_en: fix error return code in bnxt_init_board()
bnxt_en: fix error return code in bnxt_init_one()
scsi: ufs: Fix race between shutdown and runtime resume flow
batman-adv: set .owner to THIS_MODULE
phy: tegra: xusb: Fix dangling pointer on probe failure
perf/x86: fix sysfs type mismatches
scsi: target: iscsi: Fix cmd abort fabric stop race
scsi: libiscsi: Fix NOP race condition
dmaengine: pl330: _prep_dma_memcpy: Fix wrong burst size
nvme: free sq/cq dbbuf pointers when dbbuf set fails
proc: don't allow async path resolution of /proc/self components
HID: Add Logitech Dinovo Edge battery quirk
x86/xen: don't unbind uninitialized lock_kicker_irq
dmaengine: xilinx_dma: use readl_poll_timeout_atomic variant
HID: hid-sensor-hub: Fix issue with devices with no report ID
Input: i8042 - allow insmod to succeed on devices without an i8042 controller
HID: cypress: Support Varmilo Keyboards' media hotkeys
ALSA: hda/hdmi: fix incorrect locking in hdmi_pcm_close
ALSA: hda/hdmi: Use single mutex unlock in error paths
arm64: pgtable: Ensure dirty bit is preserved across pte_wrprotect()
arm64: pgtable: Fix pte_accessible()
btrfs: inode: Verify inode mode to avoid NULL pointer dereference
btrfs: adjust return values of btrfs_inode_by_name
btrfs: tree-checker: Enhance chunk checker to validate chunk profile
PCI: Add device even if driver attach failed
wireless: Use linux/stddef.h instead of stddef.h
btrfs: fix lockdep splat when reading qgroup config on mount
mm/userfaultfd: do not access vma->vm_mm after calling handle_userfault()
perf event: Check ref_reloc_sym before using it
Linux 4.14.209
x86/microcode/intel: Check patch signature before saving microcode for early loading
s390/dasd: fix null pointer dereference for ERP requests
s390/cpum_sf.c: fix file permission for cpum_sfb_size
mac80211: free sta in sta_info_insert_finish() on errors
mac80211: minstrel: fix tx status processing corner case
mac80211: minstrel: remove deferred sampling code
xtensa: disable preemption around cache alias management calls
regulator: workaround self-referent regulators
regulator: avoid resolve_supply() infinite recursion
regulator: fix memory leak with repeated set_machine_constraints()
iio: accel: kxcjk1013: Add support for KIOX010A ACPI DSM for setting tablet-mode
iio: accel: kxcjk1013: Replace is_smo8500_device with an acpi_type enum
ext4: fix bogus warning in ext4_update_dx_flag()
staging: rtl8723bs: Add 024c:0627 to the list of SDIO device-ids
efivarfs: fix memory leak in efivarfs_create()
tty: serial: imx: keep console clocks always on
ALSA: mixart: Fix mutex deadlock
ALSA: ctl: fix error path at adding user-defined element set
speakup: Do not let the line discipline be used several times
powerpc/uaccess-flush: fix missing includes in kup-radix.h
libfs: fix error cast of negative value in simple_attr_write()
xfs: revert "xfs: fix rmap key and record comparison functions"
regulator: ti-abb: Fix array out of bound read access on the first transition
MIPS: Alchemy: Fix memleak in alchemy_clk_setup_cpu
ASoC: qcom: lpass-platform: Fix memory leak
can: m_can: m_can_handle_state_change(): fix state change
can: peak_usb: fix potential integer overflow on shift of a int
can: mcba_usb: mcba_usb_start_xmit(): first fill skb, then pass to can_put_echo_skb()
can: ti_hecc: Fix memleak in ti_hecc_probe
can: dev: can_restart(): post buffer from the right context
can: af_can: prevent potential access of uninitialized member in canfd_rcv()
can: af_can: prevent potential access of uninitialized member in can_rcv()
perf lock: Don't free "lock_seq_stat" if read_count isn't zero
ARM: dts: imx50-evk: Fix the chip select 1 IOMUX
arm: dts: imx6qdl-udoo: fix rgmii phy-mode for ksz9031 phy
MIPS: export has_transparent_hugepage() for modules
Input: adxl34x - clean up a data type in adxl34x_probe()
vfs: remove lockdep bogosity in __sb_start_write
arm64: psci: Avoid printing in cpu_psci_cpu_die()
pinctrl: rockchip: enable gpio pclk for rockchip_gpio_to_irq
net: ftgmac100: Fix crash when removing driver
tcp: only postpone PROBE_RTT if RTT is < current min_rtt estimate
net: usb: qmi_wwan: Set DTR quirk for MR400
net/mlx5: Disable QoS when min_rates on all VFs are zero
sctp: change to hold/put transport for proto_unreach_timer
qlcnic: fix error return code in qlcnic_83xx_restart_hw()
net: x25: Increase refcnt of "struct x25_neigh" in x25_rx_call_request
net/mlx4_core: Fix init_hca fields offset
netlabel: fix an uninitialized warning in netlbl_unlabel_staticlist()
netlabel: fix our progress tracking in netlbl_unlabel_staticlist()
net: Have netpoll bring-up DSA management interface
net: dsa: mv88e6xxx: Avoid VTU corruption on 6097
net: bridge: add missing counters to ndo_get_stats64 callback
net: b44: fix error return code in b44_init_one()
mlxsw: core: Use variable timeout for EMAD retries
inet_diag: Fix error path to cancel the meseage in inet_req_diag_fill()
devlink: Add missing genlmsg_cancel() in devlink_nl_sb_port_pool_fill()
bnxt_en: read EEPROM A2h address using page 0
atm: nicstar: Unmap DMA on send error
ah6: fix error return code in ah6_input()
ANDROID: Fix cuttlefish defconfigs now incfs uses zstd
ANDROID: Incremental fs: Add zstd compression support
ANDROID: Incremental fs: Small improvements
ANDROID: Incremental fs: Initialize mount options correctly
ANDROID: Incremental fs: Fix read_log_test which failed sporadically
ANDROID: Incremental fs: Fix misuse of cpu_to_leXX and poll return
ANDROID: Incremental fs: Add per UID read timeouts
ANDROID: Incremental fs: Add .incomplete folder
ANDROID: Incremental fs: Fix dangling else
ANDROID: Incremental fs: Fix uninitialized variable
ANDROID: Incremental fs: Fix filled block count from get filled blocks
ANDROID: Incremental fs: Add hash block counts to IOC_IOCTL_GET_BLOCK_COUNT
ANDROID: Incremental fs: Add INCFS_IOC_GET_BLOCK_COUNT
ANDROID: Incremental fs: Make compatible with existing files
ANDROID: Incremental fs: Remove block HASH flag
ANDROID: Incremental fs: Remove back links and crcs
ANDROID: Incremental fs: Remove attributes from file
ANDROID: Incremental fs: Add .blocks_written file
ANDROID: Incremental fs: Separate pseudo-file code
ANDROID: Incremental fs: Add UID to pending_read
ANDROID: Incremental fs: Create mapped file
ANDROID: Incremental fs: Don't allow renaming .index directory.
ANDROID: Incremental fs: Fix incfs to work on virtio-9p
ANDROID: Incremental fs: Allow running a single test
ANDROID: Incremental fs: Adding perf test
ANDROID: Incremental fs: Stress tool
ANDROID: Incremental fs: Use R/W locks to read/write segment blockmap.
ANDROID: Incremental fs: Remove unnecessary dependencies
ANDROID: Incremental fs: Remove annoying pr_debugs
ANDROID: Incremental fs: dentry_revalidate should not return -EBADF.
ANDROID: Incremental fs: Fix minor bugs
ANDROID: Incremental fs: RCU locks instead of mutex for pending_reads.
ANDROID: Incremental fs: fix up attempt to copy structures with READ/WRITE_ONCE
Linux 4.14.208
ACPI: GED: fix -Wformat
KVM: x86: clflushopt should be treated as a no-op by emulation
can: proc: can_remove_proc(): silence remove_proc_entry warning
mac80211: always wind down STA state
Input: sunkbd - avoid use-after-free in teardown paths
powerpc/8xx: Always fault when _PAGE_ACCESSED is not set
gpio: mockup: fix resource leak in error path
i2c: imx: Fix external abort on interrupt in exit paths
i2c: imx: use clk notifier for rate changes
powerpc/64s: flush L1D after user accesses
powerpc/uaccess: Evaluate macro arguments once, before user access is allowed
powerpc: Fix __clear_user() with KUAP enabled
powerpc: Implement user_access_begin and friends
powerpc: Add a framework for user access tracking
powerpc/64s: flush L1D on kernel entry
powerpc/64s: move some exception handlers out of line
powerpc/64s: Define MASKABLE_RELON_EXCEPTION_PSERIES_OOL
Linux 4.14.207
mm: fix exec activate_mm vs TLB shootdown and lazy tlb switching race
Convert trailing spaces and periods in path components
reboot: fix overflow parsing reboot cpu number
Revert "kernel/reboot.c: convert simple_strtoul to kstrtoint"
perf/core: Fix race in the perf_mmap_close() function
xen/events: block rogue events for some time
xen/events: defer eoi in case of excessive number of events
xen/events: use a common cpu hotplug hook for event channels
xen/events: switch user event channels to lateeoi model
xen/pciback: use lateeoi irq binding
xen/pvcallsback: use lateeoi irq binding
xen/scsiback: use lateeoi irq binding
xen/netback: use lateeoi irq binding
xen/blkback: use lateeoi irq binding
xen/events: add a new "late EOI" evtchn framework
xen/events: fix race in evtchn_fifo_unmask()
xen/events: add a proper barrier to 2-level uevent unmasking
xen/events: avoid removing an event channel while handling it
perf/core: Fix a memory leak in perf_event_parse_addr_filter()
perf/core: Fix crash when using HW tracing kernel filters
perf/core: Fix bad use of igrab()
x86/speculation: Allow IBPB to be conditionally enabled on CPUs with always-on STIBP
random32: make prandom_u32() output unpredictable
net: Update window_clamp if SOCK_RCVBUF is set
r8169: fix potential skb double free in an error path
vrf: Fix fast path output packet handling with async Netfilter rules
net/x25: Fix null-ptr-deref in x25_connect
net/af_iucv: fix null pointer dereference on shutdown
IPv6: Set SIT tunnel hard_header_len to zero
swiotlb: fix "x86: Don't panic if can not alloc buffer for swiotlb"
pinctrl: amd: fix incorrect way to disable debounce filter
pinctrl: amd: use higher precision for 512 RtcClk
drm/gma500: Fix out-of-bounds access to struct drm_device.vblank[]
don't dump the threads that had been already exiting when zapped.
selinux: Fix error return code in sel_ib_pkey_sid_slow()
ocfs2: initialize ip_next_orphan
futex: Don't enable IRQs unconditionally in put_pi_state()
mei: protect mei_cl_mtu from null dereference
usb: cdc-acm: Add DISABLE_ECHO for Renesas USB Download mode
uio: Fix use-after-free in uio_unregister_device()
thunderbolt: Add the missed ida_simple_remove() in ring_request_msix()
ext4: unlock xattr_sem properly in ext4_inline_data_truncate()
ext4: correctly report "not supported" for {usr,grp}jquota when !CONFIG_QUOTA
perf: Fix get_recursion_context()
cosa: Add missing kfree in error path of cosa_write
of/address: Fix of_node memory leak in of_dma_is_coherent
xfs: fix a missing unlock on error in xfs_fs_map_blocks
xfs: fix rmap key and record comparison functions
xfs: fix flags argument to rmap lookup when converting shared file rmaps
nbd: fix a block_device refcount leak in nbd_release
pinctrl: aspeed: Fix GPI only function problem.
ARM: 9019/1: kprobes: Avoid fortify_panic() when copying optprobe template
pinctrl: intel: Set default bias in case no particular value given
iommu/amd: Increase interrupt remapping table limit to 512 entries
scsi: scsi_dh_alua: Avoid crash during alua_bus_detach()
cfg80211: regulatory: Fix inconsistent format argument
mac80211: fix use of skb payload instead of header
drm/amdgpu: perform srbm soft reset always on SDMA resume
scsi: hpsa: Fix memory leak in hpsa_init_one()
gfs2: check for live vs. read-only file system in gfs2_fitrim
gfs2: Add missing truncate_inode_pages_final for sd_aspace
gfs2: Free rd_bits later in gfs2_clear_rgrpd to fix use-after-free
usb: gadget: goku_udc: fix potential crashes in probe
ath9k_htc: Use appropriate rs_datalen type
Btrfs: fix missing error return if writeback for extent buffer never started
xfs: flush new eof page on truncate to avoid post-eof corruption
can: peak_canfd: pucan_handle_can_rx(): fix echo management when loopback is on
can: peak_usb: peak_usb_get_ts_time(): fix timestamp wrapping
can: peak_usb: add range checking in decode operations
can: can_create_echo_skb(): fix echo skb generation: always use skb_clone()
can: dev: __can_get_echo_skb(): fix real payload length return value for RTR frames
can: dev: can_get_echo_skb(): prevent call to kfree_skb() in hard IRQ context
can: rx-offload: don't call kfree_skb() from IRQ context
ALSA: hda: prevent undefined shift in snd_hdac_ext_bus_get_link()
perf tools: Add missing swap for ino_generation
net: xfrm: fix a race condition during allocing spi
hv_balloon: disable warning when floor reached
genirq: Let GENERIC_IRQ_IPI select IRQ_DOMAIN_HIERARCHY
btrfs: reschedule when cloning lots of extents
btrfs: sysfs: init devices outside of the chunk_mutex
nbd: don't update block size after device is started
time: Prevent undefined behaviour in timespec64_to_ns()
mm: mempolicy: fix potential pte_unmap_unlock pte error
ring-buffer: Fix recursion protection transitions between interrupt context
regulator: defer probe when trying to get voltage from unresolved supply
UPSTREAM: sched: idle: Avoid retaining the tick when it has been stopped
UPSTREAM: cpuidle: menu: Handle stopped tick more aggressively
UPSTREAM: staging: android: vsoc: fix copy_from_user overrun
UPSTREAM: ipv6: ndisc: RFC-ietf-6man-ra-pref64-09 is now published as RFC8781
BACKPORT: drm/virtio: fix missing dma_fence_put() in virtio_gpu_execbuffer_ioctl()
Conflicts:
drivers/scsi/ufs/ufshcd.c
drivers/soc/qcom/smp2p.c
drivers/usb/gadget/function/f_accessory.c
drivers/usb/gadget/function/f_fs.c
drivers/usb/gadget/function/f_uac2.c
Change-Id: I7ec83fef94dcc943abd858eb81e4a78983faae8c
2028 lines
58 KiB
C
2028 lines
58 KiB
C
/*
|
|
* linux/kernel/timer.c
|
|
*
|
|
* Kernel internal timers
|
|
*
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
*
|
|
* 1997-01-28 Modified by Finn Arne Gangstad to make timers scale better.
|
|
*
|
|
* 1997-09-10 Updated NTP code according to technical memorandum Jan '96
|
|
* "A Kernel Model for Precision Timekeeping" by Dave Mills
|
|
* 1998-12-24 Fixed a xtime SMP race (we need the xtime_lock rw spinlock to
|
|
* serialize accesses to xtime/lost_ticks).
|
|
* Copyright (C) 1998 Andrea Arcangeli
|
|
* 1999-03-10 Improved NTP compatibility by Ulrich Windl
|
|
* 2002-05-31 Move sys_sysinfo here and make its locking sane, Robert Love
|
|
* 2000-10-05 Implemented scalable SMP per-CPU timer handling.
|
|
* Copyright (C) 2000, 2001, 2002 Ingo Molnar
|
|
* Designed by David S. Miller, Alexey Kuznetsov and Ingo Molnar
|
|
*/
|
|
|
|
#include <linux/kernel_stat.h>
|
|
#include <linux/export.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/percpu.h>
|
|
#include <linux/init.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/swap.h>
|
|
#include <linux/pid_namespace.h>
|
|
#include <linux/notifier.h>
|
|
#include <linux/thread_info.h>
|
|
#include <linux/time.h>
|
|
#include <linux/jiffies.h>
|
|
#include <linux/posix-timers.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/tick.h>
|
|
#include <linux/kallsyms.h>
|
|
#include <linux/irq_work.h>
|
|
#include <linux/sched/signal.h>
|
|
#include <linux/sched/sysctl.h>
|
|
#include <linux/sched/nohz.h>
|
|
#include <linux/sched/debug.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/compat.h>
|
|
#include <linux/random.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
#include <asm/unistd.h>
|
|
#include <asm/div64.h>
|
|
#include <asm/timex.h>
|
|
#include <asm/io.h>
|
|
|
|
#include "tick-internal.h"
|
|
|
|
#define CREATE_TRACE_POINTS
|
|
#include <trace/events/timer.h>
|
|
|
|
__visible u64 jiffies_64 __cacheline_aligned_in_smp = INITIAL_JIFFIES;
|
|
|
|
EXPORT_SYMBOL(jiffies_64);
|
|
|
|
/*
|
|
* The timer wheel has LVL_DEPTH array levels. Each level provides an array of
|
|
* LVL_SIZE buckets. Each level is driven by its own clock and therefor each
|
|
* level has a different granularity.
|
|
*
|
|
* The level granularity is: LVL_CLK_DIV ^ lvl
|
|
* The level clock frequency is: HZ / (LVL_CLK_DIV ^ level)
|
|
*
|
|
* The array level of a newly armed timer depends on the relative expiry
|
|
* time. The farther the expiry time is away the higher the array level and
|
|
* therefor the granularity becomes.
|
|
*
|
|
* Contrary to the original timer wheel implementation, which aims for 'exact'
|
|
* expiry of the timers, this implementation removes the need for recascading
|
|
* the timers into the lower array levels. The previous 'classic' timer wheel
|
|
* implementation of the kernel already violated the 'exact' expiry by adding
|
|
* slack to the expiry time to provide batched expiration. The granularity
|
|
* levels provide implicit batching.
|
|
*
|
|
* This is an optimization of the original timer wheel implementation for the
|
|
* majority of the timer wheel use cases: timeouts. The vast majority of
|
|
* timeout timers (networking, disk I/O ...) are canceled before expiry. If
|
|
* the timeout expires it indicates that normal operation is disturbed, so it
|
|
* does not matter much whether the timeout comes with a slight delay.
|
|
*
|
|
* The only exception to this are networking timers with a small expiry
|
|
* time. They rely on the granularity. Those fit into the first wheel level,
|
|
* which has HZ granularity.
|
|
*
|
|
* We don't have cascading anymore. timers with a expiry time above the
|
|
* capacity of the last wheel level are force expired at the maximum timeout
|
|
* value of the last wheel level. From data sampling we know that the maximum
|
|
* value observed is 5 days (network connection tracking), so this should not
|
|
* be an issue.
|
|
*
|
|
* The currently chosen array constants values are a good compromise between
|
|
* array size and granularity.
|
|
*
|
|
* This results in the following granularity and range levels:
|
|
*
|
|
* HZ 1000 steps
|
|
* Level Offset Granularity Range
|
|
* 0 0 1 ms 0 ms - 63 ms
|
|
* 1 64 8 ms 64 ms - 511 ms
|
|
* 2 128 64 ms 512 ms - 4095 ms (512ms - ~4s)
|
|
* 3 192 512 ms 4096 ms - 32767 ms (~4s - ~32s)
|
|
* 4 256 4096 ms (~4s) 32768 ms - 262143 ms (~32s - ~4m)
|
|
* 5 320 32768 ms (~32s) 262144 ms - 2097151 ms (~4m - ~34m)
|
|
* 6 384 262144 ms (~4m) 2097152 ms - 16777215 ms (~34m - ~4h)
|
|
* 7 448 2097152 ms (~34m) 16777216 ms - 134217727 ms (~4h - ~1d)
|
|
* 8 512 16777216 ms (~4h) 134217728 ms - 1073741822 ms (~1d - ~12d)
|
|
*
|
|
* HZ 300
|
|
* Level Offset Granularity Range
|
|
* 0 0 3 ms 0 ms - 210 ms
|
|
* 1 64 26 ms 213 ms - 1703 ms (213ms - ~1s)
|
|
* 2 128 213 ms 1706 ms - 13650 ms (~1s - ~13s)
|
|
* 3 192 1706 ms (~1s) 13653 ms - 109223 ms (~13s - ~1m)
|
|
* 4 256 13653 ms (~13s) 109226 ms - 873810 ms (~1m - ~14m)
|
|
* 5 320 109226 ms (~1m) 873813 ms - 6990503 ms (~14m - ~1h)
|
|
* 6 384 873813 ms (~14m) 6990506 ms - 55924050 ms (~1h - ~15h)
|
|
* 7 448 6990506 ms (~1h) 55924053 ms - 447392423 ms (~15h - ~5d)
|
|
* 8 512 55924053 ms (~15h) 447392426 ms - 3579139406 ms (~5d - ~41d)
|
|
*
|
|
* HZ 250
|
|
* Level Offset Granularity Range
|
|
* 0 0 4 ms 0 ms - 255 ms
|
|
* 1 64 32 ms 256 ms - 2047 ms (256ms - ~2s)
|
|
* 2 128 256 ms 2048 ms - 16383 ms (~2s - ~16s)
|
|
* 3 192 2048 ms (~2s) 16384 ms - 131071 ms (~16s - ~2m)
|
|
* 4 256 16384 ms (~16s) 131072 ms - 1048575 ms (~2m - ~17m)
|
|
* 5 320 131072 ms (~2m) 1048576 ms - 8388607 ms (~17m - ~2h)
|
|
* 6 384 1048576 ms (~17m) 8388608 ms - 67108863 ms (~2h - ~18h)
|
|
* 7 448 8388608 ms (~2h) 67108864 ms - 536870911 ms (~18h - ~6d)
|
|
* 8 512 67108864 ms (~18h) 536870912 ms - 4294967288 ms (~6d - ~49d)
|
|
*
|
|
* HZ 100
|
|
* Level Offset Granularity Range
|
|
* 0 0 10 ms 0 ms - 630 ms
|
|
* 1 64 80 ms 640 ms - 5110 ms (640ms - ~5s)
|
|
* 2 128 640 ms 5120 ms - 40950 ms (~5s - ~40s)
|
|
* 3 192 5120 ms (~5s) 40960 ms - 327670 ms (~40s - ~5m)
|
|
* 4 256 40960 ms (~40s) 327680 ms - 2621430 ms (~5m - ~43m)
|
|
* 5 320 327680 ms (~5m) 2621440 ms - 20971510 ms (~43m - ~5h)
|
|
* 6 384 2621440 ms (~43m) 20971520 ms - 167772150 ms (~5h - ~1d)
|
|
* 7 448 20971520 ms (~5h) 167772160 ms - 1342177270 ms (~1d - ~15d)
|
|
*/
|
|
|
|
/* Clock divisor for the next level */
|
|
#define LVL_CLK_SHIFT 3
|
|
#define LVL_CLK_DIV (1UL << LVL_CLK_SHIFT)
|
|
#define LVL_CLK_MASK (LVL_CLK_DIV - 1)
|
|
#define LVL_SHIFT(n) ((n) * LVL_CLK_SHIFT)
|
|
#define LVL_GRAN(n) (1UL << LVL_SHIFT(n))
|
|
|
|
/*
|
|
* The time start value for each level to select the bucket at enqueue
|
|
* time.
|
|
*/
|
|
#define LVL_START(n) ((LVL_SIZE - 1) << (((n) - 1) * LVL_CLK_SHIFT))
|
|
|
|
/* Size of each clock level */
|
|
#define LVL_BITS 6
|
|
#define LVL_SIZE (1UL << LVL_BITS)
|
|
#define LVL_MASK (LVL_SIZE - 1)
|
|
#define LVL_OFFS(n) ((n) * LVL_SIZE)
|
|
|
|
/* Level depth */
|
|
#if HZ > 100
|
|
# define LVL_DEPTH 9
|
|
# else
|
|
# define LVL_DEPTH 8
|
|
#endif
|
|
|
|
/* The cutoff (max. capacity of the wheel) */
|
|
#define WHEEL_TIMEOUT_CUTOFF (LVL_START(LVL_DEPTH))
|
|
#define WHEEL_TIMEOUT_MAX (WHEEL_TIMEOUT_CUTOFF - LVL_GRAN(LVL_DEPTH - 1))
|
|
|
|
/*
|
|
* The resulting wheel size. If NOHZ is configured we allocate two
|
|
* wheels so we have a separate storage for the deferrable timers.
|
|
*/
|
|
#define WHEEL_SIZE (LVL_SIZE * LVL_DEPTH)
|
|
|
|
#ifdef CONFIG_NO_HZ_COMMON
|
|
# define NR_BASES 2
|
|
# define BASE_STD 0
|
|
# define BASE_DEF 1
|
|
#else
|
|
# define NR_BASES 1
|
|
# define BASE_STD 0
|
|
# define BASE_DEF 0
|
|
#endif
|
|
|
|
struct timer_base {
|
|
raw_spinlock_t lock;
|
|
struct timer_list *running_timer;
|
|
unsigned long clk;
|
|
unsigned long next_expiry;
|
|
unsigned int cpu;
|
|
bool migration_enabled;
|
|
bool nohz_active;
|
|
bool is_idle;
|
|
bool must_forward_clk;
|
|
DECLARE_BITMAP(pending_map, WHEEL_SIZE);
|
|
struct hlist_head vectors[WHEEL_SIZE];
|
|
} ____cacheline_aligned;
|
|
|
|
static DEFINE_PER_CPU(struct timer_base, timer_bases[NR_BASES]);
|
|
struct timer_base timer_base_deferrable;
|
|
static atomic_t deferrable_pending;
|
|
|
|
#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
|
|
unsigned int sysctl_timer_migration = 1;
|
|
|
|
void timers_update_migration(bool update_nohz)
|
|
{
|
|
bool on = sysctl_timer_migration && tick_nohz_active;
|
|
unsigned int cpu;
|
|
|
|
/* Avoid the loop, if nothing to update */
|
|
if (this_cpu_read(timer_bases[BASE_STD].migration_enabled) == on)
|
|
return;
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
per_cpu(timer_bases[BASE_STD].migration_enabled, cpu) = on;
|
|
per_cpu(timer_bases[BASE_DEF].migration_enabled, cpu) = on;
|
|
per_cpu(hrtimer_bases.migration_enabled, cpu) = on;
|
|
if (!update_nohz)
|
|
continue;
|
|
per_cpu(timer_bases[BASE_STD].nohz_active, cpu) = true;
|
|
per_cpu(timer_bases[BASE_DEF].nohz_active, cpu) = true;
|
|
per_cpu(hrtimer_bases.nohz_active, cpu) = true;
|
|
}
|
|
|
|
timer_base_deferrable.migration_enabled = on;
|
|
timer_base_deferrable.nohz_active = true;
|
|
}
|
|
|
|
int timer_migration_handler(struct ctl_table *table, int write,
|
|
void __user *buffer, size_t *lenp,
|
|
loff_t *ppos)
|
|
{
|
|
static DEFINE_MUTEX(mutex);
|
|
int ret;
|
|
|
|
mutex_lock(&mutex);
|
|
ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
|
|
if (!ret && write)
|
|
timers_update_migration(false);
|
|
mutex_unlock(&mutex);
|
|
return ret;
|
|
}
|
|
#endif
|
|
|
|
static unsigned long round_jiffies_common(unsigned long j, int cpu,
|
|
bool force_up)
|
|
{
|
|
int rem;
|
|
unsigned long original = j;
|
|
|
|
/*
|
|
* We don't want all cpus firing their timers at once hitting the
|
|
* same lock or cachelines, so we skew each extra cpu with an extra
|
|
* 3 jiffies. This 3 jiffies came originally from the mm/ code which
|
|
* already did this.
|
|
* The skew is done by adding 3*cpunr, then round, then subtract this
|
|
* extra offset again.
|
|
*/
|
|
j += cpu * 3;
|
|
|
|
rem = j % HZ;
|
|
|
|
/*
|
|
* If the target jiffie is just after a whole second (which can happen
|
|
* due to delays of the timer irq, long irq off times etc etc) then
|
|
* we should round down to the whole second, not up. Use 1/4th second
|
|
* as cutoff for this rounding as an extreme upper bound for this.
|
|
* But never round down if @force_up is set.
|
|
*/
|
|
if (rem < HZ/4 && !force_up) /* round down */
|
|
j = j - rem;
|
|
else /* round up */
|
|
j = j - rem + HZ;
|
|
|
|
/* now that we have rounded, subtract the extra skew again */
|
|
j -= cpu * 3;
|
|
|
|
/*
|
|
* Make sure j is still in the future. Otherwise return the
|
|
* unmodified value.
|
|
*/
|
|
return time_is_after_jiffies(j) ? j : original;
|
|
}
|
|
|
|
/**
|
|
* __round_jiffies - function to round jiffies to a full second
|
|
* @j: the time in (absolute) jiffies that should be rounded
|
|
* @cpu: the processor number on which the timeout will happen
|
|
*
|
|
* __round_jiffies() rounds an absolute time in the future (in jiffies)
|
|
* up or down to (approximately) full seconds. This is useful for timers
|
|
* for which the exact time they fire does not matter too much, as long as
|
|
* they fire approximately every X seconds.
|
|
*
|
|
* By rounding these timers to whole seconds, all such timers will fire
|
|
* at the same time, rather than at various times spread out. The goal
|
|
* of this is to have the CPU wake up less, which saves power.
|
|
*
|
|
* The exact rounding is skewed for each processor to avoid all
|
|
* processors firing at the exact same time, which could lead
|
|
* to lock contention or spurious cache line bouncing.
|
|
*
|
|
* The return value is the rounded version of the @j parameter.
|
|
*/
|
|
unsigned long __round_jiffies(unsigned long j, int cpu)
|
|
{
|
|
return round_jiffies_common(j, cpu, false);
|
|
}
|
|
EXPORT_SYMBOL_GPL(__round_jiffies);
|
|
|
|
/**
|
|
* __round_jiffies_relative - function to round jiffies to a full second
|
|
* @j: the time in (relative) jiffies that should be rounded
|
|
* @cpu: the processor number on which the timeout will happen
|
|
*
|
|
* __round_jiffies_relative() rounds a time delta in the future (in jiffies)
|
|
* up or down to (approximately) full seconds. This is useful for timers
|
|
* for which the exact time they fire does not matter too much, as long as
|
|
* they fire approximately every X seconds.
|
|
*
|
|
* By rounding these timers to whole seconds, all such timers will fire
|
|
* at the same time, rather than at various times spread out. The goal
|
|
* of this is to have the CPU wake up less, which saves power.
|
|
*
|
|
* The exact rounding is skewed for each processor to avoid all
|
|
* processors firing at the exact same time, which could lead
|
|
* to lock contention or spurious cache line bouncing.
|
|
*
|
|
* The return value is the rounded version of the @j parameter.
|
|
*/
|
|
unsigned long __round_jiffies_relative(unsigned long j, int cpu)
|
|
{
|
|
unsigned long j0 = jiffies;
|
|
|
|
/* Use j0 because jiffies might change while we run */
|
|
return round_jiffies_common(j + j0, cpu, false) - j0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(__round_jiffies_relative);
|
|
|
|
/**
|
|
* round_jiffies - function to round jiffies to a full second
|
|
* @j: the time in (absolute) jiffies that should be rounded
|
|
*
|
|
* round_jiffies() rounds an absolute time in the future (in jiffies)
|
|
* up or down to (approximately) full seconds. This is useful for timers
|
|
* for which the exact time they fire does not matter too much, as long as
|
|
* they fire approximately every X seconds.
|
|
*
|
|
* By rounding these timers to whole seconds, all such timers will fire
|
|
* at the same time, rather than at various times spread out. The goal
|
|
* of this is to have the CPU wake up less, which saves power.
|
|
*
|
|
* The return value is the rounded version of the @j parameter.
|
|
*/
|
|
unsigned long round_jiffies(unsigned long j)
|
|
{
|
|
return round_jiffies_common(j, raw_smp_processor_id(), false);
|
|
}
|
|
EXPORT_SYMBOL_GPL(round_jiffies);
|
|
|
|
/**
|
|
* round_jiffies_relative - function to round jiffies to a full second
|
|
* @j: the time in (relative) jiffies that should be rounded
|
|
*
|
|
* round_jiffies_relative() rounds a time delta in the future (in jiffies)
|
|
* up or down to (approximately) full seconds. This is useful for timers
|
|
* for which the exact time they fire does not matter too much, as long as
|
|
* they fire approximately every X seconds.
|
|
*
|
|
* By rounding these timers to whole seconds, all such timers will fire
|
|
* at the same time, rather than at various times spread out. The goal
|
|
* of this is to have the CPU wake up less, which saves power.
|
|
*
|
|
* The return value is the rounded version of the @j parameter.
|
|
*/
|
|
unsigned long round_jiffies_relative(unsigned long j)
|
|
{
|
|
return __round_jiffies_relative(j, raw_smp_processor_id());
|
|
}
|
|
EXPORT_SYMBOL_GPL(round_jiffies_relative);
|
|
|
|
/**
|
|
* __round_jiffies_up - function to round jiffies up to a full second
|
|
* @j: the time in (absolute) jiffies that should be rounded
|
|
* @cpu: the processor number on which the timeout will happen
|
|
*
|
|
* This is the same as __round_jiffies() except that it will never
|
|
* round down. This is useful for timeouts for which the exact time
|
|
* of firing does not matter too much, as long as they don't fire too
|
|
* early.
|
|
*/
|
|
unsigned long __round_jiffies_up(unsigned long j, int cpu)
|
|
{
|
|
return round_jiffies_common(j, cpu, true);
|
|
}
|
|
EXPORT_SYMBOL_GPL(__round_jiffies_up);
|
|
|
|
/**
|
|
* __round_jiffies_up_relative - function to round jiffies up to a full second
|
|
* @j: the time in (relative) jiffies that should be rounded
|
|
* @cpu: the processor number on which the timeout will happen
|
|
*
|
|
* This is the same as __round_jiffies_relative() except that it will never
|
|
* round down. This is useful for timeouts for which the exact time
|
|
* of firing does not matter too much, as long as they don't fire too
|
|
* early.
|
|
*/
|
|
unsigned long __round_jiffies_up_relative(unsigned long j, int cpu)
|
|
{
|
|
unsigned long j0 = jiffies;
|
|
|
|
/* Use j0 because jiffies might change while we run */
|
|
return round_jiffies_common(j + j0, cpu, true) - j0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(__round_jiffies_up_relative);
|
|
|
|
/**
|
|
* round_jiffies_up - function to round jiffies up to a full second
|
|
* @j: the time in (absolute) jiffies that should be rounded
|
|
*
|
|
* This is the same as round_jiffies() except that it will never
|
|
* round down. This is useful for timeouts for which the exact time
|
|
* of firing does not matter too much, as long as they don't fire too
|
|
* early.
|
|
*/
|
|
unsigned long round_jiffies_up(unsigned long j)
|
|
{
|
|
return round_jiffies_common(j, raw_smp_processor_id(), true);
|
|
}
|
|
EXPORT_SYMBOL_GPL(round_jiffies_up);
|
|
|
|
/**
|
|
* round_jiffies_up_relative - function to round jiffies up to a full second
|
|
* @j: the time in (relative) jiffies that should be rounded
|
|
*
|
|
* This is the same as round_jiffies_relative() except that it will never
|
|
* round down. This is useful for timeouts for which the exact time
|
|
* of firing does not matter too much, as long as they don't fire too
|
|
* early.
|
|
*/
|
|
unsigned long round_jiffies_up_relative(unsigned long j)
|
|
{
|
|
return __round_jiffies_up_relative(j, raw_smp_processor_id());
|
|
}
|
|
EXPORT_SYMBOL_GPL(round_jiffies_up_relative);
|
|
|
|
|
|
static inline unsigned int timer_get_idx(struct timer_list *timer)
|
|
{
|
|
return (timer->flags & TIMER_ARRAYMASK) >> TIMER_ARRAYSHIFT;
|
|
}
|
|
|
|
static inline void timer_set_idx(struct timer_list *timer, unsigned int idx)
|
|
{
|
|
timer->flags = (timer->flags & ~TIMER_ARRAYMASK) |
|
|
idx << TIMER_ARRAYSHIFT;
|
|
}
|
|
|
|
/*
|
|
* Helper function to calculate the array index for a given expiry
|
|
* time.
|
|
*/
|
|
static inline unsigned calc_index(unsigned expires, unsigned lvl)
|
|
{
|
|
if (expires & ~(UINT_MAX << LVL_SHIFT(lvl)))
|
|
expires = (expires + LVL_GRAN(lvl)) >> LVL_SHIFT(lvl);
|
|
else
|
|
expires = expires >> LVL_SHIFT(lvl);
|
|
|
|
return LVL_OFFS(lvl) + (expires & LVL_MASK);
|
|
}
|
|
|
|
static inline unsigned int calc_index_min_granularity(unsigned int expires)
|
|
{
|
|
return LVL_OFFS(0) + ((expires >> LVL_SHIFT(0)) & LVL_MASK);
|
|
}
|
|
|
|
static int calc_wheel_index(unsigned long expires, unsigned long clk)
|
|
{
|
|
unsigned long delta = expires - clk;
|
|
unsigned int idx;
|
|
|
|
if (delta < LVL_START(1)) {
|
|
idx = calc_index_min_granularity(expires);
|
|
} else if (delta < LVL_START(2)) {
|
|
idx = calc_index(expires, 1);
|
|
} else if (delta < LVL_START(3)) {
|
|
idx = calc_index(expires, 2);
|
|
} else if (delta < LVL_START(4)) {
|
|
idx = calc_index(expires, 3);
|
|
} else if (delta < LVL_START(5)) {
|
|
idx = calc_index(expires, 4);
|
|
} else if (delta < LVL_START(6)) {
|
|
idx = calc_index(expires, 5);
|
|
} else if (delta < LVL_START(7)) {
|
|
idx = calc_index(expires, 6);
|
|
} else if (LVL_DEPTH > 8 && delta < LVL_START(8)) {
|
|
idx = calc_index(expires, 7);
|
|
} else if ((long) delta < 0) {
|
|
idx = clk & LVL_MASK;
|
|
} else {
|
|
/*
|
|
* Force expire obscene large timeouts to expire at the
|
|
* capacity limit of the wheel.
|
|
*/
|
|
if (delta >= WHEEL_TIMEOUT_CUTOFF)
|
|
expires = clk + WHEEL_TIMEOUT_MAX;
|
|
|
|
idx = calc_index(expires, LVL_DEPTH - 1);
|
|
}
|
|
return idx;
|
|
}
|
|
|
|
/*
|
|
* Enqueue the timer into the hash bucket, mark it pending in
|
|
* the bitmap and store the index in the timer flags.
|
|
*/
|
|
static void enqueue_timer(struct timer_base *base, struct timer_list *timer,
|
|
unsigned int idx)
|
|
{
|
|
hlist_add_head(&timer->entry, base->vectors + idx);
|
|
__set_bit(idx, base->pending_map);
|
|
timer_set_idx(timer, idx);
|
|
}
|
|
|
|
static void
|
|
__internal_add_timer(struct timer_base *base, struct timer_list *timer)
|
|
{
|
|
unsigned int idx;
|
|
|
|
idx = calc_wheel_index(timer->expires, base->clk);
|
|
enqueue_timer(base, timer, idx);
|
|
}
|
|
|
|
static void
|
|
trigger_dyntick_cpu(struct timer_base *base, struct timer_list *timer)
|
|
{
|
|
if (!IS_ENABLED(CONFIG_NO_HZ_COMMON) || !base->nohz_active)
|
|
return;
|
|
|
|
/*
|
|
* TODO: This wants some optimizing similar to the code below, but we
|
|
* will do that when we switch from push to pull for deferrable timers.
|
|
*/
|
|
if (timer->flags & TIMER_DEFERRABLE) {
|
|
if (tick_nohz_full_cpu(base->cpu))
|
|
wake_up_nohz_cpu(base->cpu);
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* We might have to IPI the remote CPU if the base is idle and the
|
|
* timer is not deferrable. If the other CPU is on the way to idle
|
|
* then it can't set base->is_idle as we hold the base lock:
|
|
*/
|
|
if (!base->is_idle)
|
|
return;
|
|
|
|
/* Check whether this is the new first expiring timer: */
|
|
if (time_after_eq(timer->expires, base->next_expiry))
|
|
return;
|
|
|
|
/*
|
|
* Set the next expiry time and kick the CPU so it can reevaluate the
|
|
* wheel:
|
|
*/
|
|
base->next_expiry = timer->expires;
|
|
wake_up_nohz_cpu(base->cpu);
|
|
}
|
|
|
|
static void
|
|
internal_add_timer(struct timer_base *base, struct timer_list *timer)
|
|
{
|
|
__internal_add_timer(base, timer);
|
|
trigger_dyntick_cpu(base, timer);
|
|
}
|
|
|
|
#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
|
|
|
|
static struct debug_obj_descr timer_debug_descr;
|
|
|
|
static void *timer_debug_hint(void *addr)
|
|
{
|
|
return ((struct timer_list *) addr)->function;
|
|
}
|
|
|
|
static bool timer_is_static_object(void *addr)
|
|
{
|
|
struct timer_list *timer = addr;
|
|
|
|
return (timer->entry.pprev == NULL &&
|
|
timer->entry.next == TIMER_ENTRY_STATIC);
|
|
}
|
|
|
|
/*
|
|
* fixup_init is called when:
|
|
* - an active object is initialized
|
|
*/
|
|
static bool timer_fixup_init(void *addr, enum debug_obj_state state)
|
|
{
|
|
struct timer_list *timer = addr;
|
|
|
|
switch (state) {
|
|
case ODEBUG_STATE_ACTIVE:
|
|
del_timer_sync(timer);
|
|
debug_object_init(timer, &timer_debug_descr);
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/* Stub timer callback for improperly used timers. */
|
|
static void stub_timer(unsigned long data)
|
|
{
|
|
WARN_ON(1);
|
|
}
|
|
|
|
/*
|
|
* fixup_activate is called when:
|
|
* - an active object is activated
|
|
* - an unknown non-static object is activated
|
|
*/
|
|
static bool timer_fixup_activate(void *addr, enum debug_obj_state state)
|
|
{
|
|
struct timer_list *timer = addr;
|
|
|
|
switch (state) {
|
|
case ODEBUG_STATE_NOTAVAILABLE:
|
|
setup_timer(timer, stub_timer, 0);
|
|
return true;
|
|
|
|
case ODEBUG_STATE_ACTIVE:
|
|
WARN_ON(1);
|
|
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* fixup_free is called when:
|
|
* - an active object is freed
|
|
*/
|
|
static bool timer_fixup_free(void *addr, enum debug_obj_state state)
|
|
{
|
|
struct timer_list *timer = addr;
|
|
|
|
switch (state) {
|
|
case ODEBUG_STATE_ACTIVE:
|
|
del_timer_sync(timer);
|
|
debug_object_free(timer, &timer_debug_descr);
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* fixup_assert_init is called when:
|
|
* - an untracked/uninit-ed object is found
|
|
*/
|
|
static bool timer_fixup_assert_init(void *addr, enum debug_obj_state state)
|
|
{
|
|
struct timer_list *timer = addr;
|
|
|
|
switch (state) {
|
|
case ODEBUG_STATE_NOTAVAILABLE:
|
|
setup_timer(timer, stub_timer, 0);
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static struct debug_obj_descr timer_debug_descr = {
|
|
.name = "timer_list",
|
|
.debug_hint = timer_debug_hint,
|
|
.is_static_object = timer_is_static_object,
|
|
.fixup_init = timer_fixup_init,
|
|
.fixup_activate = timer_fixup_activate,
|
|
.fixup_free = timer_fixup_free,
|
|
.fixup_assert_init = timer_fixup_assert_init,
|
|
};
|
|
|
|
static inline void debug_timer_init(struct timer_list *timer)
|
|
{
|
|
debug_object_init(timer, &timer_debug_descr);
|
|
}
|
|
|
|
static inline void debug_timer_activate(struct timer_list *timer)
|
|
{
|
|
debug_object_activate(timer, &timer_debug_descr);
|
|
}
|
|
|
|
static inline void debug_timer_deactivate(struct timer_list *timer)
|
|
{
|
|
debug_object_deactivate(timer, &timer_debug_descr);
|
|
}
|
|
|
|
static inline void debug_timer_free(struct timer_list *timer)
|
|
{
|
|
debug_object_free(timer, &timer_debug_descr);
|
|
}
|
|
|
|
static inline void debug_timer_assert_init(struct timer_list *timer)
|
|
{
|
|
debug_object_assert_init(timer, &timer_debug_descr);
|
|
}
|
|
|
|
static void do_init_timer(struct timer_list *timer, unsigned int flags,
|
|
const char *name, struct lock_class_key *key);
|
|
|
|
void init_timer_on_stack_key(struct timer_list *timer, unsigned int flags,
|
|
const char *name, struct lock_class_key *key)
|
|
{
|
|
debug_object_init_on_stack(timer, &timer_debug_descr);
|
|
do_init_timer(timer, flags, name, key);
|
|
}
|
|
EXPORT_SYMBOL_GPL(init_timer_on_stack_key);
|
|
|
|
void destroy_timer_on_stack(struct timer_list *timer)
|
|
{
|
|
debug_object_free(timer, &timer_debug_descr);
|
|
}
|
|
EXPORT_SYMBOL_GPL(destroy_timer_on_stack);
|
|
|
|
#else
|
|
static inline void debug_timer_init(struct timer_list *timer) { }
|
|
static inline void debug_timer_activate(struct timer_list *timer) { }
|
|
static inline void debug_timer_deactivate(struct timer_list *timer) { }
|
|
static inline void debug_timer_assert_init(struct timer_list *timer) { }
|
|
#endif
|
|
|
|
static inline void debug_init(struct timer_list *timer)
|
|
{
|
|
debug_timer_init(timer);
|
|
trace_timer_init(timer);
|
|
}
|
|
|
|
static inline void
|
|
debug_activate(struct timer_list *timer, unsigned long expires)
|
|
{
|
|
debug_timer_activate(timer);
|
|
trace_timer_start(timer, expires, timer->flags);
|
|
}
|
|
|
|
static inline void debug_deactivate(struct timer_list *timer)
|
|
{
|
|
debug_timer_deactivate(timer);
|
|
trace_timer_cancel(timer);
|
|
}
|
|
|
|
static inline void debug_assert_init(struct timer_list *timer)
|
|
{
|
|
debug_timer_assert_init(timer);
|
|
}
|
|
|
|
static void do_init_timer(struct timer_list *timer, unsigned int flags,
|
|
const char *name, struct lock_class_key *key)
|
|
{
|
|
timer->entry.pprev = NULL;
|
|
timer->flags = flags | raw_smp_processor_id();
|
|
lockdep_init_map(&timer->lockdep_map, name, key, 0);
|
|
}
|
|
|
|
/**
|
|
* init_timer_key - initialize a timer
|
|
* @timer: the timer to be initialized
|
|
* @flags: timer flags
|
|
* @name: name of the timer
|
|
* @key: lockdep class key of the fake lock used for tracking timer
|
|
* sync lock dependencies
|
|
*
|
|
* init_timer_key() must be done to a timer prior calling *any* of the
|
|
* other timer functions.
|
|
*/
|
|
void init_timer_key(struct timer_list *timer, unsigned int flags,
|
|
const char *name, struct lock_class_key *key)
|
|
{
|
|
debug_init(timer);
|
|
do_init_timer(timer, flags, name, key);
|
|
}
|
|
EXPORT_SYMBOL(init_timer_key);
|
|
|
|
static inline void detach_timer(struct timer_list *timer, bool clear_pending)
|
|
{
|
|
struct hlist_node *entry = &timer->entry;
|
|
|
|
debug_deactivate(timer);
|
|
|
|
__hlist_del(entry);
|
|
if (clear_pending)
|
|
entry->pprev = NULL;
|
|
entry->next = LIST_POISON2;
|
|
}
|
|
|
|
static int detach_if_pending(struct timer_list *timer, struct timer_base *base,
|
|
bool clear_pending)
|
|
{
|
|
unsigned idx = timer_get_idx(timer);
|
|
|
|
if (!timer_pending(timer))
|
|
return 0;
|
|
|
|
if (hlist_is_singular_node(&timer->entry, base->vectors + idx))
|
|
__clear_bit(idx, base->pending_map);
|
|
|
|
detach_timer(timer, clear_pending);
|
|
return 1;
|
|
}
|
|
|
|
static inline struct timer_base *get_timer_cpu_base(u32 tflags, u32 cpu)
|
|
{
|
|
struct timer_base *base = per_cpu_ptr(&timer_bases[BASE_STD], cpu);
|
|
|
|
/*
|
|
* If the timer is deferrable and NO_HZ_COMMON is set then we need
|
|
* to use the deferrable base.
|
|
*/
|
|
if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && (tflags & TIMER_DEFERRABLE)) {
|
|
base = &timer_base_deferrable;
|
|
if (tflags & TIMER_PINNED)
|
|
base = per_cpu_ptr(&timer_bases[BASE_DEF], cpu);
|
|
}
|
|
return base;
|
|
}
|
|
|
|
static inline struct timer_base *get_timer_this_cpu_base(u32 tflags)
|
|
{
|
|
struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
|
|
|
|
/*
|
|
* If the timer is deferrable and NO_HZ_COMMON is set then we need
|
|
* to use the deferrable base.
|
|
*/
|
|
if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && (tflags & TIMER_DEFERRABLE)) {
|
|
base = &timer_base_deferrable;
|
|
if (tflags & TIMER_PINNED)
|
|
base = this_cpu_ptr(&timer_bases[BASE_DEF]);
|
|
}
|
|
return base;
|
|
}
|
|
|
|
static inline struct timer_base *get_timer_base(u32 tflags)
|
|
{
|
|
return get_timer_cpu_base(tflags, tflags & TIMER_CPUMASK);
|
|
}
|
|
|
|
#ifdef CONFIG_NO_HZ_COMMON
|
|
static inline struct timer_base *
|
|
get_target_base(struct timer_base *base, unsigned tflags)
|
|
{
|
|
#ifdef CONFIG_SMP
|
|
if ((tflags & TIMER_PINNED) || !base->migration_enabled)
|
|
return get_timer_this_cpu_base(tflags);
|
|
return get_timer_cpu_base(tflags, get_nohz_timer_target());
|
|
#else
|
|
return get_timer_this_cpu_base(tflags);
|
|
#endif
|
|
}
|
|
|
|
static inline void forward_timer_base(struct timer_base *base)
|
|
{
|
|
unsigned long jnow;
|
|
|
|
/*
|
|
* We only forward the base when we are idle or have just come out of
|
|
* idle (must_forward_clk logic), and have a delta between base clock
|
|
* and jiffies. In the common case, run_timers will take care of it.
|
|
*/
|
|
if (likely(!base->must_forward_clk))
|
|
return;
|
|
|
|
jnow = READ_ONCE(jiffies);
|
|
base->must_forward_clk = base->is_idle;
|
|
if ((long)(jnow - base->clk) < 2)
|
|
return;
|
|
|
|
/*
|
|
* If the next expiry value is > jiffies, then we fast forward to
|
|
* jiffies otherwise we forward to the next expiry value.
|
|
*/
|
|
if (time_after(base->next_expiry, jnow))
|
|
base->clk = jnow;
|
|
else
|
|
base->clk = base->next_expiry;
|
|
}
|
|
#else
|
|
static inline struct timer_base *
|
|
get_target_base(struct timer_base *base, unsigned tflags)
|
|
{
|
|
return get_timer_this_cpu_base(tflags);
|
|
}
|
|
|
|
static inline void forward_timer_base(struct timer_base *base) { }
|
|
#endif
|
|
|
|
|
|
/*
|
|
* We are using hashed locking: Holding per_cpu(timer_bases[x]).lock means
|
|
* that all timers which are tied to this base are locked, and the base itself
|
|
* is locked too.
|
|
*
|
|
* So __run_timers/migrate_timers can safely modify all timers which could
|
|
* be found in the base->vectors array.
|
|
*
|
|
* When a timer is migrating then the TIMER_MIGRATING flag is set and we need
|
|
* to wait until the migration is done.
|
|
*/
|
|
static struct timer_base *lock_timer_base(struct timer_list *timer,
|
|
unsigned long *flags)
|
|
__acquires(timer->base->lock)
|
|
{
|
|
for (;;) {
|
|
struct timer_base *base;
|
|
u32 tf;
|
|
|
|
/*
|
|
* We need to use READ_ONCE() here, otherwise the compiler
|
|
* might re-read @tf between the check for TIMER_MIGRATING
|
|
* and spin_lock().
|
|
*/
|
|
tf = READ_ONCE(timer->flags);
|
|
|
|
if (!(tf & TIMER_MIGRATING)) {
|
|
base = get_timer_base(tf);
|
|
raw_spin_lock_irqsave(&base->lock, *flags);
|
|
if (timer->flags == tf)
|
|
return base;
|
|
raw_spin_unlock_irqrestore(&base->lock, *flags);
|
|
}
|
|
cpu_relax();
|
|
ndelay(TIMER_LOCK_TIGHT_LOOP_DELAY_NS);
|
|
}
|
|
}
|
|
|
|
static inline int
|
|
__mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only)
|
|
{
|
|
struct timer_base *base, *new_base;
|
|
unsigned int idx = UINT_MAX;
|
|
unsigned long clk = 0, flags;
|
|
int ret = 0;
|
|
|
|
BUG_ON(!timer->function);
|
|
|
|
/*
|
|
* This is a common optimization triggered by the networking code - if
|
|
* the timer is re-modified to have the same timeout or ends up in the
|
|
* same array bucket then just return:
|
|
*/
|
|
if (timer_pending(timer)) {
|
|
/*
|
|
* The downside of this optimization is that it can result in
|
|
* larger granularity than you would get from adding a new
|
|
* timer with this expiry.
|
|
*/
|
|
if (timer->expires == expires)
|
|
return 1;
|
|
|
|
/*
|
|
* We lock timer base and calculate the bucket index right
|
|
* here. If the timer ends up in the same bucket, then we
|
|
* just update the expiry time and avoid the whole
|
|
* dequeue/enqueue dance.
|
|
*/
|
|
base = lock_timer_base(timer, &flags);
|
|
forward_timer_base(base);
|
|
|
|
clk = base->clk;
|
|
idx = calc_wheel_index(expires, clk);
|
|
|
|
/*
|
|
* Retrieve and compare the array index of the pending
|
|
* timer. If it matches set the expiry to the new value so a
|
|
* subsequent call will exit in the expires check above.
|
|
*/
|
|
if (idx == timer_get_idx(timer)) {
|
|
timer->expires = expires;
|
|
ret = 1;
|
|
goto out_unlock;
|
|
}
|
|
} else {
|
|
base = lock_timer_base(timer, &flags);
|
|
forward_timer_base(base);
|
|
}
|
|
|
|
ret = detach_if_pending(timer, base, false);
|
|
if (!ret && pending_only)
|
|
goto out_unlock;
|
|
|
|
new_base = get_target_base(base, timer->flags);
|
|
|
|
if (base != new_base) {
|
|
/*
|
|
* We are trying to schedule the timer on the new base.
|
|
* However we can't change timer's base while it is running,
|
|
* otherwise del_timer_sync() can't detect that the timer's
|
|
* handler yet has not finished. This also guarantees that the
|
|
* timer is serialized wrt itself.
|
|
*/
|
|
if (likely(base->running_timer != timer)) {
|
|
/* See the comment in lock_timer_base() */
|
|
timer->flags |= TIMER_MIGRATING;
|
|
|
|
raw_spin_unlock(&base->lock);
|
|
base = new_base;
|
|
raw_spin_lock(&base->lock);
|
|
WRITE_ONCE(timer->flags,
|
|
(timer->flags & ~TIMER_BASEMASK) | base->cpu);
|
|
forward_timer_base(base);
|
|
}
|
|
}
|
|
|
|
debug_activate(timer, expires);
|
|
|
|
timer->expires = expires;
|
|
/*
|
|
* If 'idx' was calculated above and the base time did not advance
|
|
* between calculating 'idx' and possibly switching the base, only
|
|
* enqueue_timer() and trigger_dyntick_cpu() is required. Otherwise
|
|
* we need to (re)calculate the wheel index via
|
|
* internal_add_timer().
|
|
*/
|
|
if (idx != UINT_MAX && clk == base->clk) {
|
|
enqueue_timer(base, timer, idx);
|
|
trigger_dyntick_cpu(base, timer);
|
|
} else {
|
|
internal_add_timer(base, timer);
|
|
}
|
|
|
|
out_unlock:
|
|
raw_spin_unlock_irqrestore(&base->lock, flags);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* mod_timer_pending - modify a pending timer's timeout
|
|
* @timer: the pending timer to be modified
|
|
* @expires: new timeout in jiffies
|
|
*
|
|
* mod_timer_pending() is the same for pending timers as mod_timer(),
|
|
* but will not re-activate and modify already deleted timers.
|
|
*
|
|
* It is useful for unserialized use of timers.
|
|
*/
|
|
int mod_timer_pending(struct timer_list *timer, unsigned long expires)
|
|
{
|
|
return __mod_timer(timer, expires, true);
|
|
}
|
|
EXPORT_SYMBOL(mod_timer_pending);
|
|
|
|
/**
|
|
* mod_timer - modify a timer's timeout
|
|
* @timer: the timer to be modified
|
|
* @expires: new timeout in jiffies
|
|
*
|
|
* mod_timer() is a more efficient way to update the expire field of an
|
|
* active timer (if the timer is inactive it will be activated)
|
|
*
|
|
* mod_timer(timer, expires) is equivalent to:
|
|
*
|
|
* del_timer(timer); timer->expires = expires; add_timer(timer);
|
|
*
|
|
* Note that if there are multiple unserialized concurrent users of the
|
|
* same timer, then mod_timer() is the only safe way to modify the timeout,
|
|
* since add_timer() cannot modify an already running timer.
|
|
*
|
|
* The function returns whether it has modified a pending timer or not.
|
|
* (ie. mod_timer() of an inactive timer returns 0, mod_timer() of an
|
|
* active timer returns 1.)
|
|
*/
|
|
int mod_timer(struct timer_list *timer, unsigned long expires)
|
|
{
|
|
return __mod_timer(timer, expires, false);
|
|
}
|
|
EXPORT_SYMBOL(mod_timer);
|
|
|
|
/**
|
|
* add_timer - start a timer
|
|
* @timer: the timer to be added
|
|
*
|
|
* The kernel will do a ->function(->data) callback from the
|
|
* timer interrupt at the ->expires point in the future. The
|
|
* current time is 'jiffies'.
|
|
*
|
|
* The timer's ->expires, ->function (and if the handler uses it, ->data)
|
|
* fields must be set prior calling this function.
|
|
*
|
|
* Timers with an ->expires field in the past will be executed in the next
|
|
* timer tick.
|
|
*/
|
|
void add_timer(struct timer_list *timer)
|
|
{
|
|
BUG_ON(timer_pending(timer));
|
|
mod_timer(timer, timer->expires);
|
|
}
|
|
EXPORT_SYMBOL(add_timer);
|
|
|
|
/**
|
|
* add_timer_on - start a timer on a particular CPU
|
|
* @timer: the timer to be added
|
|
* @cpu: the CPU to start it on
|
|
*
|
|
* This is not very scalable on SMP. Double adds are not possible.
|
|
*/
|
|
void add_timer_on(struct timer_list *timer, int cpu)
|
|
{
|
|
struct timer_base *new_base, *base;
|
|
unsigned long flags;
|
|
|
|
BUG_ON(timer_pending(timer) || !timer->function);
|
|
|
|
new_base = get_timer_cpu_base(timer->flags, cpu);
|
|
|
|
/*
|
|
* If @timer was on a different CPU, it should be migrated with the
|
|
* old base locked to prevent other operations proceeding with the
|
|
* wrong base locked. See lock_timer_base().
|
|
*/
|
|
base = lock_timer_base(timer, &flags);
|
|
if (base != new_base) {
|
|
timer->flags |= TIMER_MIGRATING;
|
|
|
|
raw_spin_unlock(&base->lock);
|
|
base = new_base;
|
|
raw_spin_lock(&base->lock);
|
|
WRITE_ONCE(timer->flags,
|
|
(timer->flags & ~TIMER_BASEMASK) | cpu);
|
|
}
|
|
forward_timer_base(base);
|
|
|
|
debug_activate(timer, timer->expires);
|
|
internal_add_timer(base, timer);
|
|
raw_spin_unlock_irqrestore(&base->lock, flags);
|
|
}
|
|
EXPORT_SYMBOL_GPL(add_timer_on);
|
|
|
|
/**
|
|
* del_timer - deactivate a timer.
|
|
* @timer: the timer to be deactivated
|
|
*
|
|
* del_timer() deactivates a timer - this works on both active and inactive
|
|
* timers.
|
|
*
|
|
* The function returns whether it has deactivated a pending timer or not.
|
|
* (ie. del_timer() of an inactive timer returns 0, del_timer() of an
|
|
* active timer returns 1.)
|
|
*/
|
|
int del_timer(struct timer_list *timer)
|
|
{
|
|
struct timer_base *base;
|
|
unsigned long flags;
|
|
int ret = 0;
|
|
|
|
debug_assert_init(timer);
|
|
|
|
if (timer_pending(timer)) {
|
|
base = lock_timer_base(timer, &flags);
|
|
ret = detach_if_pending(timer, base, true);
|
|
raw_spin_unlock_irqrestore(&base->lock, flags);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(del_timer);
|
|
|
|
/**
|
|
* try_to_del_timer_sync - Try to deactivate a timer
|
|
* @timer: timer to delete
|
|
*
|
|
* This function tries to deactivate a timer. Upon successful (ret >= 0)
|
|
* exit the timer is not queued and the handler is not running on any CPU.
|
|
*/
|
|
int try_to_del_timer_sync(struct timer_list *timer)
|
|
{
|
|
struct timer_base *base;
|
|
unsigned long flags;
|
|
int ret = -1;
|
|
|
|
debug_assert_init(timer);
|
|
|
|
base = lock_timer_base(timer, &flags);
|
|
|
|
if (base->running_timer != timer)
|
|
ret = detach_if_pending(timer, base, true);
|
|
|
|
raw_spin_unlock_irqrestore(&base->lock, flags);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(try_to_del_timer_sync);
|
|
|
|
#ifdef CONFIG_SMP
|
|
/**
|
|
* del_timer_sync - deactivate a timer and wait for the handler to finish.
|
|
* @timer: the timer to be deactivated
|
|
*
|
|
* This function only differs from del_timer() on SMP: besides deactivating
|
|
* the timer it also makes sure the handler has finished executing on other
|
|
* CPUs.
|
|
*
|
|
* Synchronization rules: Callers must prevent restarting of the timer,
|
|
* otherwise this function is meaningless. It must not be called from
|
|
* interrupt contexts unless the timer is an irqsafe one. The caller must
|
|
* not hold locks which would prevent completion of the timer's
|
|
* handler. The timer's handler must not call add_timer_on(). Upon exit the
|
|
* timer is not queued and the handler is not running on any CPU.
|
|
*
|
|
* Note: For !irqsafe timers, you must not hold locks that are held in
|
|
* interrupt context while calling this function. Even if the lock has
|
|
* nothing to do with the timer in question. Here's why:
|
|
*
|
|
* CPU0 CPU1
|
|
* ---- ----
|
|
* <SOFTIRQ>
|
|
* call_timer_fn();
|
|
* base->running_timer = mytimer;
|
|
* spin_lock_irq(somelock);
|
|
* <IRQ>
|
|
* spin_lock(somelock);
|
|
* del_timer_sync(mytimer);
|
|
* while (base->running_timer == mytimer);
|
|
*
|
|
* Now del_timer_sync() will never return and never release somelock.
|
|
* The interrupt on the other CPU is waiting to grab somelock but
|
|
* it has interrupted the softirq that CPU0 is waiting to finish.
|
|
*
|
|
* The function returns whether it has deactivated a pending timer or not.
|
|
*/
|
|
int del_timer_sync(struct timer_list *timer)
|
|
{
|
|
#ifdef CONFIG_LOCKDEP
|
|
unsigned long flags;
|
|
|
|
/*
|
|
* If lockdep gives a backtrace here, please reference
|
|
* the synchronization rules above.
|
|
*/
|
|
local_irq_save(flags);
|
|
lock_map_acquire(&timer->lockdep_map);
|
|
lock_map_release(&timer->lockdep_map);
|
|
local_irq_restore(flags);
|
|
#endif
|
|
/*
|
|
* don't use it in hardirq context, because it
|
|
* could lead to deadlock.
|
|
*/
|
|
WARN_ON(in_irq() && !(timer->flags & TIMER_IRQSAFE));
|
|
for (;;) {
|
|
int ret = try_to_del_timer_sync(timer);
|
|
if (ret >= 0)
|
|
return ret;
|
|
cpu_relax();
|
|
ndelay(TIMER_LOCK_TIGHT_LOOP_DELAY_NS);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(del_timer_sync);
|
|
#endif
|
|
|
|
static void call_timer_fn(struct timer_list *timer, void (*fn)(unsigned long),
|
|
unsigned long data)
|
|
{
|
|
int count = preempt_count();
|
|
|
|
#ifdef CONFIG_LOCKDEP
|
|
/*
|
|
* It is permissible to free the timer from inside the
|
|
* function that is called from it, this we need to take into
|
|
* account for lockdep too. To avoid bogus "held lock freed"
|
|
* warnings as well as problems when looking into
|
|
* timer->lockdep_map, make a copy and use that here.
|
|
*/
|
|
struct lockdep_map lockdep_map;
|
|
|
|
lockdep_copy_map(&lockdep_map, &timer->lockdep_map);
|
|
#endif
|
|
/*
|
|
* Couple the lock chain with the lock chain at
|
|
* del_timer_sync() by acquiring the lock_map around the fn()
|
|
* call here and in del_timer_sync().
|
|
*/
|
|
lock_map_acquire(&lockdep_map);
|
|
|
|
trace_timer_expire_entry(timer);
|
|
fn(data);
|
|
trace_timer_expire_exit(timer);
|
|
|
|
lock_map_release(&lockdep_map);
|
|
|
|
if (count != preempt_count()) {
|
|
WARN_ONCE(1, "timer: %pF preempt leak: %08x -> %08x\n",
|
|
fn, count, preempt_count());
|
|
/*
|
|
* Restore the preempt count. That gives us a decent
|
|
* chance to survive and extract information. If the
|
|
* callback kept a lock held, bad luck, but not worse
|
|
* than the BUG() we had.
|
|
*/
|
|
preempt_count_set(count);
|
|
}
|
|
}
|
|
|
|
static void expire_timers(struct timer_base *base, struct hlist_head *head)
|
|
{
|
|
while (!hlist_empty(head)) {
|
|
struct timer_list *timer;
|
|
void (*fn)(unsigned long);
|
|
unsigned long data;
|
|
|
|
timer = hlist_entry(head->first, struct timer_list, entry);
|
|
|
|
base->running_timer = timer;
|
|
detach_timer(timer, true);
|
|
|
|
fn = timer->function;
|
|
data = timer->data;
|
|
|
|
if (timer->flags & TIMER_IRQSAFE) {
|
|
raw_spin_unlock(&base->lock);
|
|
call_timer_fn(timer, fn, data);
|
|
raw_spin_lock(&base->lock);
|
|
} else {
|
|
raw_spin_unlock_irq(&base->lock);
|
|
call_timer_fn(timer, fn, data);
|
|
raw_spin_lock_irq(&base->lock);
|
|
}
|
|
}
|
|
}
|
|
|
|
static int __collect_expired_timers(struct timer_base *base,
|
|
struct hlist_head *heads)
|
|
{
|
|
unsigned long clk = base->clk;
|
|
struct hlist_head *vec;
|
|
int i, levels = 0;
|
|
unsigned int idx;
|
|
|
|
for (i = 0; i < LVL_DEPTH; i++) {
|
|
idx = (clk & LVL_MASK) + i * LVL_SIZE;
|
|
|
|
if (__test_and_clear_bit(idx, base->pending_map)) {
|
|
vec = base->vectors + idx;
|
|
hlist_move_list(vec, heads++);
|
|
levels++;
|
|
}
|
|
/* Is it time to look at the next level? */
|
|
if (clk & LVL_CLK_MASK)
|
|
break;
|
|
/* Shift clock for the next level granularity */
|
|
clk >>= LVL_CLK_SHIFT;
|
|
}
|
|
return levels;
|
|
}
|
|
|
|
#ifdef CONFIG_NO_HZ_COMMON
|
|
/*
|
|
* Find the next pending bucket of a level. Search from level start (@offset)
|
|
* + @clk upwards and if nothing there, search from start of the level
|
|
* (@offset) up to @offset + clk.
|
|
*/
|
|
static int next_pending_bucket(struct timer_base *base, unsigned offset,
|
|
unsigned int clk, int lvl)
|
|
{
|
|
unsigned int pos_up = -1, pos_down, start = offset + clk;
|
|
unsigned end = offset + LVL_SIZE;
|
|
unsigned int pos;
|
|
|
|
pos = find_next_bit(base->pending_map, end, start);
|
|
if (pos < end)
|
|
pos_up = pos - start;
|
|
|
|
pos = find_next_bit(base->pending_map, start, offset);
|
|
pos_down = pos < start ? pos + LVL_SIZE - start : -1;
|
|
if (((pos_up + (u64)base->clk) << LVL_SHIFT(lvl)) >
|
|
((pos_down + (u64)base->clk) << LVL_SHIFT(lvl)))
|
|
return pos_down;
|
|
return pos_up;
|
|
}
|
|
|
|
/*
|
|
* Search the first expiring timer in the various clock levels. Caller must
|
|
* hold base->lock.
|
|
*/
|
|
static unsigned long __next_timer_interrupt(struct timer_base *base)
|
|
{
|
|
unsigned long clk, next, adj;
|
|
unsigned lvl, offset = 0;
|
|
|
|
next = base->clk + NEXT_TIMER_MAX_DELTA;
|
|
clk = base->clk;
|
|
for (lvl = 0; lvl < LVL_DEPTH; lvl++, offset += LVL_SIZE) {
|
|
int pos = next_pending_bucket(base, offset, clk & LVL_MASK,
|
|
lvl);
|
|
|
|
if (pos >= 0) {
|
|
unsigned long tmp = clk + (unsigned long) pos;
|
|
|
|
tmp <<= LVL_SHIFT(lvl);
|
|
if (time_before(tmp, next))
|
|
next = tmp;
|
|
}
|
|
/*
|
|
* Clock for the next level. If the current level clock lower
|
|
* bits are zero, we look at the next level as is. If not we
|
|
* need to advance it by one because that's going to be the
|
|
* next expiring bucket in that level. base->clk is the next
|
|
* expiring jiffie. So in case of:
|
|
*
|
|
* LVL5 LVL4 LVL3 LVL2 LVL1 LVL0
|
|
* 0 0 0 0 0 0
|
|
*
|
|
* we have to look at all levels @index 0. With
|
|
*
|
|
* LVL5 LVL4 LVL3 LVL2 LVL1 LVL0
|
|
* 0 0 0 0 0 2
|
|
*
|
|
* LVL0 has the next expiring bucket @index 2. The upper
|
|
* levels have the next expiring bucket @index 1.
|
|
*
|
|
* In case that the propagation wraps the next level the same
|
|
* rules apply:
|
|
*
|
|
* LVL5 LVL4 LVL3 LVL2 LVL1 LVL0
|
|
* 0 0 0 0 F 2
|
|
*
|
|
* So after looking at LVL0 we get:
|
|
*
|
|
* LVL5 LVL4 LVL3 LVL2 LVL1
|
|
* 0 0 0 1 0
|
|
*
|
|
* So no propagation from LVL1 to LVL2 because that happened
|
|
* with the add already, but then we need to propagate further
|
|
* from LVL2 to LVL3.
|
|
*
|
|
* So the simple check whether the lower bits of the current
|
|
* level are 0 or not is sufficient for all cases.
|
|
*/
|
|
adj = clk & LVL_CLK_MASK ? 1 : 0;
|
|
clk >>= LVL_CLK_SHIFT;
|
|
clk += adj;
|
|
}
|
|
return next;
|
|
}
|
|
|
|
/*
|
|
* Check, if the next hrtimer event is before the next timer wheel
|
|
* event:
|
|
*/
|
|
static u64 cmp_next_hrtimer_event(u64 basem, u64 expires)
|
|
{
|
|
u64 nextevt = hrtimer_get_next_event();
|
|
|
|
/*
|
|
* If high resolution timers are enabled
|
|
* hrtimer_get_next_event() returns KTIME_MAX.
|
|
*/
|
|
if (expires <= nextevt)
|
|
return expires;
|
|
|
|
/*
|
|
* If the next timer is already expired, return the tick base
|
|
* time so the tick is fired immediately.
|
|
*/
|
|
if (nextevt <= basem)
|
|
return basem;
|
|
|
|
/*
|
|
* Round up to the next jiffie. High resolution timers are
|
|
* off, so the hrtimers are expired in the tick and we need to
|
|
* make sure that this tick really expires the timer to avoid
|
|
* a ping pong of the nohz stop code.
|
|
*
|
|
* Use DIV_ROUND_UP_ULL to prevent gcc calling __divdi3
|
|
*/
|
|
return DIV_ROUND_UP_ULL(nextevt, TICK_NSEC) * TICK_NSEC;
|
|
}
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
/*
|
|
* check_pending_deferrable_timers - Check for unbound deferrable timer expiry
|
|
* @cpu - Current CPU
|
|
*
|
|
* The function checks whether any global deferrable pending timers
|
|
* are exipired or not. This function does not check cpu bounded
|
|
* diferrable pending timers expiry.
|
|
*
|
|
* The function returns true when a cpu unbounded deferrable timer is expired.
|
|
*/
|
|
bool check_pending_deferrable_timers(int cpu)
|
|
{
|
|
if (cpu == tick_do_timer_cpu ||
|
|
tick_do_timer_cpu == TICK_DO_TIMER_NONE) {
|
|
if (time_after_eq(jiffies, timer_base_deferrable.clk)
|
|
&& !atomic_cmpxchg(&deferrable_pending, 0, 1)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
/**
|
|
* get_next_timer_interrupt - return the time (clock mono) of the next timer
|
|
* @basej: base time jiffies
|
|
* @basem: base time clock monotonic
|
|
*
|
|
* Returns the tick aligned clock monotonic time of the next pending
|
|
* timer or KTIME_MAX if no timer is pending.
|
|
*/
|
|
u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
|
|
{
|
|
struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
|
|
u64 expires = KTIME_MAX;
|
|
unsigned long nextevt;
|
|
bool is_max_delta;
|
|
|
|
/*
|
|
* Pretend that there is no timer pending if the cpu is offline.
|
|
* Possible pending timers will be migrated later to an active cpu.
|
|
*/
|
|
if (cpu_is_offline(smp_processor_id()))
|
|
return expires;
|
|
|
|
raw_spin_lock(&base->lock);
|
|
nextevt = __next_timer_interrupt(base);
|
|
is_max_delta = (nextevt == base->clk + NEXT_TIMER_MAX_DELTA);
|
|
base->next_expiry = nextevt;
|
|
/*
|
|
* We have a fresh next event. Check whether we can forward the
|
|
* base. We can only do that when @basej is past base->clk
|
|
* otherwise we might rewind base->clk.
|
|
*/
|
|
if (time_after(basej, base->clk)) {
|
|
if (time_after(nextevt, basej))
|
|
base->clk = basej;
|
|
else if (time_after(nextevt, base->clk))
|
|
base->clk = nextevt;
|
|
}
|
|
|
|
if (time_before_eq(nextevt, basej)) {
|
|
expires = basem;
|
|
base->is_idle = false;
|
|
} else {
|
|
if (!is_max_delta)
|
|
expires = basem + (u64)(nextevt - basej) * TICK_NSEC;
|
|
/*
|
|
* If we expect to sleep more than a tick, mark the base idle.
|
|
* Also the tick is stopped so any added timer must forward
|
|
* the base clk itself to keep granularity small. This idle
|
|
* logic is only maintained for the BASE_STD base, deferrable
|
|
* timers may still see large granularity skew (by design).
|
|
*/
|
|
if ((expires - basem) > TICK_NSEC) {
|
|
base->must_forward_clk = true;
|
|
base->is_idle = true;
|
|
}
|
|
}
|
|
raw_spin_unlock(&base->lock);
|
|
|
|
return cmp_next_hrtimer_event(basem, expires);
|
|
}
|
|
|
|
/**
|
|
* timer_clear_idle - Clear the idle state of the timer base
|
|
*
|
|
* Called with interrupts disabled
|
|
*/
|
|
void timer_clear_idle(void)
|
|
{
|
|
struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
|
|
|
|
/*
|
|
* We do this unlocked. The worst outcome is a remote enqueue sending
|
|
* a pointless IPI, but taking the lock would just make the window for
|
|
* sending the IPI a few instructions smaller for the cost of taking
|
|
* the lock in the exit from idle path.
|
|
*/
|
|
base->is_idle = false;
|
|
}
|
|
|
|
static int collect_expired_timers(struct timer_base *base,
|
|
struct hlist_head *heads)
|
|
{
|
|
unsigned long now = READ_ONCE(jiffies);
|
|
|
|
/*
|
|
* NOHZ optimization. After a long idle sleep we need to forward the
|
|
* base to current jiffies. Avoid a loop by searching the bitfield for
|
|
* the next expiring timer.
|
|
*/
|
|
if ((long)(now - base->clk) > 2) {
|
|
unsigned long next = __next_timer_interrupt(base);
|
|
|
|
/*
|
|
* If the next timer is ahead of time forward to current
|
|
* jiffies, otherwise forward to the next expiry time:
|
|
*/
|
|
if (time_after(next, now)) {
|
|
/* The call site will increment clock! */
|
|
base->clk = now - 1;
|
|
return 0;
|
|
}
|
|
base->clk = next;
|
|
}
|
|
return __collect_expired_timers(base, heads);
|
|
}
|
|
#else
|
|
static inline int collect_expired_timers(struct timer_base *base,
|
|
struct hlist_head *heads)
|
|
{
|
|
return __collect_expired_timers(base, heads);
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
* Called from the timer interrupt handler to charge one tick to the current
|
|
* process. user_tick is 1 if the tick is user time, 0 for system.
|
|
*/
|
|
void update_process_times(int user_tick)
|
|
{
|
|
struct task_struct *p = current;
|
|
|
|
/* Note: this timer irq context must be accounted for as well. */
|
|
account_process_tick(p, user_tick);
|
|
run_local_timers();
|
|
rcu_check_callbacks(user_tick);
|
|
#ifdef CONFIG_IRQ_WORK
|
|
if (in_irq())
|
|
irq_work_tick();
|
|
#endif
|
|
scheduler_tick();
|
|
if (IS_ENABLED(CONFIG_POSIX_TIMERS))
|
|
run_posix_cpu_timers(p);
|
|
}
|
|
|
|
/**
|
|
* __run_timers - run all expired timers (if any) on this CPU.
|
|
* @base: the timer vector to be processed.
|
|
*/
|
|
static inline void __run_timers(struct timer_base *base)
|
|
{
|
|
struct hlist_head heads[LVL_DEPTH];
|
|
int levels;
|
|
|
|
if (!time_after_eq(jiffies, base->clk))
|
|
return;
|
|
|
|
raw_spin_lock_irq(&base->lock);
|
|
|
|
/*
|
|
* timer_base::must_forward_clk must be cleared before running
|
|
* timers so that any timer functions that call mod_timer() will
|
|
* not try to forward the base. Idle tracking / clock forwarding
|
|
* logic is only used with BASE_STD timers.
|
|
*
|
|
* The must_forward_clk flag is cleared unconditionally also for
|
|
* the deferrable base. The deferrable base is not affected by idle
|
|
* tracking and never forwarded, so clearing the flag is a NOOP.
|
|
*
|
|
* The fact that the deferrable base is never forwarded can cause
|
|
* large variations in granularity for deferrable timers, but they
|
|
* can be deferred for long periods due to idle anyway.
|
|
*/
|
|
base->must_forward_clk = false;
|
|
|
|
while (time_after_eq(jiffies, base->clk)) {
|
|
|
|
levels = collect_expired_timers(base, heads);
|
|
base->clk++;
|
|
|
|
while (levels--)
|
|
expire_timers(base, heads + levels);
|
|
}
|
|
base->running_timer = NULL;
|
|
raw_spin_unlock_irq(&base->lock);
|
|
}
|
|
|
|
/*
|
|
* This function runs timers and the timer-tq in bottom half context.
|
|
*/
|
|
static __latent_entropy void run_timer_softirq(struct softirq_action *h)
|
|
{
|
|
struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
|
|
|
|
__run_timers(base);
|
|
if (IS_ENABLED(CONFIG_NO_HZ_COMMON)) {
|
|
__run_timers(this_cpu_ptr(&timer_bases[BASE_DEF]));
|
|
}
|
|
|
|
if ((atomic_cmpxchg(&deferrable_pending, 1, 0) &&
|
|
tick_do_timer_cpu == TICK_DO_TIMER_NONE) ||
|
|
tick_do_timer_cpu == smp_processor_id())
|
|
__run_timers(&timer_base_deferrable);
|
|
}
|
|
|
|
/*
|
|
* Called by the local, per-CPU timer interrupt on SMP.
|
|
*/
|
|
void run_local_timers(void)
|
|
{
|
|
struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
|
|
|
|
hrtimer_run_queues();
|
|
/* Raise the softirq only if required. */
|
|
if (time_before(jiffies, base->clk)) {
|
|
if (!IS_ENABLED(CONFIG_NO_HZ_COMMON))
|
|
return;
|
|
/* CPU is awake, so check the deferrable base. */
|
|
base++;
|
|
if (time_before(jiffies, base->clk))
|
|
return;
|
|
}
|
|
raise_softirq(TIMER_SOFTIRQ);
|
|
}
|
|
|
|
static void process_timeout(unsigned long __data)
|
|
{
|
|
wake_up_process((struct task_struct *)__data);
|
|
}
|
|
|
|
/**
|
|
* schedule_timeout - sleep until timeout
|
|
* @timeout: timeout value in jiffies
|
|
*
|
|
* Make the current task sleep until @timeout jiffies have
|
|
* elapsed. The routine will return immediately unless
|
|
* the current task state has been set (see set_current_state()).
|
|
*
|
|
* You can set the task state as follows -
|
|
*
|
|
* %TASK_UNINTERRUPTIBLE - at least @timeout jiffies are guaranteed to
|
|
* pass before the routine returns unless the current task is explicitly
|
|
* woken up, (e.g. by wake_up_process())".
|
|
*
|
|
* %TASK_INTERRUPTIBLE - the routine may return early if a signal is
|
|
* delivered to the current task or the current task is explicitly woken
|
|
* up.
|
|
*
|
|
* The current task state is guaranteed to be TASK_RUNNING when this
|
|
* routine returns.
|
|
*
|
|
* Specifying a @timeout value of %MAX_SCHEDULE_TIMEOUT will schedule
|
|
* the CPU away without a bound on the timeout. In this case the return
|
|
* value will be %MAX_SCHEDULE_TIMEOUT.
|
|
*
|
|
* Returns 0 when the timer has expired otherwise the remaining time in
|
|
* jiffies will be returned. In all cases the return value is guaranteed
|
|
* to be non-negative.
|
|
*/
|
|
signed long __sched schedule_timeout(signed long timeout)
|
|
{
|
|
struct timer_list timer;
|
|
unsigned long expire;
|
|
|
|
switch (timeout)
|
|
{
|
|
case MAX_SCHEDULE_TIMEOUT:
|
|
/*
|
|
* These two special cases are useful to be comfortable
|
|
* in the caller. Nothing more. We could take
|
|
* MAX_SCHEDULE_TIMEOUT from one of the negative value
|
|
* but I' d like to return a valid offset (>=0) to allow
|
|
* the caller to do everything it want with the retval.
|
|
*/
|
|
schedule();
|
|
goto out;
|
|
default:
|
|
/*
|
|
* Another bit of PARANOID. Note that the retval will be
|
|
* 0 since no piece of kernel is supposed to do a check
|
|
* for a negative retval of schedule_timeout() (since it
|
|
* should never happens anyway). You just have the printk()
|
|
* that will tell you if something is gone wrong and where.
|
|
*/
|
|
if (timeout < 0) {
|
|
printk(KERN_ERR "schedule_timeout: wrong timeout "
|
|
"value %lx\n", timeout);
|
|
dump_stack();
|
|
current->state = TASK_RUNNING;
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
expire = timeout + jiffies;
|
|
|
|
setup_timer_on_stack(&timer, process_timeout, (unsigned long)current);
|
|
__mod_timer(&timer, expire, false);
|
|
schedule();
|
|
del_singleshot_timer_sync(&timer);
|
|
|
|
/* Remove the timer from the object tracker */
|
|
destroy_timer_on_stack(&timer);
|
|
|
|
timeout = expire - jiffies;
|
|
|
|
out:
|
|
return timeout < 0 ? 0 : timeout;
|
|
}
|
|
EXPORT_SYMBOL(schedule_timeout);
|
|
|
|
/*
|
|
* We can use __set_current_state() here because schedule_timeout() calls
|
|
* schedule() unconditionally.
|
|
*/
|
|
signed long __sched schedule_timeout_interruptible(signed long timeout)
|
|
{
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
|
return schedule_timeout(timeout);
|
|
}
|
|
EXPORT_SYMBOL(schedule_timeout_interruptible);
|
|
|
|
signed long __sched schedule_timeout_killable(signed long timeout)
|
|
{
|
|
__set_current_state(TASK_KILLABLE);
|
|
return schedule_timeout(timeout);
|
|
}
|
|
EXPORT_SYMBOL(schedule_timeout_killable);
|
|
|
|
signed long __sched schedule_timeout_uninterruptible(signed long timeout)
|
|
{
|
|
__set_current_state(TASK_UNINTERRUPTIBLE);
|
|
return schedule_timeout(timeout);
|
|
}
|
|
EXPORT_SYMBOL(schedule_timeout_uninterruptible);
|
|
|
|
/*
|
|
* Like schedule_timeout_uninterruptible(), except this task will not contribute
|
|
* to load average.
|
|
*/
|
|
signed long __sched schedule_timeout_idle(signed long timeout)
|
|
{
|
|
__set_current_state(TASK_IDLE);
|
|
return schedule_timeout(timeout);
|
|
}
|
|
EXPORT_SYMBOL(schedule_timeout_idle);
|
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
static void migrate_timer_list(struct timer_base *new_base,
|
|
struct hlist_head *head, bool remove_pinned)
|
|
{
|
|
struct timer_list *timer;
|
|
int cpu = new_base->cpu;
|
|
struct hlist_node *n;
|
|
int is_pinned;
|
|
|
|
hlist_for_each_entry_safe(timer, n, head, entry) {
|
|
is_pinned = timer->flags & TIMER_PINNED;
|
|
if (!remove_pinned && is_pinned)
|
|
continue;
|
|
|
|
detach_if_pending(timer, get_timer_base(timer->flags), false);
|
|
timer->flags = (timer->flags & ~TIMER_BASEMASK) | cpu;
|
|
internal_add_timer(new_base, timer);
|
|
}
|
|
}
|
|
|
|
int timers_prepare_cpu(unsigned int cpu)
|
|
{
|
|
struct timer_base *base;
|
|
int b;
|
|
|
|
for (b = 0; b < NR_BASES; b++) {
|
|
base = per_cpu_ptr(&timer_bases[b], cpu);
|
|
base->clk = jiffies;
|
|
base->next_expiry = base->clk + NEXT_TIMER_MAX_DELTA;
|
|
base->is_idle = false;
|
|
base->must_forward_clk = true;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void __migrate_timers(unsigned int cpu, bool remove_pinned)
|
|
{
|
|
struct timer_base *old_base;
|
|
struct timer_base *new_base;
|
|
unsigned long flags;
|
|
int b, i;
|
|
|
|
for (b = 0; b < NR_BASES; b++) {
|
|
old_base = per_cpu_ptr(&timer_bases[b], cpu);
|
|
new_base = get_cpu_ptr(&timer_bases[b]);
|
|
/*
|
|
* The caller is globally serialized and nobody else
|
|
* takes two locks at once, deadlock is not possible.
|
|
*/
|
|
raw_spin_lock_irqsave(&new_base->lock, flags);
|
|
raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING);
|
|
|
|
if (!cpu_online(cpu))
|
|
BUG_ON(old_base->running_timer);
|
|
/*
|
|
* The current CPUs base clock might be stale. Update it
|
|
* before moving the timers over.
|
|
*/
|
|
forward_timer_base(new_base);
|
|
|
|
for (i = 0; i < WHEEL_SIZE; i++)
|
|
migrate_timer_list(new_base, old_base->vectors + i,
|
|
remove_pinned);
|
|
|
|
raw_spin_unlock(&old_base->lock);
|
|
raw_spin_unlock_irqrestore(&new_base->lock, flags);
|
|
put_cpu_ptr(&timer_bases);
|
|
}
|
|
}
|
|
|
|
int timers_dead_cpu(unsigned int cpu)
|
|
{
|
|
BUG_ON(cpu_online(cpu));
|
|
__migrate_timers(cpu, true);
|
|
return 0;
|
|
}
|
|
|
|
void timer_quiesce_cpu(void *cpup)
|
|
{
|
|
__migrate_timers(*(unsigned int *)cpup, false);
|
|
}
|
|
|
|
#endif /* CONFIG_HOTPLUG_CPU */
|
|
|
|
static void __init init_timer_cpu(int cpu)
|
|
{
|
|
struct timer_base *base;
|
|
int i;
|
|
|
|
for (i = 0; i < NR_BASES; i++) {
|
|
base = per_cpu_ptr(&timer_bases[i], cpu);
|
|
base->cpu = cpu;
|
|
raw_spin_lock_init(&base->lock);
|
|
base->clk = jiffies;
|
|
}
|
|
}
|
|
|
|
static inline void init_timer_deferrable_global(void)
|
|
{
|
|
timer_base_deferrable.cpu = nr_cpu_ids;
|
|
raw_spin_lock_init(&timer_base_deferrable.lock);
|
|
timer_base_deferrable.clk = jiffies;
|
|
}
|
|
|
|
static void __init init_timer_cpus(void)
|
|
{
|
|
int cpu;
|
|
|
|
init_timer_deferrable_global();
|
|
|
|
for_each_possible_cpu(cpu)
|
|
init_timer_cpu(cpu);
|
|
}
|
|
|
|
void __init init_timers(void)
|
|
{
|
|
init_timer_cpus();
|
|
open_softirq(TIMER_SOFTIRQ, run_timer_softirq);
|
|
}
|
|
|
|
/**
|
|
* msleep - sleep safely even with waitqueue interruptions
|
|
* @msecs: Time in milliseconds to sleep for
|
|
*/
|
|
void msleep(unsigned int msecs)
|
|
{
|
|
unsigned long timeout = msecs_to_jiffies(msecs) + 1;
|
|
|
|
while (timeout)
|
|
timeout = schedule_timeout_uninterruptible(timeout);
|
|
}
|
|
|
|
EXPORT_SYMBOL(msleep);
|
|
|
|
/**
|
|
* msleep_interruptible - sleep waiting for signals
|
|
* @msecs: Time in milliseconds to sleep for
|
|
*/
|
|
unsigned long msleep_interruptible(unsigned int msecs)
|
|
{
|
|
unsigned long timeout = msecs_to_jiffies(msecs) + 1;
|
|
|
|
while (timeout && !signal_pending(current))
|
|
timeout = schedule_timeout_interruptible(timeout);
|
|
return jiffies_to_msecs(timeout);
|
|
}
|
|
|
|
EXPORT_SYMBOL(msleep_interruptible);
|
|
|
|
/**
|
|
* usleep_range - Sleep for an approximate time
|
|
* @min: Minimum time in usecs to sleep
|
|
* @max: Maximum time in usecs to sleep
|
|
*
|
|
* In non-atomic context where the exact wakeup time is flexible, use
|
|
* usleep_range() instead of udelay(). The sleep improves responsiveness
|
|
* by avoiding the CPU-hogging busy-wait of udelay(), and the range reduces
|
|
* power usage by allowing hrtimers to take advantage of an already-
|
|
* scheduled interrupt instead of scheduling a new one just for this sleep.
|
|
*/
|
|
void __sched usleep_range(unsigned long min, unsigned long max)
|
|
{
|
|
ktime_t exp = ktime_add_us(ktime_get(), min);
|
|
u64 delta = (u64)(max - min) * NSEC_PER_USEC;
|
|
|
|
for (;;) {
|
|
__set_current_state(TASK_UNINTERRUPTIBLE);
|
|
/* Do not return before the requested sleep time has elapsed */
|
|
if (!schedule_hrtimeout_range(&exp, delta, HRTIMER_MODE_ABS))
|
|
break;
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(usleep_range);
|