Skip to content

Commit ba5e506

Browse files
JasonXingkawasaki
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. Reviewed-by: Yushan Zhou <[email protected]> Reviewed-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Jason Xing <[email protected]>
1 parent 326ba49 commit ba5e506

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

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
@@ -701,6 +701,36 @@ void relay_flush(struct rchan *chan)
701701
}
702702
EXPORT_SYMBOL_GPL(relay_flush);
703703

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

0 commit comments

Comments
 (0)