From 8aab84713dfbf633fa49fb6d351cd596e1236ea6 Mon Sep 17 00:00:00 2001 From: Augusto Bott Date: Sat, 10 Dec 2011 13:02:42 -0200 Subject: [PATCH] Added CPU freq and chipset info to Status Overview page * from Tomato RAF * K24 only --- release/src/linux/linux/arch/mips/bcm947xx/setup.c | 4 + release/src/linux/linux/arch/mips/bcm947xx/time.c | 4 + release/src/linux/linux/arch/mips/kernel/proc.c | 2 + release/src/router/httpd/Makefile | 2 +- release/src/router/httpd/cpuinfo.c | 169 +++++++++++++++++++++ release/src/router/httpd/misc.c | 19 ++- release/src/router/www/status-data.jsx | 4 +- release/src/router/www/status-overview.asp | 2 + 8 files changed, 202 insertions(+), 4 deletions(-) create mode 100644 release/src/router/httpd/cpuinfo.c diff --git a/release/src/linux/linux/arch/mips/bcm947xx/setup.c b/release/src/linux/linux/arch/mips/bcm947xx/setup.c index 14ec3cc53c..38572177a5 100644 --- a/release/src/linux/linux/arch/mips/bcm947xx/setup.c +++ b/release/src/linux/linux/arch/mips/bcm947xx/setup.c @@ -70,6 +70,10 @@ spinlock_t bcm947xx_sbh_lock = SPIN_LOCK_UNLOCKED; EXPORT_SYMBOL(bcm947xx_sbh); EXPORT_SYMBOL(bcm947xx_sbh_lock); +/* CPU freq Tomato RAF features */ +int bcm947xx_cpu_clk; +EXPORT_SYMBOL(bcm947xx_cpu_clk); + /* Convenience */ #define sbh bcm947xx_sbh #define sbh_lock bcm947xx_sbh_lock diff --git a/release/src/linux/linux/arch/mips/bcm947xx/time.c b/release/src/linux/linux/arch/mips/bcm947xx/time.c index f1e67f776c..6b12098304 100644 --- a/release/src/linux/linux/arch/mips/bcm947xx/time.c +++ b/release/src/linux/linux/arch/mips/bcm947xx/time.c @@ -44,6 +44,8 @@ extern int panic_timeout; static int watchdog = 0; static u8 *mcr = NULL; +extern int bcm947xx_cpu_clk; //Tomato RAF features + void __init bcm947xx_time_init(void) { @@ -67,6 +69,8 @@ bcm947xx_time_init(void) printk("CPU: BCM%04x rev %d pkg %d at %d MHz\n", sb_chip(sbh), sb_chiprev(sbh), sb_chippkg(sbh), (hz + 500000) / 1000000); + bcm947xx_cpu_clk = (hz + 500000) / 1000000; //Tomato RAF feature + /* Set MIPS counter frequency for fixed_rate_gettimeoffset() */ if (sb_chip(sbh) == BCM5354_CHIP_ID && strncmp(nvram_safe_get("hardware_version"), "WL520G", 6) == 0) diff --git a/release/src/linux/linux/arch/mips/kernel/proc.c b/release/src/linux/linux/arch/mips/kernel/proc.c index 622be896e9..721c908cae 100644 --- a/release/src/linux/linux/arch/mips/kernel/proc.c +++ b/release/src/linux/linux/arch/mips/kernel/proc.c @@ -16,6 +16,7 @@ #include unsigned int vced_count, vcei_count; +extern int bcm947xx_cpu_clk; //Tomato RAF features #ifndef CONFIG_CPU_HAS_LLSC unsigned long ll_ops, sc_ops; @@ -116,6 +117,7 @@ static int show_cpuinfo(struct seq_file *m, void *v) seq_printf(m, "BogoMIPS\t\t: %lu.%02lu\n", loops_per_jiffy / (500000/HZ), (loops_per_jiffy / (5000/HZ)) % 100); + seq_printf(m, "cpu MHz \t\t: %d\n", bcm947xx_cpu_clk); //Tomato RAF features seq_printf(m, "wait instruction\t: %s\n", cpu_wait ? "yes" : "no"); seq_printf(m, "microsecond timers\t: %s\n", cpu_has_counter ? "yes" : "no"); diff --git a/release/src/router/httpd/Makefile b/release/src/router/httpd/Makefile index 4ff42c7c18..1bb502e3c1 100644 --- a/release/src/router/httpd/Makefile +++ b/release/src/router/httpd/Makefile @@ -6,7 +6,7 @@ CFLAGS += -I$(SRCBASE) -I$(SRCBASE)/include -I. -I$(TOP)/shared OBJS = httpd.o cgi.o tomato.o version.o OBJS += misc.o dhcp.o upgrade.o traceping.o parser.o upnp.o ctnf.o OBJS += nvram.o log.o webio.o wl.o devlist.o ddns.o config.o bwm.o -OBJS += blackhole.o utf8.o +OBJS += blackhole.o utf8.o cpuinfo.o ifeq ($(TCONFIG_USB),y) OBJS += usb.o endif diff --git a/release/src/router/httpd/cpuinfo.c b/release/src/router/httpd/cpuinfo.c new file mode 100644 index 0000000000..6acc91b74b --- /dev/null +++ b/release/src/router/httpd/cpuinfo.c @@ -0,0 +1,169 @@ +#include +#include +#include +#include +#include "tomato.h" + +struct occupy +{ + char name[20]; + unsigned int user; + unsigned int nice; + unsigned int system; + unsigned int idle; +}; + +void trim( char *str) +{ + char *copied, *tail = NULL; + if ( str == NULL ) + return ; + + for( copied = str; *str; str++ ) + { + if ( (unsigned char)*str > 0x20 ) + { + *copied++ = *str; + tail = copied; + } + else { + if ( tail ) + *copied++ = *str; + } + } + + if ( tail ) + *tail = 0; + else + *copied = 0; + return ; +} + +static float g_cpu_used; +static int cpu_num; + +static void cal_occupy(struct occupy *, struct occupy *); +static void get_occupy(struct occupy *); + + +/* +system type : Broadcom BCM5354 chip rev 2 pkg 0 +processor : 0 +cpu model : BCM3302 V2.9 +BogoMIPS : 238.38 +*/ +int strncmp_ex(char *str1, char *str2) +{ + return strncmp(str1, str2, strlen(str2)); +} + +int get_cpuinfo(char *system_type, char *cpu_model, char *bogomips, char *cpuclk) + +{ + FILE *fd; + char *next; + char buff[1024]; + char title[128], value[512]; + int okcount=0; + + fd = fopen ("/proc/cpuinfo", "r"); + while (fgets(buff, sizeof(buff), fd)) { + next = buff; + strcpy(title, strsep(&next, ":")); + if (next == NULL) continue; + strcpy(value, next); + trim(value); + if (strncmp_ex(title, "system type")==0) { + okcount++; + //printf("system type: %s\n", value); + if (strncmp_ex(value, "Broadcom BCM5354")==0) { + strcpy(system_type, "Broadcom BCM5354"); + } + else { + strcpy(system_type, value); + } + } + if (strncmp_ex(title, "cpu model")==0) { + okcount++; + //printf("cpu model: %s\n", value); + strcpy(cpu_model, value); + } + if (strncmp_ex(title, "BogoMIPS")==0) { + okcount++; + //printf("bogomips: %s\n", value); + strcpy(bogomips, value); + } + if (strncmp_ex(title, "cpu MHz")==0) { + okcount++; + //printf("cpuclk: %s\n", value); + strcpy(cpuclk, value); + } + + //fprintf (stderr, "%s - %s", title, value); + } + fclose(fd); + return (okcount==3); +} + +/* +int main() +{ + char system_type[64]; + char cpu_model[64]; + char bogomips[64]; + char cpuclk[64]; + if get_cpuinfo(system_type, cpu_model, bogomips, cpuclk) { + printf("system type: %s, cpu model: %s, bogomips: %s, cpuclk: %s\n", system_type, cpu_model, bogomips, cpuclk); + } +} +*/ + +float get_cpupercent() +{ + struct occupy ocpu[10]; + struct occupy ncpu[10]; + int i; + +// cpu_num = sysconf(_SC_NPROCESSORS_ONLN); + cpu_num = 1; + get_occupy(ocpu); + sleep(1); + get_occupy(ncpu); + for (i=0; iuser + o->nice + o->system + o->idle); + nd = (double) (n->user + n->nice + n->system + n->idle); + scale = 100.0 / (float)(nd-od); + id = (double) (n->user - o->user); + sd = (double) (n->system - o->system); + g_cpu_used = ((sd+id)*100.0)/(nd-od); +} + +static void get_occupy (struct occupy *o) +{ + FILE *fd; + int n; + char buff[1024]; + + fd = fopen ("/proc/stat", "r"); + fgets (buff, sizeof(buff), fd); + for(n=0;n / ' + (sysinfo.loads[1] / 65536.0).toFixed(2) + ' / ' + (sysinfo.loads[2] / 65536.0).toFixed(2)); diff --git a/release/src/router/www/status-overview.asp b/release/src/router/www/status-overview.asp index aec1262395..d445954bf3 100644 --- a/release/src/router/www/status-overview.asp +++ b/release/src/router/www/status-overview.asp @@ -201,6 +201,8 @@ function init() createFieldTable('', [ { title: 'Name', text: nvram.router_name }, { title: 'Model', text: nvram.t_model_name }, + { title: 'Chipset', text: stats.systemtype }, + { title: 'CPU Freq', text: stats.cpumhz, hidden: (stats.cpumhz == ' MHz') }, { title: 'Flash RAM Size', text: stats.flashsize }, null, { title: 'Time', rid: 'time', text: stats.time }, -- 2.11.4.GIT