blob: aa74c71faaad3e3c9d56c722cc8f093671656940 [file] [log] [blame]
Rishabh Bhatnagare9a05bb2018-12-10 11:09:45 -08001// SPDX-License-Identifier: GPL-2.0-only
Laura Abbott35cded22014-09-22 13:26:28 -07002/*
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 Menon6ecb9972015-04-16 16:51:47 -070012ATOMIC_NOTIFIER_HEAD(show_mem_notifier);
Laura Abbott35cded22014-09-22 13:26:28 -070013
14int show_mem_notifier_register(struct notifier_block *nb)
15{
Vinayak Menon6ecb9972015-04-16 16:51:47 -070016 return atomic_notifier_chain_register(&show_mem_notifier, nb);
Laura Abbott35cded22014-09-22 13:26:28 -070017}
18
19int show_mem_notifier_unregister(struct notifier_block *nb)
20{
Vinayak Menon6ecb9972015-04-16 16:51:47 -070021 return atomic_notifier_chain_unregister(&show_mem_notifier, nb);
Laura Abbott35cded22014-09-22 13:26:28 -070022}
23
24void show_mem_call_notifiers(void)
25{
Vinayak Menon6ecb9972015-04-16 16:51:47 -070026 atomic_notifier_call_chain(&show_mem_notifier, 0, NULL);
Laura Abbott35cded22014-09-22 13:26:28 -070027}
28
29static int show_mem_notifier_get(void *dat, u64 *val)
30{
31 show_mem_call_notifiers();
32 *val = 0;
33 return 0;
34}
35
36DEFINE_SIMPLE_ATTRIBUTE(show_mem_notifier_debug_ops, show_mem_notifier_get,
37 NULL, "%llu\n");
38
39int 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}
46late_initcall(show_mem_notifier_debugfs_register);