void cpu_check(void) { /* * TODO: - Get numcpus check user load on cpus (not sysload, as it * includes the idle-loop) report if higher than treshold */ struct cpu_state *buf; //struct cpu_state_pct *cpupct; //struct cpu_state *total; #ifdef SOLARIS int cpu=0, error=0; ks_chain_update(kc); for (cpu=0;cpu<numcpus;cpu++) { buf = get_cpu_data(cpuksp[cpu]); if (buf == NULL) error++; } #else buf = get_cpu_data(); dbprintf("CPU: idle: %d user: %d system: %d total %d\n", buf->idle, buf->user, buf->syst, buf->total ); free(buf); #endif return; }
/******************************************************************************* * This function gets the state id of the current cpu from the power state * parameter saved in the per-cpu data array. Returns PSCI_INVALID_DATA if the * power state saved is invalid. ******************************************************************************/ int psci_get_suspend_stateid() { unsigned int power_state; power_state = get_cpu_data(psci_svc_cpu_data.power_state); return ((power_state == PSCI_INVALID_DATA) ? power_state : psci_get_pstate_id(power_state)); }
/******************************************************************************* * This function reads the saved highest affinity level which is in OFF * state. The affinity instance with which the level is associated is determined * by the caller. ******************************************************************************/ uint32_t psci_get_max_phys_off_afflvl(void) { /* * Ensure that the last update of this value in this cpu's cache is * flushed to main memory and any speculatively pre-fetched stale copies * are invalidated from the caches of other cpus in the same coherency * domain. This ensures that the value is always read from the main * memory when it was written before the data cache was enabled. */ flush_cpu_data(psci_svc_cpu_data.max_phys_off_afflvl); return get_cpu_data(psci_svc_cpu_data.max_phys_off_afflvl); }
/* * Top-level Standard Service SMC handler. This handler will in turn dispatch * calls to PSCI SMC handler */ static uintptr_t std_svc_smc_handler(uint32_t smc_fid, u_register_t x1, u_register_t x2, u_register_t x3, u_register_t x4, void *cookie, void *handle, u_register_t flags) { /* * Dispatch PSCI calls to PSCI SMC handler and return its return * value */ if (is_psci_fid(smc_fid)) { uint64_t ret; #if ENABLE_RUNTIME_INSTRUMENTATION /* * Flush cache line so that even if CPU power down happens * the timestamp update is reflected in memory. */ PMF_WRITE_TIMESTAMP(rt_instr_svc, RT_INSTR_ENTER_PSCI, PMF_CACHE_MAINT, get_cpu_data(cpu_data_pmf_ts[CPU_DATA_PMF_TS0_IDX])); #endif ret = psci_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags); #if ENABLE_RUNTIME_INSTRUMENTATION PMF_CAPTURE_TIMESTAMP(rt_instr_svc, RT_INSTR_EXIT_PSCI, PMF_NO_CACHE_MAINT); #endif SMC_RET1(handle, ret); } #if ENABLE_SPM && SPM_DEPRECATED /* * Dispatch SPM calls to SPM SMC handler and return its return * value */ if (is_spm_fid(smc_fid)) { return spm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags); } #endif #if SDEI_SUPPORT if (is_sdei_fid(smc_fid)) { return sdei_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags); } #endif switch (smc_fid) { case ARM_STD_SVC_CALL_COUNT: /* * Return the number of Standard Service Calls. PSCI is the only * standard service implemented; so return number of PSCI calls */ SMC_RET1(handle, PSCI_NUM_CALLS); case ARM_STD_SVC_UID: /* Return UID to the caller */ SMC_UUID_RET(handle, arm_svc_uid); case ARM_STD_SVC_VERSION: /* Return the version of current implementation */ SMC_RET2(handle, STD_SVC_VERSION_MAJOR, STD_SVC_VERSION_MINOR); default: WARN("Unimplemented Standard Service Call: 0x%x \n", smc_fid); SMC_RET1(handle, SMC_UNK); } }
static pe_exc_data_t *this_cpu_data(void) { return &get_cpu_data(ehf_data); }
int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { unsigned long long cpu_val[4]; unsigned long long interval_size; char cpuname[MAX_STRING_LEN]; char mode[MAX_STRING_LEN]; int info_id = 0; int ret = SYSINFO_RET_FAIL; if(num_param(param) > 2) { return SYSINFO_RET_FAIL; } if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0) { cpuname[0] = '\0'; } if(cpuname[0] == '\0') { /* default parameter */ zbx_snprintf(cpuname, sizeof(cpuname), "all"); } if(0 == strncmp(cpuname, "all", MAX_STRING_LEN)) { cpuname[0] = '\0'; } if(get_param(param, 2, mode, sizeof(mode)) != 0) { mode[0] = '\0'; } if(mode[0] == '\0') { /* default parameter */ zbx_snprintf(mode, sizeof(mode),"idle"); } if(strcmp(mode,"idle") == 0) { info_id = CPU_I; } else if(strcmp(mode,"user") == 0) { info_id = CPU_U; } else if(strcmp(mode,"kernel") == 0) { info_id = CPU_K; } else if(strcmp(mode,"wait") == 0) { info_id = CPU_W; } else { return SYSINFO_RET_FAIL; } if (get_cpu_data(cpuname,&cpu_val[CPU_I], &cpu_val[CPU_K], &cpu_val[CPU_U], &cpu_val[CPU_W])) { interval_size = cpu_val[CPU_I] + cpu_val[CPU_K] + cpu_val[CPU_U] + cpu_val[CPU_W]; if (interval_size > 0) { SET_DBL_RESULT(result, (cpu_val[info_id] * 100.0)/interval_size); } else { SET_DBL_RESULT(result, 0); } ret = SYSINFO_RET_OK; } return ret; }
/******************************************************************************* * This function returns a pointer to the most recent 'cpu_context' structure * for the calling CPU that was set as the context for the specified security * state. NULL is returned if no such structure has been specified. ******************************************************************************/ void *cm_get_context(uint32_t security_state) { assert(security_state <= NON_SECURE); return get_cpu_data(cpu_context[security_state]); }