From 77b769e7d4a80f62a45e141602c3307aa9b6b16a Mon Sep 17 00:00:00 2001 From: Ed Nash Date: Sat, 27 Jul 2013 20:48:42 -0400 Subject: add debugfs statistics and some code cleanup --- arch/arm/mach-mvf/mvf_sema4.c | 58 +++++++++++++++++++++++++------------------ drivers/i2c/busses/i2c-imx.c | 2 +- include/linux/mvf_sema4.h | 12 +++++++++ 3 files changed, 47 insertions(+), 25 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 //#endif +#include + #include // ************************************ 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; igate_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; } diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 853e0688998e..8cc086247245 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -441,7 +441,7 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter, // since this can get called before probe, assign happens here if(!sema4) { - result = mvf_sema4_assign(3, true, &sema4); + result = mvf_sema4_assign(MCC_I2C_SEMAPHORE_NUMBER, true, &sema4); if(result) { printk(KERN_ERR "can't assign sema4 %s %s exiting.\n",__FILE__,__func__); return result; diff --git a/include/linux/mvf_sema4.h b/include/linux/mvf_sema4.h index 898065afb23f..7a93551e4905 100644 --- a/include/linux/mvf_sema4.h +++ b/include/linux/mvf_sema4.h @@ -1,10 +1,22 @@ #ifndef __MVF_SEMA4__ #define __MVF_SEMA4__ +#include + +#define MVF_SHMEM_SEMAPHORE_NUMBER (1) +#define MVF_PRINTF_SEMAPHORE_NUMBER (2) +#define MVF_I2C_SEMAPHORE_NUMBER (3) +#define MVF_RESERVED1_SEMAPHORE_NUMBER (4) +#define MVF_RESERVED2_SEMAPHORE_NUMBER (5) + typedef struct mvf_sema4_handle_struct { int gate_num; int use_interrupts; wait_queue_head_t wait_queue; + // stats + unsigned long attempts; + unsigned long interrupts; + struct dentry *debugfs_file; } MVF_SEMA4; int mvf_sema4_assign(int gate_num, bool use_interrupts, MVF_SEMA4** sema4_p); -- cgit v1.2.3