Commit Graph

108 Commits

Author SHA1 Message Date
Gregory Nutt
9f80e4ccf1 sched/: Various fixes for typos, improved parameter verification. 2018-01-12 18:26:45 -06:00
Masayuki Ishikawa
e1f71f988b sched/semaphore/spinlock.c: Add memory barrier operations in spin_unlock()
In ARM document regarding memory barrires, SP_DMB() must be issued
before changing a spinlock state to SP_UNLOCKED. However, we found
that SP_DSB() is also needed to ensure that spin_unlock() works
correctly for network streaming aging test.

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2017-12-21 17:40:08 +09:00
Masayuki Ishikawa
5acd26c88f sched/semaphore/spinlock.c: Disable local interrupts in spin_setbit() and spin_clrbit() in order to avoid a deadlock condition. 2017-11-23 06:55:53 -06:00
Gregory Nutt
e7c52bac60 Squashed commit of the following:
sched/mqueue:  Rename all private static functions for use the nxmq_ vs. mq_ naming.

    sched/mqueue:  Rename all OS internal functions declared in sched/mqueue/mqueue.h to begin with nxmq_ vs. mq_.  The mq_ prefix is reserved for standard application interfaces.
2017-10-09 09:06:46 -06:00
Gregory Nutt
21c97b16cf Revert "sem_wait.c edited online with Bitbucket. Fix some correct but useless code."
What was I thinking?  I missed that litle minus sign and the possibility that the errno might be some positive non-zero value.

This reverts commit 43880878e4.
2017-10-05 16:01:01 -06:00
Gregory Nutt
43880878e4 sem_wait.c edited online with Bitbucket. Fix some correct but useless code. 2017-10-05 21:55:24 +00:00
Gregory Nutt
8198ba6a6d This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_
This is analogous to similar renaming that was done previously for semaphores.

Squashed commit of the following:

    sched/signal:  Fix a few compile warnings introduced by naming changes.

    sched/signal:  Rename all private, internal signl functions to use the nxsig_ prefix.

    sched/signal:  Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces.

    sched/signal:  Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces.

    sched/signal:  Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces.

    sched/signal:  Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces.

    sched/signal:  Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces.

    sched/signal:  Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces.

    sched/signal:  Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 13:25:25 -06:00
Gregory Nutt
7cc63f90d9 sched/semaphore: sem_trywait() modifies the errno value and, hence, should not be used within the OS. Use nxsem_trywait() instead. 2017-10-05 07:59:06 -06:00
Gregory Nutt
29b5b3667f sched/semaphore: sem_timedwait() is a cancellation point and, hence, cannot be called from within the OS. Created nxsem_timedwait() that is equivalent but does not modify the errno and does not cause cancellation. All calls to sem_timedwait() change to calls to nxsem_timedwait() in the OS. 2017-10-05 07:24:54 -06:00
Gregory Nutt
9568600ab1 Squashed commit of the following:
This commit backs out most of commit b4747286b1.  That change was added because sem_wait() would sometimes cause cancellation points inappropriated.  But with these recent changes, nxsem_wait() is used instead and it is not a cancellation point.

    In the OS, all calls to sem_wait() changed to nxsem_wait().  nxsem_wait() does not return errors via errno so each place where nxsem_wait() is now called must not examine the errno variable.

    In all OS functions (not libraries), change sem_wait() to nxsem_wait().  This will prevent the OS from creating bogus cancellation points and from modifying the per-task errno variable.

    sched/semaphore:  Add the function nxsem_wait().  This is a new internal OS interface.  It is functionally equivalent to sem_wait() except that (1) it is not a cancellation point, and (2) it does not set the per-thread errno value on return.
2017-10-04 15:22:27 -06:00
Gregory Nutt
42a0796615 Squashed commit of the following:
sched/semaphore:  Add nxsem_post() which is identical to sem_post() except that it never modifies the errno variable.  Changed all references to sem_post in the OS to nxsem_post().

    sched/semaphore:  Add nxsem_destroy() which is identical to sem_destroy() except that it never modifies the errno variable.  Changed all references to sem_destroy() in the OS to nxsem_destroy().

    libc/semaphore and sched/semaphore:  Add nxsem_getprotocol() and nxsem_setprotocola which are identical to sem_getprotocol() and set_setprotocol() except that they never modifies the errno variable.  Changed all references to sem_setprotocol in the OS to nxsem_setprotocol().  sem_getprotocol() was not used in the OS
