Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 1 | #ifndef IOCONTEXT_H |
| 2 | #define IOCONTEXT_H |
| 3 | |
Jens Axboe | 4ac845a | 2008-01-24 08:44:49 +0100 | [diff] [blame] | 4 | #include <linux/radix-tree.h> |
Fabio Checconi | 34e6bbf | 2008-04-02 14:31:02 +0200 | [diff] [blame] | 5 | #include <linux/rcupdate.h> |
Tejun Heo | b2efa05 | 2011-12-14 00:33:39 +0100 | [diff] [blame] | 6 | #include <linux/workqueue.h> |
Jens Axboe | 4ac845a | 2008-01-24 08:44:49 +0100 | [diff] [blame] | 7 | |
Tejun Heo | dc86900 | 2011-12-14 00:33:38 +0100 | [diff] [blame] | 8 | enum { |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame^] | 9 | ICQ_IOPRIO_CHANGED, |
| 10 | ICQ_CGROUP_CHANGED, |
Tejun Heo | dc86900 | 2011-12-14 00:33:38 +0100 | [diff] [blame] | 11 | }; |
| 12 | |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame^] | 13 | struct io_cq { |
| 14 | struct request_queue *q; |
| 15 | struct io_context *ioc; |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 16 | |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame^] | 17 | struct list_head q_node; |
| 18 | struct hlist_node ioc_node; |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 19 | |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame^] | 20 | unsigned long changed; |
| 21 | struct rcu_head rcu_head; |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 22 | |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame^] | 23 | void (*exit)(struct io_cq *); |
| 24 | void (*release)(struct io_cq *); |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | /* |
Jens Axboe | d38ecf9 | 2008-01-24 08:53:35 +0100 | [diff] [blame] | 28 | * I/O subsystem state of the associated processes. It is refcounted |
| 29 | * and kmalloc'ed. These could be shared between processes. |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 30 | */ |
| 31 | struct io_context { |
Nikanth Karthikesan | d9c7d39 | 2009-06-10 12:57:06 -0700 | [diff] [blame] | 32 | atomic_long_t refcount; |
Jens Axboe | d38ecf9 | 2008-01-24 08:53:35 +0100 | [diff] [blame] | 33 | atomic_t nr_tasks; |
| 34 | |
| 35 | /* all the fields below are protected by this lock */ |
| 36 | spinlock_t lock; |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 37 | |
| 38 | unsigned short ioprio; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 39 | |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 40 | /* |
| 41 | * For request batching |
| 42 | */ |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 43 | int nr_batch_requests; /* Number of requests left in the batch */ |
Richard Kennedy | 58c24a6 | 2010-02-26 14:00:43 +0100 | [diff] [blame] | 44 | unsigned long last_waited; /* Time last woken after wait for request */ |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 45 | |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame^] | 46 | struct radix_tree_root icq_tree; |
| 47 | struct io_cq __rcu *icq_hint; |
| 48 | struct hlist_head icq_list; |
Tejun Heo | b2efa05 | 2011-12-14 00:33:39 +0100 | [diff] [blame] | 49 | |
| 50 | struct work_struct release_work; |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 51 | }; |
| 52 | |
Jens Axboe | d38ecf9 | 2008-01-24 08:53:35 +0100 | [diff] [blame] | 53 | static inline struct io_context *ioc_task_link(struct io_context *ioc) |
| 54 | { |
| 55 | /* |
| 56 | * if ref count is zero, don't allow sharing (ioc is going away, it's |
| 57 | * a race). |
| 58 | */ |
Nikanth Karthikesan | d9c7d39 | 2009-06-10 12:57:06 -0700 | [diff] [blame] | 59 | if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) { |
Li Zefan | cbb4f26 | 2009-07-31 08:55:48 +0200 | [diff] [blame] | 60 | atomic_inc(&ioc->nr_tasks); |
Jens Axboe | d38ecf9 | 2008-01-24 08:53:35 +0100 | [diff] [blame] | 61 | return ioc; |
Jens Axboe | d237e5c | 2008-04-15 09:25:33 +0200 | [diff] [blame] | 62 | } |
Jens Axboe | d38ecf9 | 2008-01-24 08:53:35 +0100 | [diff] [blame] | 63 | |
| 64 | return NULL; |
| 65 | } |
| 66 | |
Louis Rilling | b69f229 | 2009-12-04 14:52:42 +0100 | [diff] [blame] | 67 | struct task_struct; |
Jens Axboe | da9cbc8 | 2008-06-30 20:42:08 +0200 | [diff] [blame] | 68 | #ifdef CONFIG_BLOCK |
Tejun Heo | b2efa05 | 2011-12-14 00:33:39 +0100 | [diff] [blame] | 69 | void put_io_context(struct io_context *ioc, struct request_queue *locked_q); |
Louis Rilling | b69f229 | 2009-12-04 14:52:42 +0100 | [diff] [blame] | 70 | void exit_io_context(struct task_struct *task); |
Tejun Heo | 6e736be | 2011-12-14 00:33:38 +0100 | [diff] [blame] | 71 | struct io_context *get_task_io_context(struct task_struct *task, |
| 72 | gfp_t gfp_flags, int node); |
Tejun Heo | dc86900 | 2011-12-14 00:33:38 +0100 | [diff] [blame] | 73 | void ioc_ioprio_changed(struct io_context *ioc, int ioprio); |
| 74 | void ioc_cgroup_changed(struct io_context *ioc); |
Jens Axboe | da9cbc8 | 2008-06-30 20:42:08 +0200 | [diff] [blame] | 75 | #else |
Jens Axboe | da9cbc8 | 2008-06-30 20:42:08 +0200 | [diff] [blame] | 76 | struct io_context; |
Tejun Heo | b2efa05 | 2011-12-14 00:33:39 +0100 | [diff] [blame] | 77 | static inline void put_io_context(struct io_context *ioc, |
| 78 | struct request_queue *locked_q) { } |
Tejun Heo | 42ec57a | 2011-12-14 00:33:37 +0100 | [diff] [blame] | 79 | static inline void exit_io_context(struct task_struct *task) { } |
Jens Axboe | da9cbc8 | 2008-06-30 20:42:08 +0200 | [diff] [blame] | 80 | #endif |
| 81 | |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 82 | #endif |