[SIGAR-17] Fix possible bad cpu list number on Solaris
This commit is contained in:
		
							parent
							
								
									769634ef4b
								
							
						
					
					
						commit
						39d8d0930b
					
				@ -1,3 +1,7 @@
 | 
				
			|||||||
 | 
					2007-02-12  Doug MacEachern  <dougm@hyperic.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        * [SIGAR-17] Fix possible bad cpu list number on Solaris
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2007-02-07  Doug MacEachern  <dougm@hyperic.com>
 | 
					2007-02-07  Doug MacEachern  <dougm@hyperic.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        * Make sure solaris has _POSIX_PTHREAD_SEMANTICS defined
 | 
					        * Make sure solaris has _POSIX_PTHREAD_SEMANTICS defined
 | 
				
			||||||
 | 
				
			|||||||
@ -62,8 +62,7 @@ int sigar_get_multi_kstats(sigar_t *sigar,
 | 
				
			|||||||
int sigar_get_kstats(sigar_t *sigar)
 | 
					int sigar_get_kstats(sigar_t *sigar)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    kstat_ctl_t *kc = sigar->kc;
 | 
					    kstat_ctl_t *kc = sigar->kc;
 | 
				
			||||||
    kstat_t *ksp;
 | 
					    unsigned int i, id, ncpu = sysconf(_SC_NPROCESSORS_CONF);
 | 
				
			||||||
    unsigned int i, ncpu = sysconf(_SC_NPROCESSORS_CONF);
 | 
					 | 
				
			||||||
    int is_debug = SIGAR_LOG_IS_DEBUG(sigar);
 | 
					    int is_debug = SIGAR_LOG_IS_DEBUG(sigar);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (ncpu != sigar->ncpu) {
 | 
					    if (ncpu != sigar->ncpu) {
 | 
				
			||||||
@ -93,35 +92,29 @@ int sigar_get_kstats(sigar_t *sigar)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        sigar->ncpu = ncpu;
 | 
					        sigar->ncpu = ncpu;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (i=0, ksp=kc->kc_chain; i<ncpu; ksp=ksp->ks_next) {
 | 
					        /* from man p_online:
 | 
				
			||||||
            char *id;
 | 
					         * ``Processor numbers are integers,
 | 
				
			||||||
            kstat_t *cpu_info;
 | 
					         *   greater than or equal to 0,
 | 
				
			||||||
 | 
					         *   and are defined by the hardware platform.
 | 
				
			||||||
 | 
					         *   Processor numbers are not necessarily contiguous,
 | 
				
			||||||
 | 
					         *   but "not too sparse."``
 | 
				
			||||||
 | 
					         * so we maintain our own mapping in ks.cpuid[]
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!ksp) {
 | 
					        /* lookup in order, which kstat chain may not be in */
 | 
				
			||||||
                break;
 | 
					        for (i=0, id=0; i<ncpu; id++) {
 | 
				
			||||||
            }
 | 
					            kstat_t *cpu_info, *cpu_stat;
 | 
				
			||||||
            if (strncmp(ksp->ks_name, "cpu_stat", 8)) {
 | 
					
 | 
				
			||||||
 | 
					            if (!(cpu_stat = kstat_lookup(kc, "cpu_stat", id, NULL))) {
 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* from man p_online:
 | 
					            sigar->ks.cpu[i] = cpu_stat;
 | 
				
			||||||
             * ``Processor numbers are integers,
 | 
					            sigar->ks.cpuid[i] = id;
 | 
				
			||||||
             *   greater than or equal to 0,
 | 
					            if ((cpu_info = kstat_lookup(kc, "cpu_info", id, NULL))) {
 | 
				
			||||||
             *   and are defined by the hardware platform.
 | 
					 | 
				
			||||||
             *   Processor numbers are not necessarily contiguous,
 | 
					 | 
				
			||||||
             *   but "not too sparse."``
 | 
					 | 
				
			||||||
             * so we maintain our own mapping in ks.cpuid[]
 | 
					 | 
				
			||||||
             */
 | 
					 | 
				
			||||||
            id = ksp->ks_name;
 | 
					 | 
				
			||||||
            while (!sigar_isdigit(*id)) {
 | 
					 | 
				
			||||||
                id++;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            sigar->ks.cpu[i] = ksp;
 | 
					 | 
				
			||||||
            sigar->ks.cpuid[i] = atoi(id);
 | 
					 | 
				
			||||||
            if ((cpu_info = kstat_lookup(kc, "cpu_info", sigar->ks.cpuid[i], NULL))) {
 | 
					 | 
				
			||||||
                sigar->ks.cpu_info[i] = cpu_info;
 | 
					                sigar->ks.cpu_info[i] = cpu_info;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (is_debug) {
 | 
					            if (is_debug) {
 | 
				
			||||||
                sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
 | 
					                sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
 | 
				
			||||||
                                 "cpu %d id=%d", i, sigar->ks.cpuid[i]);
 | 
					                                 "cpu %d id=%d", i, sigar->ks.cpuid[i]);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user