2017-10-03 15:35:24 -06:00
Gregory Nutt
83cdb0c552 Squashed commit of the following:
libc/semaphore:  Add nxsem_getvalue() which is identical to sem_getvalue() except that it never modifies the errno variable.  Changed all references to sem_getvalue in the OS to nxsem_getvalue().

    sched/semaphore:  Rename all internal private functions from sem_xyz to nxsem_xyz.  The sem_ prefix is (will be) reserved only for the application semaphore interfaces.

    libc/semaphore:  Add nxsem_init() which is identical to sem_init() except that it never modifies the errno variable.  Changed all references to sem_init in the OS to nxsem_init().

    sched/semaphore:  Rename sem_tickwait() to nxsem_tickwait() so that it is clear this is an internal OS function.

    sched/semaphoate:  Rename sem_reset() to nxsem_reset() so that it is clear this is an internal OS function.
2017-10-03 12:52:31 -06:00
Arjun Hary
b274a97840 Miscellaneous fixes from astyle tool. 2017-08-14 17:19:27 -06:00
Gregory Nutt
2245dddaf9 Break up some long lines 2017-06-14 13:42:56 -06:00
Gregory Nutt
d5207efb5a Be consistent... Use Name: consistent in function headers vs Function: 2017-04-21 16:33:14 -06:00
Jussi Kivilinna
c57d49f420 clock: Add new type ssystime_t for relative 64-bit ticks, change ticks<->time conversion functions to use ssystime_t 2017-04-21 08:51:31 -06:00
Gregory Nutt
6893843cc5 sched/semaphore: Fix a warning aout an unused variable when priority inheritance is enabled. 2017-03-21 13:47:56 -06:00
Gregory Nutt
e8e3c2f362 sched/semaphore: Convert strange use of DEBUGASSERT to DEBUGPANIC. 2017-03-21 13:34:17 -06:00
David Sidrane
d76157db7b sem_holder:Clean up from Review
Spelling and backward DEBUGASSERT along with one gem

  if (sem->holder[0].htcb != NULL || sem->holder[**1**].htcb != NULL)
2017-03-21 08:03:06 -10:00
David Sidrane
7601a27cee sem_holder:The logic for the list version is unchanged 2017-03-16 14:16:18 -10:00
David Sidrane
3cc2a4f7c9 sem_holder: Fixes improper restoration of base_priority
in the case of CONFIG_SEM_PREALLOCHOLDERS=0

   The call to sem_restorebaseprio_task context switches in the
   sem_foreachholder(sem, sem_restoreholderprioB, stcb); call
   prior to releasing the holder. So the running task is left
   as a holder as is the started task. Leaving both slots filled
   Thus failing to perforem the boost/or restoration on the
   correct tcb.

   This PR fixes this by releasing the running task slot prior
   to reprioritization that can lead to the context switch.
   To faclitate this, the interface to sem_restorebaseprio
   needed to take the tcb from the holder prior to the
   holder being freed. In the failure case where sched_verifytcb
   fails it added the overhead of looking up the holder.

   There is also the adfitinal thunking on the foreach to
   get from holer to holder->tcb.

   An alternate approach could be to leve the interface the same
   and allocate a holder on the stack of sem_restoreholderprioB
   copy the sem's holder to it, free it as is done in this pr
   and and then pass that address sem_restoreholderprio as the
   holder. It could then get the holder's tcb but we would
   keep the same sem_findholder in sched_verifytcb.
2017-03-15 17:12:45 -10:00
David Sidrane
caf8bac7fb missing semi 2017-03-13 22:54:13 +00:00
David Sidrane
d66fd9f965 semaphore:sem_boostholderprio prevent overrun of pend_reprios
The second case rtcb->sched_priority <= htcb->sched_priority
  did not check if there is sufficient space in the pend_reprios
  array.
