s390dbf.txt 21 KB

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