2 * Sysctl operations for Coda filesystem
3 * Original version: (C) 1996 P. Braam and M. Callahan
4 * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University
6 * Carnegie Mellon encourages users to contribute improvements to
7 * the Coda project. Contact Peter Braam (coda@cs.cmu.edu).
9 * CODA operation statistics
10 * (c) March, 1998 Zhanyong Wan <zhanyong.wan@yale.edu>
14 #include <linux/config.h>
15 #include <linux/sched.h>
17 #include <linux/sysctl.h>
18 #include <linux/swapctl.h>
19 #include <linux/proc_fs.h>
20 #include <linux/malloc.h>
21 #include <linux/stat.h>
22 #include <linux/ctype.h>
23 #include <asm/bitops.h>
24 #include <asm/segment.h>
25 #include <asm/uaccess.h>
26 #include <linux/utsname.h>
27 #define __NO_VERSION__
28 #include <linux/module.h>
30 #include <linux/coda.h>
31 #include <linux/coda_linux.h>
32 #include <linux/coda_fs_i.h>
33 #include <linux/coda_psdev.h>
34 #include <linux/coda_cache.h>
35 #include <linux/coda_proc.h>
37 static struct ctl_table_header
*fs_table_header
;
39 #define FS_CODA 1 /* Coda file system */
41 #define CODA_DEBUG 1 /* control debugging */
42 #define CODA_ENTRY 2 /* control enter/leave pattern */
43 #define CODA_TIMEOUT 3 /* timeout on upcalls to become intrble */
44 #define CODA_MC 4 /* use/do not use the access cache */
45 #define CODA_HARD 5 /* mount type "hard" or "soft" */
46 #define CODA_VFS 6 /* vfs statistics */
47 #define CODA_UPCALL 7 /* upcall statistics */
48 #define CODA_PERMISSION 8 /* permission statistics */
49 #define CODA_CACHE_INV 9 /* cache invalidation statistics */
51 static ctl_table coda_table
[] = {
52 {CODA_DEBUG
, "debug", &coda_debug
, sizeof(int), 0644, NULL
, &proc_dointvec
},
53 {CODA_ENTRY
, "printentry", &coda_print_entry
, sizeof(int), 0644, NULL
, &proc_dointvec
},
54 {CODA_MC
, "accesscache", &coda_access_cache
, sizeof(int), 0644, NULL
, &proc_dointvec
},
55 {CODA_TIMEOUT
, "timeout", &coda_timeout
, sizeof(int), 0644, NULL
, &proc_dointvec
},
56 {CODA_HARD
, "hard", &coda_hard
, sizeof(int), 0644, NULL
, &proc_dointvec
},
57 {CODA_VFS
, "vfs_stats", NULL
, 0, 0644, NULL
, &do_reset_coda_vfs_stats
},
58 {CODA_UPCALL
, "upcall_stats", NULL
, 0, 0644, NULL
, &do_reset_coda_upcall_stats
},
59 {CODA_PERMISSION
, "permission_stats", NULL
, 0, 0644, NULL
, &do_reset_coda_permission_stats
},
60 {CODA_CACHE_INV
, "cache_inv_stats", NULL
, 0, 0644, NULL
, &do_reset_coda_cache_inv_stats
},
64 static ctl_table fs_table
[] = {
65 {FS_CODA
, "coda", NULL
, 0, 0555, coda_table
},
69 struct coda_vfs_stats coda_vfs_stat
;
70 struct coda_permission_stats coda_permission_stat
;
71 struct coda_cache_inv_stats coda_cache_inv_stat
;
72 struct coda_upcall_stats_entry coda_upcall_stat
[CODA_NCALLS
];
73 struct coda_upcallstats coda_callstats
;
74 int coda_upcall_timestamping
= 0;
76 /* keep this in sync with coda.h! */
77 char *coda_upcall_names
[] = {
104 "purgeuser ", /* 26 */
108 "purgefid ", /* 30 */
109 "open_by_path", /* 31 */
111 "reintegrate ", /* 33 */
113 "make_cinode " /* 35 */
117 void reset_coda_vfs_stats( void )
119 memset( &coda_vfs_stat
, 0, sizeof( coda_vfs_stat
) );
122 void reset_coda_upcall_stats( void )
124 memset( &coda_upcall_stat
, 0, sizeof( coda_upcall_stat
) );
127 void reset_coda_permission_stats( void )
129 memset( &coda_permission_stat
, 0, sizeof( coda_permission_stat
) );
132 void reset_coda_cache_inv_stats( void )
134 memset( &coda_cache_inv_stat
, 0, sizeof( coda_cache_inv_stat
) );
138 void do_time_stats( struct coda_upcall_stats_entry
* pentry
,
139 unsigned long runtime
)
141 unsigned long time
= runtime
; /* time in us */
142 CDEBUG(D_SPECIAL
, "time: %ld\n", time
);
144 if ( pentry
->count
== 0 ) {
145 pentry
->time_sum
= pentry
->time_squared_sum
= 0;
149 pentry
->time_sum
+= time
;
150 pentry
->time_squared_sum
+= time
*time
;
155 void coda_upcall_stats(int opcode
, long unsigned runtime
)
157 struct coda_upcall_stats_entry
* pentry
;
159 if ( opcode
< 0 || opcode
> CODA_NCALLS
- 1) {
160 printk("Nasty opcode %d passed to coda_upcall_stats\n",
165 pentry
= &coda_upcall_stat
[opcode
];
166 do_time_stats(pentry
, runtime
);
168 /* fill in the totals */
169 pentry
= &coda_upcall_stat
[0];
170 do_time_stats(pentry
, runtime
);
174 unsigned long get_time_average( const struct coda_upcall_stats_entry
* pentry
)
176 return ( pentry
->count
== 0 ) ? 0 : pentry
->time_sum
/ pentry
->count
;
179 static inline unsigned long absolute( unsigned long x
)
181 return x
>= 0 ? x
: -x
;
184 static unsigned long sqr_root( unsigned long x
)
186 unsigned long y
= x
, r
;
203 if ( r
*r
<= x
&& x
< (r
+1)*(r
+1) )
210 unsigned long get_time_std_deviation( const struct coda_upcall_stats_entry
* pentry
)
212 unsigned long time_avg
;
214 if ( pentry
->count
<= 1 )
217 time_avg
= get_time_average( pentry
);
219 return sqr_root( (pentry
->time_squared_sum
/ pentry
->count
) -
220 time_avg
* time_avg
);
223 int do_reset_coda_vfs_stats( ctl_table
* table
, int write
, struct file
* filp
,
224 void * buffer
, size_t * lenp
)
227 reset_coda_vfs_stats();
229 filp
->f_pos
+= *lenp
;
237 int do_reset_coda_upcall_stats( ctl_table
* table
, int write
,
238 struct file
* filp
, void * buffer
,
244 if (get_user(c
, (char *)buffer
))
246 coda_upcall_timestamping
= (c
== '1');
248 reset_coda_upcall_stats();
250 filp
->f_pos
+= *lenp
;
258 int do_reset_coda_permission_stats( ctl_table
* table
, int write
,
259 struct file
* filp
, void * buffer
,
263 reset_coda_permission_stats();
265 filp
->f_pos
+= *lenp
;
273 int do_reset_coda_cache_inv_stats( ctl_table
* table
, int write
,
274 struct file
* filp
, void * buffer
,
278 reset_coda_cache_inv_stats();
280 filp
->f_pos
+= *lenp
;
288 int coda_vfs_stats_get_info( char * buffer
, char ** start
, off_t offset
,
293 struct coda_vfs_stats
* ps
= & coda_vfs_stat
;
295 /* this works as long as we are below 1024 characters! */
296 len
+= sprintf( buffer
,
297 "Coda VFS statistics\n"
298 "===================\n\n"
304 "\treaddir\t\t%9d\n\n"
314 "\tpermission\t%9d\n",
316 /* file operations */
324 /* inode operations */
336 *start
= buffer
+ begin
;
347 int coda_upcall_stats_get_info( char * buffer
, char ** start
, off_t offset
,
358 /* this works as long as we are below 1024 characters! */
360 len
+= sprintf( buffer
,"%-79s\n", "Coda upcall statistics");
362 len
+= sprintf( buffer
+ len
,"%-79s\n", "======================");
364 len
+= sprintf( buffer
+ len
,"%-79s\n", "upcall count avg time(us) std deviation(us)");
366 len
+= sprintf( buffer
+ len
,"%-79s\n", "------ ----- ------------ -----------------");
368 for ( i
= 0 ; i
< CODA_NCALLS
; i
++ ) {
369 tmplen
+= sprintf(tmpbuf
,"%s %9d %10ld %10ld",
370 coda_upcall_names
[i
],
371 coda_upcall_stat
[i
].count
,
372 get_time_average(&coda_upcall_stat
[i
]),
373 coda_upcall_stat
[i
].time_squared_sum
);
377 len
+= sprintf(buffer
+ len
, "%-79s\n", tmpbuf
);
382 begin
= len
- (pos
- offset
);
383 *start
= buffer
+ begin
;
394 int coda_permission_stats_get_info( char * buffer
, char ** start
, off_t offset
,
399 struct coda_permission_stats
* ps
= & coda_permission_stat
;
401 /* this works as long as we are below 1024 characters! */
402 len
+= sprintf( buffer
,
403 "Coda permission statistics\n"
404 "==========================\n\n"
412 *start
= buffer
+ begin
;
423 int coda_cache_inv_stats_get_info( char * buffer
, char ** start
, off_t offset
,
428 struct coda_cache_inv_stats
* ps
= & coda_cache_inv_stat
;
430 /* this works as long as we are below 1024 characters! */
431 len
+= sprintf( buffer
,
432 "Coda cache invalidation statistics\n"
433 "==================================\n\n"
450 *start
= buffer
+ begin
;
462 #ifdef CONFIG_PROC_FS
465 target directory structure:
466 /proc/fs (see linux/fs/proc/root.c)
468 /proc/fs/coda/{vfs_stats,
472 struct proc_dir_entry
* proc_fs_coda
;
476 #define coda_proc_create(name,get_info) \
477 create_proc_info_entry(name, 0, proc_fs_coda, get_info)
479 void coda_sysctl_init()
481 memset(&coda_callstats
, 0, sizeof(coda_callstats
));
482 reset_coda_vfs_stats();
483 reset_coda_upcall_stats();
484 reset_coda_permission_stats();
485 reset_coda_cache_inv_stats();
487 #ifdef CONFIG_PROC_FS
488 proc_fs_coda
= proc_mkdir("coda", proc_root_fs
);
489 proc_fs_coda
->owner
= THIS_MODULE
;
490 coda_proc_create("vfs_stats", coda_vfs_stats_get_info
);
491 coda_proc_create("upcall_stats", coda_upcall_stats_get_info
);
492 coda_proc_create("permission_stats", coda_permission_stats_get_info
);
493 coda_proc_create("cache_inv_stats", coda_cache_inv_stats_get_info
);
497 if ( !fs_table_header
)
498 fs_table_header
= register_sysctl_table(fs_table
, 0);
502 void coda_sysctl_clean()
506 if ( fs_table_header
) {
507 unregister_sysctl_table(fs_table_header
);
513 remove_proc_entry("cache_inv_stats", proc_fs_coda
);
514 remove_proc_entry("permission_stats", proc_fs_coda
);
515 remove_proc_entry("upcall_stats", proc_fs_coda
);
516 remove_proc_entry("vfs_stats", proc_fs_coda
);
517 remove_proc_entry("coda", proc_root_fs
);