summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-03-13 22:35:23 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-03-13 22:35:23 +0000
commit4735875000348485d80c093c9af83d3029a21bc6 (patch)
treefd06f80b324ecb232a912057c58e370603a154b3
parent145f2bf35bfc0e1dabae83cb78413483b01ede0b (diff)
downloadnuttx-4735875000348485d80c093c9af83d3029a21bc6.tar.gz
nuttx-4735875000348485d80c093c9af83d3029a21bc6.tar.bz2
nuttx-4735875000348485d80c093c9af83d3029a21bc6.zip
Add debug instrumentation; fix pholder freeing logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1599 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/examples/ostest/main.c4
-rw-r--r--nuttx/examples/ostest/ostest.h20
-rw-r--r--nuttx/examples/ostest/prioinherit.c12
-rw-r--r--nuttx/sched/sem_holder.c75
4 files changed, 110 insertions, 1 deletions
diff --git a/nuttx/examples/ostest/main.c b/nuttx/examples/ostest/main.c
index 9e2ad02c0..261f7974b 100644
--- a/nuttx/examples/ostest/main.c
+++ b/nuttx/examples/ostest/main.c
@@ -155,6 +155,10 @@ static void check_test_memory_usage(void)
#else
memcpy(&g_mmprevious, &g_mmafter, sizeof(struct mallinfo));
#endif
+
+ /* If so enabled, show the use of priority inheritance resources */
+
+ dump_nfreeholders("user_main:");
}
#else
# define check_test_memory_usage()
diff --git a/nuttx/examples/ostest/ostest.h b/nuttx/examples/ostest/ostest.h
index 8c71906c5..1cd705898 100644
--- a/nuttx/examples/ostest/ostest.h
+++ b/nuttx/examples/ostest/ostest.h
@@ -71,6 +71,14 @@
# define CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS 8
#endif
+/* Priority inheritance */
+
+#if defined(CONFIG_DEBUG) && defined(CONFIG_PRIORITY_INHERITANCE) && defined(CONFIG_SEM_PHDEBUG)
+# define dump_nfreeholders(s) printf(s " nfreeholders: %d\n", sem_nfreeholders())
+#else
+# define dump_nfreeholders(s)
+#endif
+
/****************************************************************************
* Public Types
****************************************************************************/
@@ -139,4 +147,16 @@ extern void barrier_test(void);
extern void priority_inheritance(void);
+/* APIs exported (conditionally) by the OS specifically for testing of
+ * priority inheritance
+ */
+
+#if defined(CONFIG_DEBUG) && defined(CONFIG_PRIORITY_INHERITANCE) && defined(CONFIG_SEM_PHDEBUG)
+extern void sem_enumholders(FAR sem_t *sem);
+extern int sem_nfreeholders(void);
+#else
+# define sem_enumholders(sem)
+# define sem_nfreeholders()
+#endif
+
#endif /* __OSTEST_H */
diff --git a/nuttx/examples/ostest/prioinherit.c b/nuttx/examples/ostest/prioinherit.c
index 92238a8c2..7f392b27a 100644
--- a/nuttx/examples/ostest/prioinherit.c
+++ b/nuttx/examples/ostest/prioinherit.c
@@ -269,6 +269,7 @@ static void *lowpri_thread(void *parameter)
printf(" g_highstate[%d]: %d\n", i, (int)g_highstate[i]);
}
printf(" I still have a count on the semaphore\n");
+ sem_enumholders(&g_sem);
fflush(stdout);
sleep(1);
}
@@ -308,6 +309,7 @@ static void *lowpri_thread(void *parameter)
}
ret = pthread_getschedparam(pthread_self(), &policy, &sparam);
+ sem_enumholders(&g_sem);
sem_post(&g_sem);
if (ret != 0)
{
@@ -352,6 +354,7 @@ static void *lowpri_thread(void *parameter)
printf(" ERROR should have been %d\n", g_lowpri);
}
}
+ sem_enumholders(&g_sem);
printf("lowpri_thread-%d: Okay... I'm done!\n", threadno);
fflush(stdout);
@@ -396,6 +399,7 @@ void priority_inheritance(void)
g_medpri = my_pri - 1;
sem_init(&g_sem, 0, NLOWPRI_THREADS);
+ dump_nfreeholders("priority_inheritance:");
/* Start the low priority threads */
@@ -429,6 +433,7 @@ void priority_inheritance(void)
}
printf("priority_inheritance: Waiting...\n");
sleep(2);
+ dump_nfreeholders("priority_inheritance:");
/* Start the medium priority thread */
@@ -458,6 +463,7 @@ void priority_inheritance(void)
}
printf("priority_inheritance: Waiting...\n");
sleep(1);
+ dump_nfreeholders("priority_inheritance:");
/* Start the high priority threads */
@@ -491,6 +497,8 @@ void priority_inheritance(void)
printf("priority_inheritance: pthread_create failed, status=%d\n", status);
}
}
+ dump_nfreeholders("priority_inheritance:");
+ fflush(stdout);
/* Wait for all thread instances to complete */
@@ -499,19 +507,23 @@ void priority_inheritance(void)
printf("priority_inheritance: Waiting for highpri_thread-%d to complete\n", i+1);
fflush(stdout);
(void)pthread_join(highpri[i], &result);
+ dump_nfreeholders("priority_inheritance:");
}
printf("priority_inheritance: Waiting for medpri_thread to complete\n");
fflush(stdout);
(void)pthread_join(medpri, &result);
+ dump_nfreeholders("priority_inheritance:");
for (i = 0; i < NLOWPRI_THREADS; i++)
{
printf("priority_inheritance: Waiting for lowpri_thread-%d to complete\n", i+1);
fflush(stdout);
(void)pthread_join(lowpri[i], &result);
+ dump_nfreeholders("priority_inheritance:");
}
printf("priority_inheritance: Finished\n");
sem_destroy(&g_sem);
+ dump_nfreeholders("priority_inheritance:");
fflush(stdout);
#endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */
}
diff --git a/nuttx/sched/sem_holder.c b/nuttx/sched/sem_holder.c
index 1388965be..74f83837e 100644
--- a/nuttx/sched/sem_holder.c
+++ b/nuttx/sched/sem_holder.c
@@ -251,6 +251,7 @@ static int sem_foreachholder(FAR sem_t *sem, holderhandler_t handler, FAR void *
static int sem_recoverholders(struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg)
{
sem_freeholder(sem, pholder);
+ return 0;
}
/****************************************************************************
@@ -377,6 +378,23 @@ static int sem_verifyholder(struct semholder_s *pholder, FAR sem_t *sem, FAR voi
#endif
/****************************************************************************
+ * Name: sem_dumpholder
+ ****************************************************************************/
+
+#if defined(CONFIG_DEBUG) && defined(CONFIG_SEM_PHDEBUG)
+static int sem_dumpholder(struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg)
+{
+#if CONFIG_SEM_PREALLOCHOLDERS > 0
+ dbg(" %08x: %08x %08x %04x\n",
+ pholder, pholder->flink, pholder->holder, pholder->counts);
+#else
+ dbg(" %08x: %08x %04x\n", pholder, pholder->holder, pholder->counts);
+#endif
+ return 0;
+}
+#endif
+
+/****************************************************************************
* Name: sem_restoreholderprio
****************************************************************************/
@@ -759,7 +777,7 @@ void sem_restorebaseprio(FAR _TCB *stcb, FAR sem_t *sem)
* Description:
* Called from sem_post() after a thread that was waiting for a semaphore
* count was awakened because of a signal and the semaphore wait has been
- * canceld.
+ * canceled.
*
* Parameters:
* sem - A reference to the semaphore no longer being waited for
@@ -784,4 +802,59 @@ void sem_canceled(FAR sem_t *sem)
(void)sem_foreachholder(sem, sem_restoreholderprio, rtcb);
}
+/****************************************************************************
+ * Function: sem_enumholders
+ *
+ * Description:
+ * Show information about threads currently waiting on this semaphore
+ *
+ * Parameters:
+ * sem - A reference to the semaphore
+ *
+ * Return Value:
+ * None
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_DEBUG) && defined(CONFIG_SEM_PHDEBUG)
+void sem_enumholders(FAR sem_t *sem)
+{
+ (void)sem_foreachholder(sem, sem_dumpholder, NULL);
+}
+#endif
+
+/****************************************************************************
+ * Function: sem_nfreeholders
+ *
+ * Description:
+ * Return the number of available holder containers. This is a good way
+ * to find out which threads are not calling sem_destroy.
+ *
+ * Parameters:
+ * sem - A reference to the semaphore
+ *
+ * Return Value:
+ * The number of available holder containers
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_DEBUG) && defined(CONFIG_SEM_PHDEBUG)
+int sem_nfreeholders(void)
+{
+#if CONFIG_SEM_PREALLOCHOLDERS > 0
+ FAR struct semholder_s *pholder;
+ int n;
+
+ for (pholder = g_freeholders, n = 0; pholder; pholder = pholder->flink) n++;
+ return n;
+#else
+ return 0;
+#endif
+}
+#endif
+
#endif /* CONFIG_PRIORITY_INHERITANCE */