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

GCC - hardfault in mktime with irq disabled #2647

Closed
svastm opened this issue Sep 8, 2016 · 7 comments
Closed

GCC - hardfault in mktime with irq disabled #2647

svastm opened this issue Sep 8, 2016 · 7 comments

Comments

@svastm
Copy link
Contributor

svastm commented Sep 8, 2016

I don't know if some other standard function are affected but it seems that every time we call mktime() in a critical section, with GCC only, an hardfault is fired. Both standard and nano libs seems to be affected. I tried with the NUCLEO_F303RE and NUCLEO_F429ZI and the mbed-cli to compile the tests.

mbed compile -m NUCLEO_F303RE -t GCC_ARM

with this main.cpp

#include "mbed.h"

int main()
{
    time_t t1, t2;
    printf("begin\n");

    struct tm timeinfo;
    timeinfo.tm_wday = 4;
    timeinfo.tm_mon  = 0;
    timeinfo.tm_mday = 1;
    timeinfo.tm_year = 70;
    timeinfo.tm_hour = 0;
    timeinfo.tm_min  = 0;
    timeinfo.tm_sec  = 5;
    // Daylight Saving Time information is not available
    timeinfo.tm_isdst  = -1;

    t1 = mktime(&timeinfo);
    printf("t1: %ld\n", t1);

    // __disable_irq();
    // printf("printf is ok ?\n");
    // __enable_irq();

    //core_util_critical_section_enter();
    __disable_irq();
    t2 = mktime(&timeinfo);
    __enable_irq();
    //core_util_critical_section_exit();

    printf("t2: %ld\n", t2);

    printf("end\n");
}

and the output, same result on GCC v5.3 and v4.9.

begin
t1: 5
printf is ok ?

An other thing that can be related, with ARM and IAR compilers, we can't use printf() in critical section (which should be the normal behaviour, the serial_api use interrupts) but with GCC the text is printed.

@svastm
Copy link
Contributor Author

svastm commented Sep 12, 2016

An update to add that the problem happen on mbed 5 and mbed 2 + RTOS but not on mbed 2. So the problem must come from the RTOS.

@sg-
Copy link
Contributor

sg- commented Sep 12, 2016

@c1728p9 I think we looked at this previously. Mind sharing what our thoughts were here?

@ciarmcom
Copy link
Member

ARM Internal Ref: IOTMORF-461

@c1728p9
Copy link
Contributor

c1728p9 commented Sep 12, 2016

Hi @svastm, a hardfault occurs because the gcc standard library (newlib) is internally using a mutex to protect global information. This causes a hardfault because a mutex is not allowed to be used inside a critical section. There should be no need for a critical section around mktime.

@svastm
Copy link
Contributor Author

svastm commented Sep 12, 2016

Hello,
I was investigating too and I reach the same conclusion. In the real application, I'm not responsible for enabling the critical section. Also i can't break a section just to use mktime().

We could consider to check the PRIMASK before using mutex.

TARGET_CORTEX_M/rt_CMSIS.c:1520

/// Wait until a Mutex becomes available
osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec) {
  if (__get_IPSR() != 0U || __get_PRIMASK() != 0U) {
    return osErrorISR;                          // Not allowed in ISR and with interrupt disabled
  }
  return __svcMutexWait(mutex_id, millisec);
}

/// Release a Mutex that was obtained with osMutexWait
osStatus osMutexRelease (osMutexId mutex_id) {
  if (__get_IPSR() != 0U || __get_PRIMASK() != 0U) {
    return osErrorISR;                          // Not allowed in ISR and with interrupt disabled
  }
  return __svcMutexRelease(mutex_id);
}

I have no more error in mktime with this small fix.

@c1728p9
Copy link
Contributor

c1728p9 commented Sep 12, 2016

Hi @svastm, a changes similar to that is being discussed here:
#2391

The problem with that is that it will mask errors. Since the mutex is never acquired, thread safety isn't provided. Even though the current thread will complete the call to mktime without being interrupted there could be another thread using the same global data that is not in a critical section. Since the second thread is relying on the mutex to protect this data, the first thread could interrupt an operation at any time since it won't block on any mutexes.

@svastm
Copy link
Contributor Author

svastm commented Sep 26, 2016

After the merge of #2391, I am able to run the small test code on a DISCO_F469NI.