2017-03-13 12:34:39 -10:00
David Sidrane
3c00651cfe semaphore:sem_holder sem_findholder missing inintalization of pholder
sem_findholder would fail and code optimization coverd this up.
2017-03-13 11:56:31 -10:00
David Sidrane
4d760c5ea4 semaphore:sem_holder add DEBUGASSERT s 2017-03-13 10:46:26 -10:00
Gregory Nutt
399f306744 A few cosmetic changes 2017-03-11 08:58:42 -06:00
David Sidrane
6cc8f9100b Priority Inversion fixes:typo 2017-03-10 06:37:46 -10:00
Gregory Nutt
360539afac Priority inheritance: When CONFIG_SEM_PREALLOCHOLDERS==0, there is only a single, hard-allocated holder structure. This is problem because in sem_wait() the holder is released, but needs to remain in the holder container until sem_restorebaseprio() is called. The call to sem_restorebaseprio() must be one of the last things the sem_wait() does because it can cause the task to be suspended. If in sem_wait(), a new task gets the semaphore count then it will fail to allocate the holder and will not participate in priority inheritance. This fix is to add two hard-allocated holders in the sem_t structure: One of the old holder and one for the new holder. 2017-03-10 09:30:15 -06:00
Gregory Nutt
a93e46d00c Cosmetic 2017-03-10 08:54:50 -06:00
Gregory Nutt
74189d84e2 Cancellation points: Fix some backward logic in conditional compilation. 2017-02-02 06:42:41 -06:00
Gregory Nutt
cfb876263a SMP: There were certain conditions that we must avoid by preventing releasing the pending tasks while withn a critical section. But this logic was incomplete; there was no logic to prevent other CPUs from adding new, running tasks while on CPU is in a critical section.
This commit corrects this.  This is matching logic in sched_addreadytorun to avoid starting new tasks within the critical section (unless the CPU is the holder of the lock).  The holder of the IRQ lock must be permitted to do whatever it needs to do.
2016-12-27 08:49:07 -06:00
Gregory Nutt
6997cda1b5 Grrr... cloned typos! 2016-12-10 09:45:55 -06:00
Gregory Nutt
842ec7e612 ifdef out some non-reachable code 2016-12-10 09:43:04 -06:00
Gregory Nutt
b52e4e5ecd Move cancellation point definitions to their own header file. 2016-12-10 09:08:26 -06:00
Gregory Nutt
bc3ca25cc7 Cancellation points: Close up some logic to eliminte some race conditions. 2016-12-10 08:36:58 -06:00
Gregory Nutt
7fce8022c6 Finishes all cancellation point logic 2016-12-09 16:50:34 -06:00
Gregory Nutt
c9ca97b4b5 cancellation points are basically function. More tested is needed and additional cancellation points must be implemented before this can be merged back to master. 2016-12-09 12:01:18 -06:00
Gregory Nutt
018db84567 Flesh out more cancellation point logic. 2016-12-09 10:31:40 -06:00
Gregory Nutt
00215fbc98 sched_note: Add spinlock instrumentation; In SMP configurations, select to log only notes from certain CPUs 2016-11-28 10:33:46 -06:00
Gregory Nutt
e3fe320e08 SMP: Add support for linking spinlocks into a special, non-cached memory region. 2016-11-26 08:47:03 -06:00
Gregory Nutt
bac7153609 SMP: Add logic to avoid a deadlock condition when CPU1 is hung waiting for g_cpu_irqlock and CPU0 is waitin for g_cpu_paused 2016-11-22 11:34:16 -06:00
Gregory Nutt
558784d06f Spinlocks: Added capability to provide architecture-specific memory barriers. This was for i.MX6 but does not help with the SMP problems. It is still a good feature. 2016-11-21 11:55:59 -06:00
Freddie Chopin
484a1b6104 sem_wait() and sem_trywait() no longer modify the errno value UNLESS an error occurs. This allows these functions to be used internallly without clobbering the errno value. 2016-11-09 07:01:49 -06:00
Gregory Nutt
6f1c5e7b43 Add some comments. 2016-11-05 09:44:29 -06:00
Gregory Nutt
4b0372e542 Missing # on endif 2016-11-03 21:27:52 -06:00
Gregory Nutt
73fc186beb sem_setprotocol: Handle a case of missing proxy for sem_setprotocol. Reorder so that (1) this error is avoided, and (2) >No proxy is needed if priority inheritance is not enabled. 2016-11-03 18:51:38 -06:00
Gregory Nutt
4c8ec0d2ca include/nuttx/semaphore.h: Fix broken macros 2016-11-03 12:49:44 -06:00
Gregory Nutt
97bf82ee05 Semaphores: Provide macros for sem_setprotobol() and sem_getprotocol() if priority inheritance is not enabled. More SEM_PRIO_* definitions to include/nuttx/semaphore.h 2016-11-02 18:21:46 -06:00
Gregory Nutt
d5b4d848d3 Move protoypes for the non-standard include/semaphore.h file to the non-standard include/nuttx/semaphore.h with the other non-standard semaphore interfaces. 2016-11-02 14:43:03 -06:00
Gregory Nutt
b738a646ad sem_getprotocol() can be in C library 2016-11-02 09:29:16 -06:00