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

sched: explicitly select the cpuload clock source configuration #11102

Merged
merged 1 commit into from Nov 1, 2023
Merged
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
Expand Up @@ -32,7 +32,7 @@ CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_RAM_SIZE=536870912
CONFIG_RAM_START=0x20200000
CONFIG_SCHED_CPULOAD=y
CONFIG_SCHED_CPULOAD_SYSCLK=y
CONFIG_START_DAY=14
CONFIG_START_MONTH=3
CONFIG_SYSTEM_NSH=y
Expand Up @@ -32,7 +32,7 @@ CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_RAM_SIZE=1048576
CONFIG_RAM_START=0x20200000
CONFIG_SCHED_CPULOAD=y
CONFIG_SCHED_CPULOAD_SYSCLK=y
CONFIG_START_DAY=14
CONFIG_START_MONTH=3
CONFIG_SYSTEM_NSH=y
Expand Up @@ -32,7 +32,7 @@ CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_RAM_SIZE=1048576
CONFIG_RAM_START=0x20200000
CONFIG_SCHED_CPULOAD=y
CONFIG_SCHED_CPULOAD_SYSCLK=y
CONFIG_START_DAY=14
CONFIG_START_MONTH=3
CONFIG_SYSTEM_NSH=y
1 change: 0 additions & 1 deletion boards/arm/imxrt/teensy-4.x/configs/pikron-bb/defconfig
Expand Up @@ -143,7 +143,6 @@ CONFIG_RAM_SIZE=1048576
CONFIG_RAM_START=0x20200000
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RR_INTERVAL=10
CONFIG_SCHED_CPULOAD=y
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_TICKLESS=y
CONFIG_SCHED_TICKLESS_ALARM=y
Expand Down
2 changes: 1 addition & 1 deletion boards/arm/lpc17xx_40xx/lx_cpu/configs/nsh/defconfig
Expand Up @@ -138,7 +138,7 @@ CONFIG_PTHREAD_STACK_MIN=1024
CONFIG_RAM_SIZE=65536
CONFIG_RAM_START=0x10000000
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_CPULOAD=y
CONFIG_SCHED_CPULOAD_SYSCLK=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_IRQMONITOR=y
Expand Down
2 changes: 1 addition & 1 deletion boards/arm/sam34/sam4s-xplained-pro/Kconfig
Expand Up @@ -18,7 +18,7 @@ config SAM4S_XPLAINED_PRO_SCHED_TIMER_DEVPATH
config SAM4S_XPLAINED_PRO_CPULOAD_TIMER_DEVPATH
string "CPU Load Timer Device Path"
default "/dev/tc0"
depends on TIMER && SCHED_CPULOAD && SCHED_CPULOAD_EXTCLK
depends on TIMER && SCHED_CPULOAD_EXTCLK

config SAM34_NAND_BLOCKMOUNT
bool "NAND FLASH auto-mount"
Expand Down
2 changes: 1 addition & 1 deletion boards/arm/stm32/stm32butterfly2/configs/nsh/defconfig
Expand Up @@ -50,7 +50,7 @@ CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_RR_INTERVAL=100
CONFIG_SCHED_CPULOAD=y
CONFIG_SCHED_CPULOAD_SYSCLK=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_HPWORKSTACKSIZE=1024
Expand Down
2 changes: 1 addition & 1 deletion boards/arm/stm32/stm32butterfly2/configs/nshnet/defconfig
Expand Up @@ -63,7 +63,7 @@ CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_RR_INTERVAL=100
CONFIG_SCHED_CPULOAD=y
CONFIG_SCHED_CPULOAD_SYSCLK=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_HPWORKSTACKSIZE=1024
Expand Down
Expand Up @@ -49,7 +49,7 @@ CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_RR_INTERVAL=100
CONFIG_SCHED_CPULOAD=y
CONFIG_SCHED_CPULOAD_SYSCLK=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_HPWORKSTACKSIZE=1024
Expand Down
Expand Up @@ -50,7 +50,7 @@ CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_RR_INTERVAL=100
CONFIG_SCHED_CPULOAD=y
CONFIG_SCHED_CPULOAD_SYSCLK=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_HPWORKSTACKSIZE=1024
Expand Down
2 changes: 1 addition & 1 deletion boards/arm/stm32h7/nucleo-h743zi2/configs/jumbo/defconfig
Expand Up @@ -88,7 +88,7 @@ CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_CPULOAD=y
CONFIG_SCHED_CPULOAD_SYSCLK=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKSTACKSIZE=2048
CONFIG_SCHED_IRQMONITOR=y
Expand Down
2 changes: 1 addition & 1 deletion boards/risc-v/bl602/bl602evb/configs/timer/defconfig
Expand Up @@ -65,7 +65,7 @@ CONFIG_RAM_SIZE=134217728
CONFIG_RAM_START=0xc0800000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_CPULOAD=y
CONFIG_SCHED_CPULOAD_SYSCLK=y
CONFIG_SCHED_WAITPID=y
CONFIG_STACK_COLORATION=y
CONFIG_START_DAY=20
Expand Down
4 changes: 2 additions & 2 deletions crypto/random_pool.c
Expand Up @@ -213,7 +213,7 @@ static void addentropy(FAR const uint32_t *buf, size_t n, bool inc_new)

