Skip to content

Commit a53202c

Browse files
JasonXingakpm00
authored andcommitted
relayfs: introduce getting relayfs statistics function
In this version, only support getting the counter for buffer full and implement the framework of how it works. Users can pass certain flag to fetch what field/statistics they expect to know. Each time it only returns one result. So do not pass multiple flags. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Jason Xing <[email protected]> Reviewed-by: Yushan Zhou <[email protected]> Reviewed-by: Masami Hiramatsu (Google) <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Steven Rostedt <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent ca01a90 commit a53202c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

include/linux/relay.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
/*
3232
* Relay buffer statistics
3333
*/
34+
enum {
35+
RELAY_STATS_BUF_FULL = (1 << 0),
36+
37+
RELAY_STATS_LAST = RELAY_STATS_BUF_FULL,
38+
};
39+
3440
struct rchan_buf_stats
3541
{
3642
unsigned int full_count; /* counter for buffer full */
@@ -167,6 +173,7 @@ struct rchan *relay_open(const char *base_filename,
167173
void *private_data);
168174
extern void relay_close(struct rchan *chan);
169175
extern void relay_flush(struct rchan *chan);
176+
size_t relay_stats(struct rchan *chan, int flags);
170177
extern void relay_subbufs_consumed(struct rchan *chan,
171178
unsigned int cpu,
172179
size_t consumed);

kernel/relay.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,36 @@ void relay_flush(struct rchan *chan)
700700
}
701701
EXPORT_SYMBOL_GPL(relay_flush);
702702

703+
/**
704+
* relay_stats - get channel buffer statistics
705+
* @chan: the channel
706+
* @flags: select particular information to get
707+
*
708+
* Returns the count of certain field that caller specifies.
709+
*/
710+
size_t relay_stats(struct rchan *chan, int flags)
711+
{
712+
unsigned int i, count = 0;
713+
struct rchan_buf *rbuf;
714+
715+
if (!chan || flags > RELAY_STATS_LAST)
716+
return 0;
717+
718+
if (chan->is_global) {
719+
rbuf = *per_cpu_ptr(chan->buf, 0);
720+
if (flags & RELAY_STATS_BUF_FULL)
721+
count = rbuf->stats.full_count;
722+
} else {
723+
for_each_online_cpu(i) {
724+
rbuf = *per_cpu_ptr(chan->buf, i);
725+
if (rbuf && flags & RELAY_STATS_BUF_FULL)
726+
count += rbuf->stats.full_count;
727+
}
728+
}
729+
730+
return count;
731+
}
732+
703733
/**
704734
* relay_file_open - open file op for relay files
705735
* @inode: the inode

0 commit comments

Comments
 (0)