1 // SPDX-License-Identifier: LGPL-2.1
2 /*
3  * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
4  */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 
9 #include "event-parse.h"
10 #include "trace-seq.h"
11 
12 #define MINORBITS	20
13 #define MINORMASK	((1U << MINORBITS) - 1)
14 
15 #define MAJOR(dev)	((unsigned int) ((dev) >> MINORBITS))
16 #define MINOR(dev)	((unsigned int) ((dev) & MINORMASK))
17 
18 static unsigned long long
process_jbd2_dev_to_name(struct trace_seq * s,unsigned long long * args)19 process_jbd2_dev_to_name(struct trace_seq *s, unsigned long long *args)
20 {
21 	unsigned int dev = args[0];
22 
23 	trace_seq_printf(s, "%d:%d", MAJOR(dev), MINOR(dev));
24 	return 0;
25 }
26 
27 static unsigned long long
process_jiffies_to_msecs(struct trace_seq * s,unsigned long long * args)28 process_jiffies_to_msecs(struct trace_seq *s, unsigned long long *args)
29 {
30 	unsigned long long jiffies = args[0];
31 
32 	trace_seq_printf(s, "%lld", jiffies);
33 	return jiffies;
34 }
35 
TEP_PLUGIN_LOADER(struct tep_handle * tep)36 int TEP_PLUGIN_LOADER(struct tep_handle *tep)
37 {
38 	tep_register_print_function(tep,
39 				    process_jbd2_dev_to_name,
40 				    TEP_FUNC_ARG_STRING,
41 				    "jbd2_dev_to_name",
42 				    TEP_FUNC_ARG_INT,
43 				    TEP_FUNC_ARG_VOID);
44 
45 	tep_register_print_function(tep,
46 				    process_jiffies_to_msecs,
47 				    TEP_FUNC_ARG_LONG,
48 				    "jiffies_to_msecs",
49 				    TEP_FUNC_ARG_LONG,
50 				    TEP_FUNC_ARG_VOID);
51 	return 0;
52 }
53 
TEP_PLUGIN_UNLOADER(struct tep_handle * tep)54 void TEP_PLUGIN_UNLOADER(struct tep_handle *tep)
55 {
56 	tep_unregister_print_function(tep, process_jbd2_dev_to_name,
57 				      "jbd2_dev_to_name");
58 
59 	tep_unregister_print_function(tep, process_jiffies_to_msecs,
60 				      "jiffies_to_msecs");
61 }
62