Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel: remove single thread support #10275

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion arch/Kconfig
Expand Up @@ -126,7 +126,6 @@ config DYNAMIC_OBJECTS

config SIMPLE_FATAL_ERROR_HANDLER
bool "Simple system fatal error handler"
default y if !MULTITHREADING
help
Provides an implementation of _SysFatalErrorHandler() that hard hangs
instead of aborting the faulting thread, and does not print anything,
Expand Down
23 changes: 7 additions & 16 deletions drivers/flash/soc_flash_nrf.c
Expand Up @@ -65,17 +65,8 @@ static int erase_op(void *context); /* instance of flash_op_handler_t */
static int erase_in_timeslice(u32_t addr, u32_t size);
#endif /* CONFIG_SOC_FLASH_NRF_RADIO_SYNC */

#if defined(CONFIG_MULTITHREADING)
/* semaphore for locking flash resources (tickers) */
static struct k_sem sem_lock;
#define SYNC_INIT() k_sem_init(&sem_lock, 1, 1)
#define SYNC_LOCK() k_sem_take(&sem_lock, K_FOREVER)
#define SYNC_UNLOCK() k_sem_give(&sem_lock)
#else
#define SYNC_INIT()
#define SYNC_LOCK()
#define SYNC_UNLOCK()
#endif

static int write(off_t addr, const void *data, size_t len);
static int erase(u32_t addr, u32_t size);
Expand Down Expand Up @@ -131,7 +122,7 @@ static int flash_nrf_write(struct device *dev, off_t addr,
return 0;
}

SYNC_LOCK();
k_sem_take(&sem_lock, K_FOREVER);

#if defined(CONFIG_SOC_FLASH_NRF_RADIO_SYNC)
if (ticker_is_initialized(0)) {
Expand All @@ -142,7 +133,7 @@ static int flash_nrf_write(struct device *dev, off_t addr,
ret = write(addr, data, len);
}

SYNC_UNLOCK();
k_sem_give(&sem_lock);

return ret;
}
Expand All @@ -166,7 +157,7 @@ static int flash_nrf_erase(struct device *dev, off_t addr, size_t size)
return 0;
}

SYNC_LOCK();
k_sem_take(&sem_lock, K_FOREVER);

#if defined(CONFIG_SOC_FLASH_NRF_RADIO_SYNC)
if (ticker_is_initialized(0)) {
Expand All @@ -177,14 +168,14 @@ static int flash_nrf_erase(struct device *dev, off_t addr, size_t size)
ret = erase(addr, size);
}

SYNC_UNLOCK();
k_sem_give(&sem_lock);

return ret;
}

static int flash_nrf_write_protection(struct device *dev, bool enable)
{
SYNC_LOCK();
k_sem_take(&sem_lock, K_FOREVER);

if (enable) {
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
Expand All @@ -193,7 +184,7 @@ static int flash_nrf_write_protection(struct device *dev, bool enable)
}
nvmc_wait_ready();

SYNC_UNLOCK();
k_sem_give(&sem_lock);

return 0;
}
Expand Down Expand Up @@ -225,7 +216,7 @@ static int nrf_flash_init(struct device *dev)
{
dev->driver_api = &flash_nrf_api;

SYNC_INIT();
k_sem_init(&sem_lock, 1, 1);

#if defined(CONFIG_SOC_FLASH_NRF_RADIO_SYNC)
k_sem_init(&sem_sync, 0, 1);
Expand Down
34 changes: 12 additions & 22 deletions drivers/flash/spi_flash_w25qxxdv.c
Expand Up @@ -14,17 +14,6 @@
#include "spi_flash_w25qxxdv.h"
#include "flash_priv.h"

#if defined(CONFIG_MULTITHREADING)
#define SYNC_INIT() k_sem_init( \
&((struct spi_flash_data *)dev->driver_data)->sem, 1, UINT_MAX)
#define SYNC_LOCK() k_sem_take(&driver_data->sem, K_FOREVER)
#define SYNC_UNLOCK() k_sem_give(&driver_data->sem)
#else
#define SYNC_INIT()
#define SYNC_LOCK()
#define SYNC_UNLOCK()
#endif

static int spi_flash_wb_access(struct spi_flash_data *ctx,
u8_t cmd, bool addressed, off_t offset,
void *data, size_t length, bool write)
Expand Down Expand Up @@ -134,14 +123,14 @@ static int spi_flash_wb_read(struct device *dev, off_t offset, void *data,
return -ENODEV;
}

SYNC_LOCK();
k_sem_take(&driver_data->sem, K_FOREVER);

wait_for_flash_idle(dev);

ret = spi_flash_wb_access(driver_data, W25QXXDV_CMD_READ,
true, offset, data, len, false);

SYNC_UNLOCK();
k_sem_give(&driver_data->sem);

return ret;
}
Expand All @@ -157,13 +146,13 @@ static int spi_flash_wb_write(struct device *dev, off_t offset,
return -ENOTSUP;
}

