Commit | Line | Data |
---|---|---|
9f36eaed MJ |
1 | /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) |
2 | * | |
42d9070d AG |
3 | * wrapper/writeback.h |
4 | * | |
5 | * wrapper around global_dirty_limit read. Using KALLSYMS with KALLSYMS_ALL | |
6 | * to get its address when available, else we need to have a kernel that | |
7 | * exports this variable to GPL modules. | |
8 | * | |
9 | * Copyright (C) 2013 Mentor Graphics Corp. | |
42d9070d AG |
10 | */ |
11 | ||
9f36eaed MJ |
12 | #ifndef _LTTNG_WRAPPER_WRITEBACK_H |
13 | #define _LTTNG_WRAPPER_WRITEBACK_H | |
14 | ||
6284ae7c | 15 | #include <lttng-kernel-version.h> |
42d9070d | 16 | |
6284ae7c | 17 | #ifdef CONFIG_KALLSYMS_ALL |
42d9070d | 18 | #include <linux/kallsyms.h> |
5a2f5e92 | 19 | #include <wrapper/kallsyms.h> |
42d9070d | 20 | |
6284ae7c MJ |
21 | |
22 | ||
23 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0) | |
24 | ||
25 | static struct wb_domain *global_wb_domain_sym; | |
26 | ||
27 | static inline | |
28 | unsigned long wrapper_global_dirty_limit(void) | |
29 | { | |
30 | if (!global_wb_domain_sym) | |
31 | global_wb_domain_sym = | |
32 | (void *) kallsyms_lookup_dataptr("global_wb_domain"); | |
33 | if (global_wb_domain_sym) { | |
34 | return global_wb_domain_sym->dirty_limit; | |
35 | } else { | |
36 | printk_once(KERN_WARNING "LTTng: global_wb_domain symbol lookup failed.\n"); | |
37 | return 0; | |
38 | } | |
39 | } | |
60c64030 MJ |
40 | |
41 | /* | |
42 | * Canary function to check for 'global_wb_domain' at compile time. | |
43 | * | |
44 | * From 'include/linux/writeback.h': | |
45 | * | |
46 | * extern struct wb_domain global_wb_domain; | |
47 | */ | |
48 | static inline | |
49 | unsigned long __canary__global_wb_domain(void) | |
50 | { | |
51 | return global_wb_domain.dirty_limit; | |
52 | } | |
53 | ||
6284ae7c MJ |
54 | #else |
55 | ||
42d9070d AG |
56 | static unsigned long *global_dirty_limit_sym; |
57 | ||
58 | static inline | |
59 | unsigned long wrapper_global_dirty_limit(void) | |
60 | { | |
61 | if (!global_dirty_limit_sym) | |
62 | global_dirty_limit_sym = | |
63 | (void *) kallsyms_lookup_dataptr("global_dirty_limit"); | |
64 | if (global_dirty_limit_sym) { | |
65 | return *global_dirty_limit_sym; | |
66 | } else { | |
e36de50d | 67 | printk_once(KERN_WARNING "LTTng: global_dirty_limit symbol lookup failed.\n"); |
42d9070d AG |
68 | return 0; |
69 | } | |
70 | } | |
60c64030 MJ |
71 | |
72 | /* | |
73 | * Canary function to check for 'global_dirty_limit' at compile time. | |
74 | * | |
75 | * From 'include/linux/writeback.h': | |
76 | * | |
77 | * extern unsigned long global_dirty_limit; | |
78 | */ | |
79 | static inline | |
80 | unsigned long __canary__global_dirty_limit(void) | |
81 | { | |
82 | return global_dirty_limit; | |
83 | } | |
84 | ||
6284ae7c | 85 | #endif |
42d9070d | 86 | |
6284ae7c | 87 | #else /* CONFIG_KALLSYMS_ALL */ |
42d9070d AG |
88 | |
89 | #include <linux/writeback.h> | |
90 | ||
91 | static inline | |
92 | unsigned long wrapper_global_dirty_limit(void) | |
93 | { | |
94 | return global_dirty_limit; | |
95 | } | |
96 | ||
97 | #endif | |
98 | ||
99 | #endif /* _LTTNG_WRAPPER_WRITEBACK_H */ |