sched.h 8.4 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * linux/include/linux/sunrpc/sched.h
 *
 * Scheduling primitives for kernel Sun RPC.
 *
 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
 */

#ifndef _LINUX_SUNRPC_SCHED_H_
#define _LINUX_SUNRPC_SCHED_H_

#include <linux/timer.h>
13
#include <linux/ktime.h>
L
Linus Torvalds 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#include <linux/sunrpc/types.h>
#include <linux/spinlock.h>
#include <linux/wait.h>
#include <linux/workqueue.h>
#include <linux/sunrpc/xdr.h>

/*
 * This is the actual RPC procedure call info.
 */
struct rpc_procinfo;
struct rpc_message {
	struct rpc_procinfo *	rpc_proc;	/* Procedure information */
	void *			rpc_argp;	/* Arguments */
	void *			rpc_resp;	/* Result */
	struct rpc_cred *	rpc_cred;	/* Credentials */
};

31
struct rpc_call_ops;
L
Linus Torvalds 已提交
32 33 34 35
struct rpc_wait_queue;
struct rpc_wait {
	struct list_head	list;		/* wait queue links */
	struct list_head	links;		/* Links to related tasks */
36 37
	struct list_head	timer_list;	/* Timer list */
	unsigned long		expires;
L
Linus Torvalds 已提交
38 39 40 41 42 43 44 45 46
};

/*
 * This is the RPC task struct
 */
struct rpc_task {
#ifdef RPC_DEBUG
	unsigned long		tk_magic;	/* 0xf00baa */
#endif
47
	atomic_t		tk_count;	/* Reference count */
L
Linus Torvalds 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
	struct list_head	tk_task;	/* global list of tasks */
	struct rpc_clnt *	tk_client;	/* RPC client */
	struct rpc_rqst *	tk_rqstp;	/* RPC request */
	int			tk_status;	/* result of last operation */

	/*
	 * RPC call state
	 */
	struct rpc_message	tk_msg;		/* RPC call info */
	__u8			tk_garb_retry;
	__u8			tk_cred_retry;

	/*
	 * callback	to be executed after waking up
	 * action	next procedure for async tasks
63
	 * tk_ops	caller callbacks
L
Linus Torvalds 已提交
64 65 66
	 */
	void			(*tk_callback)(struct rpc_task *);
	void			(*tk_action)(struct rpc_task *);
67
	const struct rpc_call_ops *tk_ops;
L
Linus Torvalds 已提交
68 69 70 71 72 73 74 75
	void *			tk_calldata;

	unsigned long		tk_timeout;	/* timeout for rpc_sleep() */
	unsigned short		tk_flags;	/* misc flags */
	unsigned long		tk_runstate;	/* Task run status */
	struct workqueue_struct	*tk_workqueue;	/* Normally rpciod, but could
						 * be any workqueue
						 */
76
	struct rpc_wait_queue 	*tk_waitqueue;	/* RPC wait queue we're on */
L
Linus Torvalds 已提交
77 78 79 80
	union {
		struct work_struct	tk_work;	/* Async task work queue */
		struct rpc_wait		tk_wait;	/* RPC wait */
	} u;
81 82 83

	unsigned short		tk_timeouts;	/* maj timeouts */
	size_t			tk_bytes_sent;	/* total bytes sent */
84 85
	ktime_t			tk_start,	/* RPC task init timestamp */
				tk_rtt;		/* round-trip time */
86

87 88 89
	pid_t			tk_owner;	/* Process id for batching tasks */
	unsigned char		tk_priority : 2;/* Task priority */

L
Linus Torvalds 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
#ifdef RPC_DEBUG
	unsigned short		tk_pid;		/* debugging aid */
#endif
};
#define tk_xprt			tk_client->cl_xprt

/* support walking a list of tasks on a wait queue */
#define	task_for_each(task, pos, head) \
	list_for_each(pos, head) \
		if ((task=list_entry(pos, struct rpc_task, u.tk_wait.list)),1)

#define	task_for_first(task, head) \
	if (!list_empty(head) &&  \
	    ((task=list_entry((head)->next, struct rpc_task, u.tk_wait.list)),1))

typedef void			(*rpc_action)(struct rpc_task *);

107
struct rpc_call_ops {
T
Trond Myklebust 已提交
108
	void (*rpc_call_prepare)(struct rpc_task *, void *);
109 110 111 112
	void (*rpc_call_done)(struct rpc_task *, void *);
	void (*rpc_release)(void *);
};

113
struct rpc_task_setup {
114
	struct rpc_task *task;
115 116 117 118
	struct rpc_clnt *rpc_client;
	const struct rpc_message *rpc_message;
	const struct rpc_call_ops *callback_ops;
	void *callback_data;
119
	struct workqueue_struct *workqueue;
120
	unsigned short flags;
121
	signed char priority;
122
};
123

L
Linus Torvalds 已提交
124 125 126 127 128 129 130 131 132 133
/*
 * RPC task flags
 */
#define RPC_TASK_ASYNC		0x0001		/* is an async task */
#define RPC_TASK_SWAPPER	0x0002		/* is swapping in/out */
#define RPC_CALL_MAJORSEEN	0x0020		/* major timeout seen */
#define RPC_TASK_ROOTCREDS	0x0040		/* force root creds */
#define RPC_TASK_DYNAMIC	0x0080		/* task was kmalloc'ed */
#define RPC_TASK_KILLED		0x0100		/* task was killed */
#define RPC_TASK_SOFT		0x0200		/* Use soft timeouts */
134
#define RPC_TASK_SOFTCONN	0x0400		/* Fail if can't connect */
L
Linus Torvalds 已提交
135 136 137 138 139 140

#define RPC_IS_ASYNC(t)		((t)->tk_flags & RPC_TASK_ASYNC)
#define RPC_IS_SWAPPER(t)	((t)->tk_flags & RPC_TASK_SWAPPER)
#define RPC_DO_ROOTOVERRIDE(t)	((t)->tk_flags & RPC_TASK_ROOTCREDS)
#define RPC_ASSASSINATED(t)	((t)->tk_flags & RPC_TASK_KILLED)
#define RPC_IS_SOFT(t)		((t)->tk_flags & RPC_TASK_SOFT)
141
#define RPC_IS_SOFTCONN(t)	((t)->tk_flags & RPC_TASK_SOFTCONN)
L
Linus Torvalds 已提交
142 143 144

#define RPC_TASK_RUNNING	0
#define RPC_TASK_QUEUED		1
145
#define RPC_TASK_ACTIVE		2
L
Linus Torvalds 已提交
146

147 148
#define RPC_IS_RUNNING(t)	test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
#define rpc_set_running(t)	set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
L
Linus Torvalds 已提交
149
#define rpc_test_and_set_running(t) \
150
				test_and_set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
L
Linus Torvalds 已提交
151 152 153 154 155 156 157
#define rpc_clear_running(t)	\
	do { \
		smp_mb__before_clear_bit(); \
		clear_bit(RPC_TASK_RUNNING, &(t)->tk_runstate); \
		smp_mb__after_clear_bit(); \
	} while (0)

158 159
#define RPC_IS_QUEUED(t)	test_bit(RPC_TASK_QUEUED, &(t)->tk_runstate)
#define rpc_set_queued(t)	set_bit(RPC_TASK_QUEUED, &(t)->tk_runstate)
L
Linus Torvalds 已提交
160 161 162 163 164 165 166
#define rpc_clear_queued(t)	\
	do { \
		smp_mb__before_clear_bit(); \
		clear_bit(RPC_TASK_QUEUED, &(t)->tk_runstate); \
		smp_mb__after_clear_bit(); \
	} while (0)

167
#define RPC_IS_ACTIVATED(t)	test_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate)
168

L
Linus Torvalds 已提交
169 170 171 172 173
/*
 * Task priorities.
 * Note: if you change these, you must also change
 * the task initialization definitions below.
 */
174 175 176
#define RPC_PRIORITY_LOW	(-1)
#define RPC_PRIORITY_NORMAL	(0)
#define RPC_PRIORITY_HIGH	(1)
177 178
#define RPC_PRIORITY_PRIVILEGED	(2)
#define RPC_NR_PRIORITY		(1 + RPC_PRIORITY_PRIVILEGED - RPC_PRIORITY_LOW)
L
Linus Torvalds 已提交
179

180 181 182 183 184 185
struct rpc_timer {
	struct timer_list timer;
	struct list_head list;
	unsigned long expires;
};

L
Linus Torvalds 已提交
186 187 188 189 190 191
/*
 * RPC synchronization objects
 */
struct rpc_wait_queue {
	spinlock_t		lock;
	struct list_head	tasks[RPC_NR_PRIORITY];	/* task queue for each priority level */
192
	pid_t			owner;			/* process id of last task serviced */
L
Linus Torvalds 已提交
193 194 195 196
	unsigned char		maxpriority;		/* maximum priority (0 if queue is not a priority queue) */
	unsigned char		priority;		/* current priority */
	unsigned char		count;			/* # task groups remaining serviced so far */
	unsigned char		nr;			/* # tasks remaining for cookie */
197
	unsigned short		qlen;			/* total # tasks waiting in queue */
198
	struct rpc_timer	timer_list;
L
Linus Torvalds 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
#ifdef RPC_DEBUG
	const char *		name;
#endif
};

/*
 * This is the # requests to send consecutively
 * from a single cookie.  The aim is to improve
 * performance of NFS operations such as read/write.
 */
#define RPC_BATCH_COUNT			16
#define RPC_IS_PRIORITY(q)		((q)->maxpriority > 0)

/*
 * Function prototypes
 */
215
struct rpc_task *rpc_new_task(const struct rpc_task_setup *);
T
Trond Myklebust 已提交
216
struct rpc_task *rpc_run_task(const struct rpc_task_setup *);
217 218
struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req,
				const struct rpc_call_ops *ops);
219
void		rpc_put_task(struct rpc_task *);
T
Trond Myklebust 已提交
220
void		rpc_exit_task(struct rpc_task *);
221
void		rpc_release_calldata(const struct rpc_call_ops *, void *);
L
Linus Torvalds 已提交
222
void		rpc_killall_tasks(struct rpc_clnt *);
T
Trond Myklebust 已提交
223
void		rpc_execute(struct rpc_task *);
L
Linus Torvalds 已提交
224 225
void		rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *);
void		rpc_init_wait_queue(struct rpc_wait_queue *, const char *);
226
void		rpc_destroy_wait_queue(struct rpc_wait_queue *);
L
Linus Torvalds 已提交
227
void		rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *,
228
					rpc_action action);
229 230
void		rpc_wake_up_queued_task(struct rpc_wait_queue *,
					struct rpc_task *);
L
Linus Torvalds 已提交
231 232 233
void		rpc_wake_up(struct rpc_wait_queue *);
struct rpc_task *rpc_wake_up_next(struct rpc_wait_queue *);
void		rpc_wake_up_status(struct rpc_wait_queue *, int);
234
int		rpc_queue_empty(struct rpc_wait_queue *);
L
Linus Torvalds 已提交
235 236
void		rpc_delay(struct rpc_task *, unsigned long);
void *		rpc_malloc(struct rpc_task *, size_t);
237
void		rpc_free(void *);
L
Linus Torvalds 已提交
238 239
int		rpciod_up(void);
void		rpciod_down(void);
240
int		__rpc_wait_for_completion_task(struct rpc_task *task, int (*)(void *));
L
Linus Torvalds 已提交
241 242 243 244 245
#ifdef RPC_DEBUG
void		rpc_show_tasks(void);
#endif
int		rpc_init_mempool(void);
void		rpc_destroy_mempool(void);
246
extern struct workqueue_struct *rpciod_workqueue;
247
void		rpc_prepare_task(struct rpc_task *task);
L
Linus Torvalds 已提交
248 249 250 251

static inline void rpc_exit(struct rpc_task *task, int status)
{
	task->tk_status = status;
T
Trond Myklebust 已提交
252
	task->tk_action = rpc_exit_task;
L
Linus Torvalds 已提交
253 254
}

255 256 257 258 259
static inline int rpc_wait_for_completion_task(struct rpc_task *task)
{
	return __rpc_wait_for_completion_task(task, NULL);
}

260 261 262 263 264 265 266 267 268 269
static inline void rpc_task_set_priority(struct rpc_task *task, unsigned char prio)
{
	task->tk_priority = prio - RPC_PRIORITY_LOW;
}

static inline int rpc_task_has_priority(struct rpc_task *task, unsigned char prio)
{
	return (task->tk_priority + RPC_PRIORITY_LOW == prio);
}

L
Linus Torvalds 已提交
270 271 272 273 274 275 276 277
#ifdef RPC_DEBUG
static inline const char * rpc_qname(struct rpc_wait_queue *q)
{
	return ((q && q->name) ? q->name : "unknown");
}
#endif

#endif /* _LINUX_SUNRPC_SCHED_H_ */