Skip to content

Commit f81add2

Browse files
dcpleungkartben
authored andcommitted
posix: pin init functions and data for demand paging
Boot time initialization functions and data used there must be available at boot. With demand paging, these may not exist in memory when they are being used, resulting in page faults. So pin these functions and data in linker sections to make sure they are in memory at boot time. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
1 parent feb06d2 commit f81add2

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

lib/posix/options/barrier.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ struct posix_barrier {
1919
uint32_t count;
2020
};
2121

22+
__pinned_bss
2223
static struct posix_barrier posix_barrier_pool[CONFIG_MAX_PTHREAD_BARRIER_COUNT];
24+
2325
SYS_BITARRAY_DEFINE_STATIC(posix_barrier_bitarray, CONFIG_MAX_PTHREAD_BARRIER_COUNT);
2426

2527
/*
@@ -195,6 +197,7 @@ int pthread_barrierattr_destroy(pthread_barrierattr_t *attr)
195197
return 0;
196198
}
197199

200+
__boot_func
198201
static int pthread_barrier_pool_init(void)
199202
{
200203
int err;

lib/posix/options/cond.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ LOG_MODULE_REGISTER(pthread_cond, CONFIG_PTHREAD_COND_LOG_LEVEL);
1717

1818
int64_t timespec_to_timeoutms(const struct timespec *abstime);
1919

20+
__pinned_bss
2021
static struct k_condvar posix_cond_pool[CONFIG_MAX_PTHREAD_COND_COUNT];
22+
2123
SYS_BITARRAY_DEFINE_STATIC(posix_cond_bitarray, CONFIG_MAX_PTHREAD_COND_COUNT);
2224

2325
/*
@@ -209,6 +211,7 @@ int pthread_cond_destroy(pthread_cond_t *cvar)
209211
return 0;
210212
}
211213

214+
__boot_func
212215
static int pthread_cond_pool_init(void)
213216
{
214217
int err;

lib/posix/options/mutex.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ static const struct pthread_mutexattr def_attr = {
2929
.type = PTHREAD_MUTEX_DEFAULT,
3030
};
3131

32+
__pinned_bss
3233
static struct k_mutex posix_mutex_pool[CONFIG_MAX_PTHREAD_MUTEX_COUNT];
34+
3335
static uint8_t posix_mutex_type[CONFIG_MAX_PTHREAD_MUTEX_COUNT];
3436
SYS_BITARRAY_DEFINE_STATIC(posix_mutex_bitarray, CONFIG_MAX_PTHREAD_MUTEX_COUNT);
3537

@@ -451,6 +453,7 @@ int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, int prioceiling)
451453

452454
#endif /* CONFIG_POSIX_THREAD_PRIO_PROTECT */
453455

456+
__boot_func
454457
static int pthread_mutex_pool_init(void)
455458
{
456459
int err;

lib/posix/options/pthread.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,17 @@ BUILD_ASSERT(CONFIG_POSIX_PTHREAD_ATTR_STACKSIZE_BITS + CONFIG_POSIX_PTHREAD_ATT
8383

8484
int64_t timespec_to_timeoutms(const struct timespec *abstime);
8585
static void posix_thread_recycle(void);
86+
87+
__pinned_data
8688
static sys_dlist_t posix_thread_q[] = {
8789
SYS_DLIST_STATIC_INIT(&posix_thread_q[POSIX_THREAD_READY_Q]),
8890
SYS_DLIST_STATIC_INIT(&posix_thread_q[POSIX_THREAD_RUN_Q]),
8991
SYS_DLIST_STATIC_INIT(&posix_thread_q[POSIX_THREAD_DONE_Q]),
9092
};
93+
94+
__pinned_bss
9195
static struct posix_thread posix_thread_pool[CONFIG_MAX_PTHREAD_COUNT];
96+
9297
static SYS_SEM_DEFINE(pthread_pool_lock, 1, 1);
9398
static int pthread_concurrency;
9499

@@ -1536,6 +1541,7 @@ int pthread_sigmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT
15361541
return ret;
15371542
}
15381543

1544+
__boot_func
15391545
static int posix_thread_pool_init(void)
15401546
{
15411547
ARRAY_FOR_EACH_PTR(posix_thread_pool, th) {

0 commit comments

Comments
 (0)