casacore
Loading...
Searching...
No Matches
HostInfoOsf1.h
Go to the documentation of this file.
1// # HostInfo_osf1.h: DEC OSF/1 specific memory, swap, and CPU code.
2
3/*
4** This is a greatly MODIFIED version of a "top" machine dependent file.
5** The only resemblance it bears to the original is with respect to the
6** mechanics of finding various system details. The copyright details
7** follow.
8**
9** --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
10**
11** Top users/processes display for Unix
12** Version 3
13**
14** This program may be freely redistributed,
15** but this entire comment MUST remain intact.
16**
17** Copyright (c) 1984, 1989, William LeFebvre, Rice University
18** Copyright (c) 1989 - 1994, William LeFebvre, Northwestern University
19** Copyright (c) 1994, 1995, William LeFebvre, Argonne National Laboratory
20** Copyright (c) 1996, William LeFebvre, Group sys Consulting
21** Copyright (c) 2002, Associated Universities Inc.
22*/
23
24/*
25 * LIBS: -lmach -lpset
26 *
27 * AUTHOR: Darrell Schiebel <drs@nrao.edu>
28 *
29 * ORIGINAL AUTHOR: Anthony Baxter <anthony@aaii.oz.au>
30 * ORIGINAL CONTRIBUTORS: David S. Comay <dsc@seismo.css.gov>
31 * Claus Kalle
32 * Pat Welch <tpw@physics.orst.edu>
33 * William LeFebvre <lefebvre@dis.anl.gov>
34 * Rainer Orth <ro@techfak.uni-bielefeld.de>
35 */
36
37#ifndef CASA_HOSTINFOOSF1_H
38#define CASA_HOSTINFOOSF1_H
39
40#if defined(HOSTINFO_DO_IMPLEMENT)
41
42//
43//--> /usr/include/mach/mach_interface.h:297: <-
44//--> previous declaration of `int vm_statistics(long int, struct vm_statistics *)' with C++ linkage
45//<-
46//
47// so, we hack this by defining _mach to kick <mach/mach_interface.h> out of inclusion,
48// and then below we make this extern "C"... likely this is fixed in some version of
49// DEC OSF/1 which is newer than what we have...
50//
51#define _mach
52
53#include <stdio.h>
54
55#include <unistd.h>
56#include <mach.h>
57#include <mach/mach_types.h>
58#include <mach/vm_statistics.h>
59#include <mach/host_info.h>
60#include <sys/table.h>
61
62namespace casacore { // # NAMESPACE CASACORE - BEGIN
63
64// <summary>
65// HostInfo for OSF1 machines.
66// </summary>
67
68// <use visibility=local>
69
70// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
71// </reviewed>
72
73// <prerequisite>
74// <li> <linkto class=HostInfo>HostInfo</linkto>
75// </prerequisite>
76
77// <synopsis>
78// This file provides the OSF1 specific functions for HostInfo.
79// It is selectively included by HostInfo.cc.
80// </synopsis>
81//
82// <group name="HostInfo">
83
84extern "C" kern_return_t host_info(int, int, host_info_t, unsigned int *);
85extern "C" int host_self();
86extern "C" int vm_statistics(long, struct vm_statistics *);
87
88/* Log base 2 of 1024 is 10 (2^10 == 1024) */
89#define LOG1024 10
90
91/* these are for getting the memory statistics */
92/* define pagetok in terms of pageshift */
93#define pagetok(size) ((size) << pageshift)
94
95class HostMachineInfo {
96 friend class HostInfo;
97
98 HostMachineInfo();
99 void update_info();
100
101 int valid;
102 int cpus;
103
104 ptrdiff_t swap_total;
105 ptrdiff_t swap_used;
106 ptrdiff_t swap_free;
107
108 ptrdiff_t memory_total;
109 ptrdiff_t memory_used;
110 ptrdiff_t memory_free;
111
112 int pageshift; /* log base 2 of the pagesize */
113};
114
115// </group>
116
117HostMachineInfo::HostMachineInfo() : valid(1) {
118 int i = 0;
119 int pagesize;
120 struct tbl_sysinfo sibuf;
121
122 kern_return_t ret;
123 struct host_basic_info basic_info;
124 unsigned int count = HOST_BASIC_INFO_COUNT;
125
126 /* get the page size with "getpagesize" and calculate pageshift from it */
127 pagesize = getpagesize();
128 pageshift = 0;
129 while (pagesize > 1) {
130 pageshift++;
131 pagesize >>= 1;
132 }
133
134 /* we only need the amount of log(2)1024 for our conversion */
135 pageshift -= LOG1024;
136
137 ret = host_info(host_self(), HOST_BASIC_INFO, (host_info_t)&basic_info, &count);
138 if (ret != KERN_SUCCESS) {
139 valid = 0;
140 } else {
141 memory_total = basic_info.memory_size / 1024;
142 cpus = basic_info.avail_cpus;
143 }
144}
145
146void HostMachineInfo::update_info() {
147 struct tbl_swapinfo swbuf;
148 vm_statistics_data_t vmstats;
149 int swappages = 0, swapfree = 0, i;
150
151 /* memory information */
152 /* this is possibly bogus - we work out total # pages by */
153 /* adding up the free, active, inactive, wired down, and */
154 /* zero filled. Anyone who knows a better way, TELL ME! */
155 /* Change: dont use zero filled. */
156 (void)vm_statistics(task_self(), &vmstats);
157
158 /* thanks DEC for the table() command. No thanks at all for */
159 /* omitting the man page for it from OSF/1 1.2, and failing */
160 /* to document SWAPINFO in the 1.3 man page. Lets hear it for */
161 /* include files. */
162 i = 0;
163 while (table(TBL_SWAPINFO, i, &swbuf, 1, sizeof(struct tbl_swapinfo)) > 0) {
164 swappages += swbuf.size;
165 swapfree += swbuf.free;
166 i++;
167 }
168
169 swap_total = pagetok(swappages);
170 swap_used = pagetok(swappages - swapfree);
171 swap_free = pagetok(swapfree);
172
173 memory_free = pagetok(vmstats.free_count);
174 memory_used = memory_total - memory_free;
175 // some memory is left unaccounted for, using the following...
176 // memory_used = pagetok(vmstats.active_count + vmstats.inactive_count + vmstats.wire_count);
177}
178
179#endif
180
181} // # NAMESPACE CASACORE - END
182
183#endif
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28