internal.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /* Internal definitions for FS-Cache
  2. *
  3. * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. /*
  12. * Lock order, in the order in which multiple locks should be obtained:
  13. * - fscache_addremove_sem
  14. * - cookie->lock
  15. * - cookie->parent->lock
  16. * - cache->object_list_lock
  17. * - object->lock
  18. * - object->parent->lock
  19. * - fscache_thread_lock
  20. *
  21. */
  22. #include <linux/fscache-cache.h>
  23. #include <linux/sched.h>
  24. #define FSCACHE_MIN_THREADS 4
  25. #define FSCACHE_MAX_THREADS 32
  26. /*
  27. * fsc-histogram.c
  28. */
  29. #ifdef CONFIG_FSCACHE_HISTOGRAM
  30. extern atomic_t fscache_obj_instantiate_histogram[HZ];
  31. extern atomic_t fscache_objs_histogram[HZ];
  32. extern atomic_t fscache_ops_histogram[HZ];
  33. extern atomic_t fscache_retrieval_delay_histogram[HZ];
  34. extern atomic_t fscache_retrieval_histogram[HZ];
  35. static inline void fscache_hist(atomic_t histogram[], unsigned long start_jif)
  36. {
  37. unsigned long jif = jiffies - start_jif;
  38. if (jif >= HZ)
  39. jif = HZ - 1;
  40. atomic_inc(&histogram[jif]);
  41. }
  42. extern const struct file_operations fscache_histogram_fops;
  43. #else
  44. #define fscache_hist(hist, start_jif) do {} while (0)
  45. #endif
  46. /*
  47. * fsc-main.c
  48. */
  49. extern unsigned fscache_defer_lookup;
  50. extern unsigned fscache_defer_create;
  51. extern unsigned fscache_debug;
  52. extern struct kobject *fscache_root;
  53. /*
  54. * fsc-proc.c
  55. */
  56. #ifdef CONFIG_PROC_FS
  57. extern int __init fscache_proc_init(void);
  58. extern void fscache_proc_cleanup(void);
  59. #else
  60. #define fscache_proc_init() (0)
  61. #define fscache_proc_cleanup() do {} while (0)
  62. #endif
  63. /*
  64. * fsc-stats.c
  65. */
  66. #ifdef CONFIG_FSCACHE_STATS
  67. extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
  68. extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
  69. extern atomic_t fscache_n_op_pend;
  70. extern atomic_t fscache_n_op_run;
  71. extern atomic_t fscache_n_op_enqueue;
  72. extern atomic_t fscache_n_op_deferred_release;
  73. extern atomic_t fscache_n_op_release;
  74. extern atomic_t fscache_n_op_gc;
  75. extern atomic_t fscache_n_attr_changed;
  76. extern atomic_t fscache_n_attr_changed_ok;
  77. extern atomic_t fscache_n_attr_changed_nobufs;
  78. extern atomic_t fscache_n_attr_changed_nomem;
  79. extern atomic_t fscache_n_attr_changed_calls;
  80. extern atomic_t fscache_n_allocs;
  81. extern atomic_t fscache_n_allocs_ok;
  82. extern atomic_t fscache_n_allocs_wait;
  83. extern atomic_t fscache_n_allocs_nobufs;
  84. extern atomic_t fscache_n_alloc_ops;
  85. extern atomic_t fscache_n_alloc_op_waits;
  86. extern atomic_t fscache_n_retrievals;
  87. extern atomic_t fscache_n_retrievals_ok;
  88. extern atomic_t fscache_n_retrievals_wait;
  89. extern atomic_t fscache_n_retrievals_nodata;
  90. extern atomic_t fscache_n_retrievals_nobufs;
  91. extern atomic_t fscache_n_retrievals_intr;
  92. extern atomic_t fscache_n_retrievals_nomem;
  93. extern atomic_t fscache_n_retrieval_ops;
  94. extern atomic_t fscache_n_retrieval_op_waits;
  95. extern atomic_t fscache_n_stores;
  96. extern atomic_t fscache_n_stores_ok;
  97. extern atomic_t fscache_n_stores_again;
  98. extern atomic_t fscache_n_stores_nobufs;
  99. extern atomic_t fscache_n_stores_oom;
  100. extern atomic_t fscache_n_store_ops;
  101. extern atomic_t fscache_n_store_calls;
  102. extern atomic_t fscache_n_marks;
  103. extern atomic_t fscache_n_uncaches;
  104. extern atomic_t fscache_n_acquires;
  105. extern atomic_t fscache_n_acquires_null;
  106. extern atomic_t fscache_n_acquires_no_cache;
  107. extern atomic_t fscache_n_acquires_ok;
  108. extern atomic_t fscache_n_acquires_nobufs;
  109. extern atomic_t fscache_n_acquires_oom;
  110. extern atomic_t fscache_n_updates;
  111. extern atomic_t fscache_n_updates_null;
  112. extern atomic_t fscache_n_updates_run;
  113. extern atomic_t fscache_n_relinquishes;
  114. extern atomic_t fscache_n_relinquishes_null;
  115. extern atomic_t fscache_n_relinquishes_waitcrt;
  116. extern atomic_t fscache_n_cookie_index;
  117. extern atomic_t fscache_n_cookie_data;
  118. extern atomic_t fscache_n_cookie_special;
  119. extern atomic_t fscache_n_object_alloc;
  120. extern atomic_t fscache_n_object_no_alloc;
  121. extern atomic_t fscache_n_object_lookups;
  122. extern atomic_t fscache_n_object_lookups_negative;
  123. extern atomic_t fscache_n_object_lookups_positive;
  124. extern atomic_t fscache_n_object_created;
  125. extern atomic_t fscache_n_object_avail;
  126. extern atomic_t fscache_n_object_dead;
  127. extern atomic_t fscache_n_checkaux_none;
  128. extern atomic_t fscache_n_checkaux_okay;
  129. extern atomic_t fscache_n_checkaux_update;
  130. extern atomic_t fscache_n_checkaux_obsolete;
  131. static inline void fscache_stat(atomic_t *stat)
  132. {
  133. atomic_inc(stat);
  134. }
  135. extern const struct file_operations fscache_stats_fops;
  136. #else
  137. #define fscache_stat(stat) do {} while (0)
  138. #endif
  139. /*****************************************************************************/
  140. /*
  141. * debug tracing
  142. */
  143. #define dbgprintk(FMT, ...) \
  144. printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
  145. /* make sure we maintain the format strings, even when debugging is disabled */
  146. static inline __attribute__((format(printf, 1, 2)))
  147. void _dbprintk(const char *fmt, ...)
  148. {
  149. }
  150. #define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
  151. #define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
  152. #define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
  153. #define kjournal(FMT, ...) _dbprintk(FMT, ##__VA_ARGS__)
  154. #ifdef __KDEBUG
  155. #define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
  156. #define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
  157. #define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
  158. #elif defined(CONFIG_FSCACHE_DEBUG)
  159. #define _enter(FMT, ...) \
  160. do { \
  161. if (__do_kdebug(ENTER)) \
  162. kenter(FMT, ##__VA_ARGS__); \
  163. } while (0)
  164. #define _leave(FMT, ...) \
  165. do { \
  166. if (__do_kdebug(LEAVE)) \
  167. kleave(FMT, ##__VA_ARGS__); \
  168. } while (0)
  169. #define _debug(FMT, ...) \
  170. do { \
  171. if (__do_kdebug(DEBUG)) \
  172. kdebug(FMT, ##__VA_ARGS__); \
  173. } while (0)
  174. #else
  175. #define _enter(FMT, ...) _dbprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
  176. #define _leave(FMT, ...) _dbprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
  177. #define _debug(FMT, ...) _dbprintk(FMT, ##__VA_ARGS__)
  178. #endif
  179. /*
  180. * determine whether a particular optional debugging point should be logged
  181. * - we need to go through three steps to persuade cpp to correctly join the
  182. * shorthand in FSCACHE_DEBUG_LEVEL with its prefix
  183. */
  184. #define ____do_kdebug(LEVEL, POINT) \
  185. unlikely((fscache_debug & \
  186. (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
  187. #define ___do_kdebug(LEVEL, POINT) \
  188. ____do_kdebug(LEVEL, POINT)
  189. #define __do_kdebug(POINT) \
  190. ___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
  191. #define FSCACHE_DEBUG_CACHE 0
  192. #define FSCACHE_DEBUG_COOKIE 1
  193. #define FSCACHE_DEBUG_PAGE 2
  194. #define FSCACHE_DEBUG_OPERATION 3
  195. #define FSCACHE_POINT_ENTER 1
  196. #define FSCACHE_POINT_LEAVE 2
  197. #define FSCACHE_POINT_DEBUG 4
  198. #ifndef FSCACHE_DEBUG_LEVEL
  199. #define FSCACHE_DEBUG_LEVEL CACHE
  200. #endif
  201. /*
  202. * assertions
  203. */
  204. #if 1 /* defined(__KDEBUGALL) */
  205. #define ASSERT(X) \
  206. do { \
  207. if (unlikely(!(X))) { \
  208. printk(KERN_ERR "\n"); \
  209. printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
  210. BUG(); \
  211. } \
  212. } while (0)
  213. #define ASSERTCMP(X, OP, Y) \
  214. do { \
  215. if (unlikely(!((X) OP (Y)))) { \
  216. printk(KERN_ERR "\n"); \
  217. printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
  218. printk(KERN_ERR "%lx " #OP " %lx is false\n", \
  219. (unsigned long)(X), (unsigned long)(Y)); \
  220. BUG(); \
  221. } \
  222. } while (0)
  223. #define ASSERTIF(C, X) \
  224. do { \
  225. if (unlikely((C) && !(X))) { \
  226. printk(KERN_ERR "\n"); \
  227. printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
  228. BUG(); \
  229. } \
  230. } while (0)
  231. #define ASSERTIFCMP(C, X, OP, Y) \
  232. do { \
  233. if (unlikely((C) && !((X) OP (Y)))) { \
  234. printk(KERN_ERR "\n"); \
  235. printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
  236. printk(KERN_ERR "%lx " #OP " %lx is false\n", \
  237. (unsigned long)(X), (unsigned long)(Y)); \
  238. BUG(); \
  239. } \
  240. } while (0)
  241. #else
  242. #define ASSERT(X) do {} while (0)
  243. #define ASSERTCMP(X, OP, Y) do {} while (0)
  244. #define ASSERTIF(C, X) do {} while (0)
  245. #define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
  246. #endif /* assert or not */