^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/sched/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/irqnr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/sched/cputime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/tick.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #ifndef arch_irq_stat_cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define arch_irq_stat_cpu(cpu) 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #ifndef arch_irq_stat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define arch_irq_stat() 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #ifdef arch_idle_time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) u64 get_idle_time(struct kernel_cpustat *kcs, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) u64 idle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) idle = kcs->cpustat[CPUTIME_IDLE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (cpu_online(cpu) && !nr_iowait_cpu(cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) idle += arch_idle_time(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) return idle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static u64 get_iowait_time(struct kernel_cpustat *kcs, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) u64 iowait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) iowait = kcs->cpustat[CPUTIME_IOWAIT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (cpu_online(cpu) && nr_iowait_cpu(cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) iowait += arch_idle_time(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return iowait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u64 get_idle_time(struct kernel_cpustat *kcs, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u64 idle, idle_usecs = -1ULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (cpu_online(cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) idle_usecs = get_cpu_idle_time_us(cpu, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (idle_usecs == -1ULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* !NO_HZ or cpu offline so we can rely on cpustat.idle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) idle = kcs->cpustat[CPUTIME_IDLE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) idle = idle_usecs * NSEC_PER_USEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) return idle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static u64 get_iowait_time(struct kernel_cpustat *kcs, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u64 iowait, iowait_usecs = -1ULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (cpu_online(cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) iowait_usecs = get_cpu_iowait_time_us(cpu, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (iowait_usecs == -1ULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* !NO_HZ or cpu offline so we can rely on cpustat.iowait */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) iowait = kcs->cpustat[CPUTIME_IOWAIT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) iowait = iowait_usecs * NSEC_PER_USEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return iowait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static void show_irq_gap(struct seq_file *p, unsigned int gap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static const char zeros[] = " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) while (gap > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) unsigned int inc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) inc = min_t(unsigned int, gap, ARRAY_SIZE(zeros) / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) seq_write(p, zeros, 2 * inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) gap -= inc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static void show_all_irqs(struct seq_file *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned int i, next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) for_each_active_irq(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) show_irq_gap(p, i - next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) seq_put_decimal_ull(p, " ", kstat_irqs_usr(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) next = i + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) show_irq_gap(p, nr_irqs - next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int show_stat(struct seq_file *p, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) u64 user, nice, system, idle, iowait, irq, softirq, steal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) u64 guest, guest_nice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) u64 sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) u64 sum_softirq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct timespec64 boottime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) user = nice = system = idle = iowait =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) irq = softirq = steal = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) guest = guest_nice = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) getboottime64(&boottime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) for_each_possible_cpu(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct kernel_cpustat kcpustat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) u64 *cpustat = kcpustat.cpustat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) kcpustat_cpu_fetch(&kcpustat, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) user += cpustat[CPUTIME_USER];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) nice += cpustat[CPUTIME_NICE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) system += cpustat[CPUTIME_SYSTEM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) idle += get_idle_time(&kcpustat, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) iowait += get_iowait_time(&kcpustat, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) irq += cpustat[CPUTIME_IRQ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) softirq += cpustat[CPUTIME_SOFTIRQ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) steal += cpustat[CPUTIME_STEAL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) guest += cpustat[CPUTIME_GUEST];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) guest_nice += cpustat[CPUTIME_GUEST_NICE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) sum += kstat_cpu_irqs_sum(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) sum += arch_irq_stat_cpu(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) for (j = 0; j < NR_SOFTIRQS; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) per_softirq_sums[j] += softirq_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) sum_softirq += softirq_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) sum += arch_irq_stat();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) seq_put_decimal_ull(p, "cpu ", nsec_to_clock_t(user));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) seq_put_decimal_ull(p, " ", nsec_to_clock_t(nice));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) seq_put_decimal_ull(p, " ", nsec_to_clock_t(system));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) seq_put_decimal_ull(p, " ", nsec_to_clock_t(idle));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) seq_put_decimal_ull(p, " ", nsec_to_clock_t(iowait));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) seq_put_decimal_ull(p, " ", nsec_to_clock_t(irq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) seq_put_decimal_ull(p, " ", nsec_to_clock_t(softirq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) seq_put_decimal_ull(p, " ", nsec_to_clock_t(steal));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) seq_put_decimal_ull(p, " ", nsec_to_clock_t(guest));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) seq_put_decimal_ull(p, " ", nsec_to_clock_t(guest_nice));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) seq_putc(p, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) for_each_online_cpu(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct kernel_cpustat kcpustat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) u64 *cpustat = kcpustat.cpustat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) kcpustat_cpu_fetch(&kcpustat, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) user = cpustat[CPUTIME_USER];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) nice = cpustat[CPUTIME_NICE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) system = cpustat[CPUTIME_SYSTEM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) idle = get_idle_time(&kcpustat, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) iowait = get_iowait_time(&kcpustat, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) irq = cpustat[CPUTIME_IRQ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) softirq = cpustat[CPUTIME_SOFTIRQ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) steal = cpustat[CPUTIME_STEAL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) guest = cpustat[CPUTIME_GUEST];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) guest_nice = cpustat[CPUTIME_GUEST_NICE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) seq_printf(p, "cpu%d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) seq_put_decimal_ull(p, " ", nsec_to_clock_t(user));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) seq_put_decimal_ull(p, " ", nsec_to_clock_t(nice));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) seq_put_decimal_ull(p, " ", nsec_to_clock_t(system));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) seq_put_decimal_ull(p, " ", nsec_to_clock_t(idle));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) seq_put_decimal_ull(p, " ", nsec_to_clock_t(iowait));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) seq_put_decimal_ull(p, " ", nsec_to_clock_t(irq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) seq_put_decimal_ull(p, " ", nsec_to_clock_t(softirq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) seq_put_decimal_ull(p, " ", nsec_to_clock_t(steal));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) seq_put_decimal_ull(p, " ", nsec_to_clock_t(guest));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) seq_put_decimal_ull(p, " ", nsec_to_clock_t(guest_nice));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) seq_putc(p, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) seq_put_decimal_ull(p, "intr ", (unsigned long long)sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) show_all_irqs(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) seq_printf(p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) "\nctxt %llu\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) "btime %llu\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) "processes %lu\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) "procs_running %lu\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) "procs_blocked %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) nr_context_switches(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) (unsigned long long)boottime.tv_sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) total_forks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) nr_running(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) nr_iowait());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) seq_put_decimal_ull(p, "softirq ", (unsigned long long)sum_softirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) for (i = 0; i < NR_SOFTIRQS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) seq_put_decimal_ull(p, " ", per_softirq_sums[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) seq_putc(p, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static int stat_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) unsigned int size = 1024 + 128 * num_online_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* minimum size to display an interrupt count : 2 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) size += 2 * nr_irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return single_open_size(file, show_stat, NULL, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static const struct proc_ops stat_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) .proc_flags = PROC_ENTRY_PERMANENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .proc_open = stat_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .proc_read_iter = seq_read_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .proc_lseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) .proc_release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static int __init proc_stat_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) proc_create("stat", 0, NULL, &stat_proc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) fs_initcall(proc_stat_init);