nuttx/libs/libc
dongjiuzhu1 6802d3510b sched/clock: support using CLOCKFD to call clock_getres
This patch extends CLOCKFD support to clock_getres(), allowing
applications to query the resolution of PTP clocks through file
descriptors using the standard POSIX clock API.

Key changes include:

1. Move clock_getres() from libc to kernel:
   - Relocated from libs/libc/sched/clock_getres.c to sched/clock/
   - Enables direct kernel-level file descriptor handling
   - Maintains POSIX compliance while adding CLOCKFD support

2. CLOCKFD support in clock_getres():
   - Detects CLOCKFD-encoded clockids using CLOCKFD_TO_FD() check
   - Extracts file descriptor from clockid parameter
   - Validates file descriptor through fs_getfilep()
   - Issues PTP_CLOCK_GETRES ioctl to query clock resolution

3. PTP clock resolution query:
   - Retrieves resolution from PTP clock device via ioctl
   - Returns nanosecond-precision timing resolution
   - Enables applications to determine clock accuracy capabilities
   - Falls back to standard clock resolution for non-CLOCKFD clockids

4. Error handling:
   - Returns EINVAL for invalid CLOCKFD file descriptors
   - Properly manages file reference counting with fs_putfilep()
   - Maintains backward compatibility with existing clock types

5. Build system updates:
   - Updated libs/libc/sched/CMakeLists.txt and Make.defs
   - Updated sched/clock/CMakeLists.txt to include clock_getres.c
   - Ensures proper compilation in kernel context

Usage example:
  int fd = open("/dev/ptp0", O_RDONLY);
  struct timespec res;
  clock_getres(CLOCKFD(fd), &res);  /* Query PTP clock resolution */
  printf("Resolution: %ld.%09ld sec\n", res.tv_sec, res.tv_nsec);
  close(fd);

This completes the basic POSIX clock API support for dynamic PTP clocks,
providing applications with comprehensive clock information access.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-12-30 10:22:09 -03:00
..
aio style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
assert libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
audio libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
builtin libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
ctype style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
dirent cmake:refine nuttx cmake build system fix CMake build missing part 2024-10-13 02:25:06 +08:00
dlfcn libs: unify Private Types banners 2025-05-28 10:17:15 +08:00
elf libc/libelf:fix bug for libelf_symname 2025-12-20 11:17:55 +08:00
errno libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
eventfd libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
fdt libs/libc/fdt/Make.defs: cannot move due to directory not empty bugfix 2024-10-09 15:42:17 +08:00
fixedmath libs: unify Private Types banners 2025-05-28 10:17:15 +08:00
gdbstub style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
gnssutils libc: remove reference to non-existent readme 2025-10-11 17:07:51 -04:00
grp libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
hex2bin stream_getc: use lib_stream_eof instead of EOF 2024-11-26 10:25:36 +08:00
inttypes libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
libgen libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
locale style/FAR: remove FAR qualifier 2025-11-10 10:56:29 +01:00
lzf libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
machine string:use builtin function to optimize libc function 2025-12-20 10:38:53 +08:00
misc lib/backtrace:need init lock before use 2025-12-22 15:23:04 +08:00
net libs: unify Private Types banners 2025-05-28 10:17:15 +08:00
netdb style/FAR: remove FAR qualifier 2025-11-10 10:56:29 +01:00
obstack libs/libc/obstack/lib_obstack_free.c: fix object check within chunk 2025-12-13 18:13:19 -03:00
pthread libc/pthread/pthread_keydelete.c: reset key value 2025-10-01 12:00:43 +08:00
pwd libs/libc/unistd: add getspnam function 2024-10-16 11:15:25 +08:00
queue libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
regex style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
sched sched/clock: support using CLOCKFD to call clock_getres 2025-12-30 10:22:09 -03:00
search libc/search: add foreach api for hcreate_data 2025-12-25 09:39:03 +08:00
semaphore sched/semaphore: add support to customize semaphore max allowed value 2025-09-04 09:48:34 +08:00
signal sched/signal: Fix nxsig_ismember() return value behavior 2025-11-25 10:02:52 +08:00
spawn cmake:refine nuttx cmake build system fix CMake build missing part 2024-10-13 02:25:06 +08:00
stdio libc/fclose: Validate the user provided stream pointer 2025-09-09 23:51:35 +08:00
stdlib libc: improve libc dependencies in case of LIBM_NONE 2025-12-14 17:57:27 -03:00
stream libc: improve libc dependencies in case of LIBM_NONE 2025-12-14 17:57:27 -03:00
string string:use builtin function to optimize libc function 2025-12-20 10:38:53 +08:00
symtab lib_libvsprintf.c:add option in Kconfig to control "%p*" special format specifier. 2024-10-15 15:33:13 +08:00
syslog drivers/syslog: Add RFC 5424 protocol support 2025-06-13 20:26:57 +08:00
termios libs: unify Private Types banners 2025-05-28 10:17:15 +08:00
time libc/localtime: rename offsetp to poffset 2025-12-19 13:46:21 -05:00
tls libc: Add debug assert to prevent tls allocation failure 2024-10-18 21:34:18 +08:00
uio move readv/writev to the kernel 2024-10-30 17:07:54 +08:00
unistd libc/unistd: Replace pipe() macro with proper function implementation 2025-11-26 17:18:13 +08:00
userfs style/FAR: remove FAR qualifier 2025-11-10 10:56:29 +01:00
uuid libc: Refine the arc4random_buf implementation 2024-10-26 18:04:21 -03:00
wchar style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
wctype libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
wqueue libs: unify Private Types banners 2025-05-28 10:17:15 +08:00
zoneinfo libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
.gitignore libc/elf: rename modlib to libelf 2025-04-11 09:43:22 +08:00
CMakeLists.txt libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
Kconfig libc/elf: rename modlib to libelf 2025-04-11 09:43:22 +08:00
libc.csv libc/unistd: Replace pipe() macro with proper function implementation 2025-11-26 17:18:13 +08:00
libc.h libc/machine:Add prefixes to libc functions implemented by arch 2024-10-31 18:11:16 +08:00
Makefile libc/elf: rename modlib to libelf 2025-04-11 09:43:22 +08:00