/proc/penguin addition

Patrick St. Jean (psj@cgmlarson.com)
10 Jul 1997 20:41:06 +0200


Here's a patch to 2.1.43 that adds an entry in /proc named penguin. It
returns sort of an uptime like rating. Anything less than a day rates a
"penguin", 1 to 10 days are kilopenguins, 10 to 100 are megapenguins, 100
to 1000 are gigapenguins, and 1000 to 10000 are terapenguins. If you
think that you can keep a machine up for more than 27 years, I'll put in
more... A patch for the 2.0 series will arrive shortly

--- begin patch ---
*** linux/fs/proc/array.c.orig Fri Jun 20 14:04:35 1997
--- linux/fs/proc/array.c Thu Jul 10 11:48:06 1997
***************
*** 28,33 ****
--- 28,35 ----
*
* Yves Arrouye : remove removal of trailing spaces in get_array.
* <Yves.Arrouye@marin.fdn.fr>
+ *
+ * Patrick St. Jean : added penguin entry in /proc
+ * <stjeanp@pdq.net>
*/

#include <linux/types.h>
***************
*** 60,65 ****
--- 62,71 ----
int get_malloc(char * buffer);
#endif

+ #ifdef CONFIG_PENGUIN
+ /* needed to save it somewhere... */
+ long pengo_boot_time;
+ #endif

static long read_core(struct inode * inode, struct file * file,
char * buf, unsigned long count)
***************
*** 484,489 ****
--- 490,543 ----
return 0;
}

