/* SPDX-License-Identifier: GPL-2.0 */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Authors: Waiman Long <[email protected]> */ /* * Collect locking event counts */ #include <linux/debugfs.h> #include <linux/sched.h> #include <linux/sched/clock.h> #include <linux/fs.h> #include "lock_events.h" #undef LOCK_EVENT #define LOCK_EVENT(name) … #define LOCK_EVENTS_DIR … /* * When CONFIG_LOCK_EVENT_COUNTS is enabled, event counts of different * types of locks will be reported under the <debugfs>/lock_event_counts/ * directory. See lock_events_list.h for the list of available locking * events. * * Writing to the special ".reset_counts" file will reset all the above * locking event counts. This is a very slow operation and so should not * be done frequently. * * These event counts are implemented as per-cpu variables which are * summed and computed whenever the corresponding debugfs files are read. This * minimizes added overhead making the counts usable even in a production * environment. */ static const char * const lockevent_names[lockevent_num + 1] = …; /* * Per-cpu counts */ DEFINE_PER_CPU(unsigned long, lockevents[lockevent_num]); /* * The lockevent_read() function can be overridden. */ ssize_t __weak lockevent_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { … } /* * Function to handle write request * * When idx = reset_cnts, reset all the counts. */ static ssize_t lockevent_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { … } /* * Debugfs data structures */ static const struct file_operations fops_lockevent = …; #ifdef CONFIG_PARAVIRT_SPINLOCKS #include <asm/paravirt.h> static bool __init skip_lockevent(const char *name) { … } #else static inline bool skip_lockevent(const char *name) { return false; } #endif /* * Initialize debugfs for the locking event counts. */ static int __init init_lockevent_counts(void) { … } fs_initcall(init_lockevent_counts);