Bug #4058, was updated on 2005-May-19 00:56
Here is a current snapshot of the bug.
Project: Goodies for the Xfce desktop
Category: xfce4-systemload-plugin
Status: Open
Resolution: None
Bug Group: None
Priority: 5
Submitted by: aalmroth
Assigned to : none
Summary: Added support for Solaris
Details: Added support for Solaris SPARC/x86 by adding sections for SVR4 in the files cpu.c, uptime.c and memswap.c;
Diff files;
cpu.c.orig,cpu.c:
257a258,261
> #elif defined(__SVR4) /* Solaris, actually */
> /* Added by Phil Brown for CSW build of xfce 4.0 */
> /* Added again by Andreas Almroth for CSW build of xfce 4.2.1 */
> /* 2005-05-18 tidying up */
258a263,356
> #include <fcntl.h>
> #include <limits.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <errno.h>
> #include <sys/stat.h>
> #include <sys/types.h>
> #include <sys/time.h>
> #include <kstat.h>
> #include <sys/param.h>
> #include <sys/sysconfig.h>
>
> #include <sys/sysinfo.h>
>
> #define MAXCPUS 10 /* get real, we wont have more than 10 cpus for a GUI box*/
> cpu_stat_t olddata[MAXCPUS], newdata[MAXCPUS];
>
> /* for use by read_uptime() */
> gulong solaris_uptime_secs;
>
> gulong read_cpuload(){
> static int hz=100; /* temp value just in case */
> static kstat_ctl_t *kc = NULL;
> kstat_t *ks = NULL;
> kstat_named_t *kn = NULL;
> static int ncpus=-1;
> int count=0;
> uint_t tickstotal=0, ticksused=0;
>
> if(ncpus==-1){
> ncpus=_sysconfig(_CONFIG_NPROC_CONF);
> /* printf("DEBUG-systemload: ncpus=%d\n", ncpus);*/
> hz=HZ;
> }
> if(kc==NULL){
> memset(olddata, 0, sizeof(cpu_stat_t)*MAXCPUS);
> kc=kstat_open();
> }
>
> /* cheat and calculate uptime in here also */
> /* although couldn't we do this from one of the cpu_stat structs?*/
> ks=kstat_lookup(kc, "unix", 0, "system_misc" );
> /* printf("DEBUG-systemload: ks=%p\n",ks);*/
>
> /* random "just do it" kinda thing here */
> kstat_read(kc, ks, 0);
>
> kn=kstat_data_lookup(ks, "lbolt");
> solaris_uptime_secs=kn->value.ui32 / hz;
>
>
> for(count=0;count<ncpus;count++){
> /* It might be slow parsing this every time.
> * Should probably cache it
> */
> ks=kstat_lookup(kc, "cpu_stat", 0, NULL /*"cpu_stat"*/ );
> if(ks==NULL){
> printf("DEBUG: null output for kstat on cpu%d\n",count);
> continue;
> }
>
> kstat_read(kc, ks, &newdata[count]);
> }
>
> if(olddata[0].cpu_sysinfo.cpu[CPU_KERNEL]==0){
> /* first time here. Nothing to compare to */
> memcpy(olddata, newdata, sizeof(cpu_stat_t)*MAXCPUS);
> return 0;
>
> }
>
> for(count=0;count<ncpus;count++){
> ticksused += newdata[count].cpu_sysinfo.cpu[CPU_USER] -
> olddata[count].cpu_sysinfo.cpu[CPU_USER];
> ticksused += newdata[count].cpu_sysinfo.cpu[CPU_KERNEL] -
> olddata[count].cpu_sysinfo.cpu[CPU_KERNEL];
>
>
> tickstotal += newdata[count].cpu_sysinfo.cpu[CPU_USER] -
> olddata[count].cpu_sysinfo.cpu[CPU_USER];
> tickstotal += newdata[count].cpu_sysinfo.cpu[CPU_KERNEL] -
> olddata[count].cpu_sysinfo.cpu[CPU_KERNEL];
> tickstotal += newdata[count].cpu_sysinfo.cpu[CPU_IDLE] -
> olddata[count].cpu_sysinfo.cpu[CPU_IDLE];
> tickstotal += newdata[count].cpu_sysinfo.cpu[CPU_WAIT] -
> olddata[count].cpu_sysinfo.cpu[CPU_WAIT];
> }
>
> memcpy(olddata, newdata, sizeof(cpu_stat_t)*MAXCPUS);
>
> return ((ticksused * 100) / tickstotal) ;
> }
>
260c358
< #error "Your plattform is not yet supported"
---
> #error "Your platform is not yet supported"
uptime.c.orig, uptime.c:
112a113
> #elif defined(__SVR4) /* Solaris */
113a115,124
> extern gulong solaris_uptime_secs;
> gulong read_uptime()
> {
> /* we already have kstat open in cpu.c
> * so do the reading there, not here
> */
> return solaris_uptime_secs;
> }
>
>
memswap.c.orig, memswap.c:
442a443,446
> #elif defined(__SVR4) /* well, actually this is for Solaris */
> /* Added by Phil Brown for CSW build of xfce 4.0 */
> /* Added again by Andreas Almroth for CSW build of xfce 4.2.1 */
> /* 2005-05-18 tidying up with using kstat and new swapctl */
443a448,571
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/stat.h>
> #include <sys/swap.h>
> #include <vm/anon.h>
> #include <kstat.h>
> #include <sys/sysinfo.h>
>
> static kstat_ctl_t *kc = NULL;
> static kstat_t *sys_pagesp = NULL;
> static int pagesize = -1;
> static unsigned long physmem = 0;
> static unsigned long freemem = 0;
> static swaptbl_t *swap_entries = NULL;
>
> int alloc_table() {
> int num;
> int i;
>
> num = swapctl(SC_GETNSWP,0);
>
> if (num == 0)
> return -1;
>
> swap_entries = (swaptbl_t *)malloc(num * sizeof(swapent_t) +
> sizeof(struct swaptable));
>
> if (swap_entries == NULL)
> return -1;
>
> for (i = 0; i < (num + 1); i++)
> swap_entries->swt_ent[i].ste_path = malloc(MAXPATHLEN);
>
> swap_entries->swt_n = num + 1;
>
> return num + 1;
> }
>
> gint read_memswap(gulong *mem, gulong *swap, gulong *MT, gulong *MU, gulong *ST, gulong *SU)
> {
> kstat_named_t *kn;
> uint64_t swap_total = 0;
> uint64_t swap_free = 0;
>
> int num;
> int i,n;
>
> /* Read page size first time */
> if(pagesize == -1){
> pagesize = sysconf(_SC_PAGESIZE);
> }
>
> /* Open kstat first time and read total memory */
> if (kc == NULL) {
> kc = kstat_open(); /* Should check for rc */
>
> sys_pagesp = kstat_lookup(kc, "unix", 0, "system_pages");
>
> kstat_read(kc,sys_pagesp,0);
>
> kn = kstat_data_lookup(sys_pagesp,"physmem");
>
> if (kn != NULL)
> physmem = (kn->value.ul * pagesize) >> 10;
> else
> physmem = 0;
> }
>
> /* Read current free memory */
>
> kstat_read(kc,sys_pagesp,0);
>
> kn = kstat_data_lookup(sys_pagesp,"freemem");
>
> freemem = (kn->value.ul * pagesize) >> 10;
>
> *mem = ((physmem - freemem) * 100) / physmem;
> *MT = physmem;
> *MU = physmem - freemem;
>
> /* Get swapctl stats */
>
> if (swap_entries == NULL) {
> if ((num = alloc_table()) == -1) {
> *swap = 0;
> *ST = 0;
> *SU = 0;
> return 0;
> }
> }
> else
> num = swap_entries->swt_n;
>
> n = swapctl(SC_LIST,swap_entries);
>
> if (n > num) {
> /* Geesh, someone added swap, clean up and allocate again */
> for (i = 0; i < num; i++)
> free(swap_entries->swt_ent[i].ste_path);
>
> free(swap_entries);
>
> swap_entries = NULL;
>
> if ((num = alloc_table()) == -1)
> *swap = 0;
> *ST = 0;
> *SU = 0;
> return 0;
> }
>
> for (i = 0; i < n; i++) {
> swap_total += (swap_entries->swt_ent[i].ste_pages);
> swap_free += (swap_entries->swt_ent[i].ste_free);
> }
>
> *swap = ((swap_total - swap_free) * 100) / swap_total;
> *ST = (gulong)(swap_total * pagesize) /1024;
> *SU = (gulong)((swap_total - swap_free) * pagesize) / 1024;
>
> return 0;
> }
>
445c573
< #error "Your platform is not yet support"
---
> #error "Your platform is not yet supported"
For detailed info, follow this link:
http://developer.berlios.de/bugs/?func=detailbug&bug_id=4058&group_id=910
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.