1 #include <aros/config.h>
2 #include <exec/execbase.h>
3 #include <proto/arossupport.h>
4 #include <proto/exec.h>
5 #include <utility/tagitem.h>
9 #include <kernel_base.h>
10 #include <kernel_mm.h>
12 /*****************************************************************************
15 #include <proto/kernel.h>
17 AROS_LH2(ULONG
, KrnStatMemoryA
,
20 AROS_LHA(ULONG
, flags
, D0
),
21 AROS_LHA(struct TagItem
*, query
, A0
),
24 struct KernelBase
*, KernelBase
, 32, Kernel
)
27 Get various statistics about memory usage
30 query - An array of TagItems containing query specification. Each
31 TagItem consists of tag ID and a pointer to a value of
32 specified type which will contain the result of the query.
34 Available tag IDs are:
36 KMS_Free (IPTR) - Get amount of free memory in bytes
37 KMS_Total (IPTR) - Get total amount of memory in bytes
38 KMS_LargestAlloc (IPTR) - Get size of the largest allocated chunk in bytes
39 KMS_SmallestAlloc (IPTR) - Get size of the smallest allocated chunk in bytes
40 KMS_LargestFree (IPTR) - Get size of the largest free chunk in bytes
41 KMS_SmallestFree (IPTR) - Get size of the smallest free chunk in bytes
42 KMS_NumAlloc (IPTR) - Get number of allocated chunks
43 KMS_NumFree (IPTR) - Get number of free chunks
44 KMS_PageSize (ULONG) - Get memory page size
46 flags - Flags which specify physical properties of the memory to query.
47 These are the same flags as passed to exec.library/AllocMem().
50 TRUE if the function worked, FALSE if MMU is not up and running on the system.
51 If the function returns FALSE, values will stay uninitialized.
54 For all unknown tag IDs result values will be set to 0.
64 ******************************************************************************/
69 if (KernelBase
->kb_PageSize
)
71 const struct TagItem
*tstate
= query
;
74 BOOL do_traverse
= FALSE
;
76 while ((tag
= LibNextTagItem(&tstate
)))
81 *((ULONG
*)tag
->ti_Data
) = KernelBase
->kb_PageSize
;
85 /* Initialize all accumulated values to zero */
86 *((IPTR
*)tag
->ti_Data
) = 0;
91 /* If we needed only page size, just return */
95 /* Leave only flags that describe physical properties of the memory */
96 flags
&= MEMF_PHYSICAL_MASK
;
99 * Loop over MemHeader structures.
100 * We only add MemHeaders and never remove them, so i hope Forbid()/Permit()
101 * is not really necessary here.
103 ForeachNode(&SysBase
->MemList
, mh
)
106 * Check for the right requirements and enough free memory.
107 * The requirements are OK if there's no bit in the
108 * 'flags' that isn't set in the 'mh->mh_Attributes'.
110 if (flags
& ~mh
->mh_Attributes
)
113 /* Get statistics. Total values will be summed up. */
114 mm_StatMemHeader(mh
, query
, KernelBase
);