Skip to content

Commit b67817c

Browse files
committed
fast-get: fix userspace thread detection
Checking number of memory domain partitions in thread's domain to determine whether it's a userspace thread isn't reliable and is a layering violation. Instead check the K_USER flag which indicates exactly that. Suggested-by: Adrian Warecki <adrian.warecki@intel.com> Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 1f18231 commit b67817c

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

posix/include/rtos/kernel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ typedef struct {
2828

2929
#define Z_TIMEOUT_MS(t) ((k_timeout_t) { .ticks = clock_ms_to_ticks(PLATFORM_DEFAULT_CLOCK, t) })
3030

31+
static inline bool thread_is_userspace(struct k_thread *thread)
32+
{
33+
return false;
34+
}
35+
3136
static inline void k_sleep(k_timeout_t timeout)
3237
{
3338
wait_delay(timeout.ticks);

zephyr/include/rtos/kernel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@
88

99
#include <zephyr/kernel.h>
1010

11+
static inline bool thread_is_userspace(struct k_thread *thread)
12+
{
13+
return !!(thread->base.user_options & K_USER);
14+
}
15+
1116
#endif /* __ZEPHYR_RTOS_KERNEL_H__ */

zephyr/lib/fast-get.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ const void *fast_get(struct k_heap *heap, const void *dram_ptr, size_t size)
189189
* We only get there for large buffers, since small buffers with
190190
* enabled userspace don't create fast-get entries
191191
*/
192-
if (mdom->num_partitions > 1) {
193-
/* A userspace thread makes the request */
192+
if (thread_is_userspace(k_current_get())) {
194193
if (mdom != entry->mdom &&
195194
!fast_get_partition_exists(k_current_get(), ret,
196195
ALIGN_UP(size, CONFIG_MM_DRV_PAGE_SIZE))) {

0 commit comments

Comments
 (0)