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