xref: /openbmc/linux/include/linux/iocontext.h (revision 171f1bc7)
1 #ifndef IOCONTEXT_H
2 #define IOCONTEXT_H
3 
4 #include <linux/radix-tree.h>
5 #include <linux/rcupdate.h>
6 
7 struct cfq_queue;
8 struct cfq_ttime {
9 	unsigned long last_end_request;
10 
11 	unsigned long ttime_total;
12 	unsigned long ttime_samples;
13 	unsigned long ttime_mean;
14 };
15 
16 struct cfq_io_context {
17 	void *key;
18 
19 	struct cfq_queue *cfqq[2];
20 
21 	struct io_context *ioc;
22 
23 	struct cfq_ttime ttime;
24 
25 	struct list_head queue_list;
26 	struct hlist_node cic_list;
27 
28 	void (*dtor)(struct io_context *); /* destructor */
29 	void (*exit)(struct io_context *); /* called on task exit */
30 
31 	struct rcu_head rcu_head;
32 };
33 
34 /*
35  * I/O subsystem state of the associated processes.  It is refcounted
36  * and kmalloc'ed. These could be shared between processes.
37  */
38 struct io_context {
39 	atomic_long_t refcount;
40 	atomic_t nr_tasks;
41 
42 	/* all the fields below are protected by this lock */
43 	spinlock_t lock;
44 
45 	unsigned short ioprio;
46 	unsigned short ioprio_changed;
47 
48 #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
49 	unsigned short cgroup_changed;
50 #endif
51 
52 	/*
53 	 * For request batching
54 	 */
55 	int nr_batch_requests;     /* Number of requests left in the batch */
56 	unsigned long last_waited; /* Time last woken after wait for request */
57 
58 	struct radix_tree_root radix_root;
59 	struct hlist_head cic_list;
60 	void __rcu *ioc_data;
61 };
62 
63 static inline struct io_context *ioc_task_link(struct io_context *ioc)
64 {
65 	/*
66 	 * if ref count is zero, don't allow sharing (ioc is going away, it's
67 	 * a race).
68 	 */
69 	if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) {
70 		atomic_inc(&ioc->nr_tasks);
71 		return ioc;
72 	}
73 
74 	return NULL;
75 }
76 
77 struct task_struct;
78 #ifdef CONFIG_BLOCK
79 int put_io_context(struct io_context *ioc);
80 void exit_io_context(struct task_struct *task);
81 struct io_context *get_io_context(gfp_t gfp_flags, int node);
82 struct io_context *alloc_io_context(gfp_t gfp_flags, int node);
83 #else
84 static inline void exit_io_context(struct task_struct *task)
85 {
86 }
87 
88 struct io_context;
89 static inline int put_io_context(struct io_context *ioc)
90 {
91 	return 1;
92 }
93 #endif
94 
95 #endif
96