Zephyr Project API 3.7.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
main.c File Reference

Offload to the Kernel workqueue. More...

#include <zephyr/kernel.h>
#include <zephyr/linker/sections.h>
#include <zephyr/ztest.h>

Macros

#define NUM_MILLISECONDS   50
 
#define TEST_TIMEOUT   200
 
#define OFFLOAD_WORKQUEUE_STACK_SIZE   1024
 
#define STACK_SIZE   (1024 + CONFIG_TEST_EXTRA_STACK_SIZE)
 

Functions

static K_THREAD_STACK_DEFINE (offload_work_q_stack, 1024)
 
static K_THREAD_STACK_DEFINE (stack1,(1024+CONFIG_TEST_EXTRA_STACK_SIZE))
 
static K_THREAD_STACK_DEFINE (stack2,(1024+CONFIG_TEST_EXTRA_STACK_SIZE))
 
 K_SEM_DEFINE (ALT_SEM, 0, UINT_MAX)
 
 K_SEM_DEFINE (REGRESS_SEM, 0, UINT_MAX)
 
 K_SEM_DEFINE (TEST_SEM, 0, UINT_MAX)
 
void critical_rtn (struct k_work *unused)
 Routine to be called from a workqueue.
 
uint32_t critical_loop (const char *tag, uint32_t count)
 Common code for invoking work.
 
void alternate_thread (void *arg1, void *arg2, void *arg3)
 Alternate thread.
 
void regression_thread (void *arg1, void *arg2, void *arg3)
 Regression thread.
 
 ZTEST (kernel_offload_wq, test_offload_workqueue)
 Verify thread context.
 
 ZTEST_SUITE (kernel_offload_wq, NULL, NULL, ztest_simple_1cpu_before, ztest_simple_1cpu_after, NULL)
 

Variables

static uint32_t critical_var
 
static uint32_t alt_thread_iterations
 
static struct k_work_q offload_work_q
 
static struct k_thread thread1
 
static struct k_thread thread2
 

Detailed Description

Offload to the Kernel workqueue.

This test verifies that the kernel workqueue operates as expected.

This test has two threads that increment a counter. The routine that increments the counter is invoked from workqueue due to the two threads calling using it. The final result of the counter is expected to be the the number of times work item was called to increment the counter.

This is done with time slicing both disabled and enabled to ensure that the result always matches the number of times the workqueue is called.

Macro Definition Documentation

◆ NUM_MILLISECONDS

#define NUM_MILLISECONDS   50

◆ OFFLOAD_WORKQUEUE_STACK_SIZE

#define OFFLOAD_WORKQUEUE_STACK_SIZE   1024

◆ STACK_SIZE

#define STACK_SIZE   (1024 + CONFIG_TEST_EXTRA_STACK_SIZE)

◆ TEST_TIMEOUT

#define TEST_TIMEOUT   200

Function Documentation

◆ alternate_thread()

void alternate_thread ( void *  arg1,
void *  arg2,
void *  arg3 
)

Alternate thread.

This routine invokes the workqueue many times.

◆ critical_loop()

uint32_t critical_loop ( const char *  tag,
uint32_t  count 
)

Common code for invoking work.

Parameters
tagtext identifying the invocation context
countnumber of critical section calls made thus far
Returns
number of critical section calls made by a thread

◆ critical_rtn()

void critical_rtn ( struct k_work unused)

Routine to be called from a workqueue.

This routine increments the global variable critical_var.

◆ K_SEM_DEFINE() [1/3]

K_SEM_DEFINE ( ALT_SEM  ,
,
UINT_MAX   
)

◆ K_SEM_DEFINE() [2/3]

K_SEM_DEFINE ( REGRESS_SEM  ,
,
UINT_MAX   
)

◆ K_SEM_DEFINE() [3/3]

K_SEM_DEFINE ( TEST_SEM  ,
,
UINT_MAX   
)

◆ K_THREAD_STACK_DEFINE() [1/3]

static K_THREAD_STACK_DEFINE ( offload_work_q_stack  ,
1024   
)
static

◆ K_THREAD_STACK_DEFINE() [2/3]

static K_THREAD_STACK_DEFINE ( stack1  ,
(1024+CONFIG_TEST_EXTRA_STACK_SIZE)   
)
static

◆ K_THREAD_STACK_DEFINE() [3/3]

static K_THREAD_STACK_DEFINE ( stack2  ,
(1024+CONFIG_TEST_EXTRA_STACK_SIZE)   
)
static

◆ regression_thread()

void regression_thread ( void *  arg1,
void *  arg2,
void *  arg3 
)

Regression thread.

This routine invokes the workqueue many times. It also checks to ensure that the number of times it is called matches the global variable critical_var.

◆ ZTEST_SUITE()

ZTEST_SUITE ( kernel_offload_wq  ,
NULL  ,
NULL  ,
ztest_simple_1cpu_before  ,
ztest_simple_1cpu_after  ,
NULL   
)

Variable Documentation

◆ alt_thread_iterations

uint32_t alt_thread_iterations
static

◆ critical_var

uint32_t critical_var
static

◆ offload_work_q

struct k_work_q offload_work_q
static

◆ thread1

struct k_thread thread1
static

◆ thread2

struct k_thread thread2
static