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 | |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 8 | struct cfq_queue; |
Shaohua Li | 383cd72 | 2011-07-12 14:24:35 +0200 | [diff] [blame] | 9 | struct cfq_ttime { |
| 10 | unsigned long last_end_request; |
| 11 | |
| 12 | unsigned long ttime_total; |
| 13 | unsigned long ttime_samples; |
| 14 | unsigned long ttime_mean; |
| 15 | }; |
| 16 | |
Tejun Heo | dc86900 | 2011-12-14 00:33:38 +0100 | [diff] [blame] | 17 | enum { |
| 18 | CIC_IOPRIO_CHANGED, |
| 19 | CIC_CGROUP_CHANGED, |
| 20 | }; |
| 21 | |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 22 | struct cfq_io_context { |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 23 | void *key; |
Tejun Heo | 283287a | 2011-12-14 00:33:38 +0100 | [diff] [blame] | 24 | struct request_queue *q; |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 25 | |
| 26 | struct cfq_queue *cfqq[2]; |
| 27 | |
| 28 | struct io_context *ioc; |
| 29 | |
Shaohua Li | 383cd72 | 2011-07-12 14:24:35 +0200 | [diff] [blame] | 30 | struct cfq_ttime ttime; |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 31 | |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 32 | struct list_head queue_list; |
Jens Axboe | ffc4e75 | 2008-02-19 10:02:29 +0100 | [diff] [blame] | 33 | struct hlist_node cic_list; |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 34 | |
Tejun Heo | dc86900 | 2011-12-14 00:33:38 +0100 | [diff] [blame] | 35 | unsigned long changed; |
| 36 | |
Tejun Heo | b2efa05 | 2011-12-14 00:33:39 +0100 | [diff] [blame^] | 37 | void (*exit)(struct cfq_io_context *); |
| 38 | void (*release)(struct cfq_io_context *); |
Fabio Checconi | 34e6bbf | 2008-04-02 14:31:02 +0200 | [diff] [blame] | 39 | |
| 40 | struct rcu_head rcu_head; |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | /* |
Jens Axboe | d38ecf9 | 2008-01-24 08:53:35 +0100 | [diff] [blame] | 44 | * I/O subsystem state of the associated processes. It is refcounted |
| 45 | * and kmalloc'ed. These could be shared between processes. |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 46 | */ |
| 47 | struct io_context { |
Nikanth Karthikesan | d9c7d39 | 2009-06-10 12:57:06 -0700 | [diff] [blame] | 48 | atomic_long_t refcount; |
Jens Axboe | d38ecf9 | 2008-01-24 08:53:35 +0100 | [diff] [blame] | 49 | atomic_t nr_tasks; |
| 50 | |
| 51 | /* all the fields below are protected by this lock */ |
| 52 | spinlock_t lock; |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 53 | |
| 54 | unsigned short ioprio; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 55 | |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 56 | /* |
| 57 | * For request batching |
| 58 | */ |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 59 | int nr_batch_requests; /* Number of requests left in the batch */ |
Richard Kennedy | 58c24a6 | 2010-02-26 14:00:43 +0100 | [diff] [blame] | 60 | unsigned long last_waited; /* Time last woken after wait for request */ |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 61 | |
Jens Axboe | 4ac845a | 2008-01-24 08:44:49 +0100 | [diff] [blame] | 62 | struct radix_tree_root radix_root; |
Jens Axboe | ffc4e75 | 2008-02-19 10:02:29 +0100 | [diff] [blame] | 63 | struct hlist_head cic_list; |
Arnd Bergmann | 4d2deb4 | 2010-02-24 20:01:56 +0100 | [diff] [blame] | 64 | void __rcu *ioc_data; |
Tejun Heo | b2efa05 | 2011-12-14 00:33:39 +0100 | [diff] [blame^] | 65 | |
| 66 | struct work_struct release_work; |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 67 | }; |
| 68 | |
Jens Axboe | d38ecf9 | 2008-01-24 08:53:35 +0100 | [diff] [blame] | 69 | static inline struct io_context *ioc_task_link(struct io_context *ioc) |
| 70 | { |
| 71 | /* |
| 72 | * if ref count is zero, don't allow sharing (ioc is going away, it's |
| 73 | * a race). |
| 74 | */ |
Nikanth Karthikesan | d9c7d39 | 2009-06-10 12:57:06 -0700 | [diff] [blame] | 75 | if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) { |
Li Zefan | cbb4f26 | 2009-07-31 08:55:48 +0200 | [diff] [blame] | 76 | atomic_inc(&ioc->nr_tasks); |
Jens Axboe | d38ecf9 | 2008-01-24 08:53:35 +0100 | [diff] [blame] | 77 | return ioc; |
Jens Axboe | d237e5c | 2008-04-15 09:25:33 +0200 | [diff] [blame] | 78 | } |
Jens Axboe | d38ecf9 | 2008-01-24 08:53:35 +0100 | [diff] [blame] | 79 | |
| 80 | return NULL; |
| 81 | } |
| 82 | |
Louis Rilling | b69f229 | 2009-12-04 14:52:42 +0100 | [diff] [blame] | 83 | struct task_struct; |
Jens Axboe | da9cbc8 | 2008-06-30 20:42:08 +0200 | [diff] [blame] | 84 | #ifdef CONFIG_BLOCK |
Tejun Heo | b2efa05 | 2011-12-14 00:33:39 +0100 | [diff] [blame^] | 85 | 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] | 86 | void exit_io_context(struct task_struct *task); |
Tejun Heo | 6e736be | 2011-12-14 00:33:38 +0100 | [diff] [blame] | 87 | struct io_context *get_task_io_context(struct task_struct *task, |
| 88 | gfp_t gfp_flags, int node); |
Tejun Heo | dc86900 | 2011-12-14 00:33:38 +0100 | [diff] [blame] | 89 | void ioc_ioprio_changed(struct io_context *ioc, int ioprio); |
| 90 | void ioc_cgroup_changed(struct io_context *ioc); |
Jens Axboe | da9cbc8 | 2008-06-30 20:42:08 +0200 | [diff] [blame] | 91 | #else |
Jens Axboe | da9cbc8 | 2008-06-30 20:42:08 +0200 | [diff] [blame] | 92 | struct io_context; |
Tejun Heo | b2efa05 | 2011-12-14 00:33:39 +0100 | [diff] [blame^] | 93 | static inline void put_io_context(struct io_context *ioc, |
| 94 | struct request_queue *locked_q) { } |
Tejun Heo | 42ec57a | 2011-12-14 00:33:37 +0100 | [diff] [blame] | 95 | static inline void exit_io_context(struct task_struct *task) { } |
Jens Axboe | da9cbc8 | 2008-06-30 20:42:08 +0200 | [diff] [blame] | 96 | #endif |
| 97 | |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 98 | #endif |