From owner-freebsd-ports-bugs@FreeBSD.ORG Wed Jan 23 14:00:06 2008 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 6275716A41B for ; Wed, 23 Jan 2008 14:00:06 +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 38FE613C46B for ; Wed, 23 Jan 2008 14:00:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m0NE06eV017584 for ; Wed, 23 Jan 2008 14:00:06 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m0NE06tx017583; Wed, 23 Jan 2008 14:00:06 GMT (envelope-from gnats) Resent-Date: Wed, 23 Jan 2008 14:00:06 GMT Resent-Message-Id: <200801231400.m0NE06tx017583@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, KOIE Hidetaka Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1AC3116A418 for ; Wed, 23 Jan 2008 13:51:20 +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 010F413C4D5 for ; Wed, 23 Jan 2008 13:51:20 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m0NDnk7o034863 for ; Wed, 23 Jan 2008 13:49:46 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.2/8.14.1/Submit) id m0NDnk0f034862; Wed, 23 Jan 2008 13:49:46 GMT (envelope-from nobody) Message-Id: <200801231349.m0NDnk0f034862@www.freebsd.org> Date: Wed, 23 Jan 2008 13:49:46 GMT From: KOIE Hidetaka To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: ports/119923: [patch] sysutil/ascpu does not work FreeBSD 8.0-CURRENT 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: Wed, 23 Jan 2008 14:00:06 -0000 >Number: 119923 >Category: ports >Synopsis: [patch] sysutil/ascpu does not work FreeBSD 8.0-CURRENT >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Jan 23 14:00:05 UTC 2008 >Closed-Date: >Last-Modified: >Originator: KOIE Hidetaka >Release: 8.0-CURRENT >Organization: surigiken >Environment: FreeBSD guriandgura 8.0-CURRENT FreeBSD 8.0-CURRENT #1: Wed Jan 16 16:41:01 JST 2008 koie@guriandgura:/usr/obj/usr/src/sys/GURIANDGURA amd64 >Description: ascpu exits 1, because kvm_nlist(kd, nlst={{"_cp_time"}, {0}}) is faild. >How-To-Repeat: koie@guriandgura% ascpu kvm_open: kvm_nlist: No such file or directory ascpu : cannot get nlist koie@guriandgura% >Fix: sysctl cp_time/cp_times should be used. (If sysctl is only used, no need to set the setgid bit by do-install in Makefile.) the option -cpu will be accepted by this patch. Patch attached with submission follows: --- ascpu_x.c.orig2 2008-01-23 18:36:30.354893235 +0900 +++ ascpu_x.c 2008-01-23 18:36:51.855717860 +0900 @@ -19,6 +19,11 @@ #include #include #include +#include +#include +#include +#include +#include #endif #ifdef __hpux__ @@ -82,6 +87,8 @@ int update_request = 0; #ifdef __FreeBSD__ +static int cp_time_mib[2]; +static int cp_times_mib[2]; static kvm_t *kd; static struct nlist nlst[] = { {"_cp_time"}, {0} @@ -555,12 +562,45 @@ memcpy(&last, &fresh, sizeof(last)); #ifdef __FreeBSD__ - if (kvm_read(kd, nlst[0].n_value, &fresh, sizeof(fresh)) != sizeof(fresh)) { - printf("ascpu : cannot read kvm\n"); - exit(1); + if (state.cpu_number >= 0 && cp_times_mib[0] != 0) { + long cp_times[MAX_CPU][CPUSTATES]; + size_t cp_times_len = sizeof(cp_times); + int error = sysctl(cp_times_mib, 2, cp_times, &cp_times_len, NULL, 0); + if (error) { + printf("ascpu: cannot sysctl cp_times\n"); + exit(1); + } + + long *cp_time = cp_times[state.cpu_number]; + fresh.load[0] = cp_time[CP_USER]; + fresh.load[1] = cp_time[CP_NICE]; + fresh.load[2] = cp_time[CP_SYS] + cp_time[CP_INTR]; + fresh.load[3] = cp_time[CP_IDLE]; + } else if (state.cpu_number == -1 && cp_time_mib[0] != 0) { + long cp_time[CPUSTATES]; + size_t cp_time_len = sizeof(cp_time); + int error = sysctl(cp_time_mib, 2, cp_time, &cp_time_len, NULL, 0); + if (error) { + printf("ascpu: cannot sysctl cp_time\n"); + exit(1); + } + + fresh.load[0] = cp_time[CP_USER]; + fresh.load[1] = cp_time[CP_NICE]; + fresh.load[2] = cp_time[CP_SYS] + cp_time[CP_INTR]; + fresh.load[3] = cp_time[CP_IDLE]; + } else { + if (nlst[0].n_type == 0) { + printf("ascpu : cannot get nlist\n"); + exit(1); + } + if (kvm_read(kd, nlst[0].n_value, &fresh, sizeof(fresh)) != sizeof(fresh)) { + printf("ascpu : cannot read kvm\n"); + exit(1); + } + /* compatible with Linux(overwrite 'interrupt' with 'idle' field) */ + fresh.load[3] = fresh.load[4]; } - /* compatible with Linux(overwrite 'interrupt' with 'idle' field) */ - fresh.load[3] = fresh.load[4]; #endif #ifdef __hpux__ @@ -1094,14 +1134,12 @@ ascpu_cleanup(); } #ifdef __FreeBSD__ - if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) { - printf("ascpu : cannot open kvm\n"); - exit(1); - } - kvm_nlist(kd, nlst); - if (nlst[0].n_type == 0) { - printf("ascpu : cannot get nlist\n"); - exit(1); + size_t len = 2; + sysctlnametomib("kern.cp_times", cp_times_mib, &len); + len = 2; + sysctlnametomib("kern.cp_time", cp_time_mib, &len); + if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) != NULL) { + kvm_nlist(kd, nlst); } #endif >Release-Note: >Audit-Trail: >Unformatted: