diff options
author | Ed Nash <enash54@gmail.com> | 2013-07-29 09:08:22 -0400 |
---|---|---|
committer | roshni.shah <roshni.shah@timesys.com> | 2014-01-04 19:33:23 -0500 |
commit | 4dfc1fad0f184cfe1e81ef2405c908db5ccaaaf3 (patch) | |
tree | 607212cb56e66a3975f039f69402cfc0a0994592 | |
parent | c0916ea641fee1f5df29ff203b595a0bc976daf4 (diff) |
add latency stats and make debugfs writeable
-rw-r--r-- | arch/arm/mach-mvf/mvf_sema4.c | 43 | ||||
-rw-r--r-- | include/linux/mvf_sema4.h | 5 |
2 files changed, 40 insertions, 8 deletions
diff --git a/arch/arm/mach-mvf/mvf_sema4.c b/arch/arm/mach-mvf/mvf_sema4.c index 2176c628c166..aa354c33de4d 100644 --- a/arch/arm/mach-mvf/mvf_sema4.c +++ b/arch/arm/mach-mvf/mvf_sema4.c @@ -155,8 +155,11 @@ int mvf_sema4_assign(int gate_num, bool use_interrupts, MVF_SEMA4** sema4_p) // debugfs sprintf(debugfs_gatedir_name, "%d", gate_num); debugfs_gate_dir = debugfs_create_dir(debugfs_gatedir_name, debugfs_dir); - debugfs_create_u32("attempts", 0444, debugfs_gate_dir, &(*sema4_p)->attempts); - debugfs_create_u32("interrupts", 0444, debugfs_gate_dir, &(*sema4_p)->interrupts); + debugfs_create_u32("attempts", S_IRUGO | S_IWUGO, debugfs_gate_dir, &(*sema4_p)->attempts); + debugfs_create_u32("interrupts", S_IRUGO | S_IWUGO, debugfs_gate_dir, &(*sema4_p)->interrupts); + debugfs_create_u32("failures", S_IRUGO | S_IWUGO, debugfs_gate_dir, &(*sema4_p)->failures); + debugfs_create_u64("total_latency_us", S_IRUGO | S_IWUGO, debugfs_gate_dir, &(*sema4_p)->total_latency_us); + debugfs_create_u32("worst_latency_us", S_IRUGO | S_IWUGO, debugfs_gate_dir, &(*sema4_p)->worst_latency_us); return 0; } @@ -188,6 +191,20 @@ int mvf_sema4_deassign(MVF_SEMA4 *sema4) } EXPORT_SYMBOL(mvf_sema4_deassign); +static void add_latency_stat(MVF_SEMA4 *sema4) { + + struct timeval now; + long latency; + + do_gettimeofday(&now); + + latency = (now.tv_sec * 1000000) + now.tv_usec; + latency -= (sema4->request_time.tv_sec * 1000000) + sema4->request_time.tv_usec; + + sema4->total_latency_us += latency; + sema4->worst_latency_us = sema4->worst_latency_us < latency ? latency : sema4->worst_latency_us; +} + int mvf_sema4_lock(MVF_SEMA4 *sema4, unsigned int timeout_us) { int retval; @@ -203,21 +220,28 @@ int mvf_sema4_lock(MVF_SEMA4 *sema4, unsigned int timeout_us) // bump stats gates[gate_num]->attempts++; + do_gettimeofday(&gates[gate_num]->request_time); // try to grab it writeb(LOCK_VALUE, MVF_IO_ADDRESS(MVF_SEMA4_BASE_ADDR) + gate_num); - if(readb(MVF_IO_ADDRESS(MVF_SEMA4_BASE_ADDR) + gate_num) == LOCK_VALUE) + if(readb(MVF_IO_ADDRESS(MVF_SEMA4_BASE_ADDR) + gate_num) == LOCK_VALUE) { + add_latency_stat(gates[gate_num]); return 0; + } // no timeout, fail - if(!timeout_us) + if(!timeout_us) { + gates[gate_num]->failures++; return -EBUSY; + } // wait forever? if(timeout_us == 0xffffffff) { - if(wait_event_interruptible(sema4->wait_queue, (readb(MVF_IO_ADDRESS(MVF_SEMA4_BASE_ADDR) + gate_num) == LOCK_VALUE))) + if(wait_event_interruptible(sema4->wait_queue, (readb(MVF_IO_ADDRESS(MVF_SEMA4_BASE_ADDR) + gate_num) == LOCK_VALUE))) { + gates[gate_num]->failures++; return -ERESTARTSYS; + } } else { @@ -225,12 +249,17 @@ int mvf_sema4_lock(MVF_SEMA4 *sema4, unsigned int timeout_us) retval = wait_event_interruptible_timeout(sema4->wait_queue, (readb(MVF_IO_ADDRESS(MVF_SEMA4_BASE_ADDR) + gate_num) == LOCK_VALUE), usecs_to_jiffies(timeout_us)); - if(retval == 0) + if(retval == 0) { + gates[gate_num]->failures++; return -ETIME; - else if(retval < 0) + } + else if(retval < 0) { + gates[gate_num]->failures++; return retval; + } } + add_latency_stat(gates[gate_num]); return 0; } EXPORT_SYMBOL(mvf_sema4_lock); diff --git a/include/linux/mvf_sema4.h b/include/linux/mvf_sema4.h index 3f6e4f5d97bb..7b25996f9417 100644 --- a/include/linux/mvf_sema4.h +++ b/include/linux/mvf_sema4.h @@ -16,7 +16,10 @@ typedef struct mvf_sema4_handle_struct { // stats u32 attempts; u32 interrupts; - struct dentry *debugfs_file; + u32 failures; + struct timeval request_time; + u64 total_latency_us; + u32 worst_latency_us; } MVF_SEMA4; int mvf_sema4_assign(int gate_num, bool use_interrupts, MVF_SEMA4** sema4_p); |