SYNC_LOCK();
k_sem_take(&driver_data->sem, K_FOREVER);

wait_for_flash_idle(dev);

reg = spi_flash_wb_reg_read(dev, W25QXXDV_CMD_RDSR);
if (!(reg & W25QXXDV_WEL_BIT)) {
SYNC_UNLOCK();
k_sem_give(&driver_data->sem);
return -EIO;
}

Expand All @@ -176,7 +165,7 @@ static int spi_flash_wb_write(struct device *dev, off_t offset,
ret = spi_flash_wb_access(driver_data, W25QXXDV_CMD_PP,
true, offset, (void *)data, len, true);

SYNC_UNLOCK();
k_sem_give(&driver_data->sem);

return ret;
}
Expand All @@ -187,7 +176,7 @@ static int spi_flash_wb_write_protection_set(struct device *dev, bool enable)
u8_t reg = 0;
int ret;

SYNC_LOCK();
k_sem_take(&driver_data->sem, K_FOREVER);

wait_for_flash_idle(dev);

Expand All @@ -199,7 +188,7 @@ static int spi_flash_wb_write_protection_set(struct device *dev, bool enable)

ret = spi_flash_wb_reg_write(dev, reg);

SYNC_UNLOCK();
k_sem_give(&driver_data->sem);

return ret;
}
Expand Down Expand Up @@ -263,12 +252,12 @@ static int spi_flash_wb_erase(struct device *dev, off_t offset, size_t size)
return -ENODEV;
}

SYNC_LOCK();
k_sem_take(&driver_data->sem, K_FOREVER);

reg = spi_flash_wb_reg_read(dev, W25QXXDV_CMD_RDSR);

if (!(reg & W25QXXDV_WEL_BIT)) {
SYNC_UNLOCK();
k_sem_give(&driver_data->sem);
return -EIO;
}

Expand Down Expand Up @@ -303,7 +292,7 @@ static int spi_flash_wb_erase(struct device *dev, off_t offset, size_t size)
}
}

SYNC_UNLOCK();
k_sem_give(&driver_data->sem);

return ret;
}
Expand Down Expand Up @@ -351,9 +340,10 @@ static int spi_flash_wb_configure(struct device *dev)

static int spi_flash_init(struct device *dev)
{
struct spi_flash_data *data = dev->driver_data;
int ret;

SYNC_INIT();
k_sem_init(&data->sem, 1, UINT_MAX);

ret = spi_flash_wb_configure(dev);
if (!ret) {
Expand Down
2 changes: 0 additions & 2 deletions drivers/flash/spi_flash_w25qxxdv.h
Expand Up @@ -20,9 +20,7 @@ struct spi_flash_data {
struct spi_cs_control cs_ctrl;
#endif /* CONFIG_SPI_FLASH_W25QXXDV_GPIO_SPI_CS */
struct spi_config spi_cfg;
#if defined(CONFIG_MULTITHREADING)
struct k_sem sem;
#endif /* CONFIG_MULTITHREADING */
};


Expand Down
1 change: 0 additions & 1 deletion ext/hal/ti/simplelink/Kconfig
Expand Up @@ -9,7 +9,6 @@ config HAS_CC3220SDK
config SIMPLELINK_HOST_DRIVER
bool "Build the SimpleLink WiFi Host Driver"
depends on HAS_CC3220SDK
depends on MULTITHREADING
select NEWLIB_LIBC
select ERRNO
help
Expand Down
7 changes: 0 additions & 7 deletions include/kernel.h
Expand Up @@ -4597,17 +4597,10 @@ extern void _sys_power_save_idle_exit(s32_t ticks);
* private APIs that are utilized by one or more public APIs
*/

#ifdef CONFIG_MULTITHREADING
/**
* @internal
*/
extern void _init_static_threads(void);
#else
/**
* @internal
*/
#define _init_static_threads() do { } while (false)
#endif

/**
* @internal
Expand Down
19 changes: 2 additions & 17 deletions kernel/Kconfig
Expand Up @@ -9,22 +9,8 @@

menu "General Kernel Options"

config MULTITHREADING
bool "Multi-threading"
default y
help
If disabled, only the main thread is available, so a main() function
must be provided. Interrupts are available. Kernel objects will most
probably not behave as expected, especially with regards to pending,
since the main thread cannot pend, it being the only thread in the
system.

Many drivers and subsystems will not work with this option; use only
when you REALLY know what you are doing.

config NUM_COOP_PRIORITIES
int "Number of coop priorities" if MULTITHREADING
default 1 if !MULTITHREADING
int "Number of coop priorities"
default 16
range 0 128
help
Expand Down Expand Up @@ -52,8 +38,7 @@ config NUM_COOP_PRIORITIES
priority, and be the only thread at that priority.

config NUM_PREEMPT_PRIORITIES
int "Number of preemptible priorities" if MULTITHREADING
default 0 if !MULTITHREADING
int "Number of preemptible priorities"
default 15
range 0 128
help
Expand Down
5 changes: 0 additions & 5 deletions kernel/include/ksched.h
Expand Up @@ -11,7 +11,6 @@
#include <tracing.h>
#include <stdbool.h>

#ifdef CONFIG_MULTITHREADING
#define _VALID_PRIO(prio, entry_point) \
(((prio) == K_IDLE_PRIO && _is_idle_thread(entry_point)) || \
(_is_prio_higher_or_equal((prio), \
Expand All @@ -26,10 +25,6 @@
K_LOWEST_APPLICATION_THREAD_PRIO, \
K_HIGHEST_APPLICATION_THREAD_PRIO); \
} while (false)
#else
#define _VALID_PRIO(prio, entry_point) ((prio) == -1)
#define _ASSERT_VALID_PRIO(prio, entry_point) __ASSERT((prio) == -1, "")
#endif

void _sched_init(void);
void _add_thread_to_ready_q(struct k_thread *thread);
Expand Down
16 changes: 0 additions & 16 deletions kernel/init.c
Expand Up @@ -244,7 +244,6 @@ void __weak main(void)
/* NOP default main() if the application does not provide one. */
}

#if defined(CONFIG_MULTITHREADING)
static void init_idle_thread(struct k_thread *thr, k_thread_stack_t *stack)
{
#ifdef CONFIG_SMP
Expand All @@ -256,7 +255,6 @@ static void init_idle_thread(struct k_thread *thr, k_thread_stack_t *stack)
K_LOWEST_THREAD_PRIO, K_ESSENTIAL, IDLE_THREAD_NAME);
_mark_thread_as_started(thr);
}
#endif

