static void mod_sysstat_timer_handler(unsigned long data){ int num_cpu; int i; struct sysinfo info; long cached, shmem; struct timespec tv; struct sysinfo_snapshot *new_ent; /* get info */ si_meminfo(&info); ((void (*)(struct sysinfo *))ADDR_SI_SWAPINFO)(&info); cached = global_page_state(NR_FILE_PAGES) - ((unsigned long (*)())ADDR_TOTAL_SWAPCACHE_PAGES)() - info.bufferram; if(cached < 0) cached = 0; /* shared memory */ shmem = global_page_state(NR_SHMEM); getnstimeofday(&tv); /* count cpu */ num_cpu = 0; for_each_online_cpu(i) num_cpu++; new_ent = new_snapshot(num_cpu); if(new_ent == NULL){ print_msg("Ooops! kmalloc() fail"); mod_timer(&timer_mod_sysstat, get_jiffies_64() + (period_in_msecs*HZ)/1000); return; } new_ent->epoch_time = tv.tv_sec; new_ent->total_ram = info.totalram; new_ent->free_ram = info.freeram; new_ent->cached_ram = cached; new_ent->buffer_ram = info.bufferram; new_ent->total_swap = info.totalswap; new_ent->free_swap = info.freeswap; new_ent->shared_ram = shmem; for(i = 0; i < num_cpu; i++){ new_ent->cpuinfo_list[i].user = cputime64_to_clock_t(kcpustat_cpu(i).cpustat[CPUTIME_USER]); new_ent->cpuinfo_list[i].nice = cputime64_to_clock_t(kcpustat_cpu(i).cpustat[CPUTIME_NICE]); new_ent->cpuinfo_list[i].system = cputime64_to_clock_t(kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]); new_ent->cpuinfo_list[i].idle = cputime64_to_clock_t(((cputime64_t (*)())ADDR_GET_IDLE_TIME)(i)); new_ent->cpuinfo_list[i].iowait = cputime64_to_clock_t(((cputime64_t (*)())ADDR_IOWAIT_TIME)(i)); new_ent->cpuinfo_list[i].irq = cputime64_to_clock_t(kcpustat_cpu(i).cpustat[CPUTIME_IRQ]); new_ent->cpuinfo_list[i].softirq = cputime64_to_clock_t(kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]); } new_ent->next = NULL; insert_sysinfo_snapshot(new_ent); mod_timer(&timer_mod_sysstat, get_jiffies_64() + (period_in_msecs*HZ)/1000); }
static void inline cpufreq_greenmax_calc_load(int j) { struct greenmax_info_s *j_this_greenmax; u64 cur_wall_time, cur_idle_time, cur_iowait_time; unsigned int idle_time, wall_time, iowait_time; unsigned int cur_load; j_this_greenmax = &per_cpu(greenmax_info, j); cur_idle_time = get_cpu_idle_time_greenmax(j, &cur_wall_time); cur_iowait_time = get_cpu_iowait_time(j, &cur_wall_time); wall_time = cur_wall_time - j_this_greenmax->prev_cpu_wall; j_this_greenmax->prev_cpu_wall = cur_wall_time; idle_time = cur_idle_time - j_this_greenmax->prev_cpu_idle; j_this_greenmax->prev_cpu_idle = cur_idle_time; iowait_time = cur_iowait_time - j_this_greenmax->prev_cpu_iowait; j_this_greenmax->prev_cpu_iowait = cur_iowait_time; if (ignore_nice) { u64 cur_nice; unsigned long cur_nice_jiffies; cur_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE] - j_this_greenmax->prev_cpu_nice; cur_nice_jiffies = (unsigned long) cputime64_to_jiffies64(cur_nice); j_this_greenmax->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE]; idle_time += jiffies_to_usecs(cur_nice_jiffies); } /* * For the purpose of ondemand, waiting for disk IO is an * indication that you're performance critical, and not that * the system is actually idle. So subtract the iowait time * from the cpu idle time. */ if (io_is_busy && idle_time >= iowait_time) idle_time -= iowait_time; if (unlikely(!wall_time || wall_time < idle_time)) return; cur_load = 100 * (wall_time - idle_time) / wall_time; j_this_greenmax->cur_cpu_load = cur_load; }
static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data, const char *buf, size_t count) { struct od_dbs_tuners *od_tuners = dbs_data->tuners; unsigned int input; int ret; unsigned int j; ret = sscanf(buf, "%u", &input); if (ret != 1) return -EINVAL; if (input > 1) input = 1; if (input == od_tuners->ignore_nice_load) { /* nothing to do */ return count; } od_tuners->ignore_nice_load = input; /* we need to re-evaluate prev_cpu_idle */ for_each_online_cpu(j) { struct od_cpu_dbs_info_s *dbs_info; dbs_info = &per_cpu(od_cpu_dbs_info, j); dbs_info->cdbs.prev_cpu_idle = get_cpu_idle_time(j, &dbs_info->cdbs.prev_cpu_wall, od_tuners->io_is_busy); if (od_tuners->ignore_nice_load) dbs_info->cdbs.prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE]; } return count; }
static void dump_softlock_debug(unsigned long data) { int i, reboot; u64 system[NR_CPUS], num_jifs; memset(system, 0, NR_CPUS*sizeof(u64)); num_jifs = jiffies - beattime; for_each_possible_cpu(i) { system[i] = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM] - heartbeats[i]; } reboot = 0; for_each_possible_cpu(i) { if ((num_jifs - cputime_to_jiffies(system[i])) < msecs_to_jiffies(10)) { WARN(1, "cpu %d wedged\n", i); smp_call_function_single(i, smp_dumpstack, NULL, 1); reboot = 1; } } if (reboot) { panic_timeout = 10; trigger_all_cpu_backtrace(); panic("Soft lock on CPUs\n"); } }
static ssize_t store_ignore_nice_load(struct kobject *a, struct attribute *b, const char *buf, size_t count) { unsigned int input, j; int ret; ret = sscanf(buf, "%u", &input); if (ret != 1) return -EINVAL; if (input > 1) input = 1; if (input == cs_tuners.ignore_nice) /* nothing to do */ return count; cs_tuners.ignore_nice = input; /* we need to re-evaluate prev_cpu_idle */ for_each_online_cpu(j) { struct cs_cpu_dbs_info_s *dbs_info; dbs_info = &per_cpu(cs_cpu_dbs_info, j); dbs_info->cdbs.prev_cpu_idle = get_cpu_idle_time(j, &dbs_info->cdbs.prev_cpu_wall); if (cs_tuners.ignore_nice) dbs_info->cdbs.prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE]; } return count; }
static int uptime_proc_show(struct seq_file *m, void *v) { struct timespec uptime; struct timespec idle; u64 idletime; u64 nsec; u32 rem; int i; idletime = 0; for_each_possible_cpu(i) idletime += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE]; do_posix_clock_monotonic_gettime(&uptime); monotonic_to_bootbased(&uptime); nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC; idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem); idle.tv_nsec = rem; seq_printf(m, "%lu.%02lu %lu.%02lu\n", (unsigned long) uptime.tv_sec, (uptime.tv_nsec / (NSEC_PER_SEC / 100)), (unsigned long) idle.tv_sec, (idle.tv_nsec / (NSEC_PER_SEC / 100))); return 0; }
static cputime64_t get_idle_time(int cpu) { cputime64_t idle; idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; if (cpu_online(cpu) && !nr_iowait_cpu(cpu)) idle += arch_idle_time(cpu); return idle; }
static cputime64_t get_iowait_time(int cpu) { cputime64_t iowait; iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT]; if (cpu_online(cpu) && nr_iowait_cpu(cpu)) iowait += arch_idle_time(cpu); return iowait; }
static u64 get_idle_time(int cpu) { u64 idle, idle_time = get_cpu_idle_time_us(cpu, NULL); if (idle_time == -1ULL) idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; else idle = usecs_to_cputime64(idle_time); return idle; }
static u64 get_idle_time(int cpu) { u64 idle, idle_time = get_cpu_idle_time_us(cpu, NULL); if (idle_time == -1ULL) /* !NO_HZ or cpu offline so we can rely on cpustat.idle */ idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; else idle = usecs_to_cputime64(idle_time); return idle; }
static u64 get_idle_time(int cpu) { u64 idle, idle_time = get_cpu_idle_time_us(cpu, NULL); if (idle_time == -1ULL) /* !NO_HZ so we can rely on cpustat.idle */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0) idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; #else idle = kstat_cpu(cpu).cpustat.idle; #endif else
static u64 get_iowait_time(int cpu) { u64 iowait, iowait_time = get_cpu_iowait_time_us(cpu, NULL); if (iowait_time == -1ULL) iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT]; else iowait = usecs_to_cputime64(iowait_time); return iowait; }
static unsigned int calc_cur_load(unsigned int cpu) { struct cpu_load_data *pcpu = &per_cpu(cpuload, cpu); u64 cur_wall_time, cur_idle_time, cur_iowait_time; unsigned int idle_time, wall_time, iowait_time; cur_idle_time = get_cpu_idle_time(cpu, &cur_wall_time); cur_iowait_time = get_cpu_iowait_time(cpu, &cur_wall_time); wall_time = (unsigned int) (cur_wall_time - pcpu->prev_cpu_wall); pcpu->prev_cpu_wall = cur_wall_time; idle_time = (unsigned int) (cur_idle_time - pcpu->prev_cpu_idle); pcpu->prev_cpu_idle = cur_idle_time; iowait_time = (unsigned int) (cur_iowait_time - pcpu->prev_cpu_iowait); pcpu->prev_cpu_iowait = cur_iowait_time; if (ignore_nice) { u64 cur_nice; unsigned long cur_nice_jiffies; cur_nice = kcpustat_cpu(cpu).cpustat[CPUTIME_NICE] - pcpu->prev_cpu_nice; cur_nice_jiffies = (unsigned long) cputime64_to_jiffies64(cur_nice); pcpu->prev_cpu_nice = kcpustat_cpu(cpu).cpustat[CPUTIME_NICE]; idle_time += jiffies_to_usecs(cur_nice_jiffies); } if (io_is_busy && idle_time >= iowait_time) idle_time -= iowait_time; if (unlikely(!wall_time || wall_time < idle_time)) return 0; return 100 * (wall_time - idle_time) / wall_time; }
static u64 get_iowait_time(int cpu) { u64 iowait, iowait_usecs = -1ULL; if (cpu_online(cpu)) iowait_usecs = get_cpu_iowait_time_us(cpu, NULL); if (iowait_usecs == -1ULL) /* !NO_HZ or cpu offline so we can rely on cpustat.iowait */ iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT]; else iowait = iowait_usecs * NSEC_PER_USEC; return iowait; }
static u64 get_idle_time(int cpu) { u64 idle, idle_usecs = -1ULL; if (cpu_online(cpu)) idle_usecs = get_cpu_idle_time_us(cpu, NULL); if (idle_usecs == -1ULL) /* !NO_HZ or cpu offline so we can rely on cpustat.idle */ idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; else idle = idle_usecs * NSEC_PER_USEC; return idle; }
static u64 get_iowait_time(int cpu) { u64 iowait, iowait_time = -1ULL; if (cpu_online(cpu)) iowait_time = get_cpu_iowait_time_us(cpu, NULL); if (iowait_time == -1ULL) /* !NO_HZ or cpu offline so we can rely on cpustat.iowait */ iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT]; else iowait = usecs_to_cputime64(iowait_time); return iowait; }
static u64 get_idle_time(int cpu) { #ifdef CONFIG_MTK_IDLE_TIME_FIX u64 idle, idle_time = get_cpu_idle_time_us_wo_cpuoffline(cpu, NULL); #else u64 idle, idle_time = get_cpu_idle_time_us(cpu, NULL); #endif if (idle_time == -1ULL) /* !NO_HZ or cpu offline so we can rely on cpustat.idle */ idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; else idle = usecs_to_cputime64(idle_time); return idle; }
static u64 get_iowait_time(int cpu) { u64 iowait, iowait_time = -1ULL; #ifdef CONFIG_MTK_IDLE_TIME_FIX iowait_time = get_cpu_iowait_time_us_wo_cpuoffline(cpu, NULL); #else iowait_time = get_cpu_iowait_time_us(cpu, NULL); #endif if (iowait_time == -1ULL) /* !NO_HZ or cpu offline so we can rely on cpustat.iowait */ iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT]; else iowait = usecs_to_cputime64(iowait_time); return iowait; }
static u64 get_iowait_time(int cpu) { u64 iowait, iowait_time = -1ULL; /* FIXME: the iowait time from get_cpu_iowait_time_us() is reset while CPU is hot-pluged. * Using cpustat[CPUTIME_IOWAIT] to get iowait. It isn't very accurate, but stable */ #if 0 if (cpu_online(cpu)) iowait_time = get_cpu_iowait_time_us(cpu, NULL); #endif if (iowait_time == -1ULL) iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT]; else iowait = usecs_to_cputime64(iowait_time); return iowait; }
static void update_idle_time(bool online) { int j = 0; for_each_possible_cpu(j) { struct greenmax_info_s *j_this_greenmax; if (online && !cpu_online(j)) { continue; } j_this_greenmax = &per_cpu(greenmax_info, j); j_this_greenmax->prev_cpu_idle = get_cpu_idle_time_greenmax(j, &j_this_greenmax->prev_cpu_wall); if (ignore_nice) j_this_greenmax->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE]; } }
static void get_all_cpu_stat(struct kernel_cpustat *cpu_stat) { int i; if (!cpu_stat) return; memset(cpu_stat, 0, sizeof(struct kernel_cpustat)); for_each_possible_cpu(i) { cpu_stat->cpustat[CPUTIME_USER] += kcpustat_cpu(i).cpustat[CPUTIME_USER]; cpu_stat->cpustat[CPUTIME_NICE] += kcpustat_cpu(i).cpustat[CPUTIME_NICE]; cpu_stat->cpustat[CPUTIME_SYSTEM] += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]; cpu_stat->cpustat[CPUTIME_IDLE] += get_idle_time(i); cpu_stat->cpustat[CPUTIME_IOWAIT] += get_iowait_time(i); cpu_stat->cpustat[CPUTIME_IRQ] += kcpustat_cpu(i).cpustat[CPUTIME_IRQ]; cpu_stat->cpustat[CPUTIME_SOFTIRQ] += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]; cpu_stat->cpustat[CPUTIME_STEAL] += kcpustat_cpu(i).cpustat[CPUTIME_STEAL]; cpu_stat->cpustat[CPUTIME_GUEST] += kcpustat_cpu(i).cpustat[CPUTIME_GUEST]; cpu_stat->cpustat[CPUTIME_GUEST_NICE] += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE]; } }
/* tasklet */ static void watchdog_interrupt_tasklet_body(unsigned long data) { int ret; pr_warn(PFX "interrupt tasklet body start\n"); if (disable_kernel_watchdog) { /* disable the timer */ pr_warn(PFX "interrupt tasklet body disable set\n"); ret = intel_scu_stop(); if (ret) pr_err(PFX "cannot disable the timer\n"); return; } /* wake up read to send data to user (reminder for keep alive */ warning_flag = 1; #ifdef CONFIG_INTEL_SCU_SOFT_LOCKUP { int i; /*start timer for softlock detection */ beattime = jiffies; for_each_possible_cpu(i) { heartbeats[i] = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]; } mod_timer(&softlock_timer, jiffies + SOFT_LOCK_TIME * HZ); } #endif /* Wake up the daemon */ wake_up_interruptible(&read_wq); /* * Hold a timeout wakelock so user space watchdogd has a chance * to run after waking up from s3 */ wake_lock_timeout(&watchdog_wake_lock, 5 * HZ); }
static int uptime_proc_show(struct seq_file *m, void *v) { struct timespec64 uptime; struct timespec64 idle; u64 nsec; u32 rem; int i; nsec = 0; for_each_possible_cpu(i) nsec += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE]; ktime_get_boottime_ts64(&uptime); idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem); idle.tv_nsec = rem; seq_printf(m, "%lu.%02lu %lu.%02lu\n", (unsigned long) uptime.tv_sec, (uptime.tv_nsec / (NSEC_PER_SEC / 100)), (unsigned long) idle.tv_sec, (idle.tv_nsec / (NSEC_PER_SEC / 100))); return 0; }
static u64 get_idle_time(int cpu) { u64 idle, idle_time = -1ULL; /* FIXME: the idle time from get_cpu_idle_time_us() is reset while CPU is hot-pluged. * Using cpustat[CPUTIME_IDLE] to get idle. It isn't very accurate, but stable */ #if 0 if (cpu_online(cpu)) idle_time = get_cpu_idle_time_us(cpu, NULL); #endif if (idle_time == -1ULL) idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; else idle = usecs_to_cputime64(idle_time); //FIXME: this idle function has bug on our shark platform: // not monotone increasing if(DEBUG_PRINT) printk("acedebug: get_idle_time: cpu=%d, idle=%llu\n", cpu, idle); return idle; }
static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall) { u64 idle_time; u64 cur_wall_time; u64 busy_time; cur_wall_time = jiffies64_to_cputime64(get_jiffies_64()); busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER]; busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM]; busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ]; busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ]; busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL]; busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE]; idle_time = cur_wall_time - busy_time; if (wall) *wall = cputime_to_usecs(cur_wall_time); return cputime_to_usecs(idle_time); }
static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall) { u64 idle_time; u64 cur_wall_time; u64 busy_time; /*lint --e{718, 746, 737, 732, 712, 747 } */ cur_wall_time = jiffies64_to_cputime64(get_jiffies_64()); /*lint --e{409,550}*/ busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER]; busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM]; busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ]; busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ]; busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL]; busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE]; idle_time = cur_wall_time - busy_time; if (wall) *wall = jiffies_to_usecs(cur_wall_time); return jiffies_to_usecs(idle_time); }
static int show_stat(struct seq_file *p, void *v) { int i, j; unsigned long jif; u64 user, nice, system, idle, iowait, irq, softirq, steal; u64 guest, guest_nice; u64 sum = 0; u64 sum_softirq = 0; unsigned int per_softirq_sums[NR_SOFTIRQS] = {0}; struct timespec boottime; user = nice = system = idle = iowait = irq = softirq = steal = 0; guest = guest_nice = 0; getboottime(&boottime); jif = boottime.tv_sec; for_each_possible_cpu(i) { user += kcpustat_cpu(i).cpustat[CPUTIME_USER]; nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE]; system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]; idle += get_idle_time(i); iowait += get_iowait_time(i); irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ]; softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]; steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL]; guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST]; guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE]; sum += kstat_cpu_irqs_sum(i); sum += arch_irq_stat_cpu(i); for (j = 0; j < NR_SOFTIRQS; j++) { unsigned int softirq_stat = kstat_softirqs_cpu(j, i); per_softirq_sums[j] += softirq_stat; sum_softirq += softirq_stat; } } sum += arch_irq_stat(); seq_puts(p, "cpu "); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(system)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(idle)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(iowait)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(irq)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(softirq)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(steal)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(guest)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(guest_nice)); seq_putc(p, '\n'); for_each_online_cpu(i) { /* Copy values here to work around gcc-2.95.3, gcc-2.96 */ user = kcpustat_cpu(i).cpustat[CPUTIME_USER]; nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE]; system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]; idle = get_idle_time(i); iowait = get_iowait_time(i); irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ]; softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]; steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL]; guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST]; guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE]; seq_printf(p, "cpu%d", i); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(system)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(idle)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(iowait)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(irq)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(softirq)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(steal)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(guest)); seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(guest_nice)); seq_putc(p, '\n'); } seq_printf(p, "intr %llu", (unsigned long long)sum); /* sum again ? it could be updated? */ for_each_irq_nr(j) seq_put_decimal_ull(p, ' ', kstat_irqs(j)); seq_printf(p, "\nctxt %llu\n" "btime %lu\n" "processes %lu\n" "procs_running %lu\n" "procs_blocked %lu\n", nr_context_switches(), (unsigned long)jif, total_forks, nr_running(), nr_iowait()); seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq); for (i = 0; i < NR_SOFTIRQS; i++) seq_put_decimal_ull(p, ' ', per_softirq_sums[i]); seq_putc(p, '\n'); return 0; }
long get_cpu_usage(int cpu, long* IoWaitUsage) { u64 CurrTime = 0; u64 CurrBusyTime = 0; u64 CurrIoWaitTime = 0; long TotalTickCount = 0; long BusyTickCount = 0; long IoWaitTickCount = 0; long Usage = 0; *IoWaitUsage = 0; if(cpu >= CPU_NUMS) { return Usage; } /* get the current time */ CurrTime = jiffies_to_usecs(jiffies_64); /* get this cpu's busy time */ CurrBusyTime = kcpustat_cpu(cpu).cpustat[CPUTIME_USER]; CurrBusyTime += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM]; CurrBusyTime += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ]; CurrBusyTime += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ]; CurrBusyTime += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL]; CurrBusyTime += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE]; CurrBusyTime = jiffies_to_usecs(CurrBusyTime); CurrIoWaitTime = jiffies_to_usecs(kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT]); /* Calculate the time interval */ TotalTickCount = CurrTime - LastCheckedTime[cpu]; BusyTickCount = CurrBusyTime - LastBusyTime[cpu]; IoWaitTickCount = CurrIoWaitTime - LastIoWaitTime[cpu]; /* record last current and busy time */ LastBusyTime[cpu] = CurrBusyTime; LastCheckedTime[cpu] = CurrTime; LastIoWaitTime[cpu] = CurrIoWaitTime; Last_checked_jiffies = jiffies_64; /* Calculate the busy rate */ if (TotalTickCount >= BusyTickCount && TotalTickCount > 0) { BusyTickCount = 100 * BusyTickCount; do_div(BusyTickCount, TotalTickCount); Usage = BusyTickCount; IoWaitTickCount = 100 * IoWaitTickCount; do_div(IoWaitTickCount, TotalTickCount); *IoWaitUsage = IoWaitTickCount; } else { Usage = 0; } return Usage; }
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; }