Implement Linux-compatible TFD_TIMER_CANCEL_ON_SET flag for timerfd to
allow applications to detect discontinuous changes to CLOCK_REALTIME.
Background:
According to Linux timerfd_create(2) man page, when a timerfd is created
with CLOCK_REALTIME and TFD_TIMER_CANCEL_ON_SET flag is specified, the
read() operation should fail with ECANCELED if the real-time clock
undergoes a discontinuous change. This allows applications to detect
and respond to system time changes.
Implementation:
1. Add clock notifier infrastructure (clock_notifier.h/c) to notify
interested parties when system time changes
2. Implement TFD_TIMER_CANCEL_ON_SET flag support in timerfd
3. Register timerfd with clock notifier when flag is set
4. Cancel timer and return ECANCELED when clock change is detected
5. Notify clock changes in:
- clock_settime()
- clock_initialize()
- clock_timekeeping_set_wall_time()
- rpmsg_rtc time synchronization
Changes include:
- New files: include/nuttx/clock_notifier.h, sched/clock/clock_notifier.c
- Modified: fs/vfs/fs_timerfd.c to handle TFD_TIMER_CANCEL_ON_SET
- Modified: clock subsystem to call notifier chain on time changes
- Modified: rpmsg_rtc to notify time changes during sync
Use case example:
Applications using timerfd with absolute time can now detect when
system time is adjusted (e.g., NTP sync, manual time change) and
take appropriate action such as recalculating timeouts or updating
scheduled events.
Reference: https://man7.org/linux/man-pages/man2/timerfd_create.2.html
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Export the sched_note_event_ip function as a syscall under
CONFIG_SCHED_INSTRUMENTATION_DUMP. This allows user-space or
other kernel components to trigger event-type logs via the
instrumentation dump mechanism.
Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
Add compilation condition for 'nx_vsyslog' syscall.
Export 'sched_note_printf_ip' syscall when CONFIG_SYSLOG_TO_SCHED_NOTE=y
Put the implementation of sched_note_printf_ip in libc/misc/lib_note.c
Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
Move pthread mutex operations from kernel-space syscall
interface to user-space implementations
to reduce syscall overhead. Relocate mutex holder list
tracking from task control block (tcb) to
thread local storage (tls) to improve memory layout and
cache efficiency. Add helper macros for
conditional mutex implementations and update syscall
interface accordingly.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
Add a new boardctl command BOARDIOC_MACADDR to retrieve the MAC address of the network interface.
The board_macaddr function needs to be implemented by the board logic.
Signed-off-by: daichuan <daichuan@xiaomi.com>
Add pid field to task_info_s and move getpid() implementation to user
space TLS access. Remove getpid from syscall interface as it now returns
cached PID from thread local storage instead of kernel lookup.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
Signals in NuttX serve two primary purposes:
1. Synchronization and wake-up:
Signals can be used to block threads on specific signal sets and later
wake them up by delivering the corresponding signals to those threads.
2. Asynchronous notification:
Signals can also be used to install callback handlers for specific signals, allowing threads to
asynchronously invoke those handlers when the signals are delivered.
This change introduces the ability to disable all signal functionality to reduce footprint for NuttX.
Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
Signals in NuttX serve two primary purposes:
1. Synchronization and wake-up:
Signals can be used to block threads on specific signal sets and later
wake them up by delivering the corresponding signals to those threads.
2. Asynchronous notification:
Signals can also be used to install callback handlers for specific signals, allowing threads to
asynchronously invoke those handlers when the signals are delivered.
This change introduces the ability to partially disable signal functionality: to disable only signal functions for
Asynchronous notification, keeping functions for Synchronization and wake-up.
This enables finer-grained control over signal usage while preserving existing behavior for supported use cases.
Co-authored-by: Guo Shichao guoshichao@xiaomi.com
Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
To ensure consistency, in all places where the "sendmsg" function is used
either directly or indirectly, the type of the "struct msghdr *msg" parameter
needs to be modified to "const struct msghdr *msg".
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
When cross-compiling PSE52 VSX testcases based on Vela, VSX defines its
own "OK" constant as a macro, which conflicts with the "OK" constant
defined as an enum in <sys/types.h>. To ensure compatibility, we
have undef'd the macro version of "OK" in advance.
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
1. According to the POSIX specification, the functions `pthread_kill`
and `pthread_sigmask` have been moved from `pthread.h` to `signal.h`.
2. As required by the POSIX standard, the pthread-related constants
have been relocated from `pthread.h` to `sys/types.h`.
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
Add the RLIM_NLIMITS macro with value 16 to sys/resource.h, indicating
the total number of supported resource limit types. This improves
POSIX header completeness and aids resource enumeration in applications.
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
Add the WCOREDUMP() macro to sys/wait.h to indicate whether a terminated
process produced a core dump. This resolves implicit declaration warnings
in LTP kernel testcases and improves POSIX compliance.
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
Update the WTERMSIG() macro to extract the signal number from the wait
status, changing from constant 'false' to '(((s) >> 8) & 0x7f)' to match
POSIX semantics for processes terminated by signals.
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
Add the generic _IO() macro and aliases for FS_IOC_GETFLAGS and FS_IOC_SETFLAGS,
aligning the ioctl.h definitions with the Linux kernel API to improve source
compatibility when porting LTP linux kernel testcase code to NuttX
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
This patch implements clock_adjtime() with CLOCKFD support, enabling
precise time and frequency adjustments for PTP clocks through the
standard POSIX clock API.
Key changes include:
1. New clock_adjtime() system call:
- Added sched/clock/clock_adjtime.c implementation
- Provides POSIX-compliant time adjustment interface
- Supports both standard clocks and CLOCKFD-based dynamic clocks
- Added CONFIG_CLOCK_ADJTIME Kconfig option
2. CLOCKFD support in clock_adjtime():
- Detects CLOCKFD-encoded clockids via CLOCKFD_TO_FD() check
- Extracts file descriptor and validates through fs_getfilep()
- Issues PTP_CLOCK_ADJTIME ioctl to underlying PTP clock device
- Returns clock status and adjustment results via struct timex
3. Enhanced struct timex support:
- Extended include/sys/timex.h with additional ADJ_* flags
- Added ADJ_OFFSET, ADJ_FREQUENCY, ADJ_MAXERROR, ADJ_ESTERROR
- Added ADJ_STATUS, ADJ_TIMECONST, ADJ_TAI, ADJ_SETOFFSET
- Added ADJ_MICRO, ADJ_NANO for time unit selection
- Added STA_* status flags for clock state reporting
4. Clock operations supported:
- ADJ_SETOFFSET: Apply time offset adjustment
- ADJ_FREQUENCY: Adjust clock frequency (PPM)
- ADJ_MAXERROR: Set maximum error estimate
- ADJ_ESTERROR: Set estimated error
- ADJ_STATUS: Modify clock status bits
- ADJ_NANO: Use nanosecond resolution
- ADJ_SETOFFSET: Set absolute time offset
5. API declarations:
- Added clock_adjtime() prototype in include/nuttx/clock.h
- Enabled by CONFIG_CLOCK_ADJTIME configuration
- Compatible with Linux clock_adjtime() interface
Usage example:
int fd = open("/dev/ptp0", O_RDWR);
struct timex tx = {0};
tx.modes = ADJ_FREQUENCY;
tx.freq = 10000000; /* Adjust frequency by 10 PPM */
clock_adjtime(CLOCKFD(fd), &tx);
close(fd);
This completes the PTP clock framework's POSIX clock API integration,
providing comprehensive time control capabilities for precision timing
applications including PTP synchronization daemons (ptp4l, timemaster).
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This patch introduces the foundational PTP (Precision Time Protocol) clock
driver framework for NuttX, enabling precise time synchronization support
based on IEEE 1588 standard.
Key changes include:
1. New PTP clock driver infrastructure:
- Added drivers/timers/ptp_clock.c implementing upper-half driver
- Created include/nuttx/timers/ptp_clock.h with PTP clock interfaces
- Implemented upper/lower half driver architecture for hardware abstraction
2. Core functionality:
- Clock time get/set operations (gettime, settime)
- Frequency adjustment support (adjtime, adjfine)
- Phase adjustment capabilities
- System-device cross-timestamping for precise synchronization
3. IOCTL commands:
- PTP_CLOCK_SETTIME/GETTIME for time manipulation
- PTP_CLOCK_GETRES for resolution queries
- PTP_CLOCK_ADJTIME for time adjustment
- PTP_CLOCK_GETCAPS for capability queries
- PTP_SYS_OFFSET* for system offset measurements
4. Supporting structures:
- struct ptp_lowerhalf_s: lower-half driver interface
- struct ptp_clock_caps: clock capabilities descriptor
- struct ptp_sys_offset: system time offset measurement
- Added timex structures in include/sys/timex.h for ADJ_* operations
5. Build system integration:
- Added CONFIG_PTP_CLOCK Kconfig option
- Updated CMakeLists.txt and Make.defs
- Added PTPCLK debug macros in include/debug.h
This framework provides the base for PTP clock implementations, allowing
hardware-specific drivers to register and provide precise time services
through a standardized interface.
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
These macros are commonly provided on BSD systems. They are not part of
C nor POSIX but these types of operations can be required in drivers
implementation as well as in user space. The operations themself are
simple but kind of cryptic when placed in the code as is. Thus having
macro with an appropriate name is beneficial.
The use of BSD naming here is only to cling to at least some other
implementation instead of creating completelly NuttX specific one.
Kudos to @hartmannathan for the source code documentation.
Signed-off-by: Karel Kočí <kkoci@elektroline.cz>
packing the internal substructures will reduce the overall alignment of
`sockaddr_storage` to 2, which triggers an unaligned access warning
in 32-bit systems.
Add an overall 8-byte alignment to the outermost layer of the structure.
Related commit: 855336bf
Refer to https://datatracker.ietf.org/doc/html/rfc2553#section-3.10
Signed-off-by: nuttxs <zhaoqing.zhang@sony.com>
To save more space (equivalent to the size of one erase sector of
MTD device) and to achieve faster read and write speeds, a method
for direct writing was introduced at the FTL layer.
This can be accomplished simply by using the following oflags during
the open operation:
1. O_DIRECT. when this flag is passed in, ftl internally uses
the direct write strategy and no read cache is used in ftl;
otherwise, each write will be executed with the minimum
granularity of flash erase sector size which means a
"sector read back - erase sector - write sector" operation
is performed by using a read cache buffer in heap.
2. O_SYNC. When this flag is passed in, we assume that the
flash has been erased in advance and no erasure operation
will be performed internally within ftl. O_SYNC will take
effect only when both O_DIRECT and O_SYNC are passed in
simultaneously.
3. For uniformity, we remapped the mount flag in mount.h and
unified it with the open flag in fcntl.h. The repetitive
parts of their definitions were reused, and the remaining
part of the mount flag redefine to the unused bit of open
flags.
Signed-off-by: jingfei <jingfei@xiaomi.com>
Allow users to operate poll in the kernel using the file_poll
approach, as file is protected with reference counting,
making it more secure.
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
There is no need for a gettid() syscall, as the thread ID is stable through
the life of the process. It is safe to put a copy of TID to TLS. This way
a user processes can access TID quickly via its own stack, instead of
having to use an expensive syscall.
Signed-off-by: Ville Juven <ville.juven@unikie.com>
This avoids unnecessary syscalls in memory protected builds, when mutex
lock/unlock can be done with only atomic counter access
Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
reason:
new implementation does not requires the use of enter_critical_section,
so the source code needs to be moved to user space
This reverts commit d189a86a35.
This patch fixed userspace headers conflict. Architecture-related definition and API should not be exposed to users.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
currently, nuttx implements readv/writev on the top of read/write.
while it might work for the simplest cases, it's broken by design.
for example, it's impossible to make it work correctly for files
which need to preserve data boundaries without allocating a single
contiguous buffer. (udp socket, some character devices, etc)
this change is a start of the migration to a better design.
that is, implement read/write on the top of readv/writev.
to avoid a single huge change, following things will NOT be done in
this commit:
* fix actual bugs caused by the original readv-based-on-read design.
(cf. https://github.com/apache/nuttx/pull/12674)
* adapt filesystems/drivers to actually benefit from the new interface.
(except a few trivial examples)
* eventually retire the old interface.
* retire read/write syscalls. implement them in libc instead.
* pread/pwrite/preadv/pwritev (except the introduction of struct uio,
which is a preparation to back these variations with the new
interface.)
gprof can analyze code hot spots based on scheduled sampling.
After adding the "-pg" parameter when compiling, you can view the code call graph.
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>