static void initentropy(FAR blake2s_state *S)
{
#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
struct cpuload_s load;
#endif
uint32_t tmp;
Expand All @@ -231,7 +231,7 @@ static void initentropy(FAR blake2s_state *S)

tmp = sizeof(entropy_pool.pool);
tmp <<= 27;
#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
clock_cpuload(0, &load);
tmp += load.total ^ ROTL_32(load.active, 23);
#endif
Expand Down
2 changes: 1 addition & 1 deletion fs/procfs/Kconfig
Expand Up @@ -45,7 +45,7 @@ config FS_PROCFS_EXCLUDE_CPUINFO

config FS_PROCFS_EXCLUDE_CPULOAD
bool "Exclude CPU load"
depends on SCHED_CPULOAD
depends on !SCHED_CPULOAD_NONE
default DEFAULT_SMALL

config FS_PROCFS_EXCLUDE_ENVIRON
Expand Down
3 changes: 2 additions & 1 deletion fs/procfs/fs_procfs.c
Expand Up @@ -106,7 +106,8 @@ static const struct procfs_entry_s g_procfs_entries[] =
{ "cpuinfo", &g_cpuinfo_operations, PROCFS_FILE_TYPE },
#endif

#if defined(CONFIG_SCHED_CPULOAD) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPULOAD)
#if !defined(CONFIG_SCHED_CPULOAD_NONE) && \
!defined(CONFIG_FS_PROCFS_EXCLUDE_CPULOAD)
{ "cpuload", &g_cpuload_operations, PROCFS_FILE_TYPE },
#endif

Expand Down
3 changes: 2 additions & 1 deletion fs/procfs/fs_procfscpuload.c
Expand Up @@ -45,7 +45,8 @@
#include <nuttx/fs/procfs.h>

#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS)
#if defined(CONFIG_SCHED_CPULOAD) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPULOAD)
#if !defined(CONFIG_SCHED_CPULOAD_NONE) && \
!defined(CONFIG_FS_PROCFS_EXCLUDE_CPULOAD)

/****************************************************************************
* Pre-processor Definitions
Expand Down
16 changes: 8 additions & 8 deletions fs/procfs/fs_procfsproc.c
Expand Up @@ -54,7 +54,7 @@
#include <nuttx/fs/ioctl.h>
#include <nuttx/mm/mm.h>

#if defined(CONFIG_SCHED_CPULOAD) || defined(CONFIG_SCHED_CRITMONITOR)
#if !defined(CONFIG_SCHED_CPULOAD_NONE) || defined(CONFIG_SCHED_CRITMONITOR)
# include <nuttx/clock.h>
#endif

Expand Down Expand Up @@ -84,7 +84,7 @@ enum proc_node_e
PROC_LEVEL0 = 0, /* The top-level directory */
PROC_STATUS, /* Task/thread status */
PROC_CMDLINE, /* Task command line */
#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
PROC_LOADAVG, /* Average CPU utilization */
#endif
#ifdef CONFIG_SCHED_CRITMONITOR
Expand Down Expand Up @@ -171,7 +171,7 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile,
static ssize_t proc_cmdline(FAR struct proc_file_s *procfile,
FAR struct tcb_s *tcb, FAR char *buffer, size_t buflen,
off_t offset);
#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
static ssize_t proc_loadavg(FAR struct proc_file_s *procfile,
FAR struct tcb_s *tcb, FAR char *buffer, size_t buflen,
off_t offset);
Expand Down Expand Up @@ -278,7 +278,7 @@ static const struct proc_node_s g_cmdline =
"cmdline", "cmdline", (uint8_t)PROC_CMDLINE, DTYPE_FILE /* Task command line */
};

