Commit Graph

1539 Commits

Author SHA1 Message Date
Sebastian Huber
bc5b56ad41 libio: Use API mutex 2017-12-06 07:13:04 +01:00
Sebastian Huber
6c2b8a4b35 score: Use self-contained API mutex
Use a self-contained recursive mutex for API_Mutex_Control.  The API
mutexes are protected against asynchronous thread cancellation.

Add dedicated mutexes for libatomic and TOD.

Close #2629.
Close #2630.
2017-12-04 10:53:39 +01:00
Sebastian Huber
15e19273b2 sapi: New implementation of rtems_panic()
The previous rtems_panic() implementation was quite heavy weight.  It
depended on _exit() which calls the global destructors.  It used
fprintf(stderr, ...) for output which depends on an initialized console
device and the complex fprintf().

Introduce a new fatal source RTEMS_FATAL_SOURCE_PANIC for rtems_panic()
and output via vprintk().

Update #3244.
2017-11-22 09:40:23 +01:00
Sebastian Huber
cd3e2204c7 INTERNAL_ERROR_POSIX_INIT_THREAD_ENTRY_IS_NULL
Delete superfluous INTERNAL_ERROR_POSIX_INIT_THREAD_ENTRY_IS_NULL.

Update #3243.
2017-11-22 09:40:23 +01:00
Sebastian Huber
a7dcef97e9 score: Simplify global construction
Update #3243.
2017-11-22 09:40:22 +01:00
Sebastian Huber
c597fb166e score: Optimize scheduler priority updates
Thread priority changes may append or prepend the thread to its priority
group on the scheduler ready queue.  Previously, a separate priority
value and a prepend-it flag in the scheduler node were used to propagate
a priority change to the scheduler.

Now, use an append-it bit in the priority control and reduce the plain
priority value to 63 bits.

This change leads to a significant code size reduction (about 25%) of
the SMP schedulers.  The negligible increase of the standard priority
scheduler is due to some additional shift operations
(SCHEDULER_PRIORITY_MAP() and SCHEDULER_PRIORITY_UNMAP()).

Before:

   text filename
    136 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulersimpleblock.o
    464 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulersimplechangepriority.o
     24 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulersimple.o
    108 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulersimpleschedule.o
    292 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulersimpleunblock.o
    264 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulersimpleyield.o

   text filename
    280 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulerpriorityblock.o
    488 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulerprioritychangepriority.o
    200 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulerpriority.o
    164 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulerpriorityschedule.o
    328 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulerpriorityunblock.o
    200 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulerpriorityyield.o

   text filename
  24112 arm-rtems5/c/imx7/cpukit/score/src/libscore_a-scheduleredfsmp.o

   text filename
  37204 sparc-rtems5/c/gr740/cpukit/score/src/libscore_a-scheduleredfsmp.o

   text filename
  42236 powerpc-rtems5/c/qoriq_e6500_32/cpukit/score/src/libscore_a-scheduleredfsmp.o

After:

   text filename
    136 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulersimpleblock.o
    272 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulersimplechangepriority.o
     24 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulersimple.o
    108 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulersimpleschedule.o
    292 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulersimpleunblock.o
    264 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulersimpleyield.o

   text filename
    280 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulerpriorityblock.o
    488 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulerprioritychangepriority.o
    208 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulerpriority.o
    164 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulerpriorityschedule.o
    332 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulerpriorityunblock.o
    200 sparc-rtems5/c/erc32/cpukit/score/src/libscore_a-schedulerpriorityyield.o

   text filename
  18860 arm-rtems5/c/imx7/cpukit/score/src/libscore_a-scheduleredfsmp.o

   text filename
  28520 sparc-rtems5/c/gr740/cpukit/score/src/libscore_a-scheduleredfsmp.o

   text filename
  32664 powerpc-rtems5/c/qoriq_e6500_32/cpukit/score/src/libscore_a-scheduleredfsmp.o
2017-11-20 08:36:49 +01:00
Christian Mauderer
ddc339c51f cpukit: Add _arc4random_getentropy_fail.
Add a default implementation of _arc4random_getentropy_fail with an
internal error.

Update #3239.
2017-11-17 07:26:41 +01:00
Sebastian Huber
91a2d5e68b score: Adjust _Scheduler_EDF_SMP_Insert_ready()
Use only one parameter to compute the next generation.  Use index 0 for
LIFO ordering, and index 1 for FIFO ordering.
2017-11-17 06:55:10 +01:00
Sebastian Huber
5f02a57478 score: Change _Timecounter_Time_uptime to int32_t
Move basic timecounter API shared with BSD network stack to
<machine/_timecounter.h>.

Update #3185.
2017-11-09 08:12:12 +01:00
Sebastian Huber
64ba1a9606 posix: Change created_with_explicit_scheduler
Remove POSIX_API_Control::created_with_explicit_scheduler.  Add
Thread_Control::was_created_with_inherited_scheduler.  This fixes also
pthread_getattr_np() for Classic tasks.

Update #2514.
2017-11-09 08:12:11 +01:00
Sebastian Huber
fb272963a6 score: Use Processor_mask instead of cpu_set_t 2017-11-06 09:06:21 +01:00
Sebastian Huber
0c286e3d7c score: _Chain_Insert_ordered_unprotected()
Change the chain order relation to use a directly specified left hand
side value.  This is similar to _RBTree_Insert_inline() and helps the
compiler to better optimize the code.
2017-11-06 09:06:21 +01:00
Sebastian Huber
bceb9db600 score: Remove superfluous include
Update #3059.
2017-11-06 09:06:21 +01:00
Sebastian Huber
10827984c2 score: Add _IO_Printf() and _IO_Vprintf()
The previous vprintk() implementation had a questionable licence header,
lacks support for the 'z' and 'j' format specifiers, is not robust
against invalid format specifiers, uses a global variable for output.
Replace it with a stripped down version of the FreeBSD kernel kvprintf()
function.

The new implementation allows a low overhead rtems_snprintf() if
necessary.

Update #3199.
Close #3216.
2017-11-06 07:25:51 +01:00
Sebastian Huber
3e81d52e27 posix: Use far future for very long timeouts
Close #3205.
2017-11-02 14:08:32 +01:00
Sebastian Huber
4edcede7e9 score: Simplify SMP get lowest scheduled
There is no need to pass in the order relation since the scheduled
threads reside on an already ordered chain.  The caller will decide what
to do with the lowest scheduled thread.
2017-10-28 13:08:53 +02:00
Sebastian Huber
8388ceea05 score: Delete _Scheduler_Thread_set_priority() 2017-10-26 09:07:40 +02:00
Sebastian Huber
c310589474 score: Move thread queue timeout handling
Update #3117.
Update #3182.
2017-10-24 10:19:05 +02:00
Sebastian Huber
1666ffe535 score: Rename function threadq support function
Rename _Thread_queue_Context_set_do_nothing_enqueue_callout() into
_Thread_queue_Context_set_enqueue_do_nothing_extra().  More
_Thread_queue_Context_set_enqueue_*() functions will follow.

Update #3117.
Update #3182.
2017-10-24 09:37:28 +02:00
Sebastian Huber
6de1f92121 score: Add _Thread_Continue()
Update #3117.
Update #3182.
2017-10-24 09:37:28 +02:00
Sebastian Huber
5747962909 score: _Watchdog_Per_CPU_lazy_insert_monotonic()
Update #3117.
Update #3182.
2017-10-24 09:37:28 +02:00
Sebastian Huber
b13ec80476 score: Add _Watchdog_Monotonic_from_timespec()
Update #3117.
Update #3182.
2017-10-24 09:37:28 +02:00
Sebastian Huber
cea5ff7001 score: Add _Watchdog_Nanoseconds_per_tick
Move it from the configuration to a separate variable.

Update #3117.
Update #3182.
2017-10-24 09:37:28 +02:00
Sebastian Huber
7ed377bc69 score: _Watchdog_Is_far_future_monotonic_timespec
Update #3117.
Update #3182.
2017-10-24 09:37:28 +02:00
Sebastian Huber
d16d07fbb8 score: Add _Watchdog_Is_valid_interval_timespec()
Update #3117.
Update #3182.
2017-10-24 09:37:27 +02:00
Sebastian Huber
adaf5c232e score: _Watchdog_Is_far_future_realtime_timespec()
Update #3117.
Update #3182.
2017-10-24 09:37:27 +02:00
Sebastian Huber
ecef369875 score: Rename _Watchdog_Ticks_from_*()
Rename _Watchdog_Ticks_from_*() to _Watchdog_Realtime_from_*().

This highlights that these routines are used for the CLOCK_REALTIME
watchdogs (in contrast to CLOCK_MONOTONIC).

Update #3117.
Update #3182.
2017-10-24 09:37:27 +02:00
Sebastian Huber
27cfe7c86b score: Add _Watchdog_Ticks_per_second
This value is frequently used.  Avoid the function call overhead and the
integer division at run-time.

Update #3117.
Update #3182.
2017-10-24 09:37:22 +02:00
Sebastian Huber
028786263f score: Add _Thread_Add_timeout_ticks()
Replace _Thread_Timer_insert_monotonic() with
_Thread_Add_timeout_ticks().

