blob: 57ed07b8f0004cba3ce71e95758df6dace6811e5 [file] [log] [blame]
Laura Abbott96805232014-09-22 13:26:28 -07001/*
Vinayak Menon99e36c12015-04-16 16:51:47 -07002 * Copyright (c) 2014, 2016, The Linux Foundation. All rights reserved.
Laura Abbott96805232014-09-22 13:26:28 -07003 *
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 Menon99e36c12015-04-16 16:51:47 -070020ATOMIC_NOTIFIER_HEAD(show_mem_notifier);
Laura Abbott96805232014-09-22 13:26:28 -070021
22int show_mem_notifier_register(struct notifier_block *nb)
23{
Vinayak Menon99e36c12015-04-16 16:51:47 -070024 return atomic_notifier_chain_register(&show_mem_notifier, nb);
Laura Abbott96805232014-09-22 13:26:28 -070025}
26
27int show_mem_notifier_unregister(struct notifier_block *nb)
28{
Vinayak Menon99e36c12015-04-16 16:51:47 -070029 return atomic_notifier_chain_unregister(&show_mem_notifier, nb);
Laura Abbott96805232014-09-22 13:26:28 -070030}
31
32void show_mem_call_notifiers(void)
33{
Vinayak Menon99e36c12015-04-16 16:51:47 -070034 atomic_notifier_call_chain(&show_mem_notifier, 0, NULL);
Laura Abbott96805232014-09-22 13:26:28 -070035}
36
37static int show_mem_notifier_get(void *dat, u64 *val)
38{
39 show_mem_call_notifiers();
40 *val = 0;
41 return 0;
42}
43
44DEFINE_SIMPLE_ATTRIBUTE(show_mem_notifier_debug_ops, show_mem_notifier_get,
45 NULL, "%llu\n");
46
47int 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}
54late_initcall(show_mem_notifier_debugfs_register);