+ #ifdef CONFIG_PENGUIN
+ int get_penguin_num(char * page)
+ {
+ float penguins = 0;
+ long penguins_l = 0;
+ long penguins_r = 0;
+ long num = 1;
+ int len = 0;
+ int foo = 0;
+ char prefix[14];
+
+ /* number of days */
+ penguins = (CURRENT_TIME - pengo_boot_time) / 86400.0;
+
+ if(penguins < 1){ /* < 1 day == penguins */
+ penguins *= 10;
+ }else if(penguins < 10){ /* 1 <-> 10 days == kilo */
+ foo = sprintf(prefix, "kilo");
+ }else if(penguins < 100){ /* 10 <-> 100 days == mega */
+ num = 10;
+ foo = sprintf(prefix, "mega");
+ }else if(penguins < 1000){ /* 100 <-> 1000 days == giga */
+ num = 100;
+ foo = sprintf(prefix, "giga");
+ }else if(penguins < 10000){ /* 1000 <-> 10000 days == tera */
+ num = 1000;
+ foo = sprintf(prefix, "tera");
+ } /* you get more than 27 years uptime, call me */
+
+ /*
+ get both sides of the "." since sprintf in the kernel can't
+ do it for itself
+ */
+ penguins_l = penguins / num;
+ penguins_r = ((penguins / num) - penguins_l) * 100000;
+
+ if((penguins_l == 1) && (penguins_r == 0)){
+ foo = sprintf(prefix + foo, "penguin");
+ }else{
+ foo = sprintf(prefix + foo, "penguins");
+ }
+
+ len = sprintf(page, "%lu.%05lu %s\n",
+ penguins_l, penguins_r, prefix);
+ return len;
+ }
+ #endif
+
#if defined(__i386__)
# define KSTK_EIP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1019])
# define KSTK_ESP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1022])
***************
*** 1019,1024 ****
--- 1073,1081 ----
#ifdef CONFIG_ZORRO
extern int zorro_get_list(char *);
#endif
+ #ifdef CONFIG_PENGUIN
+ extern int get_penguin_num(char *);
+ #endif
#if defined (CONFIG_AMIGA) || defined (CONFIG_ATARI)
extern int get_hardware_list(char *);
#endif
***************
*** 1105,1110 ****
--- 1162,1171 ----
#ifdef CONFIG_ZORRO
case PROC_ZORRO:
return zorro_get_list(page);
+ #endif
+ #ifdef CONFIG_PENGUIN
+ case PROC_PENGUIN:
+ return get_penguin_num(page);
#endif
#if defined (CONFIG_AMIGA) || defined (CONFIG_ATARI)
case PROC_HARDWARE:
*** linux/fs/proc/root.c.orig Fri Jun 20 14:04:35 1997
--- linux/fs/proc/root.c Thu Jul 10 11:55:15 1997
***************
*** 416,421 ****
--- 416,429 ----
0, &proc_array_inode_operations
};
#endif
+ #ifdef CONFIG_PENGUIN
+ extern long pengo_boot_time;
+ static struct proc_dir_entry proc_root_penguin = {
+ PROC_PENGUIN, 7, "penguin",
+ S_IFREG | S_IRUGO, 1, 0, 0,
+ 0, &proc_array_inode_operations
+ };
+ #endif
static struct proc_dir_entry proc_root_cpuinfo = {
PROC_CPUINFO, 7, "cpuinfo",
S_IFREG | S_IRUGO, 1, 0, 0,
***************
*** 552,557 ****
--- 560,569 ----
#endif
#ifdef CONFIG_ZORRO
proc_register(&proc_root, &proc_root_zorro);
+ #endif
+ #ifdef CONFIG_PENGUIN
+ pengo_boot_time = CURRENT_TIME;
+ proc_register(&proc_root, &proc_root_penguin);
#endif
proc_register(&proc_root, &proc_root_cpuinfo);
proc_register(&proc_root, &proc_root_self);
*** linux/fs/Config.in.orig Fri Jun 20 14:04:33 1997
--- linux/fs/Config.in Thu Jul 10 08:51:51 1997
***************
*** 36,41 ****
--- 36,44 ----
dep_tristate 'umsdos: Unix like fs on top of std MSDOS FAT fs' CONFIG_UMSDOS_FS $CONFIG_MSDOS_FS

bool '/proc filesystem support' CONFIG_PROC_FS
+ if [ "$CONFIG_PROC_FS" = "y" ]; then
+ bool '/proc/penguin support' CONFIG_PENGUIN
+ fi
if [ "$CONFIG_INET" = "y" ]; then
tristate 'NFS filesystem support' CONFIG_NFS_FS
if [ "$CONFIG_NFS_FS" = "y" ]; then
*** linux/include/linux/proc_fs.h.orig Fri Jun 20 14:20:38 1997
--- linux/include/linux/proc_fs.h Thu Jul 10 10:45:46 1997
***************
*** 51,57 ****
PROC_HARDWARE,
PROC_SLABINFO,
PROC_PARPORT,
! PROC_OMIRR /* whether enabled or not */
};

enum pid_directory_inos {
--- 51,58 ----
PROC_HARDWARE,
PROC_SLABINFO,
PROC_PARPORT,
! PROC_OMIRR, /* whether enabled or not */
! PROC_PENGUIN
};

enum pid_directory_inos {
*** linux/Documentation/Configure.help.orig Fri Jun 20 14:04:29 1997
--- linux/Documentation/Configure.help Thu Jul 10 08:51:51 1997
***************
*** 3903,3908 ****
--- 3903,3913 ----
IRQ). Several programs depend on this, so everyone should say Y
here.

+ /proc/penguin support
+ CONFIG_PENGUIN
+ This is a counter that returns a "penguin" rating indicating how
+ long (and thus how stable) the system is.
+
NFS filesystem support
CONFIG_NFS_FS
If you are connected to some other (usually local) Unix computer
--- end patch ---

Best
Pat

-- 
+-----------------------------------------------------------------------------+
| Patrick St. Jean                                          psj@cgmlarson.com |
| Programmer & Systems Administrator                     +1 713-977-4177 x106 |
| Larson Software Technology                         http://www.cgmlarson.com |
+-----------------------------------------------------------------------------+