casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HostInfoIrix.h
Go to the documentation of this file.
1 //# HostInfo_irix.h: SGI Irix 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 #ifndef CASA_HOSTINFOIRIX_H
26 #define CASA_HOSTINFOIRIX_H
27 
28 # if defined(HOSTINFO_DO_IMPLEMENT)
29 
30 /*
31  * AUTHOR: Darrell Schiebel <drs@nrao.edu>
32  *
33  * ORIGINAL AUTHORS: Sandeep Cariapa <cariapa@sgi.com>
34  * Larry McVoy <lm@sgi.com>
35  * John Schimmel <jes@sgi.com>
36  * Ariel Faigon <ariel@sgi.com>
37  */
38 
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <sys/types.h>
42 #include <unistd.h>
43 #include <sys/stat.h>
44 #include <sys/swap.h>
45 #include <sys/sysmp.h>
46 #include <sys/sysinfo.h>
47 
48 namespace casacore { //# NAMESPACE CASACORE - BEGIN
49 
50 // <summary>
51 // HostInfo for IRIX machines.
52 // </summary>
53 
54 // <use visibility=local>
55 
56 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
57 // </reviewed>
58 
59 // <prerequisite>
60 // <li> <linkto class=HostInfo>HostInfo</linkto>
61 // </prerequisite>
62 
63 // <synopsis>
64 // This file provides the IRIX specific functions for HostInfo.
65 // It is selectively included by HostInfo.cc.
66 // </synopsis>
67 //
68 // <group name="HostInfo">
69 
70 #define pagetok(pages) ((((uint64_t) pages) * pagesize) >> 10)
71 
72 class HostMachineInfo {
73 friend class HostInfo;
74 
75  HostMachineInfo( );
76  void update_info( );
77 
78  int valid;
79  int cpus;
80 
81  ptrdiff_t swap_total;
82  ptrdiff_t swap_used;
83  ptrdiff_t swap_free;
84 
85  ptrdiff_t memory_total;
86  ptrdiff_t memory_used;
87  ptrdiff_t memory_free;
88 
89  ptrdiff_t pagesize;
90 
91 };
92 
93 // </group>
94 
95 
96 HostMachineInfo::HostMachineInfo( ) : valid(1) {
97 
98  pagesize = getpagesize();
99 
100  if ((cpus = sysmp(MP_NPROCS)) == -1) {
101  perror("sysmp(MP_NPROCS)");
102  valid = 0;
103  return;
104  }
105 
106  struct rminfo realmem;
107  if (sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof(realmem)) == -1) {
108  perror("sysmp(MP_SAGET,MPSA_RMINFO, ...)");
109  valid = 0;
110  return;
111  }
112 
113  memory_total = pagetok(realmem.physmem);
114 }
115 
116 void HostMachineInfo::update_info( ) {
117  int i;
118  struct rminfo realmem;
119  struct sysinfo sysinfo;
120  off_t fswap; /* current free swap in blocks */
121  off_t tswap; /* total swap in blocks */
122 
123  swapctl(SC_GETFREESWAP, &fswap);
124  swapctl(SC_GETSWAPTOT, &tswap);
125 
126  if (sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof(realmem)) == -1) {
127  perror("sysmp(MP_SAGET,MPSA_RMINFO, ...)");
128  valid = 0;
129  return;
130  }
131 
132  memory_free = pagetok(realmem.freemem);
133  memory_used = memory_total - memory_free;
134  swap_total = tswap / 2;
135  swap_free = fswap / 2;
136  swap_used = swap_total - swap_free;
137 }
138 
139 # endif
140 
141 } //# NAMESPACE CASACORE - END
142 
143 #endif