Rishabh Bhatnagar | e9a05bb | 2018-12-10 11:09:45 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Laura Abbott | 35cded2 | 2014-09-22 13:26:28 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2018, The Linux Foundation. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | #include <linux/kernel.h> |
| 7 | #include <linux/notifier.h> |
| 8 | #include <linux/debugfs.h> |
| 9 | #include <linux/fs.h> |
| 10 | #include <linux/init.h> |
| 11 | |
Vinayak Menon | 6ecb997 | 2015-04-16 16:51:47 -0700 | [diff] [blame] | 12 | ATOMIC_NOTIFIER_HEAD(show_mem_notifier); |
Laura Abbott | 35cded2 | 2014-09-22 13:26:28 -0700 | [diff] [blame] | 13 | |
| 14 | int show_mem_notifier_register(struct notifier_block *nb) |
| 15 | { |
Vinayak Menon | 6ecb997 | 2015-04-16 16:51:47 -0700 | [diff] [blame] | 16 | return atomic_notifier_chain_register(&show_mem_notifier, nb); |
Laura Abbott | 35cded2 | 2014-09-22 13:26:28 -0700 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | int show_mem_notifier_unregister(struct notifier_block *nb) |
| 20 | { |
Vinayak Menon | 6ecb997 | 2015-04-16 16:51:47 -0700 | [diff] [blame] | 21 | return atomic_notifier_chain_unregister(&show_mem_notifier, nb); |
Laura Abbott | 35cded2 | 2014-09-22 13:26:28 -0700 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | void show_mem_call_notifiers(void) |
| 25 | { |
Vinayak Menon | 6ecb997 | 2015-04-16 16:51:47 -0700 | [diff] [blame] | 26 | atomic_notifier_call_chain(&show_mem_notifier, 0, NULL); |
Laura Abbott | 35cded2 | 2014-09-22 13:26:28 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | static int show_mem_notifier_get(void *dat, u64 *val) |
| 30 | { |
| 31 | show_mem_call_notifiers(); |
| 32 | *val = 0; |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | DEFINE_SIMPLE_ATTRIBUTE(show_mem_notifier_debug_ops, show_mem_notifier_get, |
| 37 | NULL, "%llu\n"); |
| 38 | |
| 39 | int show_mem_notifier_debugfs_register(void) |
| 40 | { |
| 41 | debugfs_create_file("show_mem_notifier", 0664, NULL, NULL, |
| 42 | &show_mem_notifier_debug_ops); |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | late_initcall(show_mem_notifier_debugfs_register); |