diff options
author | Ed Nash <enash54@gmail.com> | 2013-07-27 20:48:42 -0400 |
---|---|---|
committer | roshni.shah <roshni.shah@timesys.com> | 2014-01-04 19:33:22 -0500 |
commit | a62c3fe5e5d0836d963165fbaf2d3930f421beec (patch) | |
tree | b31e01dcecf291b4a997601e48df6b249c67e495 /arch | |
parent | 209802ceb34b37c59a7ee1f824f04f460d13f5d4 (diff) |
add debugfs statistics and some code cleanup
Diffstat (limited to 'arch')
-rw-r--r-- | arch/arm/mach-mvf/mvf_sema4.c | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/arch/arm/mach-mvf/mvf_sema4.c b/arch/arm/mach-mvf/mvf_sema4.c index 311b56a69d73..00c3cb664d79 100644 --- a/arch/arm/mach-mvf/mvf_sema4.c +++ b/arch/arm/mach-mvf/mvf_sema4.c @@ -35,6 +35,8 @@ #include <linux/time.h> //#endif +#include <linux/debugfs.h> + #include <linux/mvf_sema4.h> // ************************************ Local Data ************************************************* @@ -46,6 +48,9 @@ static bool initialized = false; // account for the way the bits are set / returned in CP0INE and CP0NTF static const int idx[16] = {3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12}; +// debugfs +#define DEBUGFS_DIR "mvf_sema4" +static struct dentry *debugfs_dir; // ************************************ Interrupt handler ************************************************* @@ -66,9 +71,12 @@ static irqreturn_t sema4_irq_handler(int irq, void *dev_id) // make sure there's a gate assigned if(gates[gate_num]) { - if(gates[gate_num]->use_interrupts) + if(gates[gate_num]->use_interrupts) { // wake up whoever was aiting wake_up_interruptible(&(gates[gate_num]->wait_queue)); + // bump stats + gates[gate_num]->interrupts++; + } } } } @@ -78,19 +86,6 @@ static irqreturn_t sema4_irq_handler(int irq, void *dev_id) // ************************************ Utility functions ************************************************* -static int find_sema4(MVF_SEMA4 *sema4) -{ - int i; - - for(i=0; i<NUM_GATES; i++) - { - if(gates[i] == sema4) - return i; - } - - return -EINVAL; -} - static int initialize(void) { int i; @@ -109,6 +104,9 @@ static int initialize(void) return -EIO; } + // debugfs + debugfs_dir = debugfs_create_dir(DEBUGFS_DIR, NULL); + initialized = true; return 0; } @@ -118,6 +116,7 @@ int mvf_sema4_assign(int gate_num, bool use_interrupts, MVF_SEMA4** sema4_p) int retval; u32 cp0ine; unsigned long irq_flags; + char debugfs_gatedir[4]; // take the opportunity to initialize the whole sub-system if(!initialized) @@ -136,6 +135,7 @@ int mvf_sema4_assign(int gate_num, bool use_interrupts, MVF_SEMA4** sema4_p) *sema4_p = (MVF_SEMA4 *)kmalloc(sizeof(MVF_SEMA4), GFP_KERNEL); if(*sema4_p == NULL) return -ENOMEM; + memset(*sema4_p, 0, sizeof(MVF_SEMA4)); gates[gate_num] = *sema4_p; (*sema4_p)->gate_num = gate_num; @@ -151,6 +151,12 @@ int mvf_sema4_assign(int gate_num, bool use_interrupts, MVF_SEMA4** sema4_p) local_irq_restore(irq_flags); } + // debugfs + sprintf(debugfs_gatedir, "%d", gate_num); + debugfs_dir = debugfs_create_dir(debugfs_gatedir, debugfs_dir); + debugfs_create_u32("attempts", 0444, debugfs_dir, &(*sema4_p)->attempts); + debugfs_create_u32("interrupts", 0444, debugfs_dir, &(*sema4_p)->interrupts); + return 0; } @@ -159,9 +165,10 @@ int mvf_sema4_deassign(MVF_SEMA4 *sema4) u32 cp0ine; unsigned long irq_flags; - int gate_num = find_sema4(sema4); - if(gate_num < 0) - return gate_num; + int gate_num; + if(!sema4) + return -EINVAL; + gate_num = sema4->gate_num; if(sema4->use_interrupts) { @@ -181,15 +188,19 @@ int mvf_sema4_deassign(MVF_SEMA4 *sema4) int mvf_sema4_lock(MVF_SEMA4 *sema4, unsigned int timeout_us) { int retval; - int gate_num = find_sema4(sema4); - if(gate_num < 0) - return gate_num; + int gate_num; + if(!sema4) + return -EINVAL; + gate_num = sema4->gate_num; // cant use timeouts if not using interruppts // TODO use spin lock if not using interrupts if((!sema4->use_interrupts) && timeout_us) return -EINVAL; + // bump stats + gates[gate_num]->attempts++; + // 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) @@ -222,12 +233,11 @@ int mvf_sema4_lock(MVF_SEMA4 *sema4, unsigned int timeout_us) int mvf_sema4_unlock(MVF_SEMA4 *sema4) { - int gate_num = find_sema4(sema4); - if(gate_num < 0) - return gate_num; + if(!sema4) + return -EINVAL; // unlock it - writeb(0, MVF_IO_ADDRESS(MVF_SEMA4_BASE_ADDR) + gate_num); + writeb(0, MVF_IO_ADDRESS(MVF_SEMA4_BASE_ADDR) + sema4->gate_num); return 0; } |