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

[BUG] make CONFIG_SOF_ZEPHYR_STRICT_HEADERS the default #9015

Open
31 of 35 tasks
kv2019i opened this issue Apr 9, 2024 · 7 comments
Open
31 of 35 tasks

[BUG] make CONFIG_SOF_ZEPHYR_STRICT_HEADERS the default #9015

kv2019i opened this issue Apr 9, 2024 · 7 comments
Assignees
Labels
enhancement New feature or request Zephyr Issues only observed with Zephyr integrated
Milestone

Comments

@kv2019i
Copy link
Collaborator

kv2019i commented Apr 9, 2024

Describe the bug/enhancement
When rtos include layer was added in #6161 , CONFIG_SOF_ZEPHYR_STRICT_HEADERS was added as a transitory tool.

This is still in place and can cause confusing issues as both XTOS and Zephyr headers are added to the include path by default.

To Reproduce
Build target, check .config

Reproduction Rate
100%

Expected behavior
OS include paths not mixed in build.

Impact
Slows down development of new features.

Environment
SOF main as of 2024-04-09

Work breakdown

Following subtasks identified (breakdown started in v2.11 cycle):

Screenshots or console output

@kv2019i kv2019i added bug Something isn't working as expected Zephyr Issues only observed with Zephyr integrated labels Apr 9, 2024
@lgirdwood lgirdwood added this to the v2.10 milestone Apr 16, 2024
@kv2019i kv2019i self-assigned this May 28, 2024
@kv2019i
Copy link
Collaborator Author

kv2019i commented May 28, 2024

Not sure I can tackle this in time for v2.10, but assigning for myself, as nobody else is assigned.

@kv2019i
Copy link
Collaborator Author

kv2019i commented Jun 5, 2024

Update for v2.10: spent some time on this trying to make one Intel target build in strict headers mode, but could not complete the task. There is still quite a lot of use of e..g sof/lib/mailbox.h and sof/lib/memory.h in surprising places in audio code that needs to be cleaned up first. Also we have some SOF side functions list SOF list.h and perf_cnt -- for these, move to some common header might be easier. For now moving to v2.11 -- might be able to complete some of this work in June, but won't backport to 2.10 release (as no functional benefit for the release).

@kv2019i kv2019i modified the milestones: v2.10, v2.11 Jun 5, 2024
@kv2019i kv2019i added enhancement New feature or request and removed bug Something isn't working as expected labels Sep 10, 2024
@kv2019i
Copy link
Collaborator Author

kv2019i commented Sep 10, 2024

Work breakdown added to the issue description with already done worked marked as done.

kv2019i added a commit to kv2019i/sof that referenced this issue Sep 10, 2024
Implement sof/lib/dai.h for Zephyr build and do not rely o
the xtos version for Zephyr builds. Add a warning to catch
invalid build configurations.

Link: thesofproject#9015
Signed-off-by: Kai Vehmanen <[email protected]>
dbaluta pushed a commit that referenced this issue Sep 11, 2024
Implement sof/lib/dai.h for Zephyr build and do not rely o
the xtos version for Zephyr builds. Add a warning to catch
invalid build configurations.

Link: #9015
Signed-off-by: Kai Vehmanen <[email protected]>
pillo79 pushed a commit to pillo79/sof that referenced this issue Sep 11, 2024
Implement sof/lib/dai.h for Zephyr build and do not rely o
the xtos version for Zephyr builds. Add a warning to catch
invalid build configurations.

Link: thesofproject#9015
Signed-off-by: Kai Vehmanen <[email protected]>
kv2019i added a commit to kv2019i/sof that referenced this issue Sep 11, 2024
Remove the shim.h interface from RTOS layer as there is no use
of this interface anymore in SOF codebase.

Link: thesofproject#9015
Signed-off-by: Kai Vehmanen <[email protected]>
kv2019i added a commit to kv2019i/sof that referenced this issue Sep 12, 2024
sof/list.h is a software interface used by the audio pipeline
framework and should not be in the RTOS abstraction layer.

