s390dbf.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. ==================
  2. S390 Debug Feature
  3. ==================
  4. files:
  5. - arch/s390/kernel/debug.c
  6. - arch/s390/include/asm/debug.h
  7. Description:
  8. ------------
  9. The goal of this feature is to provide a kernel debug logging API
  10. where log records can be stored efficiently in memory, where each component
  11. (e.g. device drivers) can have one separate debug log.
  12. One purpose of this is to inspect the debug logs after a production system crash
  13. in order to analyze the reason for the crash.
  14. If the system still runs but only a subcomponent which uses dbf fails,
  15. it is possible to look at the debug logs on a live system via the Linux
  16. debugfs filesystem.
  17. The debug feature may also very useful for kernel and driver development.
  18. Design:
  19. -------
  20. Kernel components (e.g. device drivers) can register themselves at the debug
  21. feature with the function call :c:func:`debug_register()`.
  22. This function initializes a
  23. debug log for the caller. For each debug log exists a number of debug areas
  24. where exactly one is active at one time. Each debug area consists of contiguous
  25. pages in memory. In the debug areas there are stored debug entries (log records)
  26. which are written by event- and exception-calls.
  27. An event-call writes the specified debug entry to the active debug
  28. area and updates the log pointer for the active area. If the end
  29. of the active debug area is reached, a wrap around is done (ring buffer)
  30. and the next debug entry will be written at the beginning of the active
  31. debug area.
  32. An exception-call writes the specified debug entry to the log and
  33. switches to the next debug area. This is done in order to be sure
  34. that the records which describe the origin of the exception are not
  35. overwritten when a wrap around for the current area occurs.
  36. The debug areas themselves are also ordered in form of a ring buffer.
  37. When an exception is thrown in the last debug area, the following debug
  38. entries are then written again in the very first area.
  39. There are four versions for the event- and exception-calls: One for
  40. logging raw data, one for text, one for numbers (unsigned int and long),
  41. and one for sprintf-like formatted strings.
  42. Each debug entry contains the following data:
  43. - Timestamp
  44. - Cpu-Number of calling task
  45. - Level of debug entry (0...6)
  46. - Return Address to caller
  47. - Flag, if entry is an exception or not
  48. The debug logs can be inspected in a live system through entries in
  49. the debugfs-filesystem. Under the toplevel directory "``s390dbf``" there is
  50. a directory for each registered component, which is named like the
  51. corresponding component. The debugfs normally should be mounted to
  52. ``/sys/kernel/debug`` therefore the debug feature can be accessed under
  53. ``/sys/kernel/debug/s390dbf``.
  54. The content of the directories are files which represent different views
  55. to the debug log. Each component can decide which views should be
  56. used through registering them with the function :c:func:`debug_register_view()`.
  57. Predefined views for hex/ascii and sprintf data are provided.
  58. It is also possible to define other views. The content of
  59. a view can be inspected simply by reading the corresponding debugfs file.
  60. All debug logs have an actual debug level (range from 0 to 6).
  61. The default level is 3. Event and Exception functions have a :c:data:`level`
  62. parameter. Only debug entries with a level that is lower or equal
  63. than the actual level are written to the log. This means, when
  64. writing events, high priority log entries should have a low level
  65. value whereas low priority entries should have a high one.
  66. The actual debug level can be changed with the help of the debugfs-filesystem
  67. through writing a number string "x" to the ``level`` debugfs file which is
  68. provided for every debug log. Debugging can be switched off completely
  69. by using "-" on the ``level`` debugfs file.
  70. Example::
  71. > echo "-" > /sys/kernel/debug/s390dbf/dasd/level
  72. It is also possible to deactivate the debug feature globally for every
  73. debug log. You can change the behavior using 2 sysctl parameters in
  74. ``/proc/sys/s390dbf``:
  75. There are currently 2 possible triggers, which stop the debug feature
  76. globally. The first possibility is to use the ``debug_active`` sysctl. If
  77. set to 1 the debug feature is running. If ``debug_active`` is set to 0 the
  78. debug feature is turned off.
  79. The second trigger which stops the debug feature is a kernel oops.
  80. That prevents the debug feature from overwriting debug information that
  81. happened before the oops. After an oops you can reactivate the debug feature
  82. by piping 1 to ``/proc/sys/s390dbf/debug_active``. Nevertheless, it's not
  83. suggested to use an oopsed kernel in a production environment.
  84. If you want to disallow the deactivation of the debug feature, you can use
  85. the ``debug_stoppable`` sysctl. If you set ``debug_stoppable`` to 0 the debug
  86. feature cannot be stopped. If the debug feature is already stopped, it
  87. will stay deactivated.
  88. Kernel Interfaces:
  89. ------------------
  90. .. kernel-doc:: arch/s390/kernel/debug.c
  91. .. kernel-doc:: arch/s390/include/asm/debug.h
  92. Predefined views:
  93. -----------------
  94. .. code-block:: c
  95. extern struct debug_view debug_hex_ascii_view;
  96. extern struct debug_view debug_sprintf_view;
  97. Examples
  98. --------
  99. .. code-block:: c
  100. /*
  101. * hex_ascii-view Example
  102. */
  103. #include <linux/init.h>
  104. #include <asm/debug.h>
  105. static debug_info_t *debug_info;
  106. static int init(void)
  107. {
  108. /* register 4 debug areas with one page each and 4 byte data field */
  109. debug_info = debug_register("test", 1, 4, 4 );
  110. debug_register_view(debug_info, &debug_hex_ascii_view);
  111. debug_text_event(debug_info, 4 , "one ");
  112. debug_int_exception(debug_info, 4, 4711);
  113. debug_event(debug_info, 3, &debug_info, 4);
  114. return 0;
  115. }
  116. static void cleanup(void)
  117. {
  118. debug_unregister(debug_info);
  119. }
  120. module_init(init);
  121. module_exit(cleanup);
  122. .. code-block:: c
  123. /*
  124. * sprintf-view Example
  125. */
  126. #include <linux/init.h>
  127. #include <asm/debug.h>
  128. static debug_info_t *debug_info;
  129. static int init(void)
  130. {
  131. /* register 4 debug areas with one page each and data field for */
  132. /* format string pointer + 2 varargs (= 3 * sizeof(long)) */
  133. debug_info = debug_register("test", 1, 4, sizeof(long) * 3);
  134. debug_register_view(debug_info, &debug_sprintf_view);
  135. debug_sprintf_event(debug_info, 2 , "first event in %s:%i\n",__FILE__,__LINE__);
  136. debug_sprintf_exception(debug_info, 1, "pointer to debug info: %p\n",&debug_info);
  137. return 0;
  138. }
  139. static void cleanup(void)
  140. {
  141. debug_unregister(debug_info);
  142. }
  143. module_init(init);
  144. module_exit(cleanup);
  145. Debugfs Interface
  146. -----------------
  147. Views to the debug logs can be investigated through reading the corresponding
  148. debugfs-files:
  149. Example::
  150. > ls /sys/kernel/debug/s390dbf/dasd
  151. flush hex_ascii level pages
  152. > cat /sys/kernel/debug/s390dbf/dasd/hex_ascii | sort -k2,2 -s
  153. 00 00974733272:680099 2 - 02 0006ad7e 07 ea 4a 90 | ....
  154. 00 00974733272:682210 2 - 02 0006ade6 46 52 45 45 | FREE
  155. 00 00974733272:682213 2 - 02 0006adf6 07 ea 4a 90 | ....
  156. 00 00974733272:682281 1 * 02 0006ab08 41 4c 4c 43 | EXCP
  157. 01 00974733272:682284 2 - 02 0006ab16 45 43 4b 44 | ECKD
  158. 01 00974733272:682287 2 - 02 0006ab28 00 00 00 04 | ....
  159. 01 00974733272:682289 2 - 02 0006ab3e 00 00 00 20 | ...
  160. 01 00974733272:682297 2 - 02 0006ad7e 07 ea 4a 90 | ....
  161. 01 00974733272:684384 2 - 00 0006ade6 46 52 45 45 | FREE
  162. 01 00974733272:684388 2 - 00 0006adf6 07 ea 4a 90 | ....
  163. See section about predefined views for explanation of the above output!
  164. Changing the debug level
  165. ------------------------
  166. Example::
  167. > cat /sys/kernel/debug/s390dbf/dasd/level
  168. 3
  169. > echo "5" > /sys/kernel/debug/s390dbf/dasd/level
  170. > cat /sys/kernel/debug/s390dbf/dasd/level
  171. 5
  172. Flushing debug areas
  173. --------------------
  174. Debug areas can be flushed with piping the number of the desired
  175. area (0...n) to the debugfs file "flush". When using "-" all debug areas
  176. are flushed.
  177. Examples:
  178. 1. Flush debug area 0::
  179. > echo "0" > /sys/kernel/debug/s390dbf/dasd/flush
  180. 2. Flush all debug areas::
  181. > echo "-" > /sys/kernel/debug/s390dbf/dasd/flush
  182. Changing the size of debug areas
  183. ------------------------------------
  184. It is possible the change the size of debug areas through piping
  185. the number of pages to the debugfs file "pages". The resize request will
  186. also flush the debug areas.
  187. Example:
  188. Define 4 pages for the debug areas of debug feature "dasd"::
  189. > echo "4" > /sys/kernel/debug/s390dbf/dasd/pages
  190. Stopping the debug feature
  191. --------------------------
  192. Example:
  193. 1. Check if stopping is allowed::
  194. > cat /proc/sys/s390dbf/debug_stoppable
  195. 2. Stop debug feature::
  196. > echo 0 > /proc/sys/s390dbf/debug_active
  197. crash Interface
  198. ----------------
  199. The ``crash`` tool since v5.1.0 has a built-in command
  200. ``s390dbf`` to display all the debug logs or export them to the file system.
  201. With this tool it is possible
  202. to investigate the debug logs on a live system and with a memory dump after
  203. a system crash.
  204. Investigating raw memory
  205. ------------------------
  206. One last possibility to investigate the debug logs at a live
  207. system and after a system crash is to look at the raw memory
  208. under VM or at the Service Element.
  209. It is possible to find the anchor of the debug-logs through
  210. the ``debug_area_first`` symbol in the System map. Then one has
  211. to follow the correct pointers of the data-structures defined
  212. in debug.h and find the debug-areas in memory.
  213. Normally modules which use the debug feature will also have
  214. a global variable with the pointer to the debug-logs. Following
  215. this pointer it will also be possible to find the debug logs in
  216. memory.
  217. For this method it is recommended to use '16 * x + 4' byte (x = 0..n)
  218. for the length of the data field in :c:func:`debug_register()` in
  219. order to see the debug entries well formatted.
  220. Predefined Views
  221. ----------------
  222. There are two predefined views: hex_ascii and sprintf.
  223. The hex_ascii view shows the data field in hex and ascii representation
  224. (e.g. ``45 43 4b 44 | ECKD``).
  225. The sprintf view formats the debug entries in the same way as the sprintf
  226. function would do. The sprintf event/exception functions write to the
  227. debug entry a pointer to the format string (size = sizeof(long))
  228. and for each vararg a long value. So e.g. for a debug entry with a format
  229. string plus two varargs one would need to allocate a (3 * sizeof(long))
  230. byte data area in the debug_register() function.
  231. IMPORTANT:
  232. Using "%s" in sprintf event functions is dangerous. You can only
  233. use "%s" in the sprintf event functions, if the memory for the passed string
  234. is available as long as the debug feature exists. The reason behind this is
  235. that due to performance considerations only a pointer to the string is stored
  236. in the debug feature. If you log a string that is freed afterwards, you will
  237. get an OOPS when inspecting the debug feature, because then the debug feature
  238. will access the already freed memory.
  239. NOTE:
  240. If using the sprintf view do NOT use other event/exception functions
  241. than the sprintf-event and -exception functions.
  242. The format of the hex_ascii and sprintf view is as follows:
  243. - Number of area
  244. - Timestamp (formatted as seconds and microseconds since 00:00:00 Coordinated
  245. Universal Time (UTC), January 1, 1970)
  246. - level of debug entry
  247. - Exception flag (* = Exception)
  248. - Cpu-Number of calling task
  249. - Return Address to caller
  250. - data field
  251. A typical line of the hex_ascii view will look like the following (first line
  252. is only for explanation and will not be displayed when 'cating' the view)::
  253. area time level exception cpu caller data (hex + ascii)
  254. --------------------------------------------------------------------------
  255. 00 00964419409:440690 1 - 00 88023fe
  256. Defining views
  257. --------------
  258. Views are specified with the 'debug_view' structure. There are defined
  259. callback functions which are used for reading and writing the debugfs files:
  260. .. code-block:: c
  261. struct debug_view {
  262. char name[DEBUG_MAX_PROCF_LEN];
  263. debug_prolog_proc_t* prolog_proc;
  264. debug_header_proc_t* header_proc;
  265. debug_format_proc_t* format_proc;
  266. debug_input_proc_t* input_proc;
  267. void* private_data;
  268. };
  269. where:
  270. .. code-block:: c
  271. typedef int (debug_header_proc_t) (debug_info_t* id,
  272. struct debug_view* view,
  273. int area,
  274. debug_entry_t* entry,
  275. char* out_buf);
  276. typedef int (debug_format_proc_t) (debug_info_t* id,
  277. struct debug_view* view, char* out_buf,
  278. const char* in_buf);
  279. typedef int (debug_prolog_proc_t) (debug_info_t* id,
  280. struct debug_view* view,
  281. char* out_buf);
  282. typedef int (debug_input_proc_t) (debug_info_t* id,
  283. struct debug_view* view,
  284. struct file* file, const char* user_buf,
  285. size_t in_buf_size, loff_t* offset);
  286. The "private_data" member can be used as pointer to view specific data.
  287. It is not used by the debug feature itself.
  288. The output when reading a debugfs file is structured like this::
  289. "prolog_proc output"
  290. "header_proc output 1" "format_proc output 1"
  291. "header_proc output 2" "format_proc output 2"
  292. "header_proc output 3" "format_proc output 3"
  293. ...
  294. When a view is read from the debugfs, the Debug Feature calls the
  295. 'prolog_proc' once for writing the prolog.
  296. Then 'header_proc' and 'format_proc' are called for each
  297. existing debug entry.
  298. The input_proc can be used to implement functionality when it is written to
  299. the view (e.g. like with ``echo "0" > /sys/kernel/debug/s390dbf/dasd/level``).
  300. For header_proc there can be used the default function
  301. :c:func:`debug_dflt_header_fn()` which is defined in debug.h.
  302. and which produces the same header output as the predefined views.
  303. E.g::
  304. 00 00964419409:440761 2 - 00 88023ec
  305. In order to see how to use the callback functions check the implementation
  306. of the default views!
  307. Example:
  308. .. code-block:: c
  309. #include <asm/debug.h>
  310. #define UNKNOWNSTR "data: %08x"
  311. const char* messages[] =
  312. {"This error...........\n",
  313. "That error...........\n",
  314. "Problem..............\n",
  315. "Something went wrong.\n",
  316. "Everything ok........\n",
  317. NULL
  318. };
  319. static int debug_test_format_fn(
  320. debug_info_t *id, struct debug_view *view,
  321. char *out_buf, const char *in_buf
  322. )
  323. {
  324. int i, rc = 0;
  325. if (id->buf_size >= 4) {
  326. int msg_nr = *((int*)in_buf);
  327. if (msg_nr < sizeof(messages) / sizeof(char*) - 1)
  328. rc += sprintf(out_buf, "%s", messages[msg_nr]);
  329. else
  330. rc += sprintf(out_buf, UNKNOWNSTR, msg_nr);
  331. }
  332. return rc;
  333. }
  334. struct debug_view debug_test_view = {
  335. "myview", /* name of view */
  336. NULL, /* no prolog */
  337. &debug_dflt_header_fn, /* default header for each entry */
  338. &debug_test_format_fn, /* our own format function */
  339. NULL, /* no input function */
  340. NULL /* no private data */
  341. };
  342. test:
  343. =====
  344. .. code-block:: c
  345. debug_info_t *debug_info;
  346. int i;
  347. ...
  348. debug_info = debug_register("test", 0, 4, 4);
  349. debug_register_view(debug_info, &debug_test_view);
  350. for (i = 0; i < 10; i ++)
  351. debug_int_event(debug_info, 1, i);
  352. ::
  353. > cat /sys/kernel/debug/s390dbf/test/myview
  354. 00 00964419734:611402 1 - 00 88042ca This error...........
  355. 00 00964419734:611405 1 - 00 88042ca That error...........
  356. 00 00964419734:611408 1 - 00 88042ca Problem..............
  357. 00 00964419734:611411 1 - 00 88042ca Something went wrong.
  358. 00 00964419734:611414 1 - 00 88042ca Everything ok........
  359. 00 00964419734:611417 1 - 00 88042ca data: 00000005
  360. 00 00964419734:611419 1 - 00 88042ca data: 00000006
  361. 00 00964419734:611422 1 - 00 88042ca data: 00000007
  362. 00 00964419734:611425 1 - 00 88042ca data: 00000008
  363. 00 00964419734:611428 1 - 00 88042ca data: 00000009