1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/lvfs/lvfs_lib.c
38 * Lustre filesystem abstraction routines
40 * Author: Andreas Dilger <adilger@clusterfs.com>
43 #include <linux/module.h>
45 #include <liblustre.h>
47 #include <lustre_lib.h>
48 #include <lprocfs_status.h>
50 unsigned int obd_alloc_fail_rate = 0;
52 int obd_alloc_fail(const void *ptr, const char *name, const char *type,
53 size_t size, const char *file, int line)
56 (cfs_rand() & OBD_ALLOC_FAIL_MASK) < obd_alloc_fail_rate) {
57 CERROR("%s%salloc of %s ("LPU64" bytes) failed at %s:%d\n",
58 ptr ? "force " :"", type, name, (__u64)size, file,
60 CERROR(LPU64" total bytes and "LPU64" total pages "
61 "("LPU64" bytes) allocated by Lustre, "
62 "%d total bytes by LNET\n",
64 obd_pages_sum() << CFS_PAGE_SHIFT,
66 cfs_atomic_read(&libcfs_kmemory));
71 EXPORT_SYMBOL(obd_alloc_fail);
74 void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
77 struct lprocfs_counter *percpu_cntr;
83 /* With per-client stats, statistics are allocated only for
84 * single CPU area, so the smp_id should be 0 always. */
85 smp_id = lprocfs_stats_lock(stats, LPROCFS_GET_SMP_ID);
87 percpu_cntr = &(stats->ls_percpu[smp_id]->lp_cntr[idx]);
88 if (!(stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU))
89 cfs_atomic_inc(&percpu_cntr->lc_cntl.la_entry);
90 percpu_cntr->lc_count++;
92 if (percpu_cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) {
93 /* see comment in lprocfs_counter_sub */
94 LASSERT(!cfs_in_interrupt());
96 percpu_cntr->lc_sum += amount;
97 if (percpu_cntr->lc_config & LPROCFS_CNTR_STDDEV)
98 percpu_cntr->lc_sumsquare += (__s64)amount * amount;
99 if (amount < percpu_cntr->lc_min)
100 percpu_cntr->lc_min = amount;
101 if (amount > percpu_cntr->lc_max)
102 percpu_cntr->lc_max = amount;
104 if (!(stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU))
105 cfs_atomic_inc(&percpu_cntr->lc_cntl.la_exit);
106 lprocfs_stats_unlock(stats, LPROCFS_GET_SMP_ID);
108 EXPORT_SYMBOL(lprocfs_counter_add);
110 void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
113 struct lprocfs_counter *percpu_cntr;
119 /* With per-client stats, statistics are allocated only for
120 * single CPU area, so the smp_id should be 0 always. */
121 smp_id = lprocfs_stats_lock(stats, LPROCFS_GET_SMP_ID);
123 percpu_cntr = &(stats->ls_percpu[smp_id]->lp_cntr[idx]);
124 if (!(stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU))
125 cfs_atomic_inc(&percpu_cntr->lc_cntl.la_entry);
126 if (percpu_cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) {
128 * currently lprocfs_count_add() can only be called in thread
129 * context; sometimes we use RCU callbacks to free memory
130 * which calls lprocfs_counter_sub(), and RCU callbacks may
131 * execute in softirq context - right now that's the only case
132 * we're in softirq context here, use separate counter for that.
135 if (cfs_in_interrupt())
136 percpu_cntr->lc_sum_irq -= amount;
138 percpu_cntr->lc_sum -= amount;
140 if (!(stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU))
141 cfs_atomic_inc(&percpu_cntr->lc_cntl.la_exit);
142 lprocfs_stats_unlock(stats, LPROCFS_GET_SMP_ID);
144 EXPORT_SYMBOL(lprocfs_counter_sub);
147 EXPORT_SYMBOL(obd_alloc_fail_rate);