~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/kernel/info.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * linux/kernel/info.c
  3  *
  4  * Copyright (C) 1992 Darren Senn
  5  */
  6 
  7 /* This implements the sysinfo() system call */
  8 
  9 #include <linux/mm.h>
 10 #include <linux/unistd.h>
 11 #include <linux/swap.h>
 12 #include <linux/smp_lock.h>
 13 
 14 #include <asm/uaccess.h>
 15 
 16 asmlinkage long sys_sysinfo(struct sysinfo *info)
 17 {
 18         struct sysinfo val;
 19 
 20         memset((char *)&val, 0, sizeof(struct sysinfo));
 21 
 22         cli();
 23         val.uptime = jiffies / HZ;
 24 
 25         val.loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
 26         val.loads[1] = avenrun[1] << (SI_LOAD_SHIFT - FSHIFT);
 27         val.loads[2] = avenrun[2] << (SI_LOAD_SHIFT - FSHIFT);
 28 
 29         val.procs = nr_threads-1;
 30         sti();
 31 
 32         si_meminfo(&val);
 33         si_swapinfo(&val);
 34 
 35         {
 36                 /* If the sum of all the available memory (i.e. ram + swap +
 37                  * highmem) is less then can be stored in a 32 bit unsigned long
 38                  * then we can be binary compatible with 2.2.x kernels.  If not,
 39                  * well, who cares since in that case 2.2.x was broken anyways...
 40                  *
 41                  *  -Erik Andersen <andersee@debian.org> */
 42 
 43                 unsigned long mem_total = val.totalram + val.totalswap;
 44                 if ( !(mem_total < val.totalram || mem_total < val.totalswap)) {
 45                         unsigned long mem_total2 = mem_total + val.totalhigh; 
 46                         if (!(mem_total2 < mem_total || mem_total2 < val.totalhigh))
 47                         {
 48                                 /* If mem_total did not overflow.  Divide all memory values by
 49                                  * mem_unit and set mem_unit=1.  This leaves things compatible with
 50                                  * 2.2.x, and also retains compatibility with earlier 2.4.x
 51                                  * kernels...  */
 52 
 53                                 int bitcount = 0;
 54                                 while (val.mem_unit > 1) 
 55                                 {
 56                                         bitcount++;
 57                                         val.mem_unit >>= 1;
 58                                 }
 59                                 val.totalram <<= bitcount;
 60                                 val.freeram <<= bitcount;
 61                                 val.sharedram <<= bitcount;
 62                                 val.bufferram <<= bitcount;
 63                                 val.totalswap <<= bitcount;
 64                                 val.freeswap <<= bitcount;
 65                                 val.totalhigh <<= bitcount;
 66                                 val.freehigh <<= bitcount;
 67                         }
 68                 }
 69         }
 70 
 71         if (copy_to_user(info, &val, sizeof(struct sysinfo)))
 72                 return -EFAULT;
 73         return 0;
 74 }
 75 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.