hostres_processor_tbl.c (154860) | hostres_processor_tbl.c (160341) |
---|---|
1/*- 2 * Copyright (c) 2005-2006 The FreeBSD Project 3 * All rights reserved. 4 * 5 * Author: Victor Cruceru <soc-victor@freebsd.org> 6 * 7 * Redistribution of this software and documentation and use in source and 8 * binary forms, with or without modification, are permitted provided that --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * | 1/*- 2 * Copyright (c) 2005-2006 The FreeBSD Project 3 * All rights reserved. 4 * 5 * Author: Victor Cruceru <soc-victor@freebsd.org> 6 * 7 * Redistribution of this software and documentation and use in source and 8 * binary forms, with or without modification, are permitted provided that --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * |
29 * $FreeBSD: head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_processor_tbl.c 154860 2006-01-26 12:19:10Z harti $ | 29 * $FreeBSD: head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_processor_tbl.c 160341 2006-07-14 09:07:56Z harti $ |
30 */ 31 32/* 33 * Host Resources MIB for SNMPd. Implementation for hrProcessorTable 34 */ 35 36#include <sys/param.h> 37#include <sys/sysctl.h> --- 12 unchanged lines hidden (view full) --- 50/* 51 * This structure is used to hold a SNMP table entry 52 * for HOST-RESOURCES-MIB's hrProcessorTable. 53 * Note that index is external being allocated & maintained 54 * by the hrDeviceTable code.. 55 */ 56struct processor_entry { 57 int32_t index; | 30 */ 31 32/* 33 * Host Resources MIB for SNMPd. Implementation for hrProcessorTable 34 */ 35 36#include <sys/param.h> 37#include <sys/sysctl.h> --- 12 unchanged lines hidden (view full) --- 50/* 51 * This structure is used to hold a SNMP table entry 52 * for HOST-RESOURCES-MIB's hrProcessorTable. 53 * Note that index is external being allocated & maintained 54 * by the hrDeviceTable code.. 55 */ 56struct processor_entry { 57 int32_t index; |
58 struct asn_oid frwId; | 58 const struct asn_oid *frwId; |
59 int32_t load; 60 TAILQ_ENTRY(processor_entry) link; | 59 int32_t load; 60 TAILQ_ENTRY(processor_entry) link; |
61 u_char cpu_no; /* which cpu, counted from 0 */ | 61 u_char cpu_no; /* which cpu, counted from 0 */ |
62 pid_t idle_pid; /* PID of idle process for this CPU */ 63 64 /* the samples from the last minute, as required by MIB */ 65 double samples[MAX_CPU_SAMPLES]; 66 67 /* current sample to fill in next time, must be < MAX_CPU_SAMPLES */ 68 uint32_t cur_sample_idx; 69 --- 93 unchanged lines hidden (view full) --- 163 return (NULL); 164 dev->flags |= HR_DEVICE_IMMUTABLE; 165 STAILQ_FOREACH(map, &device_map, link) 166 if (strcmp(map->name_key, name) == 0) 167 break; 168 if (map == NULL) 169 abort(); 170 } | 62 pid_t idle_pid; /* PID of idle process for this CPU */ 63 64 /* the samples from the last minute, as required by MIB */ 65 double samples[MAX_CPU_SAMPLES]; 66 67 /* current sample to fill in next time, must be < MAX_CPU_SAMPLES */ 68 uint32_t cur_sample_idx; 69 --- 93 unchanged lines hidden (view full) --- 163 return (NULL); 164 dev->flags |= HR_DEVICE_IMMUTABLE; 165 STAILQ_FOREACH(map, &device_map, link) 166 if (strcmp(map->name_key, name) == 0) 167 break; 168 if (map == NULL) 169 abort(); 170 } |
171 | 171 |
172 if ((entry = malloc(sizeof(*entry))) == NULL) { 173 syslog(LOG_ERR, "hrProcessorTable: %s malloc " 174 "failed: %m", __func__); 175 return (NULL); 176 } 177 memset(entry, 0, sizeof(*entry)); 178 179 entry->index = map->hrIndex; 180 entry->load = 0; 181 entry->cpu_no = (u_char)cpu_no; 182 entry->idle_pid = 0; | 172 if ((entry = malloc(sizeof(*entry))) == NULL) { 173 syslog(LOG_ERR, "hrProcessorTable: %s malloc " 174 "failed: %m", __func__); 175 return (NULL); 176 } 177 memset(entry, 0, sizeof(*entry)); 178 179 entry->index = map->hrIndex; 180 entry->load = 0; 181 entry->cpu_no = (u_char)cpu_no; 182 entry->idle_pid = 0; |
183 entry->frwId = oid_zeroDotZero; /* unknown id FIXME */ | 183 entry->frwId = &oid_zeroDotZero; /* unknown id FIXME */ |
184 185 INSERT_OBJECT_INT(entry, &processor_tbl); 186 187 HRDBG("CPU %d added with SNMP index=%d", 188 entry->cpu_no, entry->index); 189 190 return (entry); 191} --- 35 unchanged lines hidden (view full) --- 227 kp->ki_comm, kp->ki_pid, kp->ki_oncpu, kp->ki_lastcpu); 228 229 TAILQ_FOREACH(entry, &processor_tbl, link) 230 if (entry->cpu_no == kp->ki_lastcpu) 231 break; 232 233 if (entry == NULL) { 234 /* create entry on non-ACPI systems */ | 184 185 INSERT_OBJECT_INT(entry, &processor_tbl); 186 187 HRDBG("CPU %d added with SNMP index=%d", 188 entry->cpu_no, entry->index); 189 190 return (entry); 191} --- 35 unchanged lines hidden (view full) --- 227 kp->ki_comm, kp->ki_pid, kp->ki_oncpu, kp->ki_lastcpu); 228 229 TAILQ_FOREACH(entry, &processor_tbl, link) 230 if (entry->cpu_no == kp->ki_lastcpu) 231 break; 232 233 if (entry == NULL) { 234 /* create entry on non-ACPI systems */ |
235 if ((entry = proc_create_entry(cpu, NULL)) == NULL) | 235 if ((entry = proc_create_entry(cpu, NULL)) == NULL) |
236 continue; 237 238 detected_processor_count++; 239 } 240 241 entry->idle_pid = kp->ki_pid; 242 HRDBG("CPU no. %d with SNMP index=%d has idle PID %d", 243 entry->cpu_no, entry->index, entry->idle_pid); --- 246 unchanged lines hidden (view full) --- 490 abort(); 491 } 492 abort(); 493 494 get: 495 switch (value->var.subs[sub - 1]) { 496 497 case LEAF_hrProcessorFrwID: | 236 continue; 237 238 detected_processor_count++; 239 } 240 241 entry->idle_pid = kp->ki_pid; 242 HRDBG("CPU no. %d with SNMP index=%d has idle PID %d", 243 entry->cpu_no, entry->index, entry->idle_pid); --- 246 unchanged lines hidden (view full) --- 490 abort(); 491 } 492 abort(); 493 494 get: 495 switch (value->var.subs[sub - 1]) { 496 497 case LEAF_hrProcessorFrwID: |
498 value->v.oid = entry->frwId; | 498 assert(entry->frwId != NULL); 499 value->v.oid = *entry->frwId; |
499 return (SNMP_ERR_NOERROR); 500 501 case LEAF_hrProcessorLoad: 502 value->v.integer = entry->load; 503 return (SNMP_ERR_NOERROR); 504 } 505 abort(); 506} | 500 return (SNMP_ERR_NOERROR); 501 502 case LEAF_hrProcessorLoad: 503 value->v.integer = entry->load; 504 return (SNMP_ERR_NOERROR); 505 } 506 abort(); 507} |