Laura Abbott | 9680523 | 2014-09-22 13:26:28 -0700 | [diff] [blame] | 1 | /* |
Vinayak Menon | 99e36c1 | 2015-04-16 16:51:47 -0700 | [diff] [blame] | 2 | * Copyright (c) 2014, 2016, The Linux Foundation. All rights reserved. |
Laura Abbott | 9680523 | 2014-09-22 13:26:28 -0700 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/notifier.h> |
| 16 | #include <linux/debugfs.h> |
| 17 | #include <linux/fs.h> |
| 18 | #include <linux/init.h> |
| 19 | |
Vinayak Menon | 99e36c1 | 2015-04-16 16:51:47 -0700 | [diff] [blame] | 20 | ATOMIC_NOTIFIER_HEAD(show_mem_notifier); |
Laura Abbott | 9680523 | 2014-09-22 13:26:28 -0700 | [diff] [blame] | 21 | |
| 22 | int show_mem_notifier_register(struct notifier_block *nb) |
| 23 | { |
Vinayak Menon | 99e36c1 | 2015-04-16 16:51:47 -0700 | [diff] [blame] | 24 | return atomic_notifier_chain_register(&show_mem_notifier, nb); |
Laura Abbott | 9680523 | 2014-09-22 13:26:28 -0700 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | int show_mem_notifier_unregister(struct notifier_block *nb) |
| 28 | { |
Vinayak Menon | 99e36c1 | 2015-04-16 16:51:47 -0700 | [diff] [blame] | 29 | return atomic_notifier_chain_unregister(&show_mem_notifier, nb); |
Laura Abbott | 9680523 | 2014-09-22 13:26:28 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | void show_mem_call_notifiers(void) |
| 33 | { |
Vinayak Menon | 99e36c1 | 2015-04-16 16:51:47 -0700 | [diff] [blame] | 34 | atomic_notifier_call_chain(&show_mem_notifier, 0, NULL); |
Laura Abbott | 9680523 | 2014-09-22 13:26:28 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static int show_mem_notifier_get(void *dat, u64 *val) |
| 38 | { |
| 39 | show_mem_call_notifiers(); |
| 40 | *val = 0; |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | DEFINE_SIMPLE_ATTRIBUTE(show_mem_notifier_debug_ops, show_mem_notifier_get, |
| 45 | NULL, "%llu\n"); |
| 46 | |
| 47 | int show_mem_notifier_debugfs_register(void) |
| 48 | { |
| 49 | debugfs_create_file("show_mem_notifier", 0664, NULL, NULL, |
| 50 | &show_mem_notifier_debug_ops); |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | late_initcall(show_mem_notifier_debugfs_register); |