回复:[Zephyr-devel] Is The tick handler "z_clock_announce" in SMP mode dupulicate caculated?


"曹子龙
 

I still cant understand this flow after read the code.
take cortex-m arch for exmaple, z_clock_isr, is hooked for NVIC vector table, so each cores would call this following the frequency.
so,  there must be a z_clock_announce invoked on each cpu, so the current tick would be duplicate caculated? although i know zephyr would nod be exsis such issue, but  i did not figure out
where am i wrong, from the coretex-m arch flow, i cant find where block the z_clock_announce calling from each cpu core?


    .word __pendsv
#if defined(CONFIG_SYS_CLOCK_EXISTS)
    .word z_clock_isr
#else
    .word __reserved
#endif

void z_clock_isr(void *arg)
{
    ARG_UNUSED(arg);
    u32_t dticks;

    cycle_count += last_load;
    dticks = (cycle_count - announced_cycles) / CYC_PER_TICK;
    announced_cycles += dticks * CYC_PER_TICK;

    overflow_cyc = SysTick->CTRL; /* Reset overflow flag */
    overflow_cyc = 0U;

    z_clock_announce(TICKLESS ? dticks : 1);
    z_ExcExit();
}



曹子龙

珠海全志科技股份有限公司      BU1-PSW

地址:广东省珠海市高新区唐家湾镇科技2路9号

TEL:13824125580

Email:caozilong@...

网址: http://www.allwinnertech.com

 


------------------------------------------------------------------
发件人:Andy Ross <andrew.j.ross@...>
发送时间:2019年8月23日(星期五) 23:35
收件人:曹子龙 <caozilong@...>; devel <devel@...>
主 题:Re: [Zephyr-devel] Is The tick handler "z_clock_announce" in SMP mode dupulicate caculated?

This is the responsibility of the timer driver.  The ticks announced needs to be globally correct.  The existing drivers do this by locking a "last count" state variable and updating it, so they see the updates made by the other cores.


Andy


On 8/23/2019 8:14 AM, "曹子龙 wrote:
Hi  friends:
    
  a puzzle in the timer tick interrupt handler in SMP mode.  look at below,  the SMP mult cores share the same "cur_tick" object to remeber the current time, each cpu would increment it when the tick hander  excutes on each CPU.
so, could this would accelerate the timer compare with the realworld?  for example, if 4cores  exist, the cur_tick would 4 times incmrent than the read world, i cant fingure out where am a wrong, so, could you figure me out?  thanks for your kinldy supply. 

void z_clock_announce(s32_t ticks)
{
#ifdef CONFIG_TIMESLICING
 z_time_slice(ticks);
#endif

 k_spinlock_key_t key = k_spin_lock(&timeout_lock);

 announce_remaining = ticks;

 while (first() != NULL && first()->dticks <= announce_remaining) {
  struct _timeout *t = first();
  int dt = t->dticks;

  curr_tick += dt;
  announce_remaining -= dt;
  t->dticks = 0;
  remove_timeout(t);

  k_spin_unlock(&timeout_lock, key);
  t->fn(t);
  key = k_spin_lock(&timeout_lock);
 }

 if (first() != NULL) {
  first()->dticks -= announce_remaining;
 }

 curr_tick += announce_remaining;
 announce_remaining = 0;

 z_clock_set_timeout(next_timeout(), false);

 k_spin_unlock(&timeout_lock, key);
}




曹子龙

珠海全志科技股份有限公司      BU1-PSW

地址:广东省珠海市高新区唐家湾镇科技2路9号

TEL:13824125580

Email:caozilong@...

网址: http://www.allwinnertech.com

 



Join devel@lists.zephyrproject.org to automatically receive all group messages.