2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
8 #include <aros/config.h>
9 #include <exec/execbase.h>
10 #include <proto/arossupport.h>
11 #include <proto/exec.h>
12 #include <utility/tagitem.h>
16 #include <kernel_base.h>
17 #include <kernel_mm.h>
19 /*****************************************************************************
22 #include <proto/kernel.h>
24 AROS_LH2(ULONG
, KrnStatMemoryA
,
27 AROS_LHA(ULONG
, flags
, D0
),
28 AROS_LHA(struct TagItem
*, query
, A0
),
31 struct KernelBase
*, KernelBase
, 32, Kernel
)
34 Get various statistics about memory usage
37 query - An array of TagItems containing query specification. Each
38 TagItem consists of tag ID and a pointer to a value of
39 specified type which will contain the result of the query.
41 Available tag IDs are:
43 KMS_Free (IPTR) - Get amount of free memory in bytes
44 KMS_Total (IPTR) - Get total amount of memory in bytes
45 KMS_LargestAlloc (IPTR) - Get size of the largest allocated chunk in bytes
46 KMS_SmallestAlloc (IPTR) - Get size of the smallest allocated chunk in bytes
47 KMS_LargestFree (IPTR) - Get size of the largest free chunk in bytes
48 KMS_SmallestFree (IPTR) - Get size of the smallest free chunk in bytes
49 KMS_NumAlloc (IPTR) - Get number of allocated chunks
50 KMS_NumFree (IPTR) - Get number of free chunks
51 KMS_PageSize (ULONG) - Get memory page size
53 flags - Flags which specify physical properties of the memory to query.
54 These are the same flags as passed to exec.library/AllocMem().
57 TRUE if the function worked, FALSE if MMU is not up and running on the system.
58 If the function returns FALSE, values will stay uninitialized.
61 For all unknown tag IDs result values will be set to 0.
71 ******************************************************************************/
76 if (KernelBase
->kb_PageSize
)
78 struct TagItem
*tag
, *tstate
= query
;
80 BOOL do_traverse
= FALSE
;
82 while ((tag
= LibNextTagItem(&tstate
)))
87 *((ULONG
*)tag
->ti_Data
) = KernelBase
->kb_PageSize
;
91 /* Initialize all accumulated values to zero */
92 *((IPTR
*)tag
->ti_Data
) = 0;
97 /* If we needed only page size, just return */
101 /* Leave only flags that describe physical properties of the memory */
102 flags
&= MEMF_PHYSICAL_MASK
;
105 * Loop over MemHeader structures.
106 * We only add MemHeaders and never remove them, so i hope Forbid()/Permit()
107 * is not really necessary here.
109 ForeachNode(&SysBase
->MemList
, mh
)
112 * Check for the right requirements and enough free memory.
113 * The requirements are OK if there's no bit in the
114 * 'flags' that isn't set in the 'mh->mh_Attributes'.
116 if (flags
& ~mh
->mh_Attributes
)
119 /* Get statistics. Total values will be summed up. */
120 mm_StatMemHeader(mh
, query
, KernelBase
);