Skip to contentSkip to conversation

I find a way to reduce latency, but I don't know why.

Xenomai 书呆子 2 participants 4 messages Mar 17, 2015 – Mar 23, 2015 1 message not in the archive

lore
Share & tools
lore

书呆子

author
#0 lore raw

The x86 machine have two CPUs, and I need periodic task on CPU1. In order to reduce latency, a busy task will run on CPU2.

cpu1_task
{
rt_task_wait_period;
real_work;
rt_sem_v(&busySEM);
}

cpu2_task
{
rt_sem_p(&busySEM);
rt_timer_spin(spin_ns);
}

And spin_ns will be long enough: spin_ns + real_work_ns > periodic cycle. Yes, it means rt_code is always running on CPU1 or CPU2.

In doing this, the cpu1_task will get low latency and drift, but why ?

thanks, zhou

#1 lore raw
Quoted 16 lines · 书呆子

The x86 machine have two CPUs, and I need periodic task on CPU1. In order to reduce latency, a busy task will run on CPU2.

cpu1_task
{
rt_task_wait_period;
real_work;
rt_sem_v(&busySEM);
}

cpu2_task
{
rt_sem_p(&busySEM);
rt_timer_spin(spin_ns);
}

Quoted 4 lines

And spin_ns will be long enough: spin_ns + real_work_ns > periodic cycle. Yes, it means rt_code is always running on CPU1 or CPU2.

In doing this, the cpu1_task will get low latency and drift, but why ?

Two possibilities:
- task2 is cache friendly, so if the cache is shared between the two cpus, it prevents Linux from evicting xenomai and I-pipe code from the cache, we know that cache has a big influence on latency;
- task2 prevents the cpu from entering idle mode, and so potentially prevents any low power optimization from happening, low power modes are generally not latency friendly.

Note however that measurements on an idle system do not really matter much for finding the worst case latency. Real measurements should last for hours and with the machine put under load. I bet with measurements done this way, the differences you observe with the tests you do would be negligible compared to the worst case latency. And if there is a real difference, then the I-pipe tracer would help you find from where it comes.

Signature · 1 line
					    Gilles.
#3 lore raw
In reply to a message not in the archive
Quoted 37 lines · Zhoupeng
Quoted 20 lines · 书呆子
Quoted 19 lines

The x86 machine have two CPUs, and I need periodic task on CPU1. In order to reduce latency, a busy task will run on CPU2.

cpu1_task
{
rt_task_wait_period;
real_work;
rt_sem_v(&busySEM);
}

cpu2_task
{
rt_sem_p(&busySEM);
rt_timer_spin(spin_ns);
}

And spin_ns will be long enough: spin_ns + real_work_ns > periodic cycle. Yes, it means rt_code is always running on CPU1 or CPU2.

Quoted 6 lines
Quoted 1 line

In doing this, the cpu1_task will get low latency and drift, but why ?

Two possibilities:
- task2 is cache friendly, so if the cache is shared between the two cpus, it prevents Linux from evicting xenomai and I-pipe code from the cache, we know that cache has a big influence on latency;

I agree this is the best guess, the I5 CPUs do share L3 cache between them.

I also use rt_timer_read() wrap real_work() to measure time consumption:
without task2 real_work() expend 20 to 36us, with task2 real_work() expend 20 to 22us to compelte.
real_work() only contain float-point arithmetic, the time stability is improved obviously.

If this is cache problem, is task2 the right way to keep code in cache ?

Quoted 8 lines
Quoted 3 lines

- task2 prevents the cpu from entering idle mode, and so potentially prevents any low power optimization from happening, low power modes are generally not latency friendly.

CONFIG_CPU_FREQ and CONFIG_CPU_IDLE is already disabled, smi workaround also enabled.
I have notice C1E mode is disabled in Xenomai 3, but not in Xenomai 2, but C1E is triggered by mwait, I don't think this is the problem.

Linux idle task uses mwait, and nothing prevents the chip maker to do any optimization he wants when hlt is called. On geode processors, with some configuration, hlt causes the tsc to be stopped for instance.

Signature · 1 line
					    Gilles.
author
#4 lore raw
Quoted 24 lines · Gilles
Quoted 15 lines
Quoted 4 lines

Two possibilities:
- task2 is cache friendly, so if the cache is shared between the two cpus, it prevents Linux from evicting xenomai and I-pipe code from the cache, we know that cache has a big influence on latency;

I agree this is the best guess, the I5 CPUs do share L3 cache between them.

I also use rt_timer_read() wrap real_work() to measure time consumption:
without task2 real_work() expend 20 to 36us, with task2 real_work() expend 20 to 22us to compelte.
real_work() only contain float-point arithmetic, the time stability is improved obviously.

If this is cache problem, is task2 the right way to keep code in cache ?

Quoted 8 lines
Quoted 3 lines

- task2 prevents the cpu from entering idle mode, and so potentially prevents any low power optimization from happening, low power modes are generally not latency friendly.

CONFIG_CPU_FREQ and CONFIG_CPU_IDLE is already disabled, smi workaround also enabled.
I have notice C1E mode is disabled in Xenomai 3, but not in Xenomai 2, but C1E is triggered by mwait, I don't think this is the problem.

Quoted 4 lines

Linux idle task uses mwait, and nothing prevents the chip maker to do any optimization he wants when hlt is called. On geode processors, with some configuration, hlt causes the tsc to be stopped for instance.

Yes, this is due to power optimization.
After add "idle=poll" to boot parameter, latency and time comsumption is just like task2 running.

Just like you said, "idle=poll" makes latency more smaller; but after long time test, the worst case is still there.

thanks, zhou