Link: thesofproject#9015
Signed-off-by: Kai Vehmanen <[email protected]>
@kv2019i
Copy link
Collaborator Author

kv2019i commented Sep 13, 2024

2.11 cutoff day. Some progress with this. Work breakdown has been done and shared as a task list in bug description. At end of 2.11 cycle, we have 23 out of 35 identified tasks completed. Pushing the remaining work to v2.12.

@kv2019i kv2019i modified the milestones: v2.11, v2.12 Sep 13, 2024
kv2019i added a commit that referenced this issue Sep 16, 2024
sof/list.h is a software interface used by the audio pipeline
framework and should not be in the RTOS abstraction layer.

Link: #9015
Signed-off-by: Kai Vehmanen <[email protected]>
kv2019i added a commit that referenced this issue Sep 16, 2024
Remove the shim.h interface from RTOS layer as there is no use
of this interface anymore in SOF codebase.

Link: #9015
Signed-off-by: Kai Vehmanen <[email protected]>
kv2019i added a commit to kv2019i/sof that referenced this issue Sep 18, 2024
Introduce a separate file for Zephyr compiler_attributes.h and
move all Zephyr-specific definitions to this file. This is
a prerequisite to build with CONFIG_SOF_ZEPHYR_STRICT_HEADERS=y.

Link: thesofproject#9015
Signed-off-by: Kai Vehmanen <[email protected]>
kv2019i added a commit to kv2019i/sof that referenced this issue Sep 18, 2024
Introduce a separate file for Zephyr compiler_attributes.h and
move all Zephyr-specific definitions to this file. This is
a prerequisite to build with CONFIG_SOF_ZEPHYR_STRICT_HEADERS=y.

Link: thesofproject#9015
Signed-off-by: Kai Vehmanen <[email protected]>
kv2019i added a commit to kv2019i/sof that referenced this issue Sep 18, 2024
The SOF agent.h interface is a system agent that is implemented on top
of SOF audio task scheduling interface. An agent task is added to the
low-latency scheduler to monitor health of the system. The current
implementation is actually RTOS agnostic and can run on top of both
Zephyr and XTOS.

Some RTOSes offer a lower level watchdog interface to implement system
monitoring. Previously agent.h was considered as the abstraction point,
onto which RTOS specific implementations can be hooked in.

