summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Nash <enash54@gmail.com>2013-07-27 20:48:42 -0400
committerroshni.shah <roshni.shah@timesys.com>2014-01-04 19:33:22 -0500
commita62c3fe5e5d0836d963165fbaf2d3930f421beec (patch)
treeb31e01dcecf291b4a997601e48df6b249c67e495
parent209802ceb34b37c59a7ee1f824f04f460d13f5d4 (diff)
add debugfs statistics and some code cleanup
-rw-r--r--arch/arm/mach-mvf/mvf_sema4.c58
-rw-r--r--drivers/i2c/busses/i2c-imx.c2
-rw-r--r--include/linux/mvf_sema4.h12
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 <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;
}
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 36bad1eaa428..65525e1c25b3 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -621,7 +621,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
#ifdef CONFIG_ARCH_MVF
// make sure not in use by MQX
- if(mvf_sema4_assign(3, true, &sema4)) {
+ if(mvf_sema4_assign(MCC_I2C_SEMAPHORE_NUMBER, true, &sema4)) {
dev_err(&pdev->dev, "could not grab MQX semaphore\n");
goto fail5;
}
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 <linux/sched.h>
+
+#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);