From owner-p4-projects@FreeBSD.ORG Sun Jul 24 22:16:35 2005 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 7545A16A421; Sun, 24 Jul 2005 22:16:35 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1E0C916A41F for ; Sun, 24 Jul 2005 22:16:35 +0000 (GMT) (envelope-from soc-victor@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id C9B4843D48 for ; Sun, 24 Jul 2005 22:16:34 +0000 (GMT) (envelope-from soc-victor@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j6OMGYxr052276 for ; Sun, 24 Jul 2005 22:16:34 GMT (envelope-from soc-victor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j6OMGYkV052273 for perforce@freebsd.org; Sun, 24 Jul 2005 22:16:34 GMT (envelope-from soc-victor@freebsd.org) Date: Sun, 24 Jul 2005 22:16:34 GMT Message-Id: <200507242216.j6OMGYkV052273@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to soc-victor@freebsd.org using -f From: Victor Cruceru To: Perforce Change Reviews Cc: Subject: PERFORCE change 80926 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Jul 2005 22:16:36 -0000 http://perforce.freebsd.org/chv.cgi?CH=80926 Change 80926 by soc-victor@soc-victor_82.76.158.176 on 2005/07/24 22:16:09 Added the SNMP instrumentation for hrProcessorTable and updated the hrDeviceTable accordingly. Still need to improve the per CPU load statistics as the HR-MIB requires ( load average per last minute). Affected files ... .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#12 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_device_tbl.c#3 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_processor_tbl.c#1 add .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#10 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#14 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c#4 edit Differences ... ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#12 (text+ko) ==== @@ -32,7 +32,9 @@ SRCS= hostres_snmp.c hostres_scalars.c \ hostres_storage_tbl.c hostres_fs_tbl.c \ hostres_swrun_tbl.c hostres_swrunperf_tbl.c \ - hostres_device_tbl.c + hostres_device_tbl.c \ + hostres_processor_tbl.c + WARNS?= 6 #Not having NDEBUG defined will enable assertions and a lot of output on stderr CFLAGS+= -DNDEBUG @@ -53,5 +55,5 @@ DEFS= ${MOD}_tree.def BMIBS= HOST-RESOURCES-MIB.txt HOST-RESOURCES-TYPES.txt -LDADD= -lkvm -ldevinfo +LDADD= -lkvm -ldevinfo -lm .include ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_device_tbl.c#3 (text+ko) ==== @@ -171,6 +171,12 @@ assert(out_type_p != NULL); if(dev_p == NULL) return; + + if (strncmp(dev_p->dd_name, "cpu", strlen("cpu")) == 0 && + strstr(dev_p->dd_location, ".CPU") != NULL) { + *out_type_p = (struct asn_oid)OIDX_hrDeviceProcessor; + return; + } *out_type_p = (struct asn_oid)OIDX_hrDeviceOther; /*FIX ME*/ } @@ -179,10 +185,9 @@ hrDevice_getStatus(struct devinfo_dev *dev) { assert(dev != NULL); switch (dev->dd_state) { + case DIS_ALIVE: /* probe succeeded */ case DIS_NOTPRESENT: /* not probed or probe failed */ return (DS_DOWN); - case DIS_ALIVE: /* probe succeeded */ - return (DS_TESTING); case DIS_ATTACHED: /* attach method called */ case DIS_BUSY: /* device is open */ return (DR_RUNNING); ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#10 (text+ko) ==== @@ -94,40 +94,50 @@ hrState_g.hrSWOSIndex = 0; + /*data structures initialization for hrStrorageTable*/ hrState_g.next_hrStorage_index = 1; STAILQ_INIT(&hrState_g.storage_name_map); TAILQ_INIT(&hrState_g.hr_storage_tbl); - + /*data structures initialization for hrFSTable*/ hrState_g.next_hrFS_index = 1; STAILQ_INIT(&hrState_g.fs_name_map); TAILQ_INIT(&hrState_g.hr_fs_tbl); - + + /*data structure initialization for hrSWRunTable & hrSWRunTable*/ TAILQ_INIT(&hrState_g.hr_swrun_tbl); - + /*data structures initialization for hrDeviceTable*/ hrState_g.next_hrDevice_index = 1; STAILQ_INIT(&hrState_g.device_name_map); TAILQ_INIT(&hrState_g.hr_device_tbl); + /*data structure initialization for hrProcessorTable*/ + hrState_g.detected_processor_count = 0; + hrState_g.hw_ncpu = 0; + hrState_g.fscale = 0; + hrState_g.ccpu = 0; + TAILQ_INIT(&hrState_g.hr_processor_tbl); hrState_g.hr_storage_tick = 0; hrState_g.hr_fs_tick = 0; hrState_g.hr_swrun_tick = 0; hrState_g.hr_device_tick = 0; - + hrState_g.hr_processor_tick = 0; + hrState_g.hrStorage_tbl_age = 0; hrState_g.hrFS_tbl_age = 0; hrState_g.hrSWRun_tbl_age = 0; hrState_g.hrDevice_tbl_age = 0; - + hrState_g.hrProcessor_tbl_age = 0; init_hrStorage_tbl_v(); init_hrFS_tbl_v(); init_hrSWRun_tbl_v(); /*also the hrSWRunPerfTable's support is initialized here */ init_hrDevice_tbl_v(); - + init_hrProcessor_tbl_v(); + HR_DPRINTF((stderr, "[%s] done.\n", __func__)); return (0); @@ -172,21 +182,28 @@ fini_hrFS_tbl_v(); fini_hrSWRun_tbl_v(); fini_hrDevice_tbl_v(); + fini_hrProcessor_tbl_v(); hrState_g.hr_storage_tick = 0; hrState_g.hr_fs_tick = 0; hrState_g.hr_swrun_tick = 0; hrState_g.hr_device_tick = 0; + hrState_g.hr_processor_tick = 0; hrState_g.hrStorage_tbl_age = 0; hrState_g.hrFS_tbl_age = 0; hrState_g.hrSWRun_tbl_age = 0; hrState_g.hrDevice_tbl_age = 0; - + hrState_g.hrProcessor_tbl_age = 0; + hrState_g.dev_root = NULL; hrState_g.hrSWOSIndex = 0; - + + hrState_g.hw_ncpu = 0; + hrState_g.fscale = 0; + hrState_g.ccpu = 0; + if( host_registration_id > 0){ or_unregister(host_registration_id); } @@ -219,6 +236,11 @@ refresh_hrDevice_tbl_v(); } + if ( (time(NULL) - hrState_g.hrProcessor_tbl_age) > HR_PROCESSOR_TBL_REFRESH ) { + HR_DPRINTF((stderr, "%s: hrProcessorTable needs refresh\n ", __func__)); + refresh_hrProcessor_tbl_v(); + } + HR_DPRINTF((stderr, "[%s] done.\n ", __func__)); } @@ -291,14 +313,6 @@ */ -int op_hrProcessorTable(struct snmp_context *ctx __unused, - struct snmp_value *value __unused, - u_int sub __unused, - u_int iidx __unused, - enum snmp_op curr_op __unused) -{ - return (SNMP_ERR_NOSUCHNAME); -} int op_hrNetworkTable(struct snmp_context *ctx __unused, ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#14 (text+ko) ==== @@ -46,6 +46,7 @@ #include #include +#include /*a debug macro*/ #ifndef NDEBUG @@ -57,8 +58,8 @@ #define HR_DPRINTF(ARGS) #endif /*NDEBUG*/ +#define IS_KERNPROC(kp) ( ((kp)->ki_flag & P_KTHREAD) == P_KTHREAD ) - /* * This structure is used to hold a SNMP table entry * for HOST-RESOURCES-MIB's hrStorageTable @@ -193,13 +194,31 @@ TAILQ_HEAD(swrun_tbl, hrSWRunTblEntry); +/* + * This structure is used to hold a SNMP table entry + * for HOST-RESOURCES-MIB's hrProcessorTable + * Note that index is external being allocated & mainatined + * by the hrDeviceTable code. + */ +struct hrProcessorTblEntry { + int32_t index; + struct asn_oid frwId; + int32_t load; + TAILQ_ENTRY(hrProcessorTblEntry) link; + /*not from SNMP table definition, only used internally*/ + u_char cpu_no; /*which cpu, counted from 0*/ + pid_t idle_pid; /*the PID of ide process for this CPU */ +}; + +TAILQ_HEAD(processor_tbl, hrProcessorTblEntry); + enum DeviceStatus { DS_UNKNOWN = 1, DR_RUNNING = 2, DS_WARNING = 3, DS_TESTING = 4, - DS_DOWN = 4 + DS_DOWN = 5 }; @@ -313,7 +332,20 @@ struct devinfo_dev *dev_root; - + + /* + * next items are used for hrProcessorTable + */ + struct + processor_tbl hr_processor_tbl; /*the head of the list with hrDeviceTable's entries */ + int32_t detected_processor_count; + int hw_ncpu; /*get it via sysctlbyname(hw.ncpu)*/ + fixpt_t ccpu; /* kernel _ccpu variable */ + int fscale; /* kernel _fscale variable */ + + time_t hrProcessor_tbl_age; + uint64_t hr_processor_tick; /*last (agent) tick when hrProcessorTable was updated */ + }; @@ -445,5 +477,28 @@ */ void refresh_hrDevice_tbl_v(void); +/* + * Init the things for hrProcessorTable + */ +void init_hrProcessor_tbl_v(void); + +/* + * Finalization routine for hrProcessorTable + * It destroys the lists and frees any allocated heap memory + */ +void fini_hrProcessor_tbl_v(void); + +/* + * Next macro represents the number of seconds + * between two consecutive queries to the OS for getting the new data + * for hrProcessorTable (only for load numbers) + */ +#define HR_PROCESSOR_TBL_REFRESH 5 +/* + * Refresh routine for hrProcessorTable + * Usable for polling the system for load numbers. + */ +void refresh_hrProcessor_tbl_v(void); + #endif /*__HOSTRES_SNMP_H_INCLUDED__ */ ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c#4 (text+ko) ==== @@ -45,7 +45,6 @@ #include -#define IS_KERNPROC(kp) ( ((kp)->ki_flag & P_KTHREAD) == P_KTHREAD ) /* * Ugly thing: PID_MAX, NO_PID defined only in kernel */