s390dbf.txt 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. S390 Debug Feature
  2. ==================
  3. files: arch/s390/kernel/debug.c
  4. arch/s390/include/asm/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 themselves 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 under
  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 a 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 a 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. debug_info_t *debug_register_mode(char *name, int pages, int nr_areas,
  99. int buf_size, mode_t mode, uid_t uid,
  100. gid_t gid);
  101. Parameter: name: Name of debug log (e.g. used for debugfs entry)
  102. pages: Number of pages, which will be allocated per area
  103. nr_areas: Number of debug areas
  104. buf_size: Size of data area in each debug entry
  105. mode: File mode for debugfs files. E.g. S_IRWXUGO
  106. uid: User ID for debugfs files. Currently only 0 is
  107. supported.
  108. gid: Group ID for debugfs files. Currently only 0 is
  109. supported.
  110. Return Value: Handle for generated debug area
  111. NULL if register failed
  112. Description: Allocates memory for a debug log
  113. Must not be called within an interrupt handler
  114. ---------------------------------------------------------------------------
  115. void debug_unregister (debug_info_t * id);
  116. Parameter: id: handle for debug log
  117. Return Value: none
  118. Description: frees memory for a debug log and removes all registered debug
  119. views.
  120. Must not be called within an interrupt handler
  121. ---------------------------------------------------------------------------
  122. void debug_set_level (debug_info_t * id, int new_level);
  123. Parameter: id: handle for debug log
  124. new_level: new debug level
  125. Return Value: none
  126. Description: Sets new actual debug level if new_level is valid.
  127. ---------------------------------------------------------------------------
  128. void debug_stop_all(void);
  129. Parameter: none
  130. Return Value: none
  131. Description: stops the debug feature if stopping is allowed. Currently
  132. used in case of a kernel oops.
  133. ---------------------------------------------------------------------------
  134. debug_entry_t* debug_event (debug_info_t* id, int level, void* data,
  135. int length);
  136. Parameter: id: handle for debug log
  137. level: debug level
  138. data: pointer to data for debug entry
  139. length: length of data in bytes
  140. Return Value: Address of written debug entry
  141. Description: writes debug entry to active debug area (if level <= actual
  142. debug level)
  143. ---------------------------------------------------------------------------
  144. debug_entry_t* debug_int_event (debug_info_t * id, int level,
  145. unsigned int data);
  146. debug_entry_t* debug_long_event(debug_info_t * id, int level,
  147. unsigned long data);
  148. Parameter: id: handle for debug log
  149. level: debug level
  150. data: integer value for debug entry
  151. Return Value: Address of written debug entry
  152. Description: writes debug entry to active debug area (if level <= actual
  153. debug level)
  154. ---------------------------------------------------------------------------
  155. debug_entry_t* debug_text_event (debug_info_t * id, int level,
  156. const char* data);
  157. Parameter: id: handle for debug log
  158. level: debug level
  159. data: string for debug entry
  160. Return Value: Address of written debug entry
  161. Description: writes debug entry in ascii format to active debug area
  162. (if level <= actual debug level)
  163. ---------------------------------------------------------------------------
  164. debug_entry_t* debug_sprintf_event (debug_info_t * id, int level,
  165. char* string,...);
  166. Parameter: id: handle for debug log
  167. level: debug level
  168. string: format string for debug entry
  169. ...: varargs used as in sprintf()
  170. Return Value: Address of written debug entry
  171. Description: writes debug entry with format string and varargs (longs) to
  172. active debug area (if level $<=$ actual debug level).
  173. floats and long long datatypes cannot be used as varargs.
  174. ---------------------------------------------------------------------------
  175. debug_entry_t* debug_exception (debug_info_t* id, int level, void* data,
  176. int length);
  177. Parameter: id: handle for debug log
  178. level: debug level
  179. data: pointer to data for debug entry
  180. length: length of data in bytes
  181. Return Value: Address of written debug entry
  182. Description: writes debug entry to active debug area (if level <= actual
  183. debug level) and switches to next debug area
  184. ---------------------------------------------------------------------------
  185. debug_entry_t* debug_int_exception (debug_info_t * id, int level,
  186. unsigned int data);
  187. debug_entry_t* debug_long_exception(debug_info_t * id, int level,
  188. unsigned long data);
  189. Parameter: id: handle for debug log
  190. level: debug level
  191. data: integer value for debug entry
  192. Return Value: Address of written debug entry
  193. Description: writes debug entry to active debug area (if level <= actual
  194. debug level) and switches to next debug area
  195. ---------------------------------------------------------------------------
  196. debug_entry_t* debug_text_exception (debug_info_t * id, int level,
  197. const char* data);
  198. Parameter: id: handle for debug log
  199. level: debug level
  200. data: string for debug entry
  201. Return Value: Address of written debug entry
  202. Description: writes debug entry in ascii format to active debug area
  203. (if level <= actual debug level) and switches to next debug
  204. area
  205. ---------------------------------------------------------------------------
  206. debug_entry_t* debug_sprintf_exception (debug_info_t * id, int level,
  207. char* string,...);
  208. Parameter: id: handle for debug log
  209. level: debug level
  210. string: format string for debug entry
  211. ...: varargs used as in sprintf()
  212. Return Value: Address of written debug entry
  213. Description: writes debug entry with format string and varargs (longs) to
  214. active debug area (if level $<=$ actual debug level) and
  215. switches to next debug area.
  216. floats and long long datatypes cannot be used as varargs.
  217. ---------------------------------------------------------------------------
  218. int debug_register_view (debug_info_t * id, struct debug_view *view);
  219. Parameter: id: handle for debug log
  220. view: pointer to debug view struct
  221. Return Value: 0 : ok
  222. < 0: Error
  223. Description: registers new debug view and creates debugfs dir entry
  224. ---------------------------------------------------------------------------
  225. int debug_unregister_view (debug_info_t * id, struct debug_view *view);
  226. Parameter: id: handle for debug log
  227. view: pointer to debug view struct
  228. Return Value: 0 : ok
  229. < 0: Error
  230. Description: unregisters debug view and removes debugfs dir entry
  231. Predefined views:
  232. -----------------
  233. extern struct debug_view debug_hex_ascii_view;
  234. extern struct debug_view debug_raw_view;
  235. extern struct debug_view debug_sprintf_view;
  236. Examples
  237. --------
  238. /*
  239. * hex_ascii- + raw-view Example
  240. */
  241. #include <linux/init.h>
  242. #include <asm/debug.h>
  243. static debug_info_t* debug_info;
  244. static int init(void)
  245. {
  246. /* register 4 debug areas with one page each and 4 byte data field */
  247. debug_info = debug_register ("test", 1, 4, 4 );
  248. debug_register_view(debug_info,&debug_hex_ascii_view);
  249. debug_register_view(debug_info,&debug_raw_view);
  250. debug_text_event(debug_info, 4 , "one ");
  251. debug_int_exception(debug_info, 4, 4711);
  252. debug_event(debug_info, 3, &debug_info, 4);
  253. return 0;
  254. }
  255. static void cleanup(void)
  256. {
  257. debug_unregister (debug_info);
  258. }
  259. module_init(init);
  260. module_exit(cleanup);
  261. ---------------------------------------------------------------------------
  262. /*
  263. * sprintf-view Example
  264. */
  265. #include <linux/init.h>
  266. #include <asm/debug.h>
  267. static debug_info_t* debug_info;
  268. static int init(void)
  269. {
  270. /* register 4 debug areas with one page each and data field for */
  271. /* format string pointer + 2 varargs (= 3 * sizeof(long)) */
  272. debug_info = debug_register ("test", 1, 4, sizeof(long) * 3);
  273. debug_register_view(debug_info,&debug_sprintf_view);
  274. debug_sprintf_event(debug_info, 2 , "first event in %s:%i\n",__FILE__,__LINE__);
  275. debug_sprintf_exception(debug_info, 1, "pointer to debug info: %p\n",&debug_info);
  276. return 0;
  277. }
  278. static void cleanup(void)
  279. {
  280. debug_unregister (debug_info);
  281. }
  282. module_init(init);
  283. module_exit(cleanup);
  284. Debugfs Interface
  285. ----------------
  286. Views to the debug logs can be investigated through reading the corresponding
  287. debugfs-files:
  288. Example:
  289. > ls /sys/kernel/debug/s390dbf/dasd
  290. flush hex_ascii level pages raw
  291. > cat /sys/kernel/debug/s390dbf/dasd/hex_ascii | sort +1
  292. 00 00974733272:680099 2 - 02 0006ad7e 07 ea 4a 90 | ....
  293. 00 00974733272:682210 2 - 02 0006ade6 46 52 45 45 | FREE
  294. 00 00974733272:682213 2 - 02 0006adf6 07 ea 4a 90 | ....
  295. 00 00974733272:682281 1 * 02 0006ab08 41 4c 4c 43 | EXCP
  296. 01 00974733272:682284 2 - 02 0006ab16 45 43 4b 44 | ECKD
  297. 01 00974733272:682287 2 - 02 0006ab28 00 00 00 04 | ....
  298. 01 00974733272:682289 2 - 02 0006ab3e 00 00 00 20 | ...
  299. 01 00974733272:682297 2 - 02 0006ad7e 07 ea 4a 90 | ....
  300. 01 00974733272:684384 2 - 00 0006ade6 46 52 45 45 | FREE
  301. 01 00974733272:684388 2 - 00 0006adf6 07 ea 4a 90 | ....
  302. See section about predefined views for explanation of the above output!
  303. Changing the debug level
  304. ------------------------
  305. Example:
  306. > cat /sys/kernel/debug/s390dbf/dasd/level
  307. 3
  308. > echo "5" > /sys/kernel/debug/s390dbf/dasd/level
  309. > cat /sys/kernel/debug/s390dbf/dasd/level
  310. 5
  311. Flushing debug areas
  312. --------------------
  313. Debug areas can be flushed with piping the number of the desired
  314. area (0...n) to the debugfs file "flush". When using "-" all debug areas
  315. are flushed.
  316. Examples:
  317. 1. Flush debug area 0:
  318. > echo "0" > /sys/kernel/debug/s390dbf/dasd/flush
  319. 2. Flush all debug areas:
  320. > echo "-" > /sys/kernel/debug/s390dbf/dasd/flush
  321. Changing the size of debug areas
  322. ------------------------------------
  323. It is possible the change the size of debug areas through piping
  324. the number of pages to the debugfs file "pages". The resize request will
  325. also flush the debug areas.
  326. Example:
  327. Define 4 pages for the debug areas of debug feature "dasd":
  328. > echo "4" > /sys/kernel/debug/s390dbf/dasd/pages
  329. Stooping the debug feature
  330. --------------------------
  331. Example:
  332. 1. Check if stopping is allowed
  333. > cat /proc/sys/s390dbf/debug_stoppable
  334. 2. Stop debug feature
  335. > echo 0 > /proc/sys/s390dbf/debug_active
  336. lcrash Interface
  337. ----------------
  338. It is planned that the dump analysis tool lcrash gets an additional command
  339. 's390dbf' to display all the debug logs. With this tool it will be possible
  340. to investigate the debug logs on a live system and with a memory dump after
  341. a system crash.
  342. Investigating raw memory
  343. ------------------------
  344. One last possibility to investigate the debug logs at a live
  345. system and after a system crash is to look at the raw memory
  346. under VM or at the Service Element.
  347. It is possible to find the anker of the debug-logs through
  348. the 'debug_area_first' symbol in the System map. Then one has
  349. to follow the correct pointers of the data-structures defined
  350. in debug.h and find the debug-areas in memory.
  351. Normally modules which use the debug feature will also have
  352. a global variable with the pointer to the debug-logs. Following
  353. this pointer it will also be possible to find the debug logs in
  354. memory.
  355. For this method it is recommended to use '16 * x + 4' byte (x = 0..n)
  356. for the length of the data field in debug_register() in
  357. order to see the debug entries well formatted.
  358. Predefined Views
  359. ----------------
  360. There are three predefined views: hex_ascii, raw and sprintf.
  361. The hex_ascii view shows the data field in hex and ascii representation
  362. (e.g. '45 43 4b 44 | ECKD').
  363. The raw view returns a bytestream as the debug areas are stored in memory.
  364. The sprintf view formats the debug entries in the same way as the sprintf
  365. function would do. The sprintf event/exception functions write to the
  366. debug entry a pointer to the format string (size = sizeof(long))
  367. and for each vararg a long value. So e.g. for a debug entry with a format
  368. string plus two varargs one would need to allocate a (3 * sizeof(long))
  369. byte data area in the debug_register() function.
  370. IMPORTANT: Using "%s" in sprintf event functions is dangerous. You can only
  371. use "%s" in the sprintf event functions, if the memory for the passed string is
  372. available as long as the debug feature exists. The reason behind this is that
  373. due to performance considerations only a pointer to the string is stored in
  374. the debug feature. If you log a string that is freed afterwards, you will get
  375. an OOPS when inspecting the debug feature, because then the debug feature will
  376. access the already freed memory.
  377. NOTE: If using the sprintf view do NOT use other event/exception functions
  378. than the sprintf-event and -exception functions.
  379. The format of the hex_ascii and sprintf view is as follows:
  380. - Number of area
  381. - Timestamp (formatted as seconds and microseconds since 00:00:00 Coordinated
  382. Universal Time (UTC), January 1, 1970)
  383. - level of debug entry
  384. - Exception flag (* = Exception)
  385. - Cpu-Number of calling task
  386. - Return Address to caller
  387. - data field
  388. The format of the raw view is:
  389. - Header as described in debug.h
  390. - datafield
  391. A typical line of the hex_ascii view will look like the following (first line
  392. is only for explanation and will not be displayed when 'cating' the view):
  393. area time level exception cpu caller data (hex + ascii)
  394. --------------------------------------------------------------------------
  395. 00 00964419409:440690 1 - 00 88023fe
  396. Defining views
  397. --------------
  398. Views are specified with the 'debug_view' structure. There are defined
  399. callback functions which are used for reading and writing the debugfs files:
  400. struct debug_view {
  401. char name[DEBUG_MAX_PROCF_LEN];
  402. debug_prolog_proc_t* prolog_proc;
  403. debug_header_proc_t* header_proc;
  404. debug_format_proc_t* format_proc;
  405. debug_input_proc_t* input_proc;
  406. void* private_data;
  407. };
  408. where
  409. typedef int (debug_header_proc_t) (debug_info_t* id,
  410. struct debug_view* view,
  411. int area,
  412. debug_entry_t* entry,
  413. char* out_buf);
  414. typedef int (debug_format_proc_t) (debug_info_t* id,
  415. struct debug_view* view, char* out_buf,
  416. const char* in_buf);
  417. typedef int (debug_prolog_proc_t) (debug_info_t* id,
  418. struct debug_view* view,
  419. char* out_buf);
  420. typedef int (debug_input_proc_t) (debug_info_t* id,
  421. struct debug_view* view,
  422. struct file* file, const char* user_buf,
  423. size_t in_buf_size, loff_t* offset);
  424. The "private_data" member can be used as pointer to view specific data.
  425. It is not used by the debug feature itself.
  426. The output when reading a debugfs file is structured like this:
  427. "prolog_proc output"
  428. "header_proc output 1" "format_proc output 1"
  429. "header_proc output 2" "format_proc output 2"
  430. "header_proc output 3" "format_proc output 3"
  431. ...
  432. When a view is read from the debugfs, the Debug Feature calls the
  433. 'prolog_proc' once for writing the prolog.
  434. Then 'header_proc' and 'format_proc' are called for each
  435. existing debug entry.
  436. The input_proc can be used to implement functionality when it is written to
  437. the view (e.g. like with 'echo "0" > /sys/kernel/debug/s390dbf/dasd/level).
  438. For header_proc there can be used the default function
  439. debug_dflt_header_fn() which is defined in debug.h.
  440. and which produces the same header output as the predefined views.
  441. E.g:
  442. 00 00964419409:440761 2 - 00 88023ec
  443. In order to see how to use the callback functions check the implementation
  444. of the default views!
  445. Example
  446. #include <asm/debug.h>
  447. #define UNKNOWNSTR "data: %08x"
  448. const char* messages[] =
  449. {"This error...........\n",
  450. "That error...........\n",
  451. "Problem..............\n",
  452. "Something went wrong.\n",
  453. "Everything ok........\n",
  454. NULL
  455. };
  456. static int debug_test_format_fn(
  457. debug_info_t * id, struct debug_view *view,
  458. char *out_buf, const char *in_buf
  459. )
  460. {
  461. int i, rc = 0;
  462. if(id->buf_size >= 4) {
  463. int msg_nr = *((int*)in_buf);
  464. if(msg_nr < sizeof(messages)/sizeof(char*) - 1)
  465. rc += sprintf(out_buf, "%s", messages[msg_nr]);
  466. else
  467. rc += sprintf(out_buf, UNKNOWNSTR, msg_nr);
  468. }
  469. out:
  470. return rc;
  471. }
  472. struct debug_view debug_test_view = {
  473. "myview", /* name of view */
  474. NULL, /* no prolog */
  475. &debug_dflt_header_fn, /* default header for each entry */
  476. &debug_test_format_fn, /* our own format function */
  477. NULL, /* no input function */
  478. NULL /* no private data */
  479. };
  480. =====
  481. test:
  482. =====
  483. debug_info_t *debug_info;
  484. ...
  485. debug_info = debug_register ("test", 0, 4, 4 ));
  486. debug_register_view(debug_info, &debug_test_view);
  487. for(i = 0; i < 10; i ++) debug_int_event(debug_info, 1, i);
  488. > cat /sys/kernel/debug/s390dbf/test/myview
  489. 00 00964419734:611402 1 - 00 88042ca This error...........
  490. 00 00964419734:611405 1 - 00 88042ca That error...........
  491. 00 00964419734:611408 1 - 00 88042ca Problem..............
  492. 00 00964419734:611411 1 - 00 88042ca Something went wrong.
  493. 00 00964419734:611414 1 - 00 88042ca Everything ok........
  494. 00 00964419734:611417 1 - 00 88042ca data: 00000005
  495. 00 00964419734:611419 1 - 00 88042ca data: 00000006
  496. 00 00964419734:611422 1 - 00 88042ca data: 00000007
  497. 00 00964419734:611425 1 - 00 88042ca data: 00000008
  498. 00 00964419734:611428 1 - 00 88042ca data: 00000009