Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at master 73 lines 1.9 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-or-later */ 2/* 3 * Copyright (C) 2025, LG Electronics. 4 * Author(s): Hyunchul Lee <hyc.lee@gmail.com> 5 * Copyright (C) 2025, Samsung Electronics. 6 * Author(s): Vedansh Bhardwaj <v.bhardwaj@samsung.com> 7 */ 8 9#ifndef __KSMBD_STATS_H__ 10#define __KSMBD_STATS_H__ 11 12#define KSMBD_COUNTER_MAX_REQS 19 13 14enum { 15 KSMBD_COUNTER_SESSIONS = 0, 16 KSMBD_COUNTER_TREE_CONNS, 17 KSMBD_COUNTER_REQUESTS, 18 KSMBD_COUNTER_READ_BYTES, 19 KSMBD_COUNTER_WRITE_BYTES, 20 KSMBD_COUNTER_FIRST_REQ, 21 KSMBD_COUNTER_LAST_REQ = KSMBD_COUNTER_FIRST_REQ + 22 KSMBD_COUNTER_MAX_REQS - 1, 23 KSMBD_COUNTER_MAX, 24}; 25 26#ifdef CONFIG_PROC_FS 27extern struct ksmbd_counters ksmbd_counters; 28 29struct ksmbd_counters { 30 struct percpu_counter counters[KSMBD_COUNTER_MAX]; 31}; 32 33static inline void ksmbd_counter_inc(int type) 34{ 35 percpu_counter_inc(&ksmbd_counters.counters[type]); 36} 37 38static inline void ksmbd_counter_dec(int type) 39{ 40 percpu_counter_dec(&ksmbd_counters.counters[type]); 41} 42 43static inline void ksmbd_counter_add(int type, s64 value) 44{ 45 percpu_counter_add(&ksmbd_counters.counters[type], value); 46} 47 48static inline void ksmbd_counter_sub(int type, s64 value) 49{ 50 percpu_counter_sub(&ksmbd_counters.counters[type], value); 51} 52 53static inline void ksmbd_counter_inc_reqs(unsigned int cmd) 54{ 55 if (cmd < KSMBD_COUNTER_MAX_REQS) 56 percpu_counter_inc(&ksmbd_counters.counters[KSMBD_COUNTER_FIRST_REQ + cmd]); 57} 58 59static inline s64 ksmbd_counter_sum(int type) 60{ 61 return percpu_counter_sum_positive(&ksmbd_counters.counters[type]); 62} 63#else 64 65static inline void ksmbd_counter_inc(int type) {} 66static inline void ksmbd_counter_dec(int type) {} 67static inline void ksmbd_counter_add(int type, s64 value) {} 68static inline void ksmbd_counter_sub(int type, s64 value) {} 69static inline void ksmbd_counter_inc_reqs(unsigned int cmd) {} 70static inline s64 ksmbd_counter_sum(int type) { return 0; } 71#endif 72 73#endif