1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5 * Author: Zach Brown <zab@zabbo.net>
6 * Author: Peter J. Braam <braam@clusterfs.com>
7 * Author: Phil Schwan <phil@clusterfs.com>
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 # define EXPORT_SYMTAB
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/kernel.h>
33 #include <linux/string.h>
34 #include <linux/stat.h>
35 #include <linux/errno.h>
36 #include <linux/smp_lock.h>
37 #include <linux/unistd.h>
39 #include <linux/uio.h>
41 #include <asm/system.h>
42 #include <asm/uaccess.h>
45 #include <linux/file.h>
46 #include <linux/stat.h>
47 #include <linux/list.h>
48 #include <asm/uaccess.h>
49 #include <asm/segment.h>
51 #include <linux/proc_fs.h>
52 #include <linux/sysctl.h>
54 # define DEBUG_SUBSYSTEM S_PORTALS
56 #include <linux/kp30.h>
57 #include <asm/div64.h>
59 static struct ctl_table_header *portals_table_header = NULL;
60 extern char debug_file_path[1024];
61 extern char debug_daemon_file_path[1024];
62 extern char portals_upcall[1024];
64 #define PSDEV_PORTALS (0x100)
66 PSDEV_DEBUG = 1, /* control debugging */
67 PSDEV_SUBSYSTEM_DEBUG, /* control debugging */
68 PSDEV_PRINTK, /* force all errors to console */
69 PSDEV_CONSOLE, /* allow _any_ messages to console */
70 PSDEV_DEBUG_PATH, /* crashdump log location */
71 PSDEV_DEBUG_DUMP_PATH, /* crashdump tracelog location */
72 PSDEV_PORTALS_UPCALL, /* User mode upcall script */
73 PSDEV_PORTALS_MEMUSED, /* bytes currently PORTAL_ALLOCated */
76 static struct ctl_table portals_table[] = {
77 {PSDEV_DEBUG, "debug", &portal_debug, sizeof(int), 0644, NULL,
79 {PSDEV_SUBSYSTEM_DEBUG, "subsystem_debug", &portal_subsystem_debug,
80 sizeof(int), 0644, NULL, &proc_dointvec},
81 {PSDEV_PRINTK, "printk", &portal_printk, sizeof(int), 0644, NULL,
83 {PSDEV_CONSOLE, "console", &portal_cerror, sizeof(int), 0644, NULL,
85 {PSDEV_DEBUG_PATH, "debug_path", debug_file_path,
86 sizeof(debug_file_path), 0644, NULL, &proc_dostring, &sysctl_string},
87 {PSDEV_DEBUG_DUMP_PATH, "debug_daemon_path", debug_daemon_file_path,
88 sizeof(debug_daemon_file_path), 0644, NULL, &proc_dostring,
90 {PSDEV_PORTALS_UPCALL, "upcall", portals_upcall,
91 sizeof(portals_upcall), 0644, NULL, &proc_dostring,
93 {PSDEV_PORTALS_MEMUSED, "memused", (int *)&portal_kmemory.counter,
94 sizeof(int), 0644, NULL, &proc_dointvec},
98 static struct ctl_table top_table[2] = {
99 {PSDEV_PORTALS, "portals", NULL, 0, 0555, portals_table},
104 #ifdef PORTALS_PROFILING
106 * profiling stuff. we do this statically for now 'cause its simple,
107 * but we could do some tricks with elf sections to have this array
108 * automatically built.
110 #define def_prof(FOO) [PROF__##FOO] = {#FOO, 0, }
112 struct prof_ent prof_ents[] = {
113 def_prof(our_recvmsg),
114 def_prof(our_sendmsg),
115 def_prof(socknal_recv),
117 def_prof(conn_list_walk),
119 def_prof(lib_finalize),
120 def_prof(pingcli_time),
121 def_prof(gmnal_send),
122 def_prof(gmnal_recv),
125 EXPORT_SYMBOL(prof_ents);
128 * this function is as crazy as the proc filling api
131 * buffer: page allocated for us to scribble in. the
132 * data returned to the user will be taken from here.
133 * *start: address of the pointer that will tell the
134 * caller where in buffer the data the user wants is.
135 * ppos: offset in the entire /proc file that the user
137 * wanted: the amount of data the user wants.
139 * while going, 'curpos' is the offset in the entire
140 * file where we currently are. We only actually
141 * start filling buffer when we get to a place in
142 * the file that the user cares about.
144 * we take care to only sprintf when the user cares because
145 * we're holding a lock while we do this.
147 * we're smart and know that we generate fixed size lines.
148 * we only start writing to the buffer when the user cares.
149 * This is unpredictable because we don't snapshot the
150 * list between calls that are filling in a file from
151 * the list. The list could change mid read and the
152 * output will look very weird indeed. oh well.
155 static int prof_read_proc(char *buffer, char **start, off_t ppos, int wanted,
156 int *eof, void *data)
160 char *header = "Interval Cycles_per (Starts Finishes Total)\n";
161 int header_len = strlen(header);
162 char *format = "%-15s %.12Ld (%.12d %.12d %.12Ld)";
163 int line_len = (15 + 1 + 12 + 2 + 12 + 1 + 12 + 1 + 12 + 1);
167 if (ppos < header_len) {
168 int diff = MIN(header_len, wanted);
169 memcpy(buffer, header + ppos, diff);
179 for ( i = 0; i < MAX_PROFS ; i++) {
181 struct prof_ent *pe = &prof_ents[i];
182 long long cycles_per;
184 * find the part of the array that the buffer wants
186 if (ppos >= (curpos + line_len)) {
190 /* the clever caller split a line */
192 *start = buffer + (ppos - curpos);
195 if (pe->finishes == 0)
199 cycles_per = pe->total_cycles;
200 do_div (cycles_per, pe->finishes);
203 copied = sprintf(buffer + len, format, pe->str, cycles_per,
204 pe->starts, pe->finishes, pe->total_cycles);
208 /* pad to line len, -1 for \n */
209 if ((copied < line_len-1)) {
210 int diff = (line_len-1) - copied;
211 memset(buffer + len, ' ', diff);
218 /* bail if we have enough */
219 if (((buffer + len) - *start) >= wanted)
230 return MIN(((buffer + len) - *start), wanted);
234 * all kids love /proc :/
236 static unsigned char basedir[]="net/portals";
237 #endif /* PORTALS_PROFILING */
239 int insert_proc(void)
241 #if PORTALS_PROFILING
242 unsigned char dir[128];
243 struct proc_dir_entry *ent;
245 if (ARRAY_SIZE(prof_ents) != MAX_PROFS) {
246 CERROR("profiling enum and array are out of sync.\n");
251 * This is pretty lame. assuming that failure just
252 * means that they already existed.
254 strcat(dir, basedir);
255 create_proc_entry(dir, S_IFDIR, 0);
257 strcat(dir, "/cycles");
258 ent = create_proc_entry(dir, 0, 0);
260 CERROR("couldn't register %s?\n", dir);
265 ent->read_proc = prof_read_proc;
266 #endif /* PORTALS_PROFILING */
269 if (!portals_table_header)
270 portals_table_header = register_sysctl_table(top_table, 0);
276 void remove_proc(void)
278 #if PORTALS_PROFILING
279 unsigned char dir[128];
283 strcat(dir, basedir);
287 strcat(dir, "/cycles");
288 remove_proc_entry(dir,0);
291 remove_proc_entry(dir,0);
292 #endif /* PORTALS_PROFILING */
295 if (portals_table_header)
296 unregister_sysctl_table(portals_table_header);
297 portals_table_header = NULL;