Skip to content

Commit f11977b

Browse files
steffen-maierVasily Gorbik
authored andcommitted
docs: s390: restore important non-kdoc parts of s390dbf.rst
Complements previous ("s390: include/asm/debug.h add kerneldoc markups") which seemed to have dropped important non-kdoc parts such as user space interface (level, size, flush) as well as views and caution regarding strings in the sprintf view. Signed-off-by: Steffen Maier <maier@linux.ibm.com> Acked-by: Christian Borntraeger <borntraeger@de.ibm.com> Message-Id: <1562149189-1417-2-git-send-email-maier@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent 555827c commit f11977b

1 file changed

Lines changed: 339 additions & 0 deletions

File tree

‎Documentation/s390/s390dbf.rst‎

Lines changed: 339 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,345 @@ Kernel Interfaces:
112112
Predefined views:
113113
-----------------
114114

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

117456
debug_info_t *debug_info;

0 commit comments

Comments
 (0)