Skip to content

Commit 2972e30

Browse files
johnkeepingrostedt
authored andcommitted
tracing: Make trace_marker{,_raw} stream-like
The tracing marker files are write-only streams with no meaningful concept of file position. Using stream_open() to mark them as stream-link indicates this and has the added advantage that a single file descriptor can now be used from multiple threads without contention thanks to clearing FMODE_ATOMIC_POS. Note that this has the potential to break existing userspace by since both lseek(2) and pwrite(2) will now return ESPIPE when previously lseek would have updated the stored offset and pwrite would have appended to the trace. A survey of libtracefs and several other projects found to use trace_marker(_raw) [1][2][3] suggests that everyone limits themselves to calling write(2) and close(2) on these file descriptors so there is a good chance this will go unnoticed and the benefits of reduced overhead and lock contention seem worth the risk. [1] https://github.com/google/perfetto [2] https://github.com/intel/media-driver/ [3] https://w1.fi/cgit/hostap/ Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: John Keeping <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent a6ed2ae commit 2972e30

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

kernel/trace/trace.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4841,6 +4841,12 @@ int tracing_open_generic_tr(struct inode *inode, struct file *filp)
48414841
return 0;
48424842
}
48434843

4844+
static int tracing_mark_open(struct inode *inode, struct file *filp)
4845+
{
4846+
stream_open(inode, filp);
4847+
return tracing_open_generic_tr(inode, filp);
4848+
}
4849+
48444850
static int tracing_release(struct inode *inode, struct file *file)
48454851
{
48464852
struct trace_array *tr = inode->i_private;
@@ -7117,9 +7123,6 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
71177123
if (tt)
71187124
event_triggers_post_call(tr->trace_marker_file, tt);
71197125

7120-
if (written > 0)
7121-
*fpos += written;
7122-
71237126
return written;
71247127
}
71257128

@@ -7178,9 +7181,6 @@ tracing_mark_raw_write(struct file *filp, const char __user *ubuf,
71787181

71797182
__buffer_unlock_commit(buffer, event);
71807183

7181-
if (written > 0)
7182-
*fpos += written;
7183-
71847184
return written;
71857185
}
71867186

@@ -7580,16 +7580,14 @@ static const struct file_operations tracing_free_buffer_fops = {
75807580
};
75817581

75827582
static const struct file_operations tracing_mark_fops = {
7583-
.open = tracing_open_generic_tr,
7583+
.open = tracing_mark_open,
75847584
.write = tracing_mark_write,
7585-
.llseek = generic_file_llseek,
75867585
.release = tracing_release_generic_tr,
75877586
};
75887587

75897588
static const struct file_operations tracing_mark_raw_fops = {
7590-
.open = tracing_open_generic_tr,
7589+
.open = tracing_mark_open,
75917590
.write = tracing_mark_raw_write,
7592-
.llseek = generic_file_llseek,
75937591
.release = tracing_release_generic_tr,
75947592
};
75957593

0 commit comments

Comments
 (0)