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