This patch moves agent.h back to application interface. In the future, a
more low-level agent hooking into a watchdog system (either hardware
watchdog directly, or software abstraction like Zephyr's task_wdt) can
be added on the side, and enabled on a per target basis. The audio
scheduler level SOF agent will continue to be available as an option,
and can be used with all RTOS'es.

Link: thesofproject#9015
Signed-off-by: Kai Vehmanen <[email protected]>
kv2019i added a commit to kv2019i/sof that referenced this issue Sep 19, 2024
The SOF perf_cnt.h provides a simple performance counter interface that
is used in SOF to track performance at audio module and pipeline level.

Majority of the implementation is RTOS agnostic, relying on
sof_cycle_get_64() to sample platform clock, and timer_get_system() for
CPU clock, both defined in rtos/timer.h. There is however some
conditional rules for Zephyr to use timing_counter_get() if SOF is built
with CONFIG_TIMING_FUNCTIONS=y.

The amount of RTOS variation does not seem to warrant branching the
whole perf_cnt.h to RTOS layer. Move perf_cnt.h back to application
interface, so the single implementation can be shared.

Link: thesofproject#9015
Signed-off-by: Kai Vehmanen <[email protected]>
lgirdwood pushed a commit that referenced this issue Sep 19, 2024
Introduce a separate file for Zephyr compiler_attributes.h and
move all Zephyr-specific definitions to this file. This is
a prerequisite to build with CONFIG_SOF_ZEPHYR_STRICT_HEADERS=y.

Link: #9015
Signed-off-by: Kai Vehmanen <[email protected]>
lgirdwood pushed a commit that referenced this issue Sep 19, 2024
The SOF agent.h interface is a system agent that is implemented on top
of SOF audio task scheduling interface. An agent task is added to the
low-latency scheduler to monitor health of the system. The current
implementation is actually RTOS agnostic and can run on top of both
Zephyr and XTOS.

Some RTOSes offer a lower level watchdog interface to implement system
monitoring. Previously agent.h was considered as the abstraction point,
onto which RTOS specific implementations can be hooked in.

This patch moves agent.h back to application interface. In the future, a
more low-level agent hooking into a watchdog system (either hardware
watchdog directly, or software abstraction like Zephyr's task_wdt) can
be added on the side, and enabled on a per target basis. The audio
scheduler level SOF agent will continue to be available as an option,
and can be used with all RTOS'es.

Link: #9015
Signed-off-by: Kai Vehmanen <[email protected]>
@LaurentiuM1234
Copy link
Contributor

LaurentiuM1234 commented Sep 19, 2024

Just thinking out loud here regarding xtos/sof/lib/mailbox.h: would it be better to define the mailbox regions inside the DT overlays and have a generic mailbox.h defining all the mailbox macros based on the DT?

i.e: something like:

chosen {
    sof,mbox-dspbox = &dspbox;
    sof,mbox-hostbox = &hostbox;
    sof,mbox-stream = &stream
};

sof-mailbox {
    dspbox: memory@cafebabe {
        reg = <0xcafebabe 0x1000>;
    };

   hostbox: memory@deadbabe {
        reg = <0xdeadbabe 0x1000>;
    };

   stream: memory@babebabe {
        reg = <0xbabebabe 0x1000>;
   };
};

The new mailbox header would look something like:

#define BUILD_FAIL_IF_MBOX_NOT_DEFINED(mbox_chosen)
    BUILD_ASSERT(DT_NODE_EXISTS(mbox_chosen), "mandatory mbox <insert name here via stringify> not defined"))

#define MAILBOX_HOSTBOX_BASE DT_REG_ADDR(DT_CHOSEN(sof_mbox_hostbox))
#define MAILBOX_HOSTBOX_SIZE DT_REG_SIZE(DT_CHOSEN(sof_mbox_hostbox))

... define all required macros this way ...

/* these should help ppl figure out if they're missing some definitions */
BUILD_FAIL_IF_MBOX_NOT_DEFINED(sof_mbox_hostbox)
BUILD_FAIL_IF_MBOX_NOT_DEFINED(sof_mbox_dspbox)
BUILD_FAIL_IF_MBOX_NOT_DEFINED(sof_mbox_stream)

/* the following chunk would allow platforms to overwrite the macros and add their custom data if need be */
#ifdef CONFIG_PLATFORM_HAS_CUSTOM_MBOX_DATA
/* TODO: include platform-specific header here */
#endif /* CONFIG_PLATFORM_HAS_CUSTOM_MBOX_DATA */

One obvious problem that I see with this is that the messages from the failed BUILD_ASSERT statements are kinda ugly but if you scroll through them the warning string should tell you exactly what you're missing.

Also, I'm not sure how well this would play out on Intel platforms. I've been messing around with this idea on nxp platforms and I think it might work out. Also, not sure how good of an idea is to add application-specific chosen nodes....

This would also get rid of having to add the platform-specific mailbox.h unless you really need to.

@kv2019i
Copy link
Collaborator Author

kv2019i commented Sep 20, 2024

Thanks @LaurentiuM1234 . mailbox.h is one of the more complex cases. With many platform interfaces, once you move to use native Zephyr drivers, most of the platform interface usage gets removed automatically (makes sense, talking to hw should go via drivers). But with mailbox we actually have quite a bit of use remaining in generic SOF code.

I think the DT overlay would work. In fact for Intel platforms, the mailbox addresses are actually already defined via DT entries in soc/src/platform/meteorlake/include/platform/lib/memory.h:
DT_REG_ADDR(DT_PHANDLE(MEM_WINDOW_NODE(n), memory))
-> WIN_BASE
-> SRAM_FOO_BASE
-> MAILBOX_FOO_BASE

That's a good question whether mandating a SOF side DT overlay adds value anymore or do we get same result by leaving a minimal platform layer for mailbox.h. And for e.g. Intel this turns into simple mapping to a DT entry already defined in Zephyr that is same for all Intel platforms.

Another approach might be to improve and scale up the "adsp_host_ipc" DT interface used by zephyr/soc/intel/intel_adsp/common/ipc.c . This is essentially the driver interface to talk to host and I think for longterm it would be better to move all current mailbox use to this interface (or maybe have two, one for IPC send/receiv and one to write to shared debug area). Majority of mailbox.h use is stll just to implement IPC to host, with a smaller set of use for debug (and some could clearly be replaced with other Zephyr mechanisms). This would also make it easier to use SOF on platforms that don't have a similar mapped memory between host and the DSP. E.g. you send IPC via ipc_send_message() Zephyr call, but implementation details are driver specific.

@LaurentiuM1234
Copy link
Contributor

LaurentiuM1234 commented Sep 20, 2024

Another approach might be to improve and scale up the "adsp_host_ipc" DT interface used by zephyr/soc/intel/intel_adsp/common/ipc.c . This is essentially the driver interface to talk to host and I think for longterm it would be better to move all current mailbox use to this interface (or maybe have two, one for IPC send/receiv and one to write to shared debug area). Majority of mailbox.h use is stll just to implement IPC to host, with a smaller set of use for debug (and some could clearly be replaced with other Zephyr mechanisms). This would also make it easier to use SOF on platforms that don't have a similar mapped memory between host and the DSP. E.g. you send IPC via ipc_send_message() Zephyr call, but implementation details are driver specific.

I like the idea of using a driver for the IPC stuff. One aparent flaw I've noticed with our current mailbox implementation is that it's not really MMU friendly. On imx93 (ARM64 architecture, MMU enabled) we had to deal with this by adding some static phys-virt mappings inside mmu_regions.c. I'm thinking that, ideally, this shouldn't be required. Instead, we should have an IPC driver handling this stuff via device_map calls on the mbox regions. Additionally, this would make it easier to port SOF to new architectures if need be.

If we are to add such a driver in Zephyr (or extend the one used by Intel) assuming we're going to be using Zephyr's mbox API, we also need to switch our mailbox unit driver (talking about the imx one) to Zephyr (we already have 2 of them, but not sure how "complete" they are - @iuliana-prodan may be able to comment on this). Nevertheless, it's some extra work, but it must be done at some point.

kv2019i added a commit to kv2019i/sof that referenced this issue Sep 27, 2024
The SOF perf_cnt.h provides a simple performance counter interface that
is used in SOF to track performance at audio module and pipeline level.

Majority of the implementation is RTOS agnostic, relying on
sof_cycle_get_64() to sample platform clock, and timer_get_system() for
CPU clock, both defined in rtos/timer.h. There is however some
conditional rules for Zephyr to use timing_counter_get() if SOF is built
with CONFIG_TIMING_FUNCTIONS=y.

The amount of RTOS variation does not seem to warrant branching the
whole perf_cnt.h to RTOS layer. Move perf_cnt.h back to application
interface, so the single implementation can be shared.

Link: thesofproject#9015
Signed-off-by: Kai Vehmanen <[email protected]>
lgirdwood pushed a commit that referenced this issue Oct 1, 2024
The SOF perf_cnt.h provides a simple performance counter interface that
is used in SOF to track performance at audio module and pipeline level.

Majority of the implementation is RTOS agnostic, relying on
sof_cycle_get_64() to sample platform clock, and timer_get_system() for
CPU clock, both defined in rtos/timer.h. There is however some
conditional rules for Zephyr to use timing_counter_get() if SOF is built
with CONFIG_TIMING_FUNCTIONS=y.

The amount of RTOS variation does not seem to warrant branching the
whole perf_cnt.h to RTOS layer. Move perf_cnt.h back to application
interface, so the single implementation can be shared.

Link: #9015
Signed-off-by: Kai Vehmanen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Zephyr Issues only observed with Zephyr integrated
Projects
None yet
Development

No branches or pull requests

3 participants