Both 'ps' and the loadav calculations got broken by thread sleeps, which
[dragonfly.git] / sys / sys / msfbuf.h
1 /*-
2  * Copyright (c) 2004 Matthew Dillon <dillon@backplane.com>.
3  * Copyright (c) 2004 Hiten Pandya <hmp@backplane.com>.
4  *
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
23  * COPYRIGHT HOLDERS, CONTRIBUTORS OR VOICES IN THE AUTHOR'S HEAD
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY
25  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * The MSF_BUF API is an augmentation similar to the SFBUF APIs and uses XIO
33  * page array handling.  The SFBUF API originally came from:
34  *
35  *      Copyright (c) 2003 Alan L. Cox <alc@cs.rice.edu>.  All rights reserved.
36  *      Copyright (c) 1998 David Greenman.  All rights reserved.
37  *      src/sys/sys/sfbuf.h,v 1.4 2004/04/01 17:58:06 dillon
38  *
39  * $DragonFly: src/sys/sys/msfbuf.h,v 1.3 2004/06/08 02:41:41 hmp Exp $
40  */
41 #ifndef _SYS_MSFBUF_H_
42 #define _SYS_MSFBUF_H_
43
44 #ifndef _SYS_QUEUE_H_
45 #include <sys/queue.h>
46 #endif
47
48 #ifndef _SYS_XIO_H_
49 #include <sys/xio.h>
50 #endif
51
52 /*
53  * MSF_BUFs are used for caching ephermal mappings that span more than
54  * one page.
55  *
56  * The interface returns an msf_buf data structure which has information
57  * about managing the ephermal mapping, its KVA pointer and an embedded
58  * XIO structure which describes the mapping.
59  *
60  * The embedded XIO structure be passed around to the DEV system because
61  * it is ref-counted; thus making it perfectly usable by anything that
62  * can accept an XIO as a transfer unit, most notably the buffer-cache
63  * and the XIO API.
64  *
65  */
66
67 struct msf_buf {
68         LIST_ENTRY(msf_buf)  active_list; /* active list of buffers */
69         TAILQ_ENTRY(msf_buf) free_list;   /* free list of buffers */
70         vm_offset_t     m_kva;                /* KVA offset */
71         cpumask_t       m_cpumask;            /* CPU mask for synchronization */
72         struct xio      m_xio;                /* xio embedded */
73         int             m_refcnt;             /* map usage tracking */
74         int             m_flags;              /* control flags */
75 };
76
77 #if defined(_KERNEL)
78
79 /*
80  * Return a KVA offset to the client
81  */
82 static __inline
83 vm_offset_t
84 msf_buf_kva(struct msf_buf *msf)
85 {
86         return (msf->m_kva);
87 }
88
89 /*
90  * Return a reference to the underlying pages of an MSF_BUF
91  */
92 static __inline
93 vm_page_t *
94 msf_buf_pages(struct msf_buf *msf)
95 {
96         return (msf->m_xio.xio_pages);
97 }
98
99 /* API function prototypes */
100 struct msf_buf  *msf_buf_alloc(vm_page_t *pg_ary, int npages, int flags);
101 void             msf_buf_free(struct msf_buf *);
102 void             msf_buf_ref(struct msf_buf *);
103
104 #endif /* _KERNEL */
105
106 #endif