s390dbf.txt 22 KB

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