/**
*
Expand All @@ -270,7 +268,6 @@ static void init_idle_thread(struct k_thread *thr, k_thread_stack_t *stack)
*
* @return N/A
*/
#ifdef CONFIG_MULTITHREADING
static void prepare_multithreading(struct k_thread *dummy_thread)
{
#ifdef CONFIG_ARCH_HAS_CUSTOM_SWAP_TO_MAIN
Expand Down Expand Up @@ -322,11 +319,9 @@ static void prepare_multithreading(struct k_thread *dummy_thread)
_mark_thread_as_started(_main_thread);
_ready_thread(_main_thread);

#ifdef CONFIG_MULTITHREADING
init_idle_thread(_idle_thread, _idle_stack);
_kernel.cpus[0].idle_thread = _idle_thread;
sys_trace_thread_create(_idle_thread);
#endif

#if defined(CONFIG_SMP) && CONFIG_MP_NUM_CPUS > 1
init_idle_thread(_idle_thread1, _idle_stack1);
Expand Down Expand Up @@ -371,7 +366,6 @@ static void switch_to_main_thread(void)
(void)_Swap(irq_lock());
#endif
}
#endif /* CONFIG_MULTITHREDING */

u32_t z_early_boot_rand32_get(void)
{
Expand Down Expand Up @@ -429,7 +423,6 @@ extern uintptr_t __stack_chk_guard;
*/
FUNC_NORETURN void _Cstart(void)
{
#ifdef CONFIG_MULTITHREADING
#ifdef CONFIG_ARCH_HAS_CUSTOM_SWAP_TO_MAIN
struct k_thread *dummy_thread = NULL;
#else
Expand All @@ -440,7 +433,6 @@ FUNC_NORETURN void _Cstart(void)
struct k_thread *dummy_thread = (struct k_thread *)&dummy_thread_memory;

(void)memset(dummy_thread_memory, 0, sizeof(dummy_thread_memory));
#endif
#endif
/*
* The interrupt library needs to be initialized early since a series
Expand All @@ -467,16 +459,8 @@ FUNC_NORETURN void _Cstart(void)
__stack_chk_guard = z_early_boot_rand32_get();
#endif

#ifdef CONFIG_MULTITHREADING
prepare_multithreading(dummy_thread);
switch_to_main_thread();
#else
bg_thread_main(NULL, NULL, NULL);

irq_lock();
while (true) {
}
#endif

/*
* Compiler can't tell that the above routines won't return and issues
Expand Down
2 changes: 0 additions & 2 deletions kernel/sched.c
Expand Up @@ -803,7 +803,6 @@ Z_SYSCALL_HANDLER0_SIMPLE_VOID(k_yield);

void _impl_k_sleep(s32_t duration)
{
#ifdef CONFIG_MULTITHREADING
/* volatile to guarantee that irq_lock() is executed after ticks is
* populated
*/
Expand All @@ -828,7 +827,6 @@ void _impl_k_sleep(s32_t duration)
_add_thread_timeout(_current, NULL, ticks);

(void)_Swap(key);
#endif
}

#ifdef CONFIG_USERSPACE
Expand Down