// SPDX-License-Identifier: GPL-2.0/* * This file contains the procedures for the handling of select and poll * * Created for Linux based loosely upon Mathius Lattner's minix * patches by Peter MacDonald. Heavily edited by Linus. * * 4 February 1994 * COFF/ELF binary emulation. If the process has the STICKY_TIMEOUTS * flag set in its personality we do *not* modify the given timeout * parameter to reflect time remaining. * * 24 January 2000 * Changed sys_poll()/do_poll() to use PAGE_SIZE chunk-based allocation * of fds to overcome nfds < 16390 descriptors limit (Tigran Aivazian). */#include<linux/kernel.h>#include<linux/sched/signal.h>#include<linux/sched/rt.h>#include<linux/syscalls.h>#include<linux/export.h>#include<linux/slab.h>#include<linux/poll.h>#include<linux/personality.h> /* for STICKY_TIMEOUTS */#include<linux/file.h>#include<linux/fdtable.h>#include<linux/fs.h>#include<linux/rcupdate.h>#include<linux/hrtimer.h>#include<linux/freezer.h>#include<net/busy_poll.h>#include<linux/vmalloc.h>#include<linux/uaccess.h>/* * Estimate expected accuracy in ns from a timeval. * * After quite a bit of churning around, we've settled on * a simple thing of taking 0.1% of the timeout as the * slack, with a cap of 100 msec. * "nice" tasks get a 0.5% slack instead. * * Consider this comment an open invitation to come up with even * better solutions.. */#define MAX_SLACK (100 * NSEC_PER_MSEC)staticlong__estimate_accuracy(structtimespec64*tv){longslack;intdivfactor=1000;if(tv->tv_sec<0)return0;if(task_nice(current)>0)divfactor=divfactor/5;if(tv->tv_sec>MAX_SLACK/(NSEC_PER_SEC/divfactor))returnMAX_SLACK;slack