2 * Copyright (C) ARM Limited 2010-2014. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
11 #include <trace/events/block.h>
16 #define BLOCK_TOTAL (BLOCK_RQ_RD+1)
18 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
19 #define EVENTWRITE REQ_RW
21 #define EVENTWRITE REQ_WRITE
24 static ulong block_rq_wr_enabled;
25 static ulong block_rq_rd_enabled;
26 static ulong block_rq_wr_key;
27 static ulong block_rq_rd_key;
28 static atomic_t blockCnt[BLOCK_TOTAL];
29 static int blockGet[BLOCK_TOTAL * 4];
31 /* Tracepoint changed in 3.15 backported to older kernels. The Makefile tries to autodetect the correct value, but if it fails change the #if below */
32 #if OLD_BLOCK_RQ_COMPLETE
33 GATOR_DEFINE_PROBE(block_rq_complete, TP_PROTO(struct request_queue *q, struct request *rq))
35 GATOR_DEFINE_PROBE(block_rq_complete, TP_PROTO(struct request_queue *q, struct request *rq, unsigned int nr_bytes))
44 write = rq->cmd_flags & EVENTWRITE;
45 #if OLD_BLOCK_RQ_COMPLETE
55 if (block_rq_wr_enabled)
56 atomic_add(size, &blockCnt[BLOCK_RQ_WR]);
58 if (block_rq_rd_enabled)
59 atomic_add(size, &blockCnt[BLOCK_RQ_RD]);
63 static int gator_events_block_create_files(struct super_block *sb, struct dentry *root)
67 /* block_complete_wr */
68 dir = gatorfs_mkdir(sb, root, "Linux_block_rq_wr");
71 gatorfs_create_ulong(sb, dir, "enabled", &block_rq_wr_enabled);
72 gatorfs_create_ro_ulong(sb, dir, "key", &block_rq_wr_key);
74 /* block_complete_rd */
75 dir = gatorfs_mkdir(sb, root, "Linux_block_rq_rd");
78 gatorfs_create_ulong(sb, dir, "enabled", &block_rq_rd_enabled);
79 gatorfs_create_ro_ulong(sb, dir, "key", &block_rq_rd_key);
84 static int gator_events_block_start(void)
86 /* register tracepoints */
87 if (block_rq_wr_enabled || block_rq_rd_enabled)
88 if (GATOR_REGISTER_TRACE(block_rq_complete))
89 goto fail_block_rq_exit;
90 pr_debug("gator: registered block event tracepoints\n");
94 /* unregister tracepoints on error */
96 pr_err("gator: block event tracepoints failed to activate, please verify that tracepoints are enabled in the linux kernel\n");
101 static void gator_events_block_stop(void)
103 if (block_rq_wr_enabled || block_rq_rd_enabled)
104 GATOR_UNREGISTER_TRACE(block_rq_complete);
105 pr_debug("gator: unregistered block event tracepoints\n");
107 block_rq_wr_enabled = 0;
108 block_rq_rd_enabled = 0;
111 static int gator_events_block_read(int **buffer, bool sched_switch)
113 int len, value, data = 0;
115 if (!on_primary_core())
119 if (block_rq_wr_enabled && (value = atomic_read(&blockCnt[BLOCK_RQ_WR])) > 0) {
120 atomic_sub(value, &blockCnt[BLOCK_RQ_WR]);
121 blockGet[len++] = block_rq_wr_key;
122 /* Indicates to Streamline that value bytes were written now, not since the last message */
124 blockGet[len++] = block_rq_wr_key;
125 blockGet[len++] = value;
128 if (block_rq_rd_enabled && (value = atomic_read(&blockCnt[BLOCK_RQ_RD])) > 0) {
129 atomic_sub(value, &blockCnt[BLOCK_RQ_RD]);
130 blockGet[len++] = block_rq_rd_key;
131 /* Indicates to Streamline that value bytes were read now, not since the last message */
133 blockGet[len++] = block_rq_rd_key;
134 blockGet[len++] = value;
144 static struct gator_interface gator_events_block_interface = {
145 .create_files = gator_events_block_create_files,
146 .start = gator_events_block_start,
147 .stop = gator_events_block_stop,
148 .read = gator_events_block_read,
151 int gator_events_block_init(void)
153 block_rq_wr_enabled = 0;
154 block_rq_rd_enabled = 0;
156 block_rq_wr_key = gator_events_get_key();
157 block_rq_rd_key = gator_events_get_key();
159 return gator_events_install(&gator_events_block_interface);