s390dbf.txt 24 KB

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