summaryrefslogtreecommitdiffstats
path: root/Documentation/s390/s390dbf.rst
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+samsung@kernel.org>2019-06-08 22:27:16 -0400
committerHeiko Carstens <heiko.carstens@de.ibm.com>2019-06-11 03:48:14 -0400
commit8b4a503d659b32cae8266aeb306f7fd6717e6a53 (patch)
tree4d16b79021d75c7dfe5db7fe13811e1031517a1d /Documentation/s390/s390dbf.rst
parentdc3988f40fdf7a51bd5480c3383372f463e4dfa9 (diff)
docs: s390: convert docs to ReST and rename to *.rst
Convert all text files with s390 documentation to ReST format. Tried to preserve as much as possible the original document format. Still, some of the files required some work in order for it to be visible on both plain text and after converted to html. The conversion is actually: - add blank lines and identation in order to identify paragraphs; - fix tables markups; - add some lists markups; - mark literal blocks; - adjust title markups. At its new index.rst, let's add a :orphan: while this is not linked to the main index.rst file, in order to avoid build warnings. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Diffstat (limited to 'Documentation/s390/s390dbf.rst')
-rw-r--r--Documentation/s390/s390dbf.rst803
1 files changed, 803 insertions, 0 deletions
diff --git a/Documentation/s390/s390dbf.rst b/Documentation/s390/s390dbf.rst
new file mode 100644
index 000000000000..ec2a1faa414b
--- /dev/null
+++ b/Documentation/s390/s390dbf.rst
@@ -0,0 +1,803 @@
1==================
2S390 Debug Feature
3==================
4
5files:
6 - arch/s390/kernel/debug.c
7 - arch/s390/include/asm/debug.h
8
9Description:
10------------
11The goal of this feature is to provide a kernel debug logging API
12where log records can be stored efficiently in memory, where each component
13(e.g. device drivers) can have one separate debug log.
14One purpose of this is to inspect the debug logs after a production system crash
15in order to analyze the reason for the crash.
16
17If the system still runs but only a subcomponent which uses dbf fails,
18it is possible to look at the debug logs on a live system via the Linux
19debugfs filesystem.
20
21The debug feature may also very useful for kernel and driver development.
22
23Design:
24-------
25Kernel components (e.g. device drivers) can register themselves at the debug
26feature with the function call debug_register(). This function initializes a
27debug log for the caller. For each debug log exists a number of debug areas
28where exactly one is active at one time. Each debug area consists of contiguous
29pages in memory. In the debug areas there are stored debug entries (log records)
30which are written by event- and exception-calls.
31
32An event-call writes the specified debug entry to the active debug
33area and updates the log pointer for the active area. If the end
34of the active debug area is reached, a wrap around is done (ring buffer)
35and the next debug entry will be written at the beginning of the active
36debug area.
37
38An exception-call writes the specified debug entry to the log and
39switches to the next debug area. This is done in order to be sure
40that the records which describe the origin of the exception are not
41overwritten when a wrap around for the current area occurs.
42
43The debug areas themselves are also ordered in form of a ring buffer.
44When an exception is thrown in the last debug area, the following debug
45entries are then written again in the very first area.
46
47There are three versions for the event- and exception-calls: One for
48logging raw data, one for text and one for numbers.
49
50Each debug entry contains the following data:
51
52- Timestamp
53- Cpu-Number of calling task
54- Level of debug entry (0...6)
55- Return Address to caller
56- Flag, if entry is an exception or not
57
58The debug logs can be inspected in a live system through entries in
59the debugfs-filesystem. Under the toplevel directory "s390dbf" there is
60a directory for each registered component, which is named like the
61corresponding component. The debugfs normally should be mounted to
62/sys/kernel/debug therefore the debug feature can be accessed under
63/sys/kernel/debug/s390dbf.
64
65The content of the directories are files which represent different views
66to the debug log. Each component can decide which views should be
67used through registering them with the function debug_register_view().
68Predefined views for hex/ascii, sprintf and raw binary data are provided.
69It is also possible to define other views. The content of
70a view can be inspected simply by reading the corresponding debugfs file.
71
72All debug logs have an actual debug level (range from 0 to 6).
73The default level is 3. Event and Exception functions have a 'level'
74parameter. Only debug entries with a level that is lower or equal
75than the actual level are written to the log. This means, when
76writing events, high priority log entries should have a low level
77value whereas low priority entries should have a high one.
78The actual debug level can be changed with the help of the debugfs-filesystem
79through writing a number string "x" to the 'level' debugfs file which is
80provided for every debug log. Debugging can be switched off completely
81by using "-" on the 'level' debugfs file.
82
83Example::
84
85 > echo "-" > /sys/kernel/debug/s390dbf/dasd/level
86
87It is also possible to deactivate the debug feature globally for every
88debug log. You can change the behavior using 2 sysctl parameters in
89/proc/sys/s390dbf:
90
91There are currently 2 possible triggers, which stop the debug feature
92globally. The first possibility is to use the "debug_active" sysctl. If
93set to 1 the debug feature is running. If "debug_active" is set to 0 the
94debug feature is turned off.
95
96The second trigger which stops the debug feature is a kernel oops.
97That prevents the debug feature from overwriting debug information that
98happened before the oops. After an oops you can reactivate the debug feature
99by piping 1 to /proc/sys/s390dbf/debug_active. Nevertheless, its not
100suggested to use an oopsed kernel in a production environment.
101
102If you want to disallow the deactivation of the debug feature, you can use
103the "debug_stoppable" sysctl. If you set "debug_stoppable" to 0 the debug
104feature cannot be stopped. If the debug feature is already stopped, it
105will stay deactivated.
106
107----------------------------------------------------------------------------
108
109Kernel Interfaces:
110------------------
111
112::
113
114 debug_info_t *debug_register(char *name, int pages, int nr_areas,
115 int buf_size);
116
117Parameter:
118 name:
119 Name of debug log (e.g. used for debugfs entry)
120 pages:
121 Number of pages, which will be allocated per area
122 nr_areas:
123 Number of debug areas
124 buf_size:
125 Size of data area in each debug entry
126
127Return Value:
128 Handle for generated debug area
129
130 NULL if register failed
131
132Description: Allocates memory for a debug log
133 Must not be called within an interrupt handler
134
135----------------------------------------------------------------------------
136
137::
138
139 debug_info_t *debug_register_mode(char *name, int pages, int nr_areas,
140 int buf_size, mode_t mode, uid_t uid,
141 gid_t gid);
142
143Parameter:
144 name:
145 Name of debug log (e.g. used for debugfs entry)
146 pages:
147 Number of pages, which will be allocated per area
148 nr_areas:
149 Number of debug areas
150 buf_size:
151 Size of data area in each debug entry
152 mode:
153 File mode for debugfs files. E.g. S_IRWXUGO
154 uid:
155 User ID for debugfs files. Currently only 0 is
156 supported.
157 gid:
158 Group ID for debugfs files. Currently only 0 is
159 supported.
160
161Return Value:
162 Handle for generated debug area
163
164 NULL if register failed
165
166Description:
167 Allocates memory for a debug log
168 Must not be called within an interrupt handler
169
170---------------------------------------------------------------------------
171
172::
173
174 void debug_unregister (debug_info_t * id);
175
176Parameter:
177 id:
178 handle for debug log
179
180Return Value:
181 none
182
183Description:
184 frees memory for a debug log and removes all registered debug
185 views.
186
187 Must not be called within an interrupt handler
188
189---------------------------------------------------------------------------
190
191::
192
193 void debug_set_level (debug_info_t * id, int new_level);
194
195Parameter: id: handle for debug log
196 new_level: new debug level
197
198Return Value:
199 none
200
201Description:
202 Sets new actual debug level if new_level is valid.
203
204---------------------------------------------------------------------------
205
206::
207
208 bool debug_level_enabled (debug_info_t * id, int level);
209
210Parameter:
211 id:
212 handle for debug log
213 level:
214 debug level
215
216Return Value:
217 True if level is less or equal to the current debug level.
218
219Description:
220 Returns true if debug events for the specified level would be
221 logged. Otherwise returns false.
222
223---------------------------------------------------------------------------
224
225::
226
227 void debug_stop_all(void);
228
229Parameter:
230 none
231
232Return Value:
233 none
234
235Description:
236 stops the debug feature if stopping is allowed. Currently
237 used in case of a kernel oops.
238
239---------------------------------------------------------------------------
240
241::
242
243 debug_entry_t* debug_event (debug_info_t* id, int level, void* data,
244 int length);
245
246Parameter:
247 id:
248 handle for debug log
249 level:
250 debug level
251 data:
252 pointer to data for debug entry
253 length:
254 length of data in bytes
255
256Return Value:
257 Address of written debug entry
258
259Description:
260 writes debug entry to active debug area (if level <= actual
261 debug level)
262
263---------------------------------------------------------------------------
264
265::
266
267 debug_entry_t* debug_int_event (debug_info_t * id, int level,
268 unsigned int data);
269 debug_entry_t* debug_long_event(debug_info_t * id, int level,
270 unsigned long data);
271
272Parameter:
273 id:
274 handle for debug log
275 level:
276 debug level
277 data:
278 integer value for debug entry
279
280Return Value:
281 Address of written debug entry
282
283Description:
284 writes debug entry to active debug area (if level <= actual
285 debug level)
286
287---------------------------------------------------------------------------
288
289::
290
291 debug_entry_t* debug_text_event (debug_info_t * id, int level,
292 const char* data);
293
294Parameter:
295 id:
296 handle for debug log
297 level:
298 debug level
299 data:
300 string for debug entry
301
302Return Value:
303 Address of written debug entry
304
305Description:
306 writes debug entry in ascii format to active debug area
307 (if level <= actual debug level)
308
309---------------------------------------------------------------------------
310
311::
312
313 debug_entry_t* debug_sprintf_event (debug_info_t * id, int level,
314 char* string,...);
315
316Parameter:
317 id:
318 handle for debug log
319 level:
320 debug level
321 string:
322 format string for debug entry
323 ...:
324 varargs used as in sprintf()
325
326Return Value: Address of written debug entry
327
328Description:
329 writes debug entry with format string and varargs (longs) to
330 active debug area (if level $<=$ actual debug level).
331 floats and long long datatypes cannot be used as varargs.
332
333---------------------------------------------------------------------------
334
335::
336
337 debug_entry_t* debug_exception (debug_info_t* id, int level, void* data,
338 int length);
339
340Parameter:
341 id:
342 handle for debug log
343 level:
344 debug level
345 data:
346 pointer to data for debug entry
347 length:
348 length of data in bytes
349
350Return Value:
351 Address of written debug entry
352
353Description:
354 writes debug entry to active debug area (if level <= actual
355 debug level) and switches to next debug area
356
357---------------------------------------------------------------------------
358
359::
360
361 debug_entry_t* debug_int_exception (debug_info_t * id, int level,
362 unsigned int data);
363 debug_entry_t* debug_long_exception(debug_info_t * id, int level,
364 unsigned long data);
365
366Parameter: id: handle for debug log
367 level: debug level
368 data: integer value for debug entry
369
370Return Value: Address of written debug entry
371
372Description: writes debug entry to active debug area (if level <= actual
373 debug level) and switches to next debug area
374
375---------------------------------------------------------------------------
376
377::
378
379 debug_entry_t* debug_text_exception (debug_info_t * id, int level,
380 const char* data);
381
382Parameter: id: handle for debug log
383 level: debug level
384 data: string for debug entry
385
386Return Value: Address of written debug entry
387
388Description: writes debug entry in ascii format to active debug area
389 (if level <= actual debug level) and switches to next debug
390 area
391
392---------------------------------------------------------------------------
393
394::
395
396 debug_entry_t* debug_sprintf_exception (debug_info_t * id, int level,
397 char* string,...);
398
399Parameter: id: handle for debug log
400 level: debug level
401 string: format string for debug entry
402 ...: varargs used as in sprintf()
403
404Return Value: Address of written debug entry
405
406Description: writes debug entry with format string and varargs (longs) to
407 active debug area (if level $<=$ actual debug level) and
408 switches to next debug area.
409 floats and long long datatypes cannot be used as varargs.
410
411---------------------------------------------------------------------------
412
413::
414
415 int debug_register_view (debug_info_t * id, struct debug_view *view);
416
417Parameter: id: handle for debug log
418 view: pointer to debug view struct
419
420Return Value: 0 : ok
421 < 0: Error
422
423Description: registers new debug view and creates debugfs dir entry
424
425---------------------------------------------------------------------------
426
427::
428
429 int debug_unregister_view (debug_info_t * id, struct debug_view *view);
430
431Parameter: id: handle for debug log
432 view: pointer to debug view struct
433
434Return Value: 0 : ok
435 < 0: Error
436
437Description: unregisters debug view and removes debugfs dir entry
438
439
440
441Predefined views:
442-----------------
443
444extern struct debug_view debug_hex_ascii_view;
445
446extern struct debug_view debug_raw_view;
447
448extern struct debug_view debug_sprintf_view;
449
450Examples
451--------
452
453::
454
455 /*
456 * hex_ascii- + raw-view Example
457 */
458
459 #include <linux/init.h>
460 #include <asm/debug.h>
461
462 static debug_info_t* debug_info;
463
464 static int init(void)
465 {
466 /* register 4 debug areas with one page each and 4 byte data field */
467
468 debug_info = debug_register ("test", 1, 4, 4 );
469 debug_register_view(debug_info,&debug_hex_ascii_view);
470 debug_register_view(debug_info,&debug_raw_view);
471
472 debug_text_event(debug_info, 4 , "one ");
473 debug_int_exception(debug_info, 4, 4711);
474 debug_event(debug_info, 3, &debug_info, 4);
475
476 return 0;
477 }
478
479 static void cleanup(void)
480 {
481 debug_unregister (debug_info);
482 }
483
484 module_init(init);
485 module_exit(cleanup);
486
487---------------------------------------------------------------------------
488
489::
490
491 /*
492 * sprintf-view Example
493 */
494
495 #include <linux/init.h>
496 #include <asm/debug.h>
497
498 static debug_info_t* debug_info;
499
500 static int init(void)
501 {
502 /* register 4 debug areas with one page each and data field for */
503 /* format string pointer + 2 varargs (= 3 * sizeof(long)) */
504
505 debug_info = debug_register ("test", 1, 4, sizeof(long) * 3);
506 debug_register_view(debug_info,&debug_sprintf_view);
507
508 debug_sprintf_event(debug_info, 2 , "first event in %s:%i\n",__FILE__,__LINE__);
509 debug_sprintf_exception(debug_info, 1, "pointer to debug info: %p\n",&debug_info);
510
511 return 0;
512 }
513
514 static void cleanup(void)
515 {
516 debug_unregister (debug_info);
517 }
518
519 module_init(init);
520 module_exit(cleanup);
521
522Debugfs Interface
523-----------------
524Views to the debug logs can be investigated through reading the corresponding
525debugfs-files:
526
527Example::
528
529 > ls /sys/kernel/debug/s390dbf/dasd
530 flush hex_ascii level pages raw
531 > cat /sys/kernel/debug/s390dbf/dasd/hex_ascii | sort -k2,2 -s
532 00 00974733272:680099 2 - 02 0006ad7e 07 ea 4a 90 | ....
533 00 00974733272:682210 2 - 02 0006ade6 46 52 45 45 | FREE
534 00 00974733272:682213 2 - 02 0006adf6 07 ea 4a 90 | ....
535 00 00974733272:682281 1 * 02 0006ab08 41 4c 4c 43 | EXCP
536 01 00974733272:682284 2 - 02 0006ab16 45 43 4b 44 | ECKD
537 01 00974733272:682287 2 - 02 0006ab28 00 00 00 04 | ....
538 01 00974733272:682289 2 - 02 0006ab3e 00 00 00 20 | ...
539 01 00974733272:682297 2 - 02 0006ad7e 07 ea 4a 90 | ....
540 01 00974733272:684384 2 - 00 0006ade6 46 52 45 45 | FREE
541 01 00974733272:684388 2 - 00 0006adf6 07 ea 4a 90 | ....
542
543See section about predefined views for explanation of the above output!
544
545Changing the debug level
546------------------------
547
548Example::
549
550
551 > cat /sys/kernel/debug/s390dbf/dasd/level
552 3
553 > echo "5" > /sys/kernel/debug/s390dbf/dasd/level
554 > cat /sys/kernel/debug/s390dbf/dasd/level
555 5
556
557Flushing debug areas
558--------------------
559Debug areas can be flushed with piping the number of the desired
560area (0...n) to the debugfs file "flush". When using "-" all debug areas
561are flushed.
562
563Examples:
564
5651. Flush debug area 0::
566
567 > echo "0" > /sys/kernel/debug/s390dbf/dasd/flush
568
5692. Flush all debug areas::
570
571 > echo "-" > /sys/kernel/debug/s390dbf/dasd/flush
572
573Changing the size of debug areas
574------------------------------------
575It is possible the change the size of debug areas through piping
576the number of pages to the debugfs file "pages". The resize request will
577also flush the debug areas.
578
579Example:
580
581Define 4 pages for the debug areas of debug feature "dasd"::
582
583 > echo "4" > /sys/kernel/debug/s390dbf/dasd/pages
584
585Stooping the debug feature
586--------------------------
587Example:
588
5891. Check if stopping is allowed::
590
591 > cat /proc/sys/s390dbf/debug_stoppable
592
5932. Stop debug feature::
594
595 > echo 0 > /proc/sys/s390dbf/debug_active
596
597lcrash Interface
598----------------
599It is planned that the dump analysis tool lcrash gets an additional command
600's390dbf' to display all the debug logs. With this tool it will be possible
601to investigate the debug logs on a live system and with a memory dump after
602a system crash.
603
604Investigating raw memory
605------------------------
606One last possibility to investigate the debug logs at a live
607system and after a system crash is to look at the raw memory
608under VM or at the Service Element.
609It is possible to find the anker of the debug-logs through
610the 'debug_area_first' symbol in the System map. Then one has
611to follow the correct pointers of the data-structures defined
612in debug.h and find the debug-areas in memory.
613Normally modules which use the debug feature will also have
614a global variable with the pointer to the debug-logs. Following
615this pointer it will also be possible to find the debug logs in
616memory.
617
618For this method it is recommended to use '16 * x + 4' byte (x = 0..n)
619for the length of the data field in debug_register() in
620order to see the debug entries well formatted.
621
622
623Predefined Views
624----------------
625
626There are three predefined views: hex_ascii, raw and sprintf.
627The hex_ascii view shows the data field in hex and ascii representation
628(e.g. '45 43 4b 44 | ECKD').
629The raw view returns a bytestream as the debug areas are stored in memory.
630
631The sprintf view formats the debug entries in the same way as the sprintf
632function would do. The sprintf event/exception functions write to the
633debug entry a pointer to the format string (size = sizeof(long))
634and for each vararg a long value. So e.g. for a debug entry with a format
635string plus two varargs one would need to allocate a (3 * sizeof(long))
636byte data area in the debug_register() function.
637
638IMPORTANT:
639 Using "%s" in sprintf event functions is dangerous. You can only
640 use "%s" in the sprintf event functions, if the memory for the passed string
641 is available as long as the debug feature exists. The reason behind this is
642 that due to performance considerations only a pointer to the string is stored
643 in the debug feature. If you log a string that is freed afterwards, you will
644 get an OOPS when inspecting the debug feature, because then the debug feature
645 will access the already freed memory.
646
647NOTE:
648 If using the sprintf view do NOT use other event/exception functions
649 than the sprintf-event and -exception functions.
650
651The format of the hex_ascii and sprintf view is as follows:
652
653- Number of area
654- Timestamp (formatted as seconds and microseconds since 00:00:00 Coordinated
655 Universal Time (UTC), January 1, 1970)
656- level of debug entry
657- Exception flag (* = Exception)
658- Cpu-Number of calling task
659- Return Address to caller
660- data field
661
662The format of the raw view is:
663
664- Header as described in debug.h
665- datafield
666
667A typical line of the hex_ascii view will look like the following (first line
668is only for explanation and will not be displayed when 'cating' the view):
669
670area time level exception cpu caller data (hex + ascii)
671--------------------------------------------------------------------------
67200 00964419409:440690 1 - 00 88023fe
673
674
675Defining views
676--------------
677
678Views are specified with the 'debug_view' structure. There are defined
679callback functions which are used for reading and writing the debugfs files::
680
681 struct debug_view {
682 char name[DEBUG_MAX_PROCF_LEN];
683 debug_prolog_proc_t* prolog_proc;
684 debug_header_proc_t* header_proc;
685 debug_format_proc_t* format_proc;
686 debug_input_proc_t* input_proc;
687 void* private_data;
688 };
689
690where::
691
692 typedef int (debug_header_proc_t) (debug_info_t* id,
693 struct debug_view* view,
694 int area,
695 debug_entry_t* entry,
696 char* out_buf);
697
698 typedef int (debug_format_proc_t) (debug_info_t* id,
699 struct debug_view* view, char* out_buf,
700 const char* in_buf);
701 typedef int (debug_prolog_proc_t) (debug_info_t* id,
702 struct debug_view* view,
703 char* out_buf);
704 typedef int (debug_input_proc_t) (debug_info_t* id,
705 struct debug_view* view,
706 struct file* file, const char* user_buf,
707 size_t in_buf_size, loff_t* offset);
708
709
710The "private_data" member can be used as pointer to view specific data.
711It is not used by the debug feature itself.
712
713The output when reading a debugfs file is structured like this::
714
715 "prolog_proc output"
716
717 "header_proc output 1" "format_proc output 1"
718 "header_proc output 2" "format_proc output 2"
719 "header_proc output 3" "format_proc output 3"
720 ...
721
722When a view is read from the debugfs, the Debug Feature calls the
723'prolog_proc' once for writing the prolog.
724Then 'header_proc' and 'format_proc' are called for each
725existing debug entry.
726
727The input_proc can be used to implement functionality when it is written to
728the view (e.g. like with 'echo "0" > /sys/kernel/debug/s390dbf/dasd/level).
729
730For header_proc there can be used the default function
731debug_dflt_header_fn() which is defined in debug.h.
732and which produces the same header output as the predefined views.
733E.g::
734
735 00 00964419409:440761 2 - 00 88023ec
736
737In order to see how to use the callback functions check the implementation
738of the default views!
739
740Example::
741
742 #include <asm/debug.h>
743
744 #define UNKNOWNSTR "data: %08x"
745
746 const char* messages[] =
747 {"This error...........\n",
748 "That error...........\n",
749 "Problem..............\n",
750 "Something went wrong.\n",
751 "Everything ok........\n",
752 NULL
753 };
754
755 static int debug_test_format_fn(
756 debug_info_t * id, struct debug_view *view,
757 char *out_buf, const char *in_buf
758 )
759 {
760 int i, rc = 0;
761
762 if(id->buf_size >= 4) {
763 int msg_nr = *((int*)in_buf);
764 if(msg_nr < sizeof(messages)/sizeof(char*) - 1)
765 rc += sprintf(out_buf, "%s", messages[msg_nr]);
766 else
767 rc += sprintf(out_buf, UNKNOWNSTR, msg_nr);
768 }
769 out:
770 return rc;
771 }
772
773 struct debug_view debug_test_view = {
774 "myview", /* name of view */
775 NULL, /* no prolog */
776 &debug_dflt_header_fn, /* default header for each entry */
777 &debug_test_format_fn, /* our own format function */
778 NULL, /* no input function */
779 NULL /* no private data */
780 };
781
782test:
783=====
784
785::
786
787 debug_info_t *debug_info;
788 ...
789 debug_info = debug_register ("test", 0, 4, 4 ));
790 debug_register_view(debug_info, &debug_test_view);
791 for(i = 0; i < 10; i ++) debug_int_event(debug_info, 1, i);
792
793 > cat /sys/kernel/debug/s390dbf/test/myview
794 00 00964419734:611402 1 - 00 88042ca This error...........
795 00 00964419734:611405 1 - 00 88042ca That error...........
796 00 00964419734:611408 1 - 00 88042ca Problem..............
797 00 00964419734:611411 1 - 00 88042ca Something went wrong.
798 00 00964419734:611414 1 - 00 88042ca Everything ok........
799 00 00964419734:611417 1 - 00 88042ca data: 00000005
800 00 00964419734:611419 1 - 00 88042ca data: 00000006
801 00 00964419734:611422 1 - 00 88042ca data: 00000007
802 00 00964419734:611425 1 - 00 88042ca data: 00000008
803 00 00964419734:611428 1 - 00 88042ca data: 00000009