2 * This is memory_tru64.cpp to retrieve memory information under Tru64/Alpha.
4 * Implemented by Tom Leitner, Tom@radar.tu-graz.ac.at
6 * WARNING: This module requires linking with -lmach
8 * This routine is based on m_decosf1.c from the "top" program written by:
10 * AUTHOR: Anthony Baxter, <anthony@aaii.oz.au>
16 #include <sys/socket.h>
18 #include <net/route.h>
19 #include <sys/table.h>
21 #include <mach/mach_traps.h>
23 #include <mach/vm_statistics.h>
25 #define pagetob(size) (MEMORY(1024L) * ((long) (size) << (long) pageshift))
28 extern "C" void vm_statistics(task_t
, vm_statistics_data_t
*);
30 void KCMMemory::fetchValues()
32 int pageshift
; /* log base 2 of the pagesize */
33 register int pagesize
;
34 vm_statistics_data_t vmstats
;
35 int swap_pages
=0,swap_free
=0,i
;
36 struct tbl_swapinfo swbuf
;
38 /* get the page size with "getpagesize" and calculate pageshift from it */
40 pagesize
= getpagesize();
42 while (pagesize
> 1) {
47 /* we only need the amount of log(2)1024 for our conversion */
51 /* memory information */
52 /* this is possibly bogus - we work out total # pages by */
53 /* adding up the free, active, inactive, wired down, and */
54 /* zero filled. Anyone who knows a better way, TELL ME! */
55 /* Change: don't use zero filled. */
57 (void) ::vm_statistics(::task_self(), &vmstats
);
59 /* thanks DEC for the table() command. No thanks at all for */
60 /* omitting the man page for it from OSF/1 1.2, and failing */
61 /* to document SWAPINFO in the 1.3 man page. Lets hear it for */
65 while(table(TBL_SWAPINFO
,i
,&swbuf
,1,sizeof(struct tbl_swapinfo
))>0) {
66 swap_pages
+= swbuf
.size
;
67 swap_free
+= swbuf
.free
;
70 memoryInfos
[TOTAL_MEM
] = pagetob((vmstats
.free_count
+
71 vmstats
.active_count
+
72 vmstats
.inactive_count
+
74 memoryInfos
[FREE_MEM
] = pagetob(vmstats
.free_count
);
75 memoryInfos
[SHARED_MEM
] = NO_MEMORY_INFO
; /* FIXME ?? */
76 memoryInfos
[BUFFER_MEM
] = NO_MEMORY_INFO
; /* FIXME ?? */
78 #warning "FIXME: memoryInfos[CACHED_MEM]"
80 memoryInfos
[CACHED_MEM
] = NO_MEMORY_INFO
; /* cached memory in ram */
81 memoryInfos
[SWAP_MEM
] = pagetob(swap_pages
);
82 memoryInfos
[FREESWAP_MEM
] = pagetob(swap_free
);