Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid division by zero in posix targets #1

Closed
wants to merge 5 commits into from
Closed

Conversation

tinti
Copy link

@tinti tinti commented Jun 6, 2013

The tick duration in microseconds may be calculated to zero depending on the
processor clock speed.

Maybe another solution could be using BogoMips for calculating the tick duration or even querying sysfs (i.e. /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq). Both have drawbacks and in some case zero will be get as a result.

Also BogoMips has recently change and now it can be specified at build time.

tinti added 5 commits June 6, 2013 16:06
The tick duration in microseconds may be calculated to zero depending on the
processor clock speed.

This patch sets it to 1 if the value is 0.

Signed-off-by: Vinicius Tinti <[email protected]>
Map all OSAL internal types to common types already defined in <stdint.h>. Also
adding support for x86_64.

Signed-off-by: Vinicius Tinti <[email protected]>
The OSAL api uses a global lock to perform some operations using mutex,
semaphores, queues and so. This leads to a possible deadlock in the program
due the following situation.

  Let "I" be the timer interrupt (SIG63):

       |[Thread 1]
       |  ...
       |  call OS_TaskGetInfo
       |    ...
       |    lock(global)
       |    ...
  I----+--------------------+
                            |[Interrupt]
                            |  ...
                            |  call OS_TaskGetInfo
                            |    ...
                            |    lock(global)  // DEADLOCK

There are some possible solutions to avoid this problem. One is to never use any
OSAL primitives on the interrupt context, which quite limit the library. Other
would be block all signals during the global lock and let them be pending. This
approach may introduce poor performance. Other would be find out how to remove
these global locks. Another could be use safe locks on interrupt handler.

This patch implements the blocking signals solution because it is the best
trade-off of the current solutions.

There is also a single special case which is not handled by this patch.

Signed-off-by: Vinicius Tinti <[email protected]>
Signed-off-by: Vinicius Tinti <[email protected]>
@skliper
Copy link
Contributor

skliper commented Sep 16, 2019

This change is obsolete, wrote #12 to address this issue in the context of the current code base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants