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

Rework Xilinx TTC driver #23567

Merged
merged 5 commits into from
Mar 21, 2020
Merged

Conversation

stephanosio
Copy link
Member

Rework Xilinx TTC driver to support tickless mode and fix the k_busy_wait hang issue when calling with interrupts locked.

Closes #19869 (tickless support issue)
Fixes #23541

This commit enables the QEMU icount emulation mode for improved timing
stability.

In normal emulation mode (without icount), the emulation timing of the
TTC system timer is particularly unstable and this results in a high CI
failure rate.

For more details, refer to the issues zephyrproject-rtos#14173 and zephyrproject-rtos#22904.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
The `tests/kernel/context` test fails for the `qemu_cortex_r5` when the
icount emulation mode is used, because the Xilinx QEMU ignores the WFI
instruction when the icount parameter is specified.

This will be fixed in the Zephyr SDK 0.11.3 and this commit must be
reverted once the CI is updated to use this new SDK version.

For more details, see zephyrproject-rtos/sdk-ng#191.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
@zephyrbot
Copy link
Collaborator

zephyrbot commented Mar 18, 2020

All checks are passing now.

Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages.

Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Some nitpicking but nothing I can see that should block merge.

drivers/timer/xlnx_psttc_timer.c Outdated Show resolved Hide resolved
@@ -9,6 +9,7 @@ set(QEMU_CPU_TYPE_${ARCH} cortex-r5)
set(QEMU_FLAGS_${ARCH}
-nographic
-machine arm-generic-fdt
-icount shift=3,align=off,sleep=off -rtc clock=vm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No complaints here, though IIRC there are still some issues in the main -icount patch. Does this work for everything?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is actually from #22904.

There is an issue with the WFI instruction in the Xilinx QEMU when icount mode is used, but this only affects one Zephyr test (tests/kernel/context) and does not really have a real impact in terms of functionality.

#22904 (comment)

@@ -2,3 +2,6 @@ tests:
kernel.common:
tags: kernel
min_ram: 20
# FIXME: Remove `qemu_cortex_r5` exclusion once Zephyr SDK 0.11.3 is
# mainlined (see #22904).
platform_exclude: qemu_cortex_r5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems cleaner to me to just rush the SDK release than to commit and revert this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be nice; though, @galak seems to be busy working on something else, so I am not sure if that is feasible.

#else
#error ("No timer is specified")
#endif
#define TICKS_PER_SEC CONFIG_SYS_CLOCK_TICKS_PER_SEC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: unless this is needed to keep line lengths under control, I'd prefer to see the existing kconfig used directly instead of a local synonym.

#error ("No timer is specified")
#endif
#define TICKS_PER_SEC CONFIG_SYS_CLOCK_TICKS_PER_SEC
#define CYCLES_PER_SEC TIMER_CLOCK_FREQUECY
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, though I guess DTS constants are really ugly, so I feel less strongly about this one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, they get very long and ugly soon after this.

drivers/timer/xlnx_psttc_timer.c Outdated Show resolved Hide resolved
drivers/timer/xlnx_psttc_timer.c Outdated Show resolved Hide resolved
CYCLES_NEXT_MAX : CYCLES_PER_TICK;
sys_write32(reg_val, TIMER_BASE_ADDR + XTTCPS_MATCH_0_OFFSET);

/* Connect timer interrupt */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: "IRQ_CONNECT(TIMER_IRQ, ..." sufficiently implies that the timer interrupt is connected without the comment. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to provide a logical flow of this function in the comments (i.e. even without reading actual code, you will know what this function does just only reading comments).

Though, I agree that this would often qualify as a "state-the-obvious" kind of comment :p

drivers/timer/xlnx_psttc_timer.c Outdated Show resolved Hide resolved
drivers/timer/xlnx_psttc_timer_priv.h Show resolved Hide resolved
This commit updates the 'xlnx_psttc_timer' to implement the current
system timer API.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
The `xlnx,ttcps` binding, despite having the file name of
`xlnx,ttcps.yaml`, had the compatible property of `cdns,ttc`.

While it is true that the Xilinx ZynqMP platform embeds the Cadence
Triple Timer Counter (TTC) IP core, its TTC differs from the original
Cadence core in that it implements 32-bit counters, instead of the
16-bit counters defined in the original; hence, the Xilinx variant is
not compatible with the original Cadence version and should be treated
as a different device.

This commit changes the `xlnx,ttcps.yaml` compatible property to
`xlnx,ttcps` for the above reasons.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
This commit reworks the Xilinx TTC timer driver to use the "match" mode
instead of the "interval" mode which counts up to the specified value
and resets to zero.

Using the "match" mode ensures that the timer keeps counting even after
an interrupt is triggered, and facilitates the tickless mode support
implementation.

This also allows `z_timer_cycle_get_32` to return the correct cycle
count when interrupt is locked; thereby, fixing the k_busy_wait hang
issue.

Note that the TTC "match" mode emulation (and tickless timer operation)
is only stable when the QEMU icount mode is enabled.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
Copy link
Member

@carlescufi carlescufi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nashif nashif merged commit fc941d5 into zephyrproject-rtos:master Mar 21, 2020
@stephanosio stephanosio deleted the xlnx_ttc_new branch April 23, 2020 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants