From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 18C87138C9D for ; Fri, 17 Apr 2015 12:53:12 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id ABFF1E0879; Fri, 17 Apr 2015 12:53:06 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3BE88E0879 for ; Fri, 17 Apr 2015 12:53:06 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 38C70340C75 for ; Fri, 17 Apr 2015 12:53:05 +0000 (UTC) Received: by oystercatcher.gentoo.org (Postfix, from userid 2170) id C1911161D3; Fri, 17 Apr 2015 12:52:59 +0000 (UTC) From: "Bernard Cafarelli (voyageur)" To: gentoo-commits@lists.gentoo.org Reply-To: gentoo-dev@lists.gentoo.org, voyageur@gentoo.org Subject: [gentoo-commits] gentoo-x86 commit in x11-plugins/wmload/files: wmload-0.9.6-solaris.patch X-VCS-Repository: gentoo-x86 X-VCS-Files: wmload-0.9.6-solaris.patch X-VCS-Directories: x11-plugins/wmload/files X-VCS-Committer: voyageur X-VCS-Committer-Name: Bernard Cafarelli Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Message-Id: <20150417125301.C1911161D3@oystercatcher.gentoo.org> Date: Fri, 17 Apr 2015 12:52:59 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 8a42c89f-f586-4acb-845c-a8880ade81d7 X-Archives-Hash: 60ceb2c6df2384d6074340d966f78ce8 voyageur 15/04/17 12:52:59 Added: wmload-0.9.6-solaris.patch Log: Version bump with new homepage, ebuild cleanup (Portage version: 2.2.18/cvs/Linux x86_64, signed Manifest commit with key 00F7AB331B0F097F) Revision Changes Path 1.1 x11-plugins/wmload/files/wmload-0.9.6-solaris.patch file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/x11-plugins/wmload/files/wmload-0.9.6-solaris.patch?rev=1.1&view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/x11-plugins/wmload/files/wmload-0.9.6-solaris.patch?rev=1.1&content-type=text/plain Index: wmload-0.9.6-solaris.patch =================================================================== * original: http://www.rampant.org/~dp/software/wmload.solaris.patch --- wmload.c +++ wmload.c @@ -6,6 +6,11 @@ #include #include #include +#ifdef sun +#include +#include +#include +#endif #include "back.xpm" #include "mask2.xbm" @@ -410,6 +415,107 @@ return (char *)p; } +#ifdef sun + +static kstat_ctl_t *kc; +static kstat_t **cpu_ksp_list; +static int ncpus; + +void +cpu_stats_init() +{ + int i = 0; + kstat_t *ksp; + static int kstats_ready = 0; + + if (!kstats_ready) { + if ((kc = kstat_open()) == NULL) { + fprintf(stderr,"wmload: can't open /dev/kstat\n"); + exit (1); + } + kstats_ready = 1; + } + + for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) { + if (strcmp(ksp->ks_module, "cpu_stat") == 0) + i++; + } + + if (cpu_ksp_list) { + free(cpu_ksp_list); + } + cpu_ksp_list = (kstat_t **) calloc(i * sizeof (kstat_t *), 1); + ncpus = i; + + /* + * stash the ksp for each CPU. + */ + i = 0; + for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) { + if (strcmp(ksp->ks_module, "cpu_stat") == 0) { + cpu_ksp_list[i] = ksp; + i++; + } + } +} + +int +get_cpu_stats() +{ + int i; + cpu_stat_t stat; + static int firsttime = 1; + + if (firsttime) { + firsttime = 0; + return (1); /* force code to go initialize kstat stuff */ + } + + /* + * Read each cpu's data. If the chain has changed (a state change + * has happened, maybe a new cpu was added to the system), then + * return 1. This will cause the code to reinitialize the cpu_ksp_list + * array. word. + */ + cp_time[0] = cp_time[1] = cp_time[2] = cp_time[3] = 0; + for (i = 0; i < ncpus; i++) { + if (kstat_read(kc, cpu_ksp_list[i], (void *) &stat) == -1) + return (1); + cp_time[0] += stat.cpu_sysinfo.cpu[CPU_USER]; /* user */ + cp_time[1] += stat.cpu_sysinfo.cpu[CPU_WAIT]; /* "nice" */ + cp_time[2] += stat.cpu_sysinfo.cpu[CPU_KERNEL]; /* sys */ + cp_time[3] += stat.cpu_sysinfo.cpu[CPU_IDLE]; /* idle ("free")*/ + } + return (0); +} + +void GetLoad(int Maximum, int *usr, int *nice, int *sys, int *free) +{ + int total; + + while (get_cpu_stats() != 0) { + cpu_stats_init(); + } + + *usr = cp_time[0] - last[0]; + *nice = cp_time[1] - last[1]; + *sys = cp_time[2] - last[2]; + *free = cp_time[3] - last[3]; + + /* printf("[%d %d %d %d]\n", *usr, *nice, *sys, *free); */ + + total = *usr + *nice + *sys + *free; + last[0] = cp_time[0]; + last[1] = cp_time[1]; + last[2] = cp_time[2]; + last[3] = cp_time[3]; + + *usr = rint(Maximum * (float)(*usr) /total); + *nice =rint(Maximum * (float)(*nice) /total); + *sys = rint(Maximum * (float)(*sys) /total); + *free = rint(Maximum * (float)(*free) /total); +} +#else /* sun */ void GetLoad(int Maximum, int *usr, int *nice, int *sys, int *free) { char buffer[100];/*[4096+1];*/ @@ -445,6 +551,7 @@ *sys = rint(Maximum * (float)(*sys) /total); *free = rint(Maximum * (float)(*free) /total); } +#endif void InsertLoad() {