- Relocate 'stats_per' in to proper /proc/sys/spl/mutex/ directory

- Shift to spinlock for mutex list addition and removal



git-svn-id: https://outreach.scidac.gov/svn/spl/trunk@98 7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c
This commit is contained in:
behlendo 2008-05-07 17:58:22 +00:00
parent 4f86a887d8
commit 404992e31a
3 changed files with 67 additions and 34 deletions

View File

@ -44,7 +44,7 @@ extern int mutex_spin_max;
#ifdef DEBUG_MUTEX #ifdef DEBUG_MUTEX
extern int mutex_stats[MUTEX_STATS_SIZE]; extern int mutex_stats[MUTEX_STATS_SIZE];
extern struct rw_semaphore mutex_stats_sem; extern spinlock_t mutex_stats_lock;
extern struct list_head mutex_stats_list; extern struct list_head mutex_stats_list;
#define MUTEX_STAT_INC(stats, stat) ((stats)[stat]++) #define MUTEX_STAT_INC(stats, stat) ((stats)[stat]++)
#else #else

View File

@ -29,7 +29,7 @@ int mutex_spin_max = 100;
#ifdef DEBUG_MUTEX #ifdef DEBUG_MUTEX
int mutex_stats[MUTEX_STATS_SIZE] = { 0 }; int mutex_stats[MUTEX_STATS_SIZE] = { 0 };
struct rw_semaphore mutex_stats_sem; spinlock_t mutex_stats_lock;
struct list_head mutex_stats_list; struct list_head mutex_stats_list;
#endif #endif
@ -88,17 +88,9 @@ __spl_mutex_init(kmutex_t *mp, char *name, int type, void *ibc)
return; return;
} }
/* We may be called when there is a non-zero preempt_count or spin_lock(&mutex_stats_lock);
* interrupts are disabled is which case we must not sleep.
*/
if (flags == KM_SLEEP)
down_write(&mutex_stats_sem);
else
while (!down_write_trylock(&mutex_stats_sem));
list_add_tail(&mp->km_list, &mutex_stats_list); list_add_tail(&mp->km_list, &mutex_stats_list);
spin_unlock(&mutex_stats_lock);
up_write(&mutex_stats_sem);
#endif #endif
} }
EXPORT_SYMBOL(__spl_mutex_init); EXPORT_SYMBOL(__spl_mutex_init);
@ -110,12 +102,9 @@ __spl_mutex_destroy(kmutex_t *mp)
ASSERT(mp->km_magic == KM_MAGIC); ASSERT(mp->km_magic == KM_MAGIC);
#ifdef DEBUG_MUTEX #ifdef DEBUG_MUTEX
/* We may be called when there is a non-zero preempt_count or spin_lock(&mutex_stats_lock);
* interrupts are disabled is which case we must not sleep.
*/
while (!down_write_trylock(&mutex_stats_sem));
list_del_init(&mp->km_list); list_del_init(&mp->km_list);
up_write(&mutex_stats_sem); spin_unlock(&mutex_stats_lock);
kmem_free(mp->km_stats, sizeof(int) * MUTEX_STATS_SIZE); kmem_free(mp->km_stats, sizeof(int) * MUTEX_STATS_SIZE);
#endif #endif
@ -261,7 +250,7 @@ spl_mutex_init(void)
{ {
ENTRY; ENTRY;
#ifdef DEBUG_MUTEX #ifdef DEBUG_MUTEX
init_rwsem(&mutex_stats_sem); spin_lock_init(&mutex_stats_lock);
INIT_LIST_HEAD(&mutex_stats_list); INIT_LIST_HEAD(&mutex_stats_list);
#endif #endif
RETURN(0); RETURN(0);

View File

@ -16,9 +16,20 @@
#define DEBUG_SUBSYSTEM S_PROC #define DEBUG_SUBSYSTEM S_PROC
static struct ctl_table_header *spl_header = NULL; #ifdef DEBUG_KMEM
static unsigned long table_min = 0; static unsigned long table_min = 0;
static unsigned long table_max = ~0; static unsigned long table_max = ~0;
#endif
#ifdef CONFIG_SYSCTL
static struct ctl_table_header *spl_header = NULL;
static struct proc_dir_entry *proc_sys = NULL;
static struct proc_dir_entry *proc_sys_spl = NULL;
#ifdef DEBUG_MUTEX
static struct proc_dir_entry *proc_sys_spl_mutex = NULL;
static struct proc_dir_entry *proc_sys_spl_mutex_stats = NULL;
#endif
#endif
#define CTL_SPL 0x87 #define CTL_SPL 0x87
#define CTL_SPL_DEBUG 0x88 #define CTL_SPL_DEBUG 0x88
@ -426,7 +437,7 @@ mutex_seq_start(struct seq_file *f, loff_t *pos)
loff_t n = *pos; loff_t n = *pos;
ENTRY; ENTRY;
down_read(&mutex_stats_sem); spin_lock(&mutex_stats_lock);
if (!n) if (!n)
mutex_seq_show_headers(f); mutex_seq_show_headers(f);
@ -454,7 +465,7 @@ mutex_seq_next(struct seq_file *f, void *p, loff_t *pos)
static void static void
mutex_seq_stop(struct seq_file *f, void *v) mutex_seq_stop(struct seq_file *f, void *v)
{ {
up_read(&mutex_stats_sem); spin_unlock(&mutex_stats_lock);
} }
static struct seq_operations mutex_seq_ops = { static struct seq_operations mutex_seq_ops = {
@ -719,9 +730,31 @@ static struct ctl_table spl_dir[] = {
{0} {0}
}; };
static int
proc_dir_entry_match(int len, const char *name, struct proc_dir_entry *de)
{
if (de->namelen != len)
return 0;
return !memcmp(name, de->name, len);
}
static struct proc_dir_entry *
proc_dir_entry_find(struct proc_dir_entry *root, const char *str)
{
struct proc_dir_entry *de;
for (de = root->subdir; de; de = de->next)
if (proc_dir_entry_match(strlen(str), str, de))
return de;
return NULL;
}
int int
proc_init(void) proc_init(void)
{ {
int rc = 0;
ENTRY; ENTRY;
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
@ -729,20 +762,31 @@ proc_init(void)
if (spl_header == NULL) if (spl_header == NULL)
RETURN(-EUNATCH); RETURN(-EUNATCH);
proc_sys = proc_dir_entry_find(&proc_root, "sys");
if (proc_sys == NULL)
GOTO(out, rc = -EUNATCH);
proc_sys_spl = proc_dir_entry_find(proc_sys, "spl");
if (proc_sys_spl == NULL)
GOTO(out, rc = -EUNATCH);
#ifdef DEBUG_MUTEX #ifdef DEBUG_MUTEX
{ proc_sys_spl_mutex = proc_dir_entry_find(proc_sys_spl, "mutex");
struct proc_dir_entry *entry = create_proc_entry("mutex_stats", if (proc_sys_spl_mutex == NULL)
0444, NULL); GOTO(out, rc = -EUNATCH);
if (entry) {
entry->proc_fops = &proc_mutex_operations; proc_sys_spl_mutex_stats = create_proc_entry("stats_per", 0444,
} else { proc_sys_spl_mutex);
unregister_sysctl_table(spl_header); if (proc_sys_spl_mutex_stats == NULL)
RETURN(-EUNATCH); GOTO(out, rc = -EUNATCH);
}
} proc_sys_spl_mutex_stats->proc_fops = &proc_mutex_operations;
#endif /* DEBUG_MUTEX */ #endif /* DEBUG_MUTEX */
#endif RETURN(rc);
RETURN(0); out:
unregister_sysctl_table(spl_header);
#endif /* CONFIG_SYSCTL */
RETURN(rc);
} }
void void
@ -752,7 +796,7 @@ proc_fini(void)
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
ASSERT(spl_header != NULL); ASSERT(spl_header != NULL);
remove_proc_entry("mutex_stats", NULL); remove_proc_entry("stats_per", proc_sys_spl_mutex);
unregister_sysctl_table(spl_header); unregister_sysctl_table(spl_header);
#endif #endif
EXIT; EXIT;