| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/* |
| 3 |
* Copyright (C) 2025, LG Electronics. |
| 4 |
* Author(s): Hyunchul Lee <[email protected]> |
| 5 |
* Copyright (C) 2025, Samsung Electronics. |
| 6 |
* Author(s): Vedansh Bhardwaj <[email protected]> |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef __KSMBD_STATS_H__ |
| 10 |
#define __KSMBD_STATS_H__ |
| 11 |
|
| 12 |
#define KSMBD_COUNTER_MAX_REQS 19 |
| 13 |
|
| 14 |
enum { |
| 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 |
| 27 |
extern struct ksmbd_counters ksmbd_counters; |
| 28 |
|
| 29 |
struct ksmbd_counters { |
| 30 |
struct percpu_counter counters[KSMBD_COUNTER_MAX]; |
| 31 |
}; |
| 32 |
|
| 33 |
static inline void ksmbd_counter_inc(int type) |
| 34 |
{ |
| 35 |
percpu_counter_inc(&ksmbd_counters.counters[type]); |
| 36 |
} |
| 37 |
|
| 38 |
static inline void ksmbd_counter_dec(int type) |
| 39 |
{ |
| 40 |
percpu_counter_dec(&ksmbd_counters.counters[type]); |
| 41 |
} |
| 42 |
|
| 43 |
static inline void ksmbd_counter_add(int type, s64 value) |
| 44 |
{ |
| 45 |
percpu_counter_add(&ksmbd_counters.counters[type], value); |
| 46 |
} |
| 47 |
|
| 48 |
static inline void ksmbd_counter_sub(int type, s64 value) |
| 49 |
{ |
| 50 |
percpu_counter_sub(&ksmbd_counters.counters[type], value); |
| 51 |
} |
| 52 |
|
| 53 |
static 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 |
|
| 59 |
static inline s64 ksmbd_counter_sum(int type) |
| 60 |
{ |
| 61 |
return percpu_counter_sum_positive(&ksmbd_counters.counters[type]); |
| 62 |
} |
| 63 |
#else |
| 64 |
|
| 65 |
static inline void ksmbd_counter_inc(int type) {} |
| 66 |
static inline void ksmbd_counter_dec(int type) {} |
| 67 |
static inline void ksmbd_counter_add(int type, s64 value) {} |
| 68 |
static inline void ksmbd_counter_sub(int type, s64 value) {} |
| 69 |
static inline void ksmbd_counter_inc_reqs(unsigned int cmd) {} |
| 70 |
static inline s64 ksmbd_counter_sum(int type) { return 0; } |
| 71 |
#endif |
| 72 |
|
| 73 |
#endif |