nuttx/include/sys
dongjiuzhu1 752a405f86 sched/clock: support using CLOCKFD to call clock_adjtime
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>
2025-12-30 10:22:09 -03:00
..
boardctl.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
custom_file.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
endian.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
epoll.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
eventfd.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
fcntl.h fcntl: add sys/fcntl.h header file 2024-12-20 11:46:14 -03:00
file.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
gmon.h libs: add gprof arm64 support 2024-10-10 18:46:51 +08:00
inotify.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
ioctl.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
ipc.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
mman.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
mount.h drivers/fs: Control the behavior of FTL by passing oflags during the open process. 2025-07-16 14:11:41 +08:00
msg.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
param.h include: add BSD rounding macros to sys/param.h 2025-11-24 14:11:41 +08:00
pciio.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
poll.h fs/poll: remove poll_fdsetup 2025-05-26 18:49:45 +08:00
prctl.h proctl: add PR_SET_DUMPABLE support 2024-12-20 11:46:14 -03:00
queue.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
random.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
resource.h sys/resource: add RLIMIT_NICE consntant 2024-12-20 11:46:14 -03:00
select.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
sem.h sem: add sys/sem.h header file 2024-12-20 11:46:14 -03:00
sendfile.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
shm.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
signal.h signal: add include/sys/signal.h to the signal 2024-12-20 11:46:14 -03:00
signalfd.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
socket.h net/ethernet: add timestamp for socket packet 2025-12-10 23:44:14 +08:00
sockio.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
stat.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
statfs.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
statvfs.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
syscall.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
syscall_lookup.h sched/gettid: Move thread ID to TLS 2025-04-08 22:53:10 +08:00
sysinfo.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
sysmacros.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
time.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
timerfd.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
times.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
timex.h sched/clock: support using CLOCKFD to call clock_adjtime 2025-12-30 10:22:09 -03:00
tree.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
types.h sys/types.h: add loff_t data type definition 2024-12-20 11:46:14 -03:00
uio.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
un.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
utsname.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
vfs.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
video_controls.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00
videoio.h style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
wait.h include: migrate to SPDX identifier 2024-10-04 08:18:42 +08:00