summaryrefslogtreecommitdiffstats
path: root/kcontrol/info/memory_sgi.cpp
blob: 2bc0d0c655182290e85e6188838f64302a952e93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

#include <stdio.h>
#include <unistd.h>
#include <sys/sysmp.h>
#include <sys/ipc.h>

// The following define is needed for SGI IRIX 6.2
#define _KMEMUSER
#include <sys/shm.h>

#include <sys/param.h>
#include <sys/swap.h>

#ifndef UBSIZE
#define UBSIZE 512
#endif


void KMemoryWidget::update()
{
  int pagesize = getpagesize();

  struct rminfo rmi;
  if( sysmp(MP_SAGET, MPSA_RMINFO, &rmi, sizeof(rmi)) == -1 )
    return;
  Memory_Info[TOTAL_MEM]    = MEMORY(rmi.physmem) * pagesize; // total physical memory (without swaps)
  Memory_Info[FREE_MEM]     = MEMORY(rmi.freemem) * pagesize; // total free physical memory (without swaps)
  Memory_Info[BUFFER_MEM]   = MEMORY(rmi.bufmem)  * pagesize;


  //FIXME: Memory_Info[CACHED_MEM]"
  Memory_Info[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram
  
  long val;
  swapctl(SC_GETSWAPTOT, &val);
  Memory_Info[SWAP_MEM]     = MEMORY(val) * UBSIZE; // total size of all swap-partitions

  swapctl(SC_GETFREESWAP, &val);
  Memory_Info[FREESWAP_MEM] = MEMORY(val) * UBSIZE; // free memory in swap-partitions

#ifndef MPKA_SHMINFO
  /* Irix 6.5 (also 6.4?) */
  Memory_Info[SHARED_MEM]   = NO_MEMORY_INFO;
#else
  FILE *kmem = fopen("/dev/kmem", "r");
  if( kmem == 0 ) {
    Memory_Info[SHARED_MEM]   = NO_MEMORY_INFO; 
    return;
  }

  long shmip = sysmp(MP_KERNADDR, MPKA_SHMINFO);
  fseek( kmem, shmip, 0 );
  struct shminfo shmi;
  fread( &shmi, sizeof(shmi), 1, kmem );

  long shmem = sysmp(MP_KERNADDR, MPKA_SHM);

  val = 0;
  long pos;
  struct shmid_ds shmid;
  for( int i=0 ; i<shmi.shmmni ; i++ ) {
    fseek( kmem, shmem, 0 );
	shmem += sizeof(shmem);
    fread( &pos, sizeof(shmem), 1, kmem );
	if(pos != 0) {
      fseek( kmem, pos, 0 );
      fread( &shmid, sizeof(shmid), 1, kmem );
      val += shmid.shm_segsz;
    }
  }
  Memory_Info[SHARED_MEM]   = MEMORY(val);

  fclose(kmem);
#endif
}