@svastm svastm closed this as completed Sep 26, 2016
artokin pushed a commit to artokin/mbed-os that referenced this issue Jun 22, 2021
…..4a3c5c5

4a3c5c5 Merge remote-tracking branch 'origin/release_internal' into release_external
2b8d2e1 Do not reset radio when MAC data request timeouts (ARMmbed#2647)
95c506a Frame counters for nw keys are now stored to NVM only after send key is set (ARMmbed#2641)
3b3010a Adjusted stagger random to [min,min+max] and for small nw set the stagger value to 10 seconds
02bc33a Adjusted security protocol (EAP-TLS,4WH,2WH) retry timers
eb26726 High Priority timestamp compare overflow support fix.
928723a FHSS WS: Initialize broadcast channel count when enabling FHSS (ARMmbed#2642)
6040d70 Updated change log
667b191 Changed initial EAPOL-key retries from trickle to exponential backup
d925145 Add RTT calculation for DHCP Time calculation
0b82953 Traceroute bug fix.
04de6e2 Merge pull request ARMmbed#2638 from PelionIoT/mbed_os_fix_ufsi_calculation
2012347 Fixed FHSS UFSI calculation unit tests
436f16e Handle timer rollover in calculate_ufsi
411cf5c coding style
d6f4421 Correct ufsi timing calculation
560619d Add network time vendor data element to DHCPv6 reply message
6d290dc System time read/write callbacks (ARMmbed#2637)
7905df6 Restart or remove transmission when MAC data request timeouts (ARMmbed#2636)
c97695c Bug fix: EAPOL parent compare fix
e283e62 Fixed channel mask usage with OFDM configurations (ARMmbed#2633)
24168f8 Do not send too old packets (ARMmbed#2632)
dbd83be Fix copyrights (ARMmbed#2631)
7f0cffd Merge pull request ARMmbed#2630 from PelionIoT/use_pelion_copyright
511bd5a Corrected coding style
57ec028 Corrected comparison
7d853de When EAPOL waiting queue is full oldest entry is removed
acf580f Update copyright in changed MDNS files
933c0bb Update copyright
3aeb2af Statistics for data request latencies (ARMmbed#2629)
3f7eae6 EAPOL FHSS temp entry discover
5200b66 DHCP time elapsed time write fix.
0536874 Removed empty EAPOL-key message send after 4WH completion to nodes on relay
8a2a683 Fixed DHCP wrong time elapsed value write.
283f2ee DHCPv6 update:
99be778 EAPOL temp neighbour update
4f9e3d1 Adaptation layer to remove oldest packet first
20f1f64 Added ignoring of retry messages from RADIUS server when waiting EAP-TLS
8a8b407 Add RSL check for ETX Calculation for RPL parent selection
c05e1da Fix DHCP server Uninitialized memory read
77229ee Fix CPP error from domain prefix check
7e47889 support filtering of EAPOL parents based device-min-sens configuration
618a191 Wi-SUN Expedite forward state update
4371462 Fix NULL read from RPL header addition
7802c7e Update CHANGELOG.md
b2c8104 CHANGELOG for Nanostack v13.0.0 (ARMmbed#2615)

git-subtree-dir: features/nanostack/sal-stack-nanostack
git-subtree-split: 4a3c5c5
artokin pushed a commit to artokin/mbed-os that referenced this issue Jun 23, 2021
…903b81..4a3c5c5

4a3c5c5 Merge remote-tracking branch 'origin/release_internal' into release_external
2b8d2e1 Do not reset radio when MAC data request timeouts (ARMmbed#2647)
95c506a Frame counters for nw keys are now stored to NVM only after send key is set (ARMmbed#2641)
3b3010a Adjusted stagger random to [min,min+max] and for small nw set the stagger value to 10 seconds
02bc33a Adjusted security protocol (EAP-TLS,4WH,2WH) retry timers
eb26726 High Priority timestamp compare overflow support fix.
928723a FHSS WS: Initialize broadcast channel count when enabling FHSS (ARMmbed#2642)
6040d70 Updated change log
667b191 Changed initial EAPOL-key retries from trickle to exponential backup
d925145 Add RTT calculation for DHCP Time calculation
0b82953 Traceroute bug fix.
04de6e2 Merge pull request ARMmbed#2638 from PelionIoT/mbed_os_fix_ufsi_calculation
2012347 Fixed FHSS UFSI calculation unit tests
436f16e Handle timer rollover in calculate_ufsi
411cf5c coding style
d6f4421 Correct ufsi timing calculation
560619d Add network time vendor data element to DHCPv6 reply message
6d290dc System time read/write callbacks (ARMmbed#2637)
7905df6 Restart or remove transmission when MAC data request timeouts (ARMmbed#2636)
c97695c Bug fix: EAPOL parent compare fix
e283e62 Fixed channel mask usage with OFDM configurations (ARMmbed#2633)
24168f8 Do not send too old packets (ARMmbed#2632)
dbd83be Fix copyrights (ARMmbed#2631)
7f0cffd Merge pull request ARMmbed#2630 from PelionIoT/use_pelion_copyright
511bd5a Corrected coding style
57ec028 Corrected comparison
7d853de When EAPOL waiting queue is full oldest entry is removed
acf580f Update copyright in changed MDNS files
933c0bb Update copyright
3aeb2af Statistics for data request latencies (ARMmbed#2629)
3f7eae6 EAPOL FHSS temp entry discover
5200b66 DHCP time elapsed time write fix.
0536874 Removed empty EAPOL-key message send after 4WH completion to nodes on relay
8a2a683 Fixed DHCP wrong time elapsed value write.
283f2ee DHCPv6 update:
99be778 EAPOL temp neighbour update
4f9e3d1 Adaptation layer to remove oldest packet first
20f1f64 Added ignoring of retry messages from RADIUS server when waiting EAP-TLS
8a8b407 Add RSL check for ETX Calculation for RPL parent selection
c05e1da Fix DHCP server Uninitialized memory read
77229ee Fix CPP error from domain prefix check
7e47889 support filtering of EAPOL parents based device-min-sens configuration
618a191 Wi-SUN Expedite forward state update
4371462 Fix NULL read from RPL header addition
7802c7e Update CHANGELOG.md
b2c8104 CHANGELOG for Nanostack v13.0.0 (ARMmbed#2615)

git-subtree-dir: connectivity/nanostack/sal-stack-nanostack
git-subtree-split: 4a3c5c5
artokin pushed a commit to artokin/mbed-os that referenced this issue Jun 28, 2021
…903b81..4a3c5c5

4a3c5c5 Merge remote-tracking branch 'origin/release_internal' into release_external
2b8d2e1 Do not reset radio when MAC data request timeouts (ARMmbed#2647)
95c506a Frame counters for nw keys are now stored to NVM only after send key is set (ARMmbed#2641)
3b3010a Adjusted stagger random to [min,min+max] and for small nw set the stagger value to 10 seconds
02bc33a Adjusted security protocol (EAP-TLS,4WH,2WH) retry timers
eb26726 High Priority timestamp compare overflow support fix.
928723a FHSS WS: Initialize broadcast channel count when enabling FHSS (ARMmbed#2642)
6040d70 Updated change log
667b191 Changed initial EAPOL-key retries from trickle to exponential backup
d925145 Add RTT calculation for DHCP Time calculation
0b82953 Traceroute bug fix.
04de6e2 Merge pull request ARMmbed#2638 from PelionIoT/mbed_os_fix_ufsi_calculation
2012347 Fixed FHSS UFSI calculation unit tests
436f16e Handle timer rollover in calculate_ufsi
411cf5c coding style
d6f4421 Correct ufsi timing calculation
560619d Add network time vendor data element to DHCPv6 reply message
6d290dc System time read/write callbacks (ARMmbed#2637)
7905df6 Restart or remove transmission when MAC data request timeouts (ARMmbed#2636)
c97695c Bug fix: EAPOL parent compare fix
e283e62 Fixed channel mask usage with OFDM configurations (ARMmbed#2633)
24168f8 Do not send too old packets (ARMmbed#2632)
dbd83be Fix copyrights (ARMmbed#2631)
7f0cffd Merge pull request ARMmbed#2630 from PelionIoT/use_pelion_copyright
511bd5a Corrected coding style
57ec028 Corrected comparison
7d853de When EAPOL waiting queue is full oldest entry is removed
acf580f Update copyright in changed MDNS files
933c0bb Update copyright
3aeb2af Statistics for data request latencies (ARMmbed#2629)
3f7eae6 EAPOL FHSS temp entry discover
5200b66 DHCP time elapsed time write fix.
0536874 Removed empty EAPOL-key message send after 4WH completion to nodes on relay
8a2a683 Fixed DHCP wrong time elapsed value write.
283f2ee DHCPv6 update:
99be778 EAPOL temp neighbour update
4f9e3d1 Adaptation layer to remove oldest packet first
20f1f64 Added ignoring of retry messages from RADIUS server when waiting EAP-TLS
8a8b407 Add RSL check for ETX Calculation for RPL parent selection
c05e1da Fix DHCP server Uninitialized memory read
77229ee Fix CPP error from domain prefix check
7e47889 support filtering of EAPOL parents based device-min-sens configuration
618a191 Wi-SUN Expedite forward state update
4371462 Fix NULL read from RPL header addition
7802c7e Update CHANGELOG.md
b2c8104 CHANGELOG for Nanostack v13.0.0 (ARMmbed#2615)

git-subtree-dir: connectivity/nanostack/sal-stack-nanostack
git-subtree-split: 4a3c5c5
artokin pushed a commit to artokin/mbed-os that referenced this issue Jun 28, 2021
…..4a3c5c5

4a3c5c5 Merge remote-tracking branch 'origin/release_internal' into release_external
2b8d2e1 Do not reset radio when MAC data request timeouts (ARMmbed#2647)
95c506a Frame counters for nw keys are now stored to NVM only after send key is set (ARMmbed#2641)
3b3010a Adjusted stagger random to [min,min+max] and for small nw set the stagger value to 10 seconds
02bc33a Adjusted security protocol (EAP-TLS,4WH,2WH) retry timers
eb26726 High Priority timestamp compare overflow support fix.
928723a FHSS WS: Initialize broadcast channel count when enabling FHSS (ARMmbed#2642)
6040d70 Updated change log
667b191 Changed initial EAPOL-key retries from trickle to exponential backup
d925145 Add RTT calculation for DHCP Time calculation
0b82953 Traceroute bug fix.
04de6e2 Merge pull request ARMmbed#2638 from PelionIoT/mbed_os_fix_ufsi_calculation
2012347 Fixed FHSS UFSI calculation unit tests
436f16e Handle timer rollover in calculate_ufsi
411cf5c coding style
d6f4421 Correct ufsi timing calculation
560619d Add network time vendor data element to DHCPv6 reply message
6d290dc System time read/write callbacks (ARMmbed#2637)
7905df6 Restart or remove transmission when MAC data request timeouts (ARMmbed#2636)
c97695c Bug fix: EAPOL parent compare fix
e283e62 Fixed channel mask usage with OFDM configurations (ARMmbed#2633)
24168f8 Do not send too old packets (ARMmbed#2632)
dbd83be Fix copyrights (ARMmbed#2631)
7f0cffd Merge pull request ARMmbed#2630 from PelionIoT/use_pelion_copyright
511bd5a Corrected coding style
57ec028 Corrected comparison
7d853de When EAPOL waiting queue is full oldest entry is removed
acf580f Update copyright in changed MDNS files
933c0bb Update copyright
3aeb2af Statistics for data request latencies (ARMmbed#2629)
3f7eae6 EAPOL FHSS temp entry discover
5200b66 DHCP time elapsed time write fix.
0536874 Removed empty EAPOL-key message send after 4WH completion to nodes on relay
8a2a683 Fixed DHCP wrong time elapsed value write.
283f2ee DHCPv6 update:
99be778 EAPOL temp neighbour update
4f9e3d1 Adaptation layer to remove oldest packet first
20f1f64 Added ignoring of retry messages from RADIUS server when waiting EAP-TLS
8a8b407 Add RSL check for ETX Calculation for RPL parent selection
c05e1da Fix DHCP server Uninitialized memory read
77229ee Fix CPP error from domain prefix check
7e47889 support filtering of EAPOL parents based device-min-sens configuration
618a191 Wi-SUN Expedite forward state update
4371462 Fix NULL read from RPL header addition
7802c7e Update CHANGELOG.md
b2c8104 CHANGELOG for Nanostack v13.0.0 (ARMmbed#2615)

git-subtree-dir: features/nanostack/sal-stack-nanostack
git-subtree-split: 4a3c5c5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants