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>
Some app with same code runs on different cores in AMP mode,
need known physical core id on which the function is called.
Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.
Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
Summary:
1.Added msync callback in struct mm_map_entry_s
2.Added msync API in fs_msync.c
3.Added static msync_rammap for rammap.
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
This interface may be used by application specific logic to start
specified slave cpu core under the pseudo AMP case which is different
with armv7-a/armv8-a SMP. Support for this function is required by
board-level logic if CONFIG_BOARDCTL_START_CPU is selected.
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
According to the mmap(2) specification, anonymous pages should be initialized to zero unless the MAP_UNINITIALIZED is specified.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit add MADV_HUGEPAGE and MADV_NOHUGEPAGE definitions for madvise. Notice that none of these flags have been implemented yet.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
reason:
BOARDIOC_SPINLOCK can support the combined semantics
of disabling interrupts (irq), trylock, and spinlock.
Signed-off-by: hujun5 <hujun5@xiaomi.com>