Minor fixes to comments.
[AROS.git] / rom / kernel / statmemory.c
blob9f28b45bdfa7817a5c3fca5e2991e856c60e0a89
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>
7 #include <inttypes.h>
9 #include <kernel_base.h>
10 #include <kernel_mm.h>
12 /*****************************************************************************
14 NAME */
15 #include <proto/kernel.h>
17 AROS_LH2(ULONG, KrnStatMemoryA,
19 /* SYNOPSIS */
20 AROS_LHA(ULONG, flags, D0),
21 AROS_LHA(struct TagItem *, query, A0),
23 /* LOCATION */
24 struct KernelBase *, KernelBase, 32, Kernel)
26 /* FUNCTION
27 Get various statistics about memory usage
29 INPUTS
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().
49 RESULT
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.
53 NOTES
54 For all unknown tag IDs result values will be set to 0.
56 EXAMPLE
58 BUGS
60 SEE ALSO
62 INTERNALS
64 ******************************************************************************/
66 AROS_LIBFUNC_INIT
68 #if USE_MMU
69 if (KernelBase->kb_PageSize)
71 struct TagItem *tag, *tstate = query;
72 struct MemHeader *mh;
73 BOOL do_traverse = FALSE;
75 while ((tag = LibNextTagItem(&tstate)))
77 switch (tag->ti_Tag)
79 case KMS_PageSize:
80 *((ULONG *)tag->ti_Data) = KernelBase->kb_PageSize;
81 break;
83 default:
84 /* Initialize all accumulated values to zero */
85 *((IPTR *)tag->ti_Data) = 0;
86 do_traverse = TRUE;
90 /* If we needed only page size, just return */
91 if (!do_traverse)
92 return TRUE;
94 /* Leave only flags that describe physical properties of the memory */
95 flags &= MEMF_PHYSICAL_MASK;
98 * Loop over MemHeader structures.
99 * We only add MemHeaders and never remove them, so i hope Forbid()/Permit()
100 * is not really necessary here.
102 ForeachNode(&SysBase->MemList, mh)
105 * Check for the right requirements and enough free memory.
106 * The requirements are OK if there's no bit in the
107 * 'flags' that isn't set in the 'mh->mh_Attributes'.
109 if (flags & ~mh->mh_Attributes)
110 continue;
112 /* Get statistics. Total values will be summed up. */
113 mm_StatMemHeader(mh, query, KernelBase);
116 return TRUE;
118 #endif
119 return FALSE;
121 AROS_LIBFUNC_EXIT