Update #3117.
Update #3182.
2017-10-24 09:29:59 +02:00
Sebastian Huber
91ce012ced score: Rename _Watchdog_Per_CPU_insert_monotonic()
Rename _Watchdog_Per_CPU_insert_monotonic() in
_Watchdog_Per_CPU_insert_ticks().

Update #3117.
Update #3182.
2017-10-17 08:15:40 +02:00
Sebastian Huber
bf2a53d272 score: Rename watchdog variants
Rename PER_CPU_WATCHDOG_RELATIVE in PER_CPU_WATCHDOG_MONOTONIC to
highlight the corresponding POSIX CLOCK_MONOTONIC.

Rename PER_CPU_WATCHDOG_ABSOLUTE in PER_CPU_WATCHDOG_REALTIME to
highlight the corresponding POSIX CLOCK_REALTIME.

Update #3117.
Update #3182.
2017-10-17 08:15:40 +02:00
Sebastian Huber
6c99abd14f score: Remove unused function declaration 2017-10-12 11:42:45 +02:00
Sebastian Huber
d8b6f1c10f timecounter: Update FreeBSD identifiers
Update #3175.
2017-10-12 07:05:07 +02:00
Konstantin Belousov
748871578c timecounter: Merge FreeBSD change r304285
Implement userspace gettimeofday(2) with HPET timecounter.

Right now, userspace (fast) gettimeofday(2) on x86 only works for
RDTSC.  For older machines, like Core2, where RDTSC is not C2/C3
invariant, and which fall to HPET hardware, this means that the call
has both the penalty of the syscall and of the uncached hw behind the
QPI or PCIe connection to the sought bridge.  Nothing can me done
against the access latency, but the syscall overhead can be removed.
System already provides mappable /dev/hpetX devices, which gives
straight access to the HPET registers page.

Add yet another algorithm to the x86 'vdso' timehands. Libc is updated
to handle both RDTSC and HPET.  For HPET, the index of the hpet device
to mmap is passed from kernel to userspace, index might be changed and
libc invalidates its mapping as needed.

Remove cpu_fill_vdso_timehands() KPI, instead require that
timecounters which can be used from userspace, to provide
tc_fill_vdso_timehands{,32}() methods.  Merge i386 and amd64
libc/<arch>/sys/__vdso_gettc.c into one source file in the new
libc/x86/sys location.  __vdso_gettc() internal interface is changed
to move timecounter algorithm detection into the MD code.

Measurements show that RDTSC even with the syscall overhead is faster
than userspace HPET access.  But still, userspace HPET is three-four
times faster than syscall HPET on several Core2 and SandyBridge
machines.

Tested by:	Howard Su <howard0su@gmail.com>
Sponsored by:	The FreeBSD Foundation
MFC after:	1 month
Differential revision:	https://reviews.freebsd.org/D7473

Update #3175.
2017-10-12 07:04:11 +02:00
Konstantin Belousov
d310aa7c61 timecounter: Merge FreeBSD change r303382
Hide the boottime and bootimebin globals, provide the getboottime(9) and getboottimebin(9) KPI. Change consumers of boottime to use the KPI. The variables were renamed to avoid shadowing issues with local variables of the same name.

Issue is that boottime* should be adjusted from tc_windup(), which
requires them to be members of the timehands structure.  As a
preparation, this commit only introduces the interface.

Some uses of boottime were found doubtful, e.g. NLM uses boottime to
identify the system boot instance.  Arguably the identity should not
change on the leap second adjustment, but the commit is about the
timekeeping code and the consumers were kept bug-to-bug compatible.

Tested by:	pho (as part of the bigger patch)
Reviewed by:	jhb (same)
Discussed with:	bde
Sponsored by:	The FreeBSD Foundation
MFC after:	1 month
X-Differential revision:	https://reviews.freebsd.org/D7302

Update #3175.
2017-10-12 07:04:11 +02:00
Pedro Giffuni
f6c9460160 timecounter: Merge FreeBSD change r298981
sys/sys: minor spelling fixes.

While the changes are minor, these headers are very visible.

MFC after:	2 weeks

Update #3175.
2017-10-12 07:04:11 +02:00
Ian Lepore
2b6d00f533 timecounter: Merge FreeBSD change r304285
Constify the pointers to eventtimer and timecounter name strings.

The need for this appears as soon as you try to set the names to something
that isn't a "quoted literal".  (I'm actually confused why quoted strings
aren't a problem as well, we must have some warning disabled.)

