1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#include <linux/module.h>
41#include "../include/lprocfs_status.h"
42#include "../include/obd_support.h"
43
44void lprocfs_counter_add(struct lprocfs_stats *stats, int idx, long amount)
45{
46 struct lprocfs_counter *percpu_cntr;
47 struct lprocfs_counter_header *header;
48 int smp_id;
49 unsigned long flags = 0;
50
51 if (!stats)
52 return;
53
54 LASSERTF(0 <= idx && idx < stats->ls_num,
55 "idx %d, ls_num %hu\n", idx, stats->ls_num);
56
57
58
59
60 smp_id = lprocfs_stats_lock(stats, LPROCFS_GET_SMP_ID, &flags);
61 if (smp_id < 0)
62 return;
63
64 header = &stats->ls_cnt_header[idx];
65 percpu_cntr = lprocfs_stats_counter_get(stats, smp_id, idx);
66 percpu_cntr->lc_count++;
67
68 if (header->lc_config & LPROCFS_CNTR_AVGMINMAX) {
69
70
71
72
73
74
75
76 if (in_interrupt() &&
77 (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
78 percpu_cntr->lc_sum_irq += amount;
79 else
80 percpu_cntr->lc_sum += amount;
81
82 if (header->lc_config & LPROCFS_CNTR_STDDEV)
83 percpu_cntr->lc_sumsquare += (__s64)amount * amount;
84 if (amount < percpu_cntr->lc_min)
85 percpu_cntr->lc_min = amount;
86 if (amount > percpu_cntr->lc_max)
87 percpu_cntr->lc_max = amount;
88 }
89 lprocfs_stats_unlock(stats, LPROCFS_GET_SMP_ID, &flags);
90}
91EXPORT_SYMBOL(lprocfs_counter_add);
92
93void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx, long amount)
94{
95 struct lprocfs_counter *percpu_cntr;
96 struct lprocfs_counter_header *header;
97 int smp_id;
98 unsigned long flags = 0;
99
100 if (!stats)
101 return;
102
103 LASSERTF(0 <= idx && idx < stats->ls_num,
104 "idx %d, ls_num %hu\n", idx, stats->ls_num);
105
106
107
108
109 smp_id = lprocfs_stats_lock(stats, LPROCFS_GET_SMP_ID, &flags);
110 if (smp_id < 0)
111 return;
112
113 header = &stats->ls_cnt_header[idx];
114 percpu_cntr = lprocfs_stats_counter_get(stats, smp_id, idx);
115 if (header->lc_config & LPROCFS_CNTR_AVGMINMAX) {
116
117
118
119
120
121
122
123
124 if (in_interrupt() &&
125 (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
126 percpu_cntr->lc_sum_irq -= amount;
127 else
128 percpu_cntr->lc_sum -= amount;
129 }
130 lprocfs_stats_unlock(stats, LPROCFS_GET_SMP_ID, &flags);
131}
132EXPORT_SYMBOL(lprocfs_counter_sub);
133