Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[fs/lustre-release.git] / lustre / ptlrpc / lproc_ptlrpc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22 #define DEBUG_SUBSYSTEM S_CLASS
23
24 #include <linux/obd_support.h>
25 #include <linux/obd.h>
26 #include <linux/lprocfs_status.h>
27 #include <linux/lustre_idl.h>
28 #include <linux/lustre_net.h>
29 #include "ptlrpc_internal.h"
30
31
32 struct ll_rpc_opcode { 
33      __u32       opcode;
34      const char *opname;
35 } ll_rpc_opcode_table[LUSTRE_MAX_OPCODES] = {
36         { OST_REPLY,        "ost_reply" },
37         { OST_GETATTR,      "ost_getattr" },
38         { OST_SETATTR,      "ost_setattr" },
39         { OST_READ,         "ost_read" },
40         { OST_WRITE,        "ost_write" },
41         { OST_CREATE ,      "ost_create" },
42         { OST_DESTROY,      "ost_destroy" },
43         { OST_GET_INFO,     "ost_get_info" },
44         { OST_CONNECT,      "ost_connect" },
45         { OST_DISCONNECT,   "ost_disconnect" },
46         { OST_PUNCH,        "ost_punch" },
47         { OST_OPEN,         "ost_open" },
48         { OST_CLOSE,        "ost_close" },
49         { OST_STATFS,       "ost_statfs" },
50         { OST_SAN_READ,     "ost_san_read" },
51         { OST_SAN_WRITE,    "ost_san_write" },
52         { OST_SYNCFS,       "ost_syncfs" },
53         { MDS_GETATTR,      "mds_getattr" },
54         { MDS_GETATTR_NAME, "mds_getattr_name" },
55         { MDS_CLOSE,        "mds_close" },
56         { MDS_REINT,        "mds_reint" },
57         { MDS_READPAGE,     "mds_readpage" },
58         { MDS_CONNECT,      "mds_connect" },
59         { MDS_DISCONNECT,   "mds_disconnect" },
60         { MDS_GETSTATUS,    "mds_getstatus" },
61         { MDS_STATFS,       "mds_statfs" },
62         { MDS_GETLOVINFO,   "mds_getlovinfo" },
63         { LDLM_ENQUEUE,     "ldlm_enqueue" },
64         { LDLM_CONVERT,     "ldlm_convert" },
65         { LDLM_CANCEL,      "ldlm_cancel" },
66         { LDLM_BL_CALLBACK, "ldlm_bl_callback" },
67         { LDLM_CP_CALLBACK, "ldlm_cp_callback" },
68         { PTLBD_QUERY,      "ptlbd_query" },
69         { PTLBD_READ,       "ptlbd_read" },
70         { PTLBD_WRITE,      "ptlbd_write" },
71         { PTLBD_FLUSH,      "ptlbd_flush" },
72         { OBD_PING,         "obd_ping" }
73 };
74
75 const char* ll_opcode2str(__u32 opcode)
76 {
77         /* When one of the assertions below fail, chances are that:
78          *     1) A new opcode was added in lustre_idl.h, but was
79          *        is missing from the table above.
80          * or  2) The opcode space was renumbered or rearranged, 
81          *        and the opcode_offset() function in 
82          *        ptlrpc_internals.h needs to be modified.
83          */
84         __u32 offset = opcode_offset(opcode);
85         LASSERT(offset < LUSTRE_MAX_OPCODES);
86         LASSERT(ll_rpc_opcode_table[offset].opcode == opcode);
87         return ll_rpc_opcode_table[offset].opname;
88 }
89
90 #ifndef LPROCFS
91 void ptlrpc_lprocfs_register_service(struct obd_device *obddev,
92                                      struct ptlrpc_service *svc) { return ; }
93 void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc) { return; }
94 #else
95
96 void ptlrpc_lprocfs_register_service(struct obd_device *obddev,
97                                      struct ptlrpc_service *svc)
98 {
99         struct proc_dir_entry   *svc_procroot;
100         struct lprocfs_counters *svc_cntrs;
101         int i, rc;
102         unsigned int svc_counter_config = LPROCFS_CNTR_EXTERNALLOCK | 
103                 LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV;
104
105         LASSERT(svc->svc_procroot == NULL);
106         LASSERT(svc->svc_counters == NULL);
107
108         svc_procroot = lprocfs_register(svc->srv_name, obddev->obd_proc_entry,
109                                         NULL, NULL);
110         if (svc_procroot == NULL) 
111                 return;
112         
113         svc_cntrs = 
114                 lprocfs_alloc_counters(PTLRPC_LAST_CNTR+LUSTRE_MAX_OPCODES);
115         if (svc_cntrs == NULL) {
116                 lprocfs_remove(svc_procroot);
117                 return;
118         }
119  
120         LPROCFS_COUNTER_INIT(&svc_cntrs->cntr[PTLRPC_REQWAIT_CNTR], 
121                              svc_counter_config, &svc->srv_lock, 
122                              "req_waittime", "cycles");
123         LPROCFS_COUNTER_INIT(&svc_cntrs->cntr[PTLRPC_SVCEQDEPTH_CNTR], 
124                              svc_counter_config, &svc->srv_lock, 
125                              "svc_eqdepth", "reqs");
126         /* no stddev on idletime */
127         LPROCFS_COUNTER_INIT(&svc_cntrs->cntr[PTLRPC_SVCIDLETIME_CNTR],
128                              (LPROCFS_CNTR_EXTERNALLOCK | LPROCFS_CNTR_AVGMINMAX),
129                              &svc->srv_lock, "svc_idletime", "cycles");
130         for (i=0; i < LUSTRE_MAX_OPCODES; i++) {
131                 __u32 opcode = ll_rpc_opcode_table[i].opcode;
132                 LPROCFS_COUNTER_INIT(&svc_cntrs->cntr[PTLRPC_LAST_CNTR+i], 
133                                      svc_counter_config, &svc->srv_lock,
134                                      ll_opcode2str(opcode), "cycles");
135         }
136         rc = lprocfs_register_counters(svc_procroot, "service_stats", 
137                                        svc_cntrs);
138         if (rc < 0) {
139                 lprocfs_remove(svc_procroot);
140                 lprocfs_free_counters(svc_cntrs);
141         } else {
142                 svc->svc_procroot = svc_procroot;
143                 svc->svc_counters = svc_cntrs;
144         }
145 }
146
147 void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc)
148 {
149         if (svc->svc_procroot) {
150                 lprocfs_remove(svc->svc_procroot);
151                 svc->svc_procroot = NULL;
152         }
153         if (svc->svc_counters) {
154                 lprocfs_free_counters(svc->svc_counters);
155                 svc->svc_counters = NULL;
156         }
157 }
158 #endif /* LPROCFS */