Update #3175.
2017-10-12 07:04:10 +02:00
Ian Lepore
51304ddeb7 timecounter: Merge FreeBSD change r282424
Implement a mechanism for making changes in the kernel<->driver PPS interface without breaking ABI or API compatibility with existing drivers.

The existing data structures used to communicate between the kernel and
driver portions of PPS processing contain no spare/padding fields and no
flags field or other straightforward mechanism for communicating changes
in the structures or behaviors of the code.  This makes it difficult to
MFC new features added to the PPS facility.  ABI compatibility is
important; out-of-tree drivers in module form are known to exist.  (Note
that the existing api_version field in the pps_params structure must
contain the value mandated by RFC 2783 and any RFCs that come along after.)

These changes introduce a pair of abi-version fields which are filled in
by the driver and the kernel respectively to indicate the interface
version.  The driver sets its version field before calling the new
pps_init_abi() function.  That lets the kernel know how much of the
pps_state structure is understood by the driver and it can avoid using
newer fields at the end of the structure that it knows about if the driver
is a lower version.  The kernel fills in its version field during the init
call, letting the driver know what features and data the kernel supports.

To implement the new version information in a way that is backwards
compatible with code from before these changes, the high bit of the
lightly-used 'kcmode' field is repurposed as a flag bit that indicates the
driver is aware of the abi versioning scheme.  Basically if this bit is
clear that indicates a "version 0" driver and if it is set the driver_abi
field indicates the version.

These changes also move the recently-added 'mtx' field of pps_state from
the middle to the end of the structure, and make the kernel code that uses
this field conditional on the driver being abi version 1 or higher.  It
changes the only driver currently supplying the mtx field, usb_serial, to
use pps_init_abi().

Reviewed by:	hselasky@

Update #3175.
2017-10-12 07:04:09 +02:00
Hans Petter Selasky
ea0b339bbc timecounter: Merge FreeBSD change r279728
Add mutex support to the pps_ioctl() API in the kernel. Bump kernel version to reflect structure change.

PR:		196897
MFC after:	1 week

Update #3175.
2017-10-12 07:04:09 +02:00
Sebastian Huber
b2dbb634ec score: Remove CPU_set_Control
Use Processor_mask instead.

Update #2514.
2017-10-11 07:37:58 +02:00
Sebastian Huber
db3a3decbd score: Add _Thread_queue_Dispatch_disable() 2017-10-10 10:03:48 +02:00
Sebastian Huber
65012bfebb score: Change Timestamp_Control to sbintime_t
The timestamp are based on the uptime.  There is no need for a 64-bit
seconds part.  The signed 32-bit seconds part of the sbintime_t limits
the uptime to roughly 68 years.

Close #2740.
2017-10-09 08:30:07 +02:00
Sebastian Huber
2256946e9c score: Use struct timespec for TOD
Use the timestamps only for uptime based values.  Use struct timespec
for the absolute time values (TOD).

Update #2740.
2017-10-09 08:30:03 +02:00
Sebastian Huber
c0623a9941 score: Simplify _Timestamp_Add_to()
Update #2740.
2017-10-09 08:17:17 +02:00
Sebastian Huber
de59c065c5 posix: Implement self-contained POSIX mutex
POSIX mutexes are now available in all configurations and no longer
depend on --enable-posix.

Update #2514.
Update #3112.
2017-10-05 14:29:02 +02:00
Sebastian Huber
5222488573 posix: Implement self-contained POSIX condvar
POSIX condition variables are now available in all configurations and no
longer depend on --enable-posix.

Update #2514.
Update #3113.
2017-10-05 14:29:02 +02:00
Sebastian Huber
89fc9345de posix: Implement self-contained POSIX rwlocks
POSIX rwlocks are now available in all configurations and no longer
depend on --enable-posix.

Update #2514.
Update #3115.
2017-10-05 14:29:02 +02:00
Sebastian Huber
e67929c4c0 posix: Implement self-contained POSIX barriers
POSIX barriers are now available in all configurations and no longer
depend on --enable-posix.

Update #2514.
Update #3114.
2017-10-05 14:29:01 +02:00
Sebastian Huber
c090db7405 posix: Implement self-contained POSIX semaphores
For semaphore object pointer and object validation see
POSIX_SEMAPHORE_VALIDATE_OBJECT().

Destruction or close of a busy semaphore returns an error status.  The
object is not flushed.

POSIX semaphores are now available in all configurations and no longer
depend on --enable-posix.

Update #2514.
Update #3116.
2017-10-05 14:29:01 +02:00
Sebastian Huber
47b1e31f11 posix: Optimize pthread_once_t
Reduce size of pthread_once_t and make it zero-initialized.

Update #3142.
2017-10-05 14:29:01 +02:00