casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HostInfoOsf1.h
Go to the documentation of this file.
1 //# HostInfo_osf1.h: DEC OSF/1 specific memory, swap, and CPU code.
2 //# $Id$
3 
4  /*
5  ** This is a greatly MODIFIED version of a "top" machine dependent file.
6  ** The only resemblance it bears to the original is with respect to the
7  ** mechanics of finding various system details. The copyright details
8  ** follow.
9  **
10  ** --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
11  **
12  ** Top users/processes display for Unix
13  ** Version 3
14  **
15  ** This program may be freely redistributed,
16  ** but this entire comment MUST remain intact.
17  **
18  ** Copyright (c) 1984, 1989, William LeFebvre, Rice University
19  ** Copyright (c) 1989 - 1994, William LeFebvre, Northwestern University
20  ** Copyright (c) 1994, 1995, William LeFebvre, Argonne National Laboratory
21  ** Copyright (c) 1996, William LeFebvre, Group sys Consulting
22  ** Copyright (c) 2002, Associated Universities Inc.
23  */
24 
25 /*
26  * LIBS: -lmach -lpset
27  *
28  * AUTHOR: Darrell Schiebel <drs@nrao.edu>
29  *
30  * ORIGINAL AUTHOR: Anthony Baxter <anthony@aaii.oz.au>
31  * ORIGINAL CONTRIBUTORS: David S. Comay <dsc@seismo.css.gov>
32  * Claus Kalle
33  * Pat Welch <tpw@physics.orst.edu>
34  * William LeFebvre <lefebvre@dis.anl.gov>
35  * Rainer Orth <ro@techfak.uni-bielefeld.de>
36  */
37 
38 #ifndef CASA_HOSTINFOOSF1_H
39 #define CASA_HOSTINFOOSF1_H
40 
41 # if defined(HOSTINFO_DO_IMPLEMENT)
42 
43 //
44 //--> /usr/include/mach/mach_interface.h:297: <-
45 //--> previous declaration of `int vm_statistics(long int, struct vm_statistics *)' with C++ linkage <-
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 
62 namespace 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 
84 extern "C" kern_return_t host_info(int, int, host_info_t, unsigned int *);
85 extern "C" int host_self( );
86 extern "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 
95 class 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 
117 
118 HostMachineInfo::HostMachineInfo( ) : valid(1) {
119 
120  int i = 0;
121  int pagesize;
122  struct tbl_sysinfo sibuf;
123 
124  kern_return_t ret;
125  struct host_basic_info basic_info;
126  unsigned int count = HOST_BASIC_INFO_COUNT;
127 
128  /* get the page size with "getpagesize" and calculate pageshift from it */
129  pagesize = getpagesize();
130  pageshift = 0;
131  while (pagesize > 1)
132  {
133  pageshift++;
134  pagesize >>= 1;
135  }
136 
137  /* we only need the amount of log(2)1024 for our conversion */
138  pageshift -= LOG1024;
139 
140  ret = host_info( host_self(), HOST_BASIC_INFO, (host_info_t) &basic_info, &count );
141  if ( ret != KERN_SUCCESS ) {
142  valid = 0;
143  } else {
144  memory_total = basic_info.memory_size / 1024;
145  cpus = basic_info.avail_cpus;
146  }
147 }
148 
149 void HostMachineInfo::update_info( ) {
150 
151  struct tbl_swapinfo swbuf;
152  vm_statistics_data_t vmstats;
153  int swappages=0,swapfree=0,i;
154 
155  /* memory information */
156  /* this is possibly bogus - we work out total # pages by */
157  /* adding up the free, active, inactive, wired down, and */
158  /* zero filled. Anyone who knows a better way, TELL ME! */
159  /* Change: dont use zero filled. */
160  (void) vm_statistics(task_self(),&vmstats);
161 
162  /* thanks DEC for the table() command. No thanks at all for */
163  /* omitting the man page for it from OSF/1 1.2, and failing */
164  /* to document SWAPINFO in the 1.3 man page. Lets hear it for */
165  /* include files. */
166  i=0;
167  while(table(TBL_SWAPINFO,i,&swbuf,1,sizeof(struct tbl_swapinfo))>0) {
168  swappages += swbuf.size;
169  swapfree += swbuf.free;
170  i++;
171  }
172 
173  swap_total = pagetok(swappages);
174  swap_used = pagetok(swappages - swapfree);
175  swap_free = pagetok(swapfree);
176 
177  memory_free = pagetok(vmstats.free_count);
178  memory_used = memory_total - memory_free;
179 // some memory is left unaccounted for, using the following...
180 // memory_used = pagetok(vmstats.active_count + vmstats.inactive_count + vmstats.wire_count);
181 }
182 
183 # endif
184 
185 } //# NAMESPACE CASACORE - END
186 
187 #endif
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42