Skip to content

Commit

Permalink
btrfs: Use trace condition for get_extent tracepoint
Browse files Browse the repository at this point in the history
Doing an if statement to test some condition to know if we should
trigger a tracepoint is pointless when tracing is disabled. This just
adds overhead and wastes a branch prediction. This is why the
TRACE_EVENT_CONDITION() was created. It places the check inside the jump
label so that the branch does not happen unless tracing is enabled.

That is, instead of doing:

	if (em)
		trace_btrfs_get_extent(root, em);

Which is basically this:

	if (em)
		if (static_key(trace_btrfs_get_extent)) {

Using a TRACE_EVENT_CONDITION() we can just do:

	trace_btrfs_get_extent(root, em);

And the condition trace event will do:

	if (static_key(trace_btrfs_get_extent)) {
		if (em) {
			...

The static key is a non conditional jump (or nop) that is faster than
having to check if em is NULL or not.

Signed-off-by: Steven Rostedt <[email protected]>
Signed-off-by: Josef Bacik <[email protected]>
Signed-off-by: Chris Mason <[email protected]>
  • Loading branch information
rostedt authored and Chris Mason committed Nov 21, 2013
1 parent 52a1575 commit 4cd8587
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -6187,8 +6187,7 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
write_unlock(&em_tree->lock);
out:

if (em)
trace_btrfs_get_extent(root, em);
trace_btrfs_get_extent(root, em);

if (path)
btrfs_free_path(path);
Expand Down
4 changes: 3 additions & 1 deletion include/trace/events/btrfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ DEFINE_EVENT(btrfs__inode, btrfs_inode_evict,
{ EXTENT_FLAG_LOGGING, "LOGGING" }, \
{ EXTENT_FLAG_FILLING, "FILLING" })

TRACE_EVENT(btrfs_get_extent,
TRACE_EVENT_CONDITION(btrfs_get_extent,

TP_PROTO(struct btrfs_root *root, struct extent_map *map),

TP_ARGS(root, map),

TP_CONDITION(map),

TP_STRUCT__entry(
__field( u64, root_objectid )
__field( u64, start )
Expand Down

0 comments on commit 4cd8587

Please sign in to comment.