/* * Read Battery Information. * * "cat /sys/devices/platform/mt6575-battery/FG_Battery_CurrentConsumption" * "cat /sys/class/power_supply/battery/batt_vol" * "cat /sys/class/power_supply/battery/batt_temp" */ static int get_sys_battery_info(char* dev) { int fd; int nRet; int nReadSize; char *pvalue = NULL; char buf[64]; oldfs = get_fs(); set_fs(KERNEL_DS); fd = sys_open(dev, O_RDONLY, 0); if (fd < 0) { THRML_LOG("[get_sys_battery_info] open fail dev:%s fd:%d \n", dev, fd); set_fs(oldfs); return fd; } nReadSize = sys_read(fd, buf, sizeof(buf) - 1); THRML_LOG("[get_sys_battery_info] nReadSize:%d\n", nReadSize); nRet = simple_strtol(buf, &pvalue, 10); set_fs(oldfs); sys_close(fd); return nRet; }
int mtk_thermal_get_extra_info( int *no_extra_attr, char ***attr_names, int **attr_values, char ***attr_units) { int size, i=0; if (no_extra_attr) *no_extra_attr = NO_EXTRA_THERMAL_ATTR; //****************** // Modem Index //****************** THRML_LOG("[mtk_thermal_get_gpu_info] mtk_mdm_get_md_info\n"); { struct md_info *p_info; mtk_mdm_get_md_info(&p_info, &size); THRML_LOG("[mtk_thermal_get_gpu_info] mtk_mdm_get_md_info size %d\n", size); if (size <= NO_EXTRA_THERMAL_ATTR-1) { for (i=0; i<size; i++) { extra_attr_names[i] = p_info[i].attribute; extra_attr_values[i] = p_info[i].value; extra_attr_units[i] = p_info[i].unit; } } } //****************** // Wifi Index //****************** /* Get Wi-Fi Tx throughput */ THRML_LOG("[mtk_thermal_get_gpu_info] get_sys_wifi_throughput\n"); extra_attr_names[i] = "WiFi_TP"; extra_attr_values[i] = get_sys_wifi_throughput("/proc/wmt_tm/tx_thro", 3); extra_attr_units[i] = "Kbps"; if (attr_names) *attr_names = extra_attr_names; if (attr_values) *attr_values = extra_attr_values; if (attr_units) *attr_units = extra_attr_units; return 0; }
int mtk_thermal_get_gpu_info( int *nocores, int **gpufreq, int **gpuloading) { //****************** // GPU Index //****************** THRML_LOG("[mtk_thermal_get_gpu_info] \n"); if (nocores) *nocores = NO_GPU_CORES; if (gpufreq) { gpufreqs[0] = mt_gpufreq_get_cur_freq()/1000; // MHz *gpufreq = gpufreqs; } if (gpuloading) { unsigned int rd_gpu_loading = 0; if (mtk_get_gpu_loading(&rd_gpu_loading)) { gpuloadings[0] = (int) rd_gpu_loading; *gpuloading = gpuloadings; } } return 0; }
static int get_sys_cpu_freq_info(char* dev, int nRetryNr) { int fd; int nRet=0; int nReadSize; int nRetryCnt=0; char *pvalue = NULL; char buf[64]; oldfs = get_fs(); set_fs(KERNEL_DS); /* If sys_open fail, it will retry three times. */ do { fd = sys_open(dev, O_RDONLY, 0); if(nRetryCnt > nRetryNr) { THRML_LOG("[get_sys_cpu_freq_info] open fail dev:%s fd:%d \n", dev, fd); set_fs(oldfs); return fd; } nRetryCnt++; }while(fd < 0); if(nRetryCnt > 1) { THRML_LOG("[get_sys_cpu_freq_info] open fail nRetryCnt:%d \n", nRetryCnt); } nReadSize = sys_read(fd, buf, sizeof(buf) - 1); //THRML_LOG("[get_sys_cpu_freq_info] nReadSize:%d\n", nReadSize); nRet = simple_strtol(buf, &pvalue, 10); set_fs(oldfs); sys_close(fd); return nRet; }
/* ********************************************* */ static int get_sys_wifi_throughput(char *dev, int nRetryNr) { int fd; int nRet; int nReadSize; int nRetryCnt = 0; char *pvalue = NULL; char buf[64]; oldfs = get_fs(); set_fs(KERNEL_DS); /* If sys_open fail, it will retry "nRetryNr" times. */ do { fd = sys_open(dev, O_RDONLY, 0); if (nRetryCnt > nRetryNr) { THRML_LOG("%s open fail dev:%s fd:%d\n", __func__, dev, fd); set_fs(oldfs); return fd; } nRetryCnt++; } while(fd < 0); if (nRetryCnt > 1) { THRML_LOG("%s open fail nRetryCnt:%d\n", __func__, nRetryCnt); } nReadSize = sys_read(fd, buf, sizeof(buf) - 1); THRML_LOG("%s nReadSize:%d\n", __func__, nReadSize); nRet = simple_strtol(buf, &pvalue, 10); set_fs(oldfs); sys_close(fd); return nRet; }
static int get_sys_cpu_usage_info_ex(void) { int nCoreIndex = 0, i; for (i = 0; i < NO_CPU_CORES; i ++) cpuloadings[i] = 0; for_each_online_cpu(nCoreIndex) { /* Get CPU Info */ cpu_index_list[nCoreIndex].u[CPU_USAGE_CURRENT_FIELD] = kcpustat_cpu(nCoreIndex).cpustat[CPUTIME_USER]; cpu_index_list[nCoreIndex].n[CPU_USAGE_CURRENT_FIELD] = kcpustat_cpu(nCoreIndex).cpustat[CPUTIME_NICE]; cpu_index_list[nCoreIndex].s[CPU_USAGE_CURRENT_FIELD] = kcpustat_cpu(nCoreIndex).cpustat[CPUTIME_SYSTEM]; cpu_index_list[nCoreIndex].i[CPU_USAGE_CURRENT_FIELD] = get_idle_time(nCoreIndex); cpu_index_list[nCoreIndex].w[CPU_USAGE_CURRENT_FIELD] = get_iowait_time(nCoreIndex); cpu_index_list[nCoreIndex].q[CPU_USAGE_CURRENT_FIELD] = kcpustat_cpu(nCoreIndex).cpustat[CPUTIME_IRQ]; cpu_index_list[nCoreIndex].sq[CPU_USAGE_CURRENT_FIELD] = kcpustat_cpu(nCoreIndex).cpustat[CPUTIME_SOFTIRQ]; /* Frame */ cpu_index_list[nCoreIndex].u[CPU_USAGE_FRAME_FIELD] = cpu_index_list[nCoreIndex].u[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].u[CPU_USAGE_SAVE_FIELD]; cpu_index_list[nCoreIndex].n[CPU_USAGE_FRAME_FIELD] = cpu_index_list[nCoreIndex].n[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].n[CPU_USAGE_SAVE_FIELD]; cpu_index_list[nCoreIndex].s[CPU_USAGE_FRAME_FIELD] = cpu_index_list[nCoreIndex].s[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].s[CPU_USAGE_SAVE_FIELD]; cpu_index_list[nCoreIndex].i[CPU_USAGE_FRAME_FIELD] = TRIMz_ex(cpu_index_list[nCoreIndex].tz, (cpu_index_list[nCoreIndex].i[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].i[CPU_USAGE_SAVE_FIELD])) ; cpu_index_list[nCoreIndex].w[CPU_USAGE_FRAME_FIELD] = cpu_index_list[nCoreIndex].w[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].w[CPU_USAGE_SAVE_FIELD]; cpu_index_list[nCoreIndex].q[CPU_USAGE_FRAME_FIELD] = cpu_index_list[nCoreIndex].q[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].q[CPU_USAGE_SAVE_FIELD] ; cpu_index_list[nCoreIndex].sq[CPU_USAGE_FRAME_FIELD] = cpu_index_list[nCoreIndex].sq[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].sq[CPU_USAGE_SAVE_FIELD]; /* Total Frame */ cpu_index_list[nCoreIndex].tot_frme = cpu_index_list[nCoreIndex].u[CPU_USAGE_FRAME_FIELD] + cpu_index_list[nCoreIndex].n[CPU_USAGE_FRAME_FIELD] + cpu_index_list[nCoreIndex].s[CPU_USAGE_FRAME_FIELD] + cpu_index_list[nCoreIndex].i[CPU_USAGE_FRAME_FIELD] + cpu_index_list[nCoreIndex].w[CPU_USAGE_FRAME_FIELD] + cpu_index_list[nCoreIndex].q[CPU_USAGE_FRAME_FIELD] + cpu_index_list[nCoreIndex].sq[CPU_USAGE_FRAME_FIELD]; /* CPU Usage */ if (cpu_index_list[nCoreIndex].tot_frme > 0) { cpuloadings[nCoreIndex] = (100-(((int)cpu_index_list[nCoreIndex].i[CPU_USAGE_FRAME_FIELD]*100)/(int)cpu_index_list[nCoreIndex].tot_frme)); } else { /* CPU unplug case */ cpuloadings[nCoreIndex] = 0; } cpu_index_list[nCoreIndex].u[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].u[CPU_USAGE_CURRENT_FIELD]; cpu_index_list[nCoreIndex].n[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].n[CPU_USAGE_CURRENT_FIELD]; cpu_index_list[nCoreIndex].s[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].s[CPU_USAGE_CURRENT_FIELD]; cpu_index_list[nCoreIndex].i[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].i[CPU_USAGE_CURRENT_FIELD]; cpu_index_list[nCoreIndex].w[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].w[CPU_USAGE_CURRENT_FIELD]; cpu_index_list[nCoreIndex].q[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].q[CPU_USAGE_CURRENT_FIELD]; cpu_index_list[nCoreIndex].sq[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].sq[CPU_USAGE_CURRENT_FIELD]; THRML_LOG("CPU%d Frame:%lu USAGE:%d\n", nCoreIndex, cpu_index_list[nCoreIndex].tot_frme, cpuloadings[nCoreIndex]); for (i=0 ; i<3 ; i++) { THRML_LOG("Index %d [u:%lu] [n:%lu] [s:%lu] [i:%lu] [w:%lu] [q:%lu] [sq:%lu] \n", i, cpu_index_list[nCoreIndex].u[i], cpu_index_list[nCoreIndex].n[i], cpu_index_list[nCoreIndex].s[i], cpu_index_list[nCoreIndex].i[i], cpu_index_list[nCoreIndex].w[i], cpu_index_list[nCoreIndex].q[i], cpu_index_list[nCoreIndex].sq[i]); } } return 0; }
static int get_sys_cpu_usage_info_ex_procstat(void) { int fd; int nReadSize; char szTempBuf[256]; char buf[512]; char *pbuf; int nCoreIndex = 0, i; oldfs = get_fs(); set_fs(KERNEL_DS); fd = sys_open("/proc/stat", O_RDONLY, 0); if (fd < 0) { THRML_LOG("[get_sys_cpu_usage_info] open fail fd:%d \n", fd); set_fs(oldfs); return -1; } nReadSize = sys_read(fd, buf, sizeof(buf) - 1); buf[510] = '\n'; buf[511] = 0x0; set_fs(oldfs); sys_close(fd); pbuf = buf; SEEK_BUFF(pbuf, '\n'); // skip first line THRML_LOG("[Read Buff]:%s \n", buf); for (nCoreIndex = 0; nCoreIndex < NUMBER_OF_CORE; nCoreIndex++) { int ret = 0; sprintf(szTempBuf, "cpu%01d %%lu %%lu %%lu %%lu %%lu %%lu %%lu", nCoreIndex); /* Get CPU Info */ if (strncmp(pbuf, "cpu", 3) == 0) { ret = sscanf(pbuf, szTempBuf, &cpu_index_list[nCoreIndex].u[CPU_USAGE_CURRENT_FIELD], &cpu_index_list[nCoreIndex].n[CPU_USAGE_CURRENT_FIELD], &cpu_index_list[nCoreIndex].s[CPU_USAGE_CURRENT_FIELD], &cpu_index_list[nCoreIndex].i[CPU_USAGE_CURRENT_FIELD], &cpu_index_list[nCoreIndex].w[CPU_USAGE_CURRENT_FIELD], &cpu_index_list[nCoreIndex].q[CPU_USAGE_CURRENT_FIELD], &cpu_index_list[nCoreIndex].sq[CPU_USAGE_CURRENT_FIELD]); SEEK_BUFF(pbuf, '\n'); THRML_LOG("sscanf = %d, buf = %0x, pbuf = %0x\n", ret, (int) &buf[0], (int) pbuf); } /* Frame */ cpu_index_list[nCoreIndex].u[CPU_USAGE_FRAME_FIELD] = cpu_index_list[nCoreIndex].u[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].u[CPU_USAGE_SAVE_FIELD]; cpu_index_list[nCoreIndex].n[CPU_USAGE_FRAME_FIELD] = cpu_index_list[nCoreIndex].n[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].n[CPU_USAGE_SAVE_FIELD]; cpu_index_list[nCoreIndex].s[CPU_USAGE_FRAME_FIELD] = cpu_index_list[nCoreIndex].s[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].s[CPU_USAGE_SAVE_FIELD]; cpu_index_list[nCoreIndex].i[CPU_USAGE_FRAME_FIELD] = TRIMz_ex(cpu_index_list[nCoreIndex].tz, (cpu_index_list[nCoreIndex].i[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].i[CPU_USAGE_SAVE_FIELD])) ; cpu_index_list[nCoreIndex].w[CPU_USAGE_FRAME_FIELD] = cpu_index_list[nCoreIndex].w[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].w[CPU_USAGE_SAVE_FIELD]; cpu_index_list[nCoreIndex].q[CPU_USAGE_FRAME_FIELD] = cpu_index_list[nCoreIndex].q[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].q[CPU_USAGE_SAVE_FIELD] ; cpu_index_list[nCoreIndex].sq[CPU_USAGE_FRAME_FIELD] = cpu_index_list[nCoreIndex].sq[CPU_USAGE_CURRENT_FIELD] - cpu_index_list[nCoreIndex].sq[CPU_USAGE_SAVE_FIELD]; /* Total Frame */ cpu_index_list[nCoreIndex].tot_frme = cpu_index_list[nCoreIndex].u[CPU_USAGE_FRAME_FIELD] + cpu_index_list[nCoreIndex].n[CPU_USAGE_FRAME_FIELD] + cpu_index_list[nCoreIndex].s[CPU_USAGE_FRAME_FIELD] + cpu_index_list[nCoreIndex].i[CPU_USAGE_FRAME_FIELD] + cpu_index_list[nCoreIndex].w[CPU_USAGE_FRAME_FIELD] + cpu_index_list[nCoreIndex].q[CPU_USAGE_FRAME_FIELD] + cpu_index_list[nCoreIndex].sq[CPU_USAGE_FRAME_FIELD]; /* CPU Usage */ if(cpu_index_list[nCoreIndex].tot_frme > 0) { cpuloadings[nCoreIndex] = (100-(((int)cpu_index_list[nCoreIndex].i[CPU_USAGE_FRAME_FIELD]*100)/(int)cpu_index_list[nCoreIndex].tot_frme)); }else { /* CPU unplug case */ cpuloadings[nCoreIndex] = 0; } cpu_index_list[nCoreIndex].u[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].u[CPU_USAGE_CURRENT_FIELD]; cpu_index_list[nCoreIndex].n[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].n[CPU_USAGE_CURRENT_FIELD]; cpu_index_list[nCoreIndex].s[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].s[CPU_USAGE_CURRENT_FIELD]; cpu_index_list[nCoreIndex].i[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].i[CPU_USAGE_CURRENT_FIELD]; cpu_index_list[nCoreIndex].w[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].w[CPU_USAGE_CURRENT_FIELD]; cpu_index_list[nCoreIndex].q[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].q[CPU_USAGE_CURRENT_FIELD]; cpu_index_list[nCoreIndex].sq[CPU_USAGE_SAVE_FIELD] = cpu_index_list[nCoreIndex].sq[CPU_USAGE_CURRENT_FIELD]; THRML_LOG("CPU%d Frame:%d USAGE:%d \n", nCoreIndex, cpu_index_list[nCoreIndex].tot_frme, cpuloadings[nCoreIndex]); for(i=0 ; i<3 ; i++) { THRML_LOG("Index [u:%d] [n:%d] [s:%d] [i:%d] [w:%d] [q:%d] [sq:%d] \n", i, cpu_index_list[nCoreIndex].u[i], cpu_index_list[nCoreIndex].n[i], cpu_index_list[nCoreIndex].s[i], cpu_index_list[nCoreIndex].i[i], cpu_index_list[nCoreIndex].w[i], cpu_index_list[nCoreIndex].q[i], cpu_index_list[nCoreIndex].sq[i]); } }//for return 0; }