histogram: add helper function to expose histograms to userspace
Subsystems (2)
PATCH v2 2/7 histogram: add helper function to expose histograms to userspace
This change introduces the histogram_print_buckets_rcu(). This API is used for implementing e.g. procfs or sysfs files exposing histograms. print_buckets can be combined with e.g. seq_file to provide a read interface for such a file.
This is a squashed, refactored, and modified version of a previously-internal implementation. Thanks to the following individuals for portions of the implementation:
Junaid Shahid <[email protected]> - Original implementation Yu Zhao <[email protected]> - Simplification
Signed-off-by Axel Rasmussen <[email protected]>
--- include/linux/histogram.h | 23 ++++++++++++++++ lib/histogram.c | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+)
include/linux/histogram.h +23 -0
@@ -65,6 +65,12 @@* histogram_destroy_rcu(&hrcu); */ +/* +* Max number of digits in decimal needed to represent U64_MAX threshold, +* plus one space. +*/ +#define HISTO_MAX_CHARS_PER_THRESHOLD (20 + 1) +struct histogram {struct rcu_head rcu;u64 __percpu *buckets;
@@ -189,6 +195,23 @@ static inline void histogram_record_rcu(struct histogram_rcu *hrcu, u64 val,ssize_t histogram_read_rcu (const struct histogram_rcu *hrcu,u64 *buckets,u64 *thresholds,size_t nr_thresholds); +/** +* histogram_print_buckets_rcu() - helper function to print histogram buckets +* @hrcu: histogram +* @buffer: output buffer to fill +* @len: length of the output buffer +* +* Reads buckets by calling histogram_read_rcu(), then fills the output buffer. +* +* Context: Performs allocation with GFP_ATOMIC. +* +* Returns: The number of characters written to @buffer, or a negative error +* code on failure. If the buffer isn't large enough to contain the output, +* -EINVAL is returned. +*/ +int histogram_print_buckets_rcu (struct histogram_rcu *hrcu,char *buffer, +int len); +/** * histogram_set_thresholds_rcu() - set RCU-protected histogram thresholds * @hrcu: histogram
lib/histogram.c +55 -0
67 lines not on this page · raw message
Signature · 1 line
2.27.0.rc0.183.gde8f92d652-goog