Reformatting and detab
[AROS.git] / rom / kernel / statmemory.c
blob65485ab682764d2005ddfc85ce304f6af354d470
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 const struct TagItem *tstate = query;
72 struct TagItem *tag;
73 struct MemHeader *mh;
74 BOOL do_traverse = FALSE;
76 while ((tag = LibNextTagItem(&tstate)))
78 switch (tag->ti_Tag)
80 case KMS_PageSize:
81 *((ULONG *)tag->ti_Data) = KernelBase->kb_PageSize;
82 break;
84 default:
85 /* Initialize all accumulated values to zero */
86 *((IPTR *)tag->ti_Data) = 0;
87 do_traverse = TRUE;
91 /* If we needed only page size, just return */
92 if (!do_traverse)
93 return TRUE;
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)
111 continue;
113 /* Get statistics. Total values will be summed up. */
114 mm_StatMemHeader(mh, query, KernelBase);
117 return TRUE;
119 #endif
120 return FALSE;
122 AROS_LIBFUNC_EXIT