LCOV - code coverage report
Current view: top level - /home/ubuntu/zephyrproject/zephyr/kernel/include - run_q.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 90.6 % 32 29
Test Date: 2026-11-06 14:43:19 Functions: 88.9 % 9 8
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 50.0 % 12 6

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * Copyright (c) Intel Corporation
       3                 :             :  * SPDX-License-Identifier: Apache-2.0
       4                 :             :  */
       5                 :             : #ifndef ZEPHYR_KERNEL_INCLUDE_RUN_Q_H_
       6                 :             : #define ZEPHYR_KERNEL_INCLUDE_RUN_Q_H_
       7                 :             : 
       8                 :             : #include <zephyr/kernel.h>
       9                 :             : #include <ksched.h>
      10                 :             : #include <zephyr/spinlock.h>
      11                 :             : #include <wait_q.h>
      12                 :             : #include <kthread.h>
      13                 :             : #include <priority_q.h>
      14                 :             : #include <ipi.h>
      15                 :             : 
      16                 :             : 
      17                 :         129 : static ALWAYS_INLINE void *thread_runq(struct k_thread *thread)
      18                 :             : {
      19                 :             : #ifdef CONFIG_SCHED_CPU_MASK_PIN_ONLY
      20                 :             :         uint32_t cpu_mask = thread->base.cpu_mask;
      21                 :             : 
      22                 :             :         __ASSERT(cpu_mask != 0U, "thread queued with empty CPU mask");
      23                 :             : 
      24                 :             :         unsigned int cpu = (unsigned int)u32_count_trailing_zeros(cpu_mask);
      25                 :             : 
      26                 :             :         __ASSERT(cpu < ARRAY_SIZE(_kernel.cpus),
      27                 :             :                  "cpu_mask bit %u exceeds cpu count %zu",
      28                 :             :                  cpu, ARRAY_SIZE(_kernel.cpus));
      29                 :             : 
      30                 :             :         /* Clamp so static-analysis tools that cannot see the assert
      31                 :             :          * above do not flag the array access as out-of-bounds.
      32                 :             :          */
      33                 :             :         cpu = MIN(cpu, (unsigned int)(ARRAY_SIZE(_kernel.cpus) - 1U));
      34                 :             : 
      35                 :             :         return &_kernel.cpus[cpu].ready_q.runq;
      36                 :             : #else
      37                 :         129 :         ARG_UNUSED(thread);
      38                 :         129 :         return &_kernel.ready_q.runq;
      39                 :             : #endif /* CONFIG_SCHED_CPU_MASK_PIN_ONLY */
      40                 :             : }
      41                 :             : 
      42                 :         130 : static ALWAYS_INLINE void *curr_cpu_runq(void)
      43                 :             : {
      44                 :             : #ifdef CONFIG_SCHED_CPU_MASK_PIN_ONLY
      45                 :             :         return &arch_curr_cpu()->ready_q.runq;
      46                 :             : #else
      47                 :         130 :         return &_kernel.ready_q.runq;
      48                 :             : #endif /* CONFIG_SCHED_CPU_MASK_PIN_ONLY */
      49                 :             : }
      50                 :             : 
      51                 :          65 : static ALWAYS_INLINE void runq_add(struct k_thread *thread)
      52                 :             : {
      53         [ -  + ]:          65 :         __ASSERT_NO_MSG(!z_is_idle_thread_object(thread));
      54         [ -  + ]:          65 :         __ASSERT_NO_MSG(!is_thread_dummy(thread));
      55                 :             : 
      56                 :          65 :         _priq_run_add(thread_runq(thread), thread);
      57                 :          65 : }
      58                 :             : 
      59                 :          64 : static ALWAYS_INLINE void runq_remove(struct k_thread *thread)
      60                 :             : {
      61         [ -  + ]:          64 :         __ASSERT_NO_MSG(!z_is_idle_thread_object(thread));
      62         [ -  + ]:          64 :         __ASSERT_NO_MSG(!is_thread_dummy(thread));
      63                 :             : 
      64                 :          64 :         _priq_run_remove(thread_runq(thread), thread);
      65                 :          64 : }
      66                 :             : 
      67                 :           0 : static ALWAYS_INLINE void runq_yield(void)
      68                 :             : {
      69                 :           0 :         _priq_run_yield(curr_cpu_runq());
      70                 :           0 : }
      71                 :             : 
      72                 :         130 : static ALWAYS_INLINE struct k_thread *runq_best(void)
      73                 :             : {
      74                 :         130 :         return _priq_run_best(curr_cpu_runq());
      75                 :             : }
      76                 :             : 
      77                 :             : /*
      78                 :             :  * _current is never in the run queue until context switch on
      79                 :             :  * SMP configurations.
      80                 :             :  */
      81                 :         129 : static inline bool should_queue_thread(struct k_thread *thread)
      82                 :             : {
      83                 :         129 :         return !IS_ENABLED(CONFIG_SMP) || (thread != _current);
      84                 :             : }
      85                 :             : 
      86                 :          65 : static ALWAYS_INLINE void queue_thread(struct k_thread *thread)
      87                 :             : {
      88                 :          65 :         z_mark_thread_as_queued(thread);
      89         [ +  - ]:          65 :         if (should_queue_thread(thread)) {
      90                 :          65 :                 runq_add(thread);
      91                 :             :         }
      92                 :             : #ifdef CONFIG_SMP
      93                 :             :         if (thread == _current) {
      94                 :             :                 /* add current to end of queue means "yield" */
      95                 :             :                 _current_cpu->swap_ok = true;
      96                 :             :         }
      97                 :             : #endif /* CONFIG_SMP */
      98                 :          65 : }
      99                 :             : 
     100                 :          64 : static ALWAYS_INLINE void dequeue_thread(struct k_thread *thread)
     101                 :             : {
     102                 :          64 :         z_mark_thread_as_not_queued(thread);
     103         [ +  - ]:          64 :         if (should_queue_thread(thread)) {
     104                 :          64 :                 runq_remove(thread);
     105                 :             :         }
     106                 :          64 : }
     107                 :             : 
     108                 :             : #endif /* ZEPHYR_KERNEL_INCLUDE_RUN_Q_H_ */
        

Generated by: LCOV version 2.0-1