Files
nuttx/sched/clock/clock.h
wangchengdong 54adf5979c sched/clock: Add clock_increase_sched_ticks() and clock_get_sched_ticks()
In the current NuttX kernel implementation, there is no function
    to represent pure scheduler ticks.
    The existing clock_systime_ticks() cannot serve this purpose,
    because it keeps increasing even when the scheduler is not running.
    This happens since the returned value reflects real hardware time:
    as long as the timer or alarm hardware is active,
    clock_systime_ticks() will continuously increase.

    This patch introduces two new functions that provide access to
    scheduler ticks — a counter that only increases when the scheduler
    itself is running.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-10-18 20:07:59 +08:00

100 lines
3.2 KiB
C

/****************************************************************************
* sched/clock/clock.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __SCHED_CLOCK_CLOCK_H
#define __SCHED_CLOCK_CLOCK_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <nuttx/clock.h>
#include <nuttx/compiler.h>
#include <nuttx/spinlock_type.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* 32-bit mask for 64-bit timer values */
#define TIMER_MASK32 0x00000000ffffffff
/* Configuration ************************************************************/
/* If CONFIG_SYSTEM_TIME64 is selected and the CPU supports long long types,
* then a 64-bit system time will be used.
*/
#ifndef CONFIG_HAVE_LONG_LONG
# undef CONFIG_SYSTEM_TIME64
#endif
/****************************************************************************
* Public Type Definitions
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#if !defined(__HAVE_KERNEL_GLOBALS)
/* The system clock exists (CONFIG_SCHED_TICKLESS), but it not prototyped
* globally in include/nuttx/clock.h.
*/
extern volatile clock_t g_system_ticks;
#endif
#ifndef CONFIG_CLOCK_TIMEKEEPING
extern struct timespec g_basetime;
extern spinlock_t g_basetime_lock;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
int clock_basetime(FAR struct timespec *tp);
void clock_initialize(void);
void clock_increase_sched_ticks(clock_t ticks);
clock_t clock_get_sched_ticks(void);
/****************************************************************************
* perf_init
****************************************************************************/
void perf_init(void);
#ifdef CONFIG_SCHED_CPULOAD_SYSCLK
void cpuload_init(void);
#endif
#endif /* __SCHED_CLOCK_CLOCK_H */