Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * /proc/schedstat implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include "sched.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Current schedstat API version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Bump this up when changing the output format or the meaning of an existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * format, so that tools can adapt (or abort)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define SCHEDSTAT_VERSION 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) static int show_schedstat(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	if (v == (void *)1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 		seq_printf(seq, "version %d\n", SCHEDSTAT_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		seq_printf(seq, "timestamp %lu\n", jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 		struct rq *rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		struct sched_domain *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		int dcount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		cpu = (unsigned long)(v - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		rq = cpu_rq(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		/* runqueue-specific stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		    "cpu%d %u 0 %u %u %u %u %llu %llu %lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		    cpu, rq->yld_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		    rq->sched_count, rq->sched_goidle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		    rq->ttwu_count, rq->ttwu_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		    rq->rq_cpu_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		    rq->rq_sched_info.run_delay, rq->rq_sched_info.pcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		seq_printf(seq, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		/* domain-specific stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		for_each_domain(cpu, sd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			enum cpu_idle_type itype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			seq_printf(seq, "domain%d %*pb", dcount++,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 				   cpumask_pr_args(sched_domain_span(sd)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			for (itype = CPU_IDLE; itype < CPU_MAX_IDLE_TYPES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 					itype++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 				seq_printf(seq, " %u %u %u %u %u %u %u %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 				    sd->lb_count[itype],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 				    sd->lb_balanced[itype],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 				    sd->lb_failed[itype],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 				    sd->lb_imbalance[itype],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 				    sd->lb_gained[itype],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 				    sd->lb_hot_gained[itype],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 				    sd->lb_nobusyq[itype],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 				    sd->lb_nobusyg[itype]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 				   " %u %u %u %u %u %u %u %u %u %u %u %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			    sd->alb_count, sd->alb_failed, sd->alb_pushed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			    sd->sbe_count, sd->sbe_balanced, sd->sbe_pushed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			    sd->sbf_count, sd->sbf_balanced, sd->sbf_pushed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			    sd->ttwu_wake_remote, sd->ttwu_move_affine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			    sd->ttwu_move_balance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * This itererator needs some explanation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * It returns 1 for the header position.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * This means 2 is cpu 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * In a hotplugged system some CPUs, including cpu 0, may be missing so we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * to use cpumask_* to iterate over the CPUs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static void *schedstat_start(struct seq_file *file, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	unsigned long n = *offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return (void *) 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	n--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (n > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		n = cpumask_next(n - 1, cpu_online_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		n = cpumask_first(cpu_online_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	*offset = n + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (n < nr_cpu_ids)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		return (void *)(unsigned long)(n + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static void *schedstat_next(struct seq_file *file, void *data, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	(*offset)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return schedstat_start(file, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static void schedstat_stop(struct seq_file *file, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static const struct seq_operations schedstat_sops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	.start = schedstat_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	.next  = schedstat_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.stop  = schedstat_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.show  = show_schedstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static int __init proc_schedstat_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	proc_create_seq("schedstat", 0, NULL, &schedstat_sops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) subsys_initcall(proc_schedstat_init);