#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
static const struct proc_node_s g_loadavg =
{
"loadavg", "loadavg", (uint8_t)PROC_LOADAVG, DTYPE_FILE /* Average CPU utilization */
Expand Down Expand Up @@ -340,7 +340,7 @@ static FAR const struct proc_node_s * const g_nodeinfo[] =
{
&g_status, /* Task/thread status */
&g_cmdline, /* Task command line */
#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
&g_loadavg, /* Average CPU utilization */
#endif
#ifdef CONFIG_SCHED_CRITMONITOR
Expand Down Expand Up @@ -369,7 +369,7 @@ static const struct proc_node_s * const g_level0info[] =
{
&g_status, /* Task/thread status */
&g_cmdline, /* Task command line */
#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
&g_loadavg, /* Average CPU utilization */
#endif
#ifdef CONFIG_SCHED_CRITMONITOR
Expand Down Expand Up @@ -706,7 +706,7 @@ static ssize_t proc_cmdline(FAR struct proc_file_s *procfile,
* Name: proc_loadavg
****************************************************************************/

#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
static ssize_t proc_loadavg(FAR struct proc_file_s *procfile,
FAR struct tcb_s *tcb, FAR char *buffer,
size_t buflen, off_t offset)
Expand Down Expand Up @@ -1521,7 +1521,7 @@ static ssize_t proc_read(FAR struct file *filep, FAR char *buffer,
ret = proc_cmdline(procfile, tcb, buffer, buflen, filep->f_pos);
break;

#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
case PROC_LOADAVG: /* Average CPU utilization */
ret = proc_loadavg(procfile, tcb, buffer, buflen, filep->f_pos);
break;
Expand Down
4 changes: 2 additions & 2 deletions include/nuttx/clock.h
Expand Up @@ -274,7 +274,7 @@

/* This structure is used to report CPU usage for a particular thread */

#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
struct cpuload_s
{
volatile uint32_t total; /* Total number of clock ticks */
Expand Down Expand Up @@ -615,7 +615,7 @@ int clock_systime_timespec(FAR struct timespec *ts);
*
****************************************************************************/

#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
int clock_cpuload(int pid, FAR struct cpuload_s *cpuload);
#endif

Expand Down
2 changes: 1 addition & 1 deletion include/nuttx/sched.h
Expand Up @@ -625,7 +625,7 @@ struct tcb_s

/* CPU load monitoring support ********************************************/

#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
uint32_t ticks; /* Number of ticks on this thread */
#endif

Expand Down
25 changes: 12 additions & 13 deletions sched/Kconfig
Expand Up @@ -914,9 +914,9 @@ config SCHED_CRITMONITOR_MAXTIME_PANIC
If this option is enabled, a panic will be triggered when
IRQ/WQUEUE/PREEMPTION execution time exceeds SCHED_CRITMONITOR_MAXTIME_xxx

config SCHED_CPULOAD
bool "Enable CPU load monitoring"
default n
choice
prompt "Select CPU load clock source"
default SCHED_CPULOAD_NONE
---help---
If this option is selected, the timer interrupt handler will monitor
if the system is IDLE or busy at the time of that the timer interrupt
Expand All @@ -932,12 +932,11 @@ config SCHED_CPULOAD
possible unless you provide an alternative clock to drive the
sampling and select SCHED_CPULOAD_EXTCLK.

if SCHED_CPULOAD

choice
prompt "Select CPU load clock source"
default SCHED_CPULOAD_EXTCLK if SCHED_TICKLESS
default SCHED_CPULOAD_CRITMONITOR if SCHED_CRITMONITOR
config SCHED_CPULOAD_NONE
bool "None CPU load clock source"
---help---
If this option is enabled, the system will not support CPU load
measurement.

config SCHED_CPULOAD_SYSCLK
bool "Use system clock"
Expand All @@ -955,8 +954,9 @@ config SCHED_CPULOAD_SYSCLK
the CPU load attributed to these threads that run synchronously with
they system timer may be grossly in error.
The CPU load measurements are determined by sampling the active
tasks periodically at the occurrence to a timer expiration. By
default, the system clock is used to do that sampling.
tasks periodically at the occurrence to a timer expiration.
If tickless is enabled, SYSCLK should not be used. Its error will be
very large, and using it for analysis will lead to wrong conclusions.

config SCHED_CPULOAD_EXTCLK
bool "Use external clock"
Expand Down Expand Up @@ -1068,14 +1068,13 @@ endif # SCHED_CPULOAD_EXTCLK

config SCHED_CPULOAD_TIMECONSTANT
int "CPU load time constant"
depends on !SCHED_CPULOAD_NONE
default 2
---help---
The accumulated CPU count is divided by two when the accumulated
tick count exceeds this time constant. This time constant is in
units of seconds.

endif # SCHED_CPULOAD

menuconfig SCHED_INSTRUMENTATION
bool "System performance monitor hooks"
default n
Expand Down
10 changes: 5 additions & 5 deletions sched/misc/assert.c
Expand Up @@ -297,7 +297,7 @@ static void dump_task(FAR struct tcb_s *tcb, FAR void *arg)
size_t stack_filled = 0;
size_t stack_used;
#endif
#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
struct cpuload_s cpuload;
size_t fracpart = 0;
size_t intpart = 0;
Expand Down Expand Up @@ -349,7 +349,7 @@ static void dump_task(FAR struct tcb_s *tcb, FAR void *arg)
#ifdef CONFIG_STACK_COLORATION
" %7zu %3zu.%1zu%%%c"
#endif
#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
" %3zu.%01zu%%"
#endif
" %s%s\n"
Expand All @@ -375,7 +375,7 @@ static void dump_task(FAR struct tcb_s *tcb, FAR void *arg)
, stack_filled / 10, stack_filled % 10
, (stack_filled >= 10 * 80 ? '!' : ' ')
#endif
#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
, intpart, fracpart
#endif
#if CONFIG_TASK_NAME_SIZE > 0
Expand Down Expand Up @@ -431,7 +431,7 @@ static void dump_tasks(void)
#ifdef CONFIG_STACK_COLORATION
" USED FILLED "
#endif
#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
" CPU"
#endif
" COMMAND\n");
Expand All @@ -450,7 +450,7 @@ static void dump_tasks(void)
# ifdef CONFIG_STACK_COLORATION
" %7zu %3zu.%1zu%%%c"
# endif
# ifdef CONFIG_SCHED_CPULOAD
# ifndef CONFIG_SCHED_CPULOAD_NONE
" ----"
# endif
" irq\n"
Expand Down
2 changes: 1 addition & 1 deletion sched/sched/CMakeLists.txt
Expand Up @@ -91,7 +91,7 @@ elseif(CONFIG_SCHED_RESUMESCHEDULER)
list(APPEND SRCS sched_resumescheduler.c)
endif()

if(CONFIG_SCHED_CPULOAD)
if(NOT CONFIG_SCHED_CPULOAD_NONE)
list(APPEND SRCS sched_cpuload.c)
if(CONFIG_CPULOAD_ONESHOT)
list(APPEND SRCS sched_cpuload_oneshot.c)
Expand Down
2 changes: 1 addition & 1 deletion sched/sched/Make.defs
Expand Up @@ -68,7 +68,7 @@ else ifeq ($(CONFIG_SCHED_RESUMESCHEDULER),y)
CSRCS += sched_resumescheduler.c
endif

ifeq ($(CONFIG_SCHED_CPULOAD),y)
ifneq ($(CONFIG_SCHED_CPULOAD_NONE),y)
CSRCS += sched_cpuload.c
ifeq ($(CONFIG_CPULOAD_ONESHOT),y)
CSRCS += sched_cpuload_oneshot.c
Expand Down
2 changes: 1 addition & 1 deletion sched/sched/sched.h
Expand Up @@ -235,7 +235,7 @@ extern volatile int g_npidhash;

extern const struct tasklist_s g_tasklisttable[NUM_TASK_STATES];

#ifdef CONFIG_SCHED_CPULOAD
#ifndef CONFIG_SCHED_CPULOAD_NONE
/* This is the total number of clock tick counts. Essentially the
* 'denominator' for all CPU load calculations.
*/
Expand Down
4 changes: 0 additions & 4 deletions sched/sched/sched_cpuload.c
Expand Up @@ -32,8 +32,6 @@

#include "sched/sched.h"

#ifdef CONFIG_SCHED_CPULOAD

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
Expand Down Expand Up @@ -227,5 +225,3 @@ int clock_cpuload(int pid, FAR struct cpuload_s *cpuload)
leave_critical_section(flags);
return ret;
}

#endif /* CONFIG_SCHED_CPULOAD */