Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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/20250612061201.34272-4-kerneljasonxing@gmail.com
Signed-off-by: Jason Xing <kernelxing@tencent.com>
Reviewed-by: Yushan Zhou <katrinzhou@tencent.com>
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Jason Xing and committed by
Andrew Morton
a53202ce ca01a90a

+37
+7
include/linux/relay.h
··· 31 31 /* 32 32 * Relay buffer statistics 33 33 */ 34 + enum { 35 + RELAY_STATS_BUF_FULL = (1 << 0), 36 + 37 + RELAY_STATS_LAST = RELAY_STATS_BUF_FULL, 38 + }; 39 + 34 40 struct rchan_buf_stats 35 41 { 36 42 unsigned int full_count; /* counter for buffer full */ ··· 173 167 void *private_data); 174 168 extern void relay_close(struct rchan *chan); 175 169 extern void relay_flush(struct rchan *chan); 170 + size_t relay_stats(struct rchan *chan, int flags); 176 171 extern void relay_subbufs_consumed(struct rchan *chan, 177 172 unsigned int cpu, 178 173 size_t consumed);
+30
kernel/relay.c
··· 701 701 EXPORT_SYMBOL_GPL(relay_flush); 702 702 703 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 + 733 + /** 704 734 * relay_file_open - open file op for relay files 705 735 * @inode: the inode 706 736 * @filp: the file