what's the intention with "static inline" port_lock declaration?

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

User avatar
russian
Posts: 364
Joined: Mon Oct 29, 2012 3:17 am
Location: Jersey City, USA
Has thanked: 16 times
Been thanked: 14 times

what's the intention with "static inline" port_lock declaration?

Postby russian » Fri Jun 09, 2017 4:29 am

What is the intention with declaring methods like for instance port_lock "static inline"?

Because 'static' we have multiple copies in the binary - does it have pros, or only cons of extra binary size?

Was the hope to have this method always inlined to save on branching?
I am looking at my objdump and it looks like method is not inlined. On the other hand __set_BASEPRI declared "__attribute__( ( always_inline ) ) __STATIC_INLINE" is in fact inlined.
Is that GCC refusing to cooperate on my current optimization level, is it playing smart and choosing to inline __set_BASEPRI but not port_lock ?

Sorry if that's not really a ChibiOS question :)

Code: Select all

08001bb0 <port_lock>:
/**
 * @brief   Kernel-lock action.
 * @details In this port this function raises the base priority to kernel
 *          level.
 */
static inline void port_lock(void) {
 8001bb0:   b082         sub   sp, #8
 8001bb2:   2320         movs   r3, #32
 8001bb4:   9301         str   r3, [sp, #4]

    \param [in]    basePri  Base Priority value to set
 */
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value)
{
  __ASM volatile ("MSR basepri, %0" : : "r" (value) : "memory");
 8001bb6:   9b01         ldr   r3, [sp, #4]
 8001bb8:   f383 8811    msr   BASEPRI, r3
#endif
#endif
#else /* CORTEX_SIMPLIFIED_PRIORITY */
  __disable_irq();
#endif /* CORTEX_SIMPLIFIED_PRIORITY */
}
 8001bbc:   bf00         nop
 8001bbe:   b002         add   sp, #8
 8001bc0:   4770         bx   lr
 8001bc2:   bf00         nop
   ...
Last edited by russian on Fri Jun 09, 2017 4:39 am, edited 2 times in total.
http://rusefi.com/ - electronic fuel injection

User avatar
russian
Posts: 364
Joined: Mon Oct 29, 2012 3:17 am
Location: Jersey City, USA
Has thanked: 16 times
Been thanked: 14 times

Re: what's the intention with "static inline" port_lock declaration?

Postby russian » Fri Jun 09, 2017 4:32 am

PS: here's where it really looks ridicolous:
static inline void port_lock_from_isr(void) {

port_lock();
}

becomes

Code: Select all

08001bf0 <port_lock_from_isr>:
 * @brief   Kernel-lock action from an interrupt handler.
 * @details In this port this function raises the base priority to kernel
 *          level.
 * @note    Same as @p port_lock() in this port.
 */
static inline void port_lock_from_isr(void) {
 8001bf0:   b508         push   {r3, lr}

  port_lock();
 8001bf2:   f7ff ffdd    bl   8001bb0 <port_lock>
}
 8001bf6:   bf00         nop
 8001bf8:   bd08         pop   {r3, pc}
 8001bfa:   bf00         nop
 8001bfc:   0000         movs   r0, r0
   ...


Would not it be better to
#define port_lock_from_isr port_lock

instead?
http://rusefi.com/ - electronic fuel injection

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: what's the intention with "static inline" port_lock declaration?

Postby Giovanni » Fri Jun 09, 2017 7:36 am

Which optimization level and compiler version are you using? "static inline" is meant to be always inlined.

I tried all settings and only -O0 does not inline it and this is expected.

Giovanni

User avatar
russian
Posts: 364
Joined: Mon Oct 29, 2012 3:17 am
Location: Jersey City, USA
Has thanked: 16 times
Been thanked: 14 times

Re: what's the intention with "static inline" port_lock declaration?

Postby russian » Fri Jun 09, 2017 1:29 pm

That's with -O0
port_lock is not inlined but __set_BASEPRI is inlined with my settings. Is __set_BASEPRI using a stronger syntax?
http://rusefi.com/ - electronic fuel injection

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: what's the intention with "static inline" port_lock declaration?

Postby Giovanni » Fri Jun 09, 2017 1:41 pm

That function has the attribute "always inline".

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 9 guests