^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * latencytop.c: Latency display infrastructure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (C) Copyright 2008 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Arjan van de Ven <arjan@linux.intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * CONFIG_LATENCYTOP enables a kernel latency tracking infrastructure that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * used by the "latencytop" userspace tool. The latency that is tracked is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * the 'traditional' interrupt latency (which is primarily caused by something
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * else consuming CPU), but instead, it is the latency an application encounters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * because the kernel sleeps on its behalf for various reasons.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * This code tracks 2 levels of statistics:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * 1) System level latency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * 2) Per process latency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * The latency is stored in fixed sized data structures in an accumulated form;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * if the "same" latency cause is hit twice, this will be tracked as one entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * in the data structure. Both the count, total accumulated latency and maximum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * latency are tracked in this data structure. When the fixed size structure is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * full, no new causes are tracked until the buffer is flushed by writing to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * the /proc file; the userspace tool does this on a regular basis.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * A latency cause is identified by a stringified backtrace at the point that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * the scheduler gets invoked. The userland tool will use this string to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * identify the cause of the latency in human readable form.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * The information is exported via /proc/latency_stats and /proc/<pid>/latency.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * These files look like this:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Latency Top version : v0.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * 70 59433 4897 i915_irq_wait drm_ioctl vfs_ioctl do_vfs_ioctl sys_ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * | | | +----> the stringified backtrace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * | | +---------> The maximum latency for this entry in microseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * | +--------------> The accumulated latency for this entry (microseconds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * +-------------------> The number of times this entry is hit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * (note: the average latency is the accumulated latency divided by the number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * of times)
^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) #include <linux/kallsyms.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <linux/latencytop.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <linux/sched/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include <linux/sched/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include <linux/stacktrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static DEFINE_RAW_SPINLOCK(latency_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define MAXLR 128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static struct latency_record latency_record[MAXLR];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int latencytop_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) void clear_tsk_latency_tracing(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) raw_spin_lock_irqsave(&latency_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) memset(&p->latency_record, 0, sizeof(p->latency_record));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) p->latency_record_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) raw_spin_unlock_irqrestore(&latency_lock, flags);
^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) static void clear_global_latency_tracing(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) raw_spin_lock_irqsave(&latency_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) memset(&latency_record, 0, sizeof(latency_record));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) raw_spin_unlock_irqrestore(&latency_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static void __sched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) account_global_scheduler_latency(struct task_struct *tsk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct latency_record *lat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int firstnonnull = MAXLR + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* skip kernel threads for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!tsk->mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) for (i = 0; i < MAXLR; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) int q, same = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* Nothing stored: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (!latency_record[i].backtrace[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (firstnonnull > i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) firstnonnull = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) for (q = 0; q < LT_BACKTRACEDEPTH; q++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) unsigned long record = lat->backtrace[q];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (latency_record[i].backtrace[q] != record) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) same = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* 0 entry marks end of backtrace: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (!record)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (same) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) latency_record[i].count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) latency_record[i].time += lat->time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (lat->time > latency_record[i].max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) latency_record[i].max = lat->time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) i = firstnonnull;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (i >= MAXLR - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* Allocted a new one: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) memcpy(&latency_record[i], lat, sizeof(struct latency_record));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * __account_scheduler_latency - record an occurred latency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * @tsk - the task struct of the task hitting the latency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * @usecs - the duration of the latency in microseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * @inter - 1 if the sleep was interruptible, 0 if uninterruptible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * This function is the main entry point for recording latency entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * as called by the scheduler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * This function has a few special cases to deal with normal 'non-latency'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * sleeps: specifically, interruptible sleep longer than 5 msec is skipped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * since this usually is caused by waiting for events via select() and co.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * Negative latencies (caused by time going backwards) are also explicitly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * skipped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) void __sched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) __account_scheduler_latency(struct task_struct *tsk, int usecs, int inter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) int i, q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct latency_record lat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /* Long interruptible waits are generally user requested... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (inter && usecs > 5000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* Negative sleeps are time going backwards */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /* Zero-time sleeps are non-interesting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (usecs <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) memset(&lat, 0, sizeof(lat));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) lat.count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) lat.time = usecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) lat.max = usecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) stack_trace_save_tsk(tsk, lat.backtrace, LT_BACKTRACEDEPTH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) raw_spin_lock_irqsave(&latency_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) account_global_scheduler_latency(tsk, &lat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) for (i = 0; i < tsk->latency_record_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct latency_record *mylat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int same = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) mylat = &tsk->latency_record[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) for (q = 0; q < LT_BACKTRACEDEPTH; q++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) unsigned long record = lat.backtrace[q];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (mylat->backtrace[q] != record) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) same = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /* 0 entry is end of backtrace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (!record)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (same) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) mylat->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) mylat->time += lat.time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (lat.time > mylat->max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) mylat->max = lat.time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * short term hack; if we're > 32 we stop; future we recycle:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (tsk->latency_record_count >= LT_SAVECOUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* Allocated a new one: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) i = tsk->latency_record_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) memcpy(&tsk->latency_record[i], &lat, sizeof(struct latency_record));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) raw_spin_unlock_irqrestore(&latency_lock, flags);
^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 lstats_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) seq_puts(m, "Latency Top version : v0.1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) for (i = 0; i < MAXLR; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct latency_record *lr = &latency_record[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (lr->backtrace[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) seq_printf(m, "%i %lu %lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) lr->count, lr->time, lr->max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) for (q = 0; q < LT_BACKTRACEDEPTH; q++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) unsigned long bt = lr->backtrace[q];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (!bt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) seq_printf(m, " %ps", (void *)bt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) seq_puts(m, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) lstats_write(struct file *file, const char __user *buf, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) loff_t *offs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) clear_global_latency_tracing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int lstats_open(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return single_open(filp, lstats_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static const struct proc_ops lstats_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) .proc_open = lstats_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .proc_read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) .proc_write = lstats_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) .proc_lseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) .proc_release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static int __init init_lstats_procfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) proc_create("latency_stats", 0644, NULL, &lstats_proc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int sysctl_latencytop(struct ctl_table *table, int write, void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) size_t *lenp, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) err = proc_dointvec(table, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (latencytop_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) force_schedstat_enabled();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) device_initcall(init_lstats_procfs);