0

I am seeing something unusual in my system. One of my application tasks 'xxxx' is "pending" for a semaphore. Its priority is 94, below is the tt.

This task is pending:
(de009e8)   329220 vxTaskEntry +5c: yyyy()
....
(de003a8)  1453384 aaaaaa +3fc: fdprintf()
(de00328)   37ea54 fdprintf +60: fioFormatV()
(de00100)   37f0ac fioFormatV +4f0: fioFormatV()
(de000e8)   37fb44 fioFormatV +f88: write()
(de000c8)   383218 write +50: iosWrite()
(de00050)   385218 iosWrite +d0: tyWrite()
(de00028)   394d80 tyWrite +60: semTake()
(de00008)   3de698 semTake +90: semBTake()

Sem Id: 0xf7dfa40  BINARY EMPTY Owner: 0x7a42e78 (yyyy)
Pended Tasks:   xxxx @ 94

But the tt of the task yyyy looks like the below. The most important point here is that, this task is in "READY" state. This task's priority is 100.

<This task is ready>
(7a42e18)   329220 vxTaskEntry +5c: gggg()
....
(7a42cd8)   37e590 printf +84: fioFormatV()
(7a42ab0)   37fab8 fioFormatV +efc: fioFormatV()
(7a42a98)   37fb44 fioFormatV +f88: write()
(7a42a78)   383218 write +50: iosWrite()
(7a42a00)   385218 iosWrite +d0: devConsCreate()
(7a429e8)   127a18 devConsCreate +f8: write()
(7a429c8)   383218 write +50: iosWrite()
(7a42950)   385218 iosWrite +d0: tyWrite()
(7a42928)   394d80 tyWrite +60: semTake()
(7a42908)   3de698 semTake +90: semBTake()

How can task 'xxxx' pend for a semaphore which is owned by 'yyyy', when 'yyyy' itself is in ready state when in semBtake()?

2 Answers 2

0

Just because a task is ready to run, doesn't mean it is actually running... In this case:

  1. The yyyy task got the semaphore first
  2. Task yyyy probably got preempted by something else with higher priority (like the shell or task xxxx for example)
  3. Task xxxx attempts to obtain the semaphore but gets blocked because yyyy already has it
  4. Eventually task yyyy will actually run further until it releases the semaphore
  5. When the semaphore is released by task yyyy the xxxx task will immediately become unblocked and run...
0

Since you have two tasks taking the same semaphore I assume you are using the semaphore to protect a critical section of your code that uses a shared resource. This assumptions may not be correct, if so let us know.

You may be dealing with an unbounded priority inversion. Task yyyy has taken the semaphore, task xxxx is pending and waiting on the semaphore. Task yyyy is not executing on the processor becuase there is a higher priority task in the system either between 94 and 100 (unbounded priority inversion) or even above 94 (normal higher priority task interference) that is using the CPU and not allowing the task yyyy to execute to completion.

If this is all true you may want to consider replacing your binary semaphore with a Mutex, with priority inheritance. This would cause Task YYYY priority to be promoted temporarily to 94 to match Task XXXX once Task XXX has started pending on the mutex. Thus blocking any task in between priority 94 and 100 from executing while the mutex is being requested by Task XXXX.

If it is a task above priority 94 that is not giving up the processor, you will need to look at your overall system and how that task is implemented and determine if something needs to change so that it allows other lower priority tasks time to execute on the CPU.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.