Subject: Rewrite of buffer queue interface
To: None <tech-kern@netbsd.org>
From: Juergen Hannken-Illjes <hannken@eis.cs.tu-bs.de>
List: tech-kern
Date: 07/13/2002 15:19:26
The current device driver buffer queue management is not
very flexible. It assumes all requests are sorted on entry
and consumed from the head of a list.

This makes it impossible to use i/o scheduling strategies
that sort on consumption or maintain the queue in arrays or
multiple lists. I propose the following interface
that makes it easy to further experiment on this area.

A buf_queue gets initialised with `bufq_init', here the
put/get functions are initialized, the method private
part gets MALLOCed and initialized.

`BUFQ_PUT' puts a buffer into the queue.

`BUFQ_GET' gets (and removes) the next buffer from the queue.

`BUFQ_PEEK' gets (without removal) the next buffer from the queue.

All names are new so a driver-by-driver migration is possible.

All other `BUFQ_XXX' macros, `disksort_XXX' functions and the
`struct buf_queue' will be removed in the future (and don't
work with new queues).


Any functionality missing? Comments?

excerpt from new `sys/sys/buf.h':

/*
 * Device driver buffer queue.
 */
struct bufq_state {
	struct buf *(*bq_get)(struct  buf_queue *, int);
	void (*bq_put)(struct buf_queue *, struct buf *);
	int bq_flags;				/* flags from bufq_init() */
	void *bq_private;
};

#ifdef _KERNEL

#define BUFQ_SORT_RAWBLOCK	0x0001		/* sort by b_rawblkno */
#define BUFQ_SORT_CYLINDER	0x0002		/* sort by b_cylinder */

#define BUFQ_FCFS		0x0010		/* first-come first-serve */
#define BUFQ_DISKSORT		0x0020		/* min seek sort */
#define BUFQ_READ_PRIO		0x0030		/* min seek with read priority */

#define BUFQ_SORT_MASK		0x000f
#define BUFQ_METHOD_MASK	0xfff0

void	bufq_init(struct buf_queue *, int);

#define BUFQ_PUT(bufq, bp)	(*(bufq)->bq_put)((bufq), (bp))
#define BUFQ_GET(bufq)		(*(bufq)->bq_get)((bufq), 1)
#define BUFQ_PEEK(bufq)		(*(bufq)->bq_get)((bufq), 0)

#endif /* _KERNEL */


-- 
Juergen Hannken-Illjes - hannken@eis.cs.tu-bs.de - TU Braunschweig (Germany)