Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 0ef03fc

Browse files
atrosinenkoOpenModelica-Hudson
authored andcommitted
Use the stack bottom value from the old threadData, if available
On linux, fetching the stack bottom involves huge amounts of user and kernel CPU time. Assuming the stack bottom does not change over time, copy it from the old threadData structure. Belonging to [master]: - #2884
1 parent 23d8d26 commit 0ef03fc

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

SimulationRuntime/c/meta/meta_modelica_data.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ void mmc_catch_dummy_fn();
248248
#define MMC_THROW() {longjmp(*((threadData_t*)pthread_getspecific(mmc_thread_data_key))->mmc_jumper,1);}
249249
#define MMC_ELSE() } else { threadData->mmc_jumper = old_jumper;
250250

251-
#define MMC_TRY_TOP() { threadData_t threadDataOnStack = {0}, *oldThreadData = (threadData_t*)pthread_getspecific(mmc_thread_data_key),*threadData = &threadDataOnStack; pthread_setspecific(mmc_thread_data_key,threadData); pthread_mutex_init(&threadData->parentMutex,NULL); mmc_init_stackoverflow(threadData); MMC_TRY_INTERNAL(mmc_jumper) threadData->mmc_stack_overflow_jumper = threadData->mmc_jumper; /* Let the default stack overflow handler be the top-level handler */
251+
#define MMC_TRY_TOP() { threadData_t threadDataOnStack = {0}, *oldThreadData = (threadData_t*)pthread_getspecific(mmc_thread_data_key),*threadData = &threadDataOnStack; pthread_setspecific(mmc_thread_data_key,threadData); pthread_mutex_init(&threadData->parentMutex,NULL); mmc_init_stackoverflow_fast(threadData, oldThreadData); MMC_TRY_INTERNAL(mmc_jumper) threadData->mmc_stack_overflow_jumper = threadData->mmc_jumper; /* Let the default stack overflow handler be the top-level handler */
252252

253-
#define MMC_TRY_TOP_SET(X) { threadData_t threadDataOnStack = *((threadData_t*)X), *oldThreadData = (threadData_t*)pthread_getspecific(mmc_thread_data_key),*threadData = &threadDataOnStack; pthread_setspecific(mmc_thread_data_key,threadData); pthread_mutex_init(&threadData->parentMutex,NULL); mmc_init_stackoverflow(threadData); MMC_TRY_INTERNAL(mmc_jumper) threadData->mmc_stack_overflow_jumper = threadData->mmc_jumper; /* Let the default stack overflow handler be the top-level handler */
253+
#define MMC_TRY_TOP_SET(X) { threadData_t threadDataOnStack = *((threadData_t*)X), *oldThreadData = (threadData_t*)pthread_getspecific(mmc_thread_data_key),*threadData = &threadDataOnStack; pthread_setspecific(mmc_thread_data_key,threadData); pthread_mutex_init(&threadData->parentMutex,NULL); mmc_init_stackoverflow_fast(threadData, oldThreadData); MMC_TRY_INTERNAL(mmc_jumper) threadData->mmc_stack_overflow_jumper = threadData->mmc_jumper; /* Let the default stack overflow handler be the top-level handler */
254254

255-
#define MMC_TRY_TOP_INTERNAL() { threadData_t *oldThreadData = (threadData_t*)pthread_getspecific(mmc_thread_data_key); pthread_setspecific(mmc_thread_data_key,threadData); pthread_mutex_init(&threadData->parentMutex,NULL); mmc_init_stackoverflow(threadData); MMC_TRY_INTERNAL(mmc_jumper) threadData->mmc_stack_overflow_jumper = threadData->mmc_jumper;
255+
#define MMC_TRY_TOP_INTERNAL() { threadData_t *oldThreadData = (threadData_t*)pthread_getspecific(mmc_thread_data_key); pthread_setspecific(mmc_thread_data_key,threadData); pthread_mutex_init(&threadData->parentMutex,NULL); mmc_init_stackoverflow_fast(threadData, oldThreadData); MMC_TRY_INTERNAL(mmc_jumper) threadData->mmc_stack_overflow_jumper = threadData->mmc_jumper;
256256
#define MMC_CATCH_TOP(X) pthread_setspecific(mmc_thread_data_key,oldThreadData); } else {pthread_setspecific(mmc_thread_data_key,oldThreadData);X;}}}
257257

258258
/* use this to allocate and initialize threadData */

SimulationRuntime/c/meta/meta_modelica_segv.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ static inline void mmc_init_stackoverflow(threadData_t *threadData)
5757
void mmc_init_stackoverflow(threadData_t *threadData);
5858
#endif
5959

60+
#if defined(linux)
61+
static inline void mmc_init_stackoverflow_fast(threadData_t *threadData, threadData_t *oldThreadData)
62+
{
63+
if (oldThreadData)
64+
threadData->stackBottom = oldThreadData->stackBottom;
65+
else
66+
mmc_init_stackoverflow(threadData);
67+
}
68+
#else
69+
static inline void mmc_init_stackoverflow_fast(threadData_t *threadData, threadData_t *oldThreadData)
70+
{
71+
mmc_init_stackoverflow(threadData);
72+
}
73+
#endif
74+
6075
#ifndef __has_builtin
6176
#define __has_builtin(x) 0 /* Compatibility with non-clang compilers */
6277
#endif

0 commit comments

Comments
 (0)