From owner-freebsd-ports-bugs@FreeBSD.ORG Sun Jan 10 17:00:17 2010 Return-Path: Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0C9E9106568B for ; Sun, 10 Jan 2010 17:00:17 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id DDA238FC0C for ; Sun, 10 Jan 2010 17:00:16 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id o0AH0GZn018757 for ; Sun, 10 Jan 2010 17:00:16 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id o0AH0GcA018755; Sun, 10 Jan 2010 17:00:16 GMT (envelope-from gnats) Resent-Date: Sun, 10 Jan 2010 17:00:16 GMT Resent-Message-Id: <201001101700.o0AH0GcA018755@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-ports-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ivan Klymenko Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A657F1065672 for ; Sun, 10 Jan 2010 16:52:47 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 9560E8FC0A for ; Sun, 10 Jan 2010 16:52:47 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o0AGqlRR005844 for ; Sun, 10 Jan 2010 16:52:47 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o0AGqksG005843; Sun, 10 Jan 2010 16:52:47 GMT (envelope-from nobody) Message-Id: <201001101652.o0AGqksG005843@www.freebsd.org> Date: Sun, 10 Jan 2010 16:52:47 GMT From: Ivan Klymenko To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: ports/142577: Programm conky does not display information for each core CPU is more than one X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Jan 2010 17:00:17 -0000 >Number: 142577 >Category: ports >Synopsis: Programm conky does not display information for each core CPU is more than one >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Jan 10 17:00:16 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Ivan Klymenko >Release: FreeBSD 8.0-RELEASE-p2 >Organization: individual >Environment: FreeBSD nonamehost 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #0: Thu Jan 7 14:31:29 EET 2010 user@nonamehost:/usr/obj/usr/src/sys/mk8 amd64 >Description: Programm conky does not display information for each core CPU is more than one. In the source code freebsd.c in written: /* XXX: FreeBSD doesn't allow to get per CPU load stats on SMP machines. * It's possible to get a CPU count, but as we fulfill only * info.cpu_usage[0], it's better to report there's only one CPU. * It should fix some bugs (e.g. cpugraph) */ >How-To-Repeat: ever >Fix: I created a patch Patch attached with submission follows: diff -u freebsd.c.orig freebsd.c --- freebsd.c.orig 2010-01-09 21:49:10.000000000 +0200 +++ freebsd.c 2010-01-10 10:21:22.000000000 +0200 @@ -289,22 +289,22 @@ }; struct cpu_load_struct fresh = { {0, 0, 0, 0, 0} }; -long cpu_used, oldtotal, oldused; +long cpu_used;//, oldtotal, oldused; +extern long * g_oldtotal, * g_oldused; void get_cpu_count(void) { - /* int cpu_count = 0; */ + int cpu_count = 0; + size_t cpu_count_len = sizeof(cpu_count); - /* XXX: FreeBSD doesn't allow to get per CPU load stats on SMP machines. - * It's possible to get a CPU count, but as we fulfill only - * info.cpu_usage[0], it's better to report there's only one CPU. - * It should fix some bugs (e.g. cpugraph) */ -#if 0 - if (GETSYSCTL("hw.ncpu", cpu_count) == 0) { - info.cpu_count = cpu_count; + if (sysctlbyname("hw.ncpu", &cpu_count, &cpu_count_len, NULL, 0) < 0) { + fprintf(stderr, "Cannot get hw.ncpu"); + info.cpu_count = 1; + } + else + { + info.cpu_count = cpu_count; } -#endif - info.cpu_count = 1; info.cpu_usage = malloc(info.cpu_count * sizeof(float)); if (info.cpu_usage == NULL) { @@ -315,9 +315,11 @@ /* XXX: SMP support */ void update_cpu_usage(void) { - long used, total; - long cp_time[CPUSTATES]; - size_t cp_len = sizeof(cp_time); + int i, j = 0; + long *used, *total; + static long *cp_time_per_cpu; + size_t cp_len = info.cpu_count * CPUSTATES * sizeof(long); + size_t len = info.cpu_count * sizeof(long); /* add check for !info.cpu_usage since that mem is freed on a SIGUSR1 */ if ((cpu_setup == 0) || (!info.cpu_usage)) { @@ -325,28 +327,41 @@ cpu_setup = 1; } - if (sysctlbyname("kern.cp_time", &cp_time, &cp_len, NULL, 0) < 0) { - fprintf(stderr, "Cannot get kern.cp_time"); - } - - fresh.load[0] = cp_time[CP_USER]; - fresh.load[1] = cp_time[CP_NICE]; - fresh.load[2] = cp_time[CP_SYS]; - fresh.load[3] = cp_time[CP_IDLE]; - fresh.load[4] = cp_time[CP_IDLE]; - - used = fresh.load[0] + fresh.load[1] + fresh.load[2]; - total = fresh.load[0] + fresh.load[1] + fresh.load[2] + fresh.load[3]; - - if ((total - oldtotal) != 0) { - info.cpu_usage[0] = ((double) (used - oldused)) / - (double) (total - oldtotal); - } else { - info.cpu_usage[0] = 0; - } - - oldused = used; - oldtotal = total; + cp_time_per_cpu = malloc(cp_len); + used = malloc(len); + total = malloc(len); + + if (sysctlbyname("kern.cp_times", cp_time_per_cpu, &cp_len, NULL, 0) < 0) { + fprintf(stderr, "Cannot get kern.cp_times"); + } + + for (i=0; iRelease-Note: >Audit-Trail: >Unformatted: