mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 05:16:47 +08:00
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
This commit is contained in:
@@ -155,6 +155,10 @@ static void check_test_memory_usage(void)
|
|||||||
#else
|
#else
|
||||||
memcpy(&g_mmprevious, &g_mmafter, sizeof(struct mallinfo));
|
memcpy(&g_mmprevious, &g_mmafter, sizeof(struct mallinfo));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* If so enabled, show the use of priority inheritance resources */
|
||||||
|
|
||||||
|
dump_nfreeholders("user_main:");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define check_test_memory_usage()
|
# define check_test_memory_usage()
|
||||||
|
|||||||
@@ -71,6 +71,14 @@
|
|||||||
# define CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS 8
|
# define CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS 8
|
||||||
#endif
|
#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
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -139,4 +147,16 @@ extern void barrier_test(void);
|
|||||||
|
|
||||||
extern void priority_inheritance(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 */
|
#endif /* __OSTEST_H */
|
||||||
|
|||||||
@@ -269,6 +269,7 @@ static void *lowpri_thread(void *parameter)
|
|||||||
printf(" g_highstate[%d]: %d\n", i, (int)g_highstate[i]);
|
printf(" g_highstate[%d]: %d\n", i, (int)g_highstate[i]);
|
||||||
}
|
}
|
||||||
printf(" I still have a count on the semaphore\n");
|
printf(" I still have a count on the semaphore\n");
|
||||||
|
sem_enumholders(&g_sem);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
@@ -308,6 +309,7 @@ static void *lowpri_thread(void *parameter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = pthread_getschedparam(pthread_self(), &policy, &sparam);
|
ret = pthread_getschedparam(pthread_self(), &policy, &sparam);
|
||||||
|
sem_enumholders(&g_sem);
|
||||||
sem_post(&g_sem);
|
sem_post(&g_sem);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
@@ -352,6 +354,7 @@ static void *lowpri_thread(void *parameter)
|
|||||||
printf(" ERROR should have been %d\n", g_lowpri);
|
printf(" ERROR should have been %d\n", g_lowpri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sem_enumholders(&g_sem);
|
||||||
|
|
||||||
printf("lowpri_thread-%d: Okay... I'm done!\n", threadno);
|
printf("lowpri_thread-%d: Okay... I'm done!\n", threadno);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@@ -396,6 +399,7 @@ void priority_inheritance(void)
|
|||||||
g_medpri = my_pri - 1;
|
g_medpri = my_pri - 1;
|
||||||
|
|
||||||
sem_init(&g_sem, 0, NLOWPRI_THREADS);
|
sem_init(&g_sem, 0, NLOWPRI_THREADS);
|
||||||
|
dump_nfreeholders("priority_inheritance:");
|
||||||
|
|
||||||
/* Start the low priority threads */
|
/* Start the low priority threads */
|
||||||
|
|
||||||
@@ -429,6 +433,7 @@ void priority_inheritance(void)
|
|||||||
}
|
}
|
||||||
printf("priority_inheritance: Waiting...\n");
|
printf("priority_inheritance: Waiting...\n");
|
||||||
sleep(2);
|
sleep(2);
|
||||||
|
dump_nfreeholders("priority_inheritance:");
|
||||||
|
|
||||||
/* Start the medium priority thread */
|
/* Start the medium priority thread */
|
||||||
|
|
||||||
@@ -458,6 +463,7 @@ void priority_inheritance(void)
|
|||||||
}
|
}
|
||||||
printf("priority_inheritance: Waiting...\n");
|
printf("priority_inheritance: Waiting...\n");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
dump_nfreeholders("priority_inheritance:");
|
||||||
|
|
||||||
/* Start the high priority threads */
|
/* Start the high priority threads */
|
||||||
|
|
||||||
@@ -491,6 +497,8 @@ void priority_inheritance(void)
|
|||||||
printf("priority_inheritance: pthread_create failed, status=%d\n", status);
|
printf("priority_inheritance: pthread_create failed, status=%d\n", status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dump_nfreeholders("priority_inheritance:");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
/* Wait for all thread instances to complete */
|
/* 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);
|
printf("priority_inheritance: Waiting for highpri_thread-%d to complete\n", i+1);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
(void)pthread_join(highpri[i], &result);
|
(void)pthread_join(highpri[i], &result);
|
||||||
|
dump_nfreeholders("priority_inheritance:");
|
||||||
}
|
}
|
||||||
printf("priority_inheritance: Waiting for medpri_thread to complete\n");
|
printf("priority_inheritance: Waiting for medpri_thread to complete\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
(void)pthread_join(medpri, &result);
|
(void)pthread_join(medpri, &result);
|
||||||
|
dump_nfreeholders("priority_inheritance:");
|
||||||
for (i = 0; i < NLOWPRI_THREADS; i++)
|
for (i = 0; i < NLOWPRI_THREADS; i++)
|
||||||
{
|
{
|
||||||
printf("priority_inheritance: Waiting for lowpri_thread-%d to complete\n", i+1);
|
printf("priority_inheritance: Waiting for lowpri_thread-%d to complete\n", i+1);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
(void)pthread_join(lowpri[i], &result);
|
(void)pthread_join(lowpri[i], &result);
|
||||||
|
dump_nfreeholders("priority_inheritance:");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("priority_inheritance: Finished\n");
|
printf("priority_inheritance: Finished\n");
|
||||||
sem_destroy(&g_sem);
|
sem_destroy(&g_sem);
|
||||||
|
dump_nfreeholders("priority_inheritance:");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
#endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */
|
#endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */
|
||||||
}
|
}
|
||||||
|
|||||||
+74
-1
@@ -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)
|
static int sem_recoverholders(struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg)
|
||||||
{
|
{
|
||||||
sem_freeholder(sem, pholder);
|
sem_freeholder(sem, pholder);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -376,6 +377,23 @@ static int sem_verifyholder(struct semholder_s *pholder, FAR sem_t *sem, FAR voi
|
|||||||
}
|
}
|
||||||
#endif
|
#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
|
* Name: sem_restoreholderprio
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -759,7 +777,7 @@ void sem_restorebaseprio(FAR _TCB *stcb, FAR sem_t *sem)
|
|||||||
* Description:
|
* Description:
|
||||||
* Called from sem_post() after a thread that was waiting for a semaphore
|
* 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
|
* count was awakened because of a signal and the semaphore wait has been
|
||||||
* canceld.
|
* canceled.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* sem - A reference to the semaphore no longer being waited for
|
* 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);
|
(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 */
|
#endif /* CONFIG_PRIORITY_INHERITANCE */
|
||||||
|
|||||||
Reference in New Issue
Block a user