Skip to content
Snippets Groups Projects
Select Git revision
  • bd2f55361f18347e890d52ff9cfd8895455ec11b
  • master default protected
  • android-msm-bullhead-3.10-nougat_kgdb_less_changes
  • android-msm-bullhead-3.10-nougat_kgdb
  • android-msm-bullhead-3.10-nougat_klist
  • android-4.4
  • android-msm-vega-4.4-oreo-daydream
  • android-msm-wahoo-4.4-p-preview-5
  • android-msm-wahoo-4.4-pie
  • android-msm-marlin-3.18-p-preview-5
  • android-msm-marlin-3.18-pie
  • android-msm-wahoo-2018.07-oreo-m2
  • android-msm-wahoo-2018.07-oreo-m4
  • android-msm-wahoo-4.4-p-preview-4
  • android-msm-bullhead-3.10-oreo-m6
  • android-msm-angler-3.10-oreo-m6
  • android-msm-marlin-3.18-p-preview-4
  • android-msm-stargazer-3.18-oreo-wear-dr
  • android-msm-catshark-3.18-oreo-wear-dr
  • android-msm-wahoo-4.4-oreo-m2
  • android-msm-wahoo-4.4-oreo-m4
  • android-daydreamos-8.0.0_r0.5
  • android-8.1.0_r0.92
  • android-8.1.0_r0.91
  • android-daydreamos-8.0.0_r0.4
  • android-p-preview-5_r0.2
  • android-p-preview-5_r0.1
  • android-9.0.0_r0.5
  • android-9.0.0_r0.4
  • android-9.0.0_r0.2
  • android-9.0.0_r0.1
  • android-8.1.0_r0.81
  • android-8.1.0_r0.80
  • android-8.1.0_r0.78
  • android-8.1.0_r0.76
  • android-8.1.0_r0.75
  • android-8.1.0_r0.72
  • android-8.1.0_r0.70
  • android-p-preview-4_r0.2
  • android-p-preview-4_r0.1
  • android-wear-8.0.0_r0.30
41 results

eventpoll.c

Blame
  • eventpoll.c 50.09 KiB
    /*
     *  fs/eventpoll.c (Efficient event retrieval implementation)
     *  Copyright (C) 2001,...,2009	 Davide Libenzi
     *
     *  This program is free software; you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation; either version 2 of the License, or
     *  (at your option) any later version.
     *
     *  Davide Libenzi <davidel@xmailserver.org>
     *
     */
    
    #include <linux/init.h>
    #include <linux/kernel.h>
    #include <linux/sched.h>
    #include <linux/fs.h>
    #include <linux/file.h>
    #include <linux/signal.h>
    #include <linux/errno.h>
    #include <linux/mm.h>
    #include <linux/slab.h>
    #include <linux/poll.h>
    #include <linux/string.h>
    #include <linux/list.h>
    #include <linux/hash.h>
    #include <linux/spinlock.h>
    #include <linux/syscalls.h>
    #include <linux/rbtree.h>
    #include <linux/wait.h>
    #include <linux/eventpoll.h>
    #include <linux/mount.h>
    #include <linux/bitops.h>
    #include <linux/mutex.h>
    #include <linux/anon_inodes.h>
    #include <asm/uaccess.h>
    #include <asm/system.h>
    #include <asm/io.h>
    #include <asm/mman.h>
    #include <linux/atomic.h>
    
    /*
     * LOCKING:
     * There are three level of locking required by epoll :
     *
     * 1) epmutex (mutex)
     * 2) ep->mtx (mutex)
     * 3) ep->lock (spinlock)
     *
     * The acquire order is the one listed above, from 1 to 3.
     * We need a spinlock (ep->lock) because we manipulate objects
     * from inside the poll callback, that might be triggered from
     * a wake_up() that in turn might be called from IRQ context.
     * So we can't sleep inside the poll callback and hence we need
     * a spinlock. During the event transfer loop (from kernel to
     * user space) we could end up sleeping due a copy_to_user(), so
     * we need a lock that will allow us to sleep. This lock is a
     * mutex (ep->mtx). It is acquired during the event transfer loop,
     * during epoll_ctl(EPOLL_CTL_DEL) and during eventpoll_release_file().
     * Then we also need a global mutex to serialize eventpoll_release_file()
     * and ep_free().
     * This mutex is acquired by ep_free() during the epoll file
     * cleanup path and it is also acquired by eventpoll_release_file()
     * if a file has been pushed inside an epoll set and it is then
     * close()d without a previous call to epoll_ctl(EPOLL_CTL_DEL).
     * It is also acquired when inserting an epoll fd onto another epoll
     * fd. We do this so that we walk the epoll tree and ensure that this
     * insertion does not create a cycle of epoll file descriptors, which
     * could lead to deadlock. We need a global mutex to prevent two
     * simultaneous inserts (A into B and B into A) from racing and