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

library_manager: Update module load flow #8544

Merged
merged 2 commits into from
Jan 24, 2024

Conversation

softwarecki
Copy link
Collaborator

The previous code have several issues:

  • Did not support empty data segment.
  • It assumed that certain types of segments would be at fixed indexes, without taking into account their flags/types.
  • Incorrect handling of mapping error. If the virtual address cannot be mapped because is already in use, the error handler will unmap this address.
  • If there is an error loading one of the modules marked as lib_code, previously loaded modules are not unloaded.

This commit fixes the above issues, but it probably introduces new problems :)

@softwarecki softwarecki marked this pull request as ready for review November 28, 2023 15:36
Copy link
Contributor

@pjdobrowolski pjdobrowolski left a comment

Choose a reason for hiding this comment

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

Good move to split that long procedure into separate functions.

lyakh
lyakh previously requested changes Nov 29, 2023
src/library_manager/lib_manager.c Outdated Show resolved Hide resolved
src/library_manager/lib_manager.c Outdated Show resolved Hide resolved
src/library_manager/lib_manager.c Outdated Show resolved Hide resolved
@keqiaozhang
Copy link
Collaborator

SOFCI TEST

Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

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

I'd have preferred separate commits as there are distinct separate issues you are addressing. Now the diff is really hard to follow so I instead just read the new code on its own and seems fine.

src/library_manager/lib_manager.c Show resolved Hide resolved

for (idx = 0; idx < ARRAY_SIZE(mod->segment); ++idx) {
if (!mod->segment[idx].flags.r.load)
continue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this skips .bss, so effectively you made a loop for 2 elements. Should we go a step further and integrate .bss here too by either copying data for .data and .text or clearing the buffer for .bss?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lyakh The .bss section is handled differently. Its size is divided by the maximum number of module instances and only the selected fragment for a given instance is mapped.

Copy link
Collaborator

Choose a reason for hiding this comment

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

well, that special .bss handling seems strange to me - it's too ad-hoc IMHO. This means, that you cannot have the same file used both as a loadable module and built-in, because its .bss will be handled differently. Besides it's too special - developers would need to think about it every time they put something in .bss. We discussed this with @pjdobrowolski briefly and maybe we can and should drop that behaviour.
And if we don't and we keep .bss out and only handle .text and .data here, we effectively get a loop over three elements to then throw away one of them, leaving a loop over two iterations - you could just keep it as is unfolded.

Copy link
Member

Choose a reason for hiding this comment

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

@softwarecki @lyakh any update here, should we put a big inline comment here spelling out this difference and its expected behavior from ROM i.e. its done for current compatibility reasons

Copy link
Contributor

Choose a reason for hiding this comment

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

any communication between modules, build-in or loadable should be done by using native-system-services. I'm no sure if making shared bss is good practice for such behavior. Especially if we load and unload modules on fly, what will happen with common bss? Each module will leave it own stuff in there until we will have an overflow/

Copy link
Contributor

Choose a reason for hiding this comment

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

DSP has restricted 3MB of ram which is shared between modules. BSS is defining how much of we use. Can you explain me how removing BSS sections from elf will improve working on such small space?

Copy link
Contributor

Choose a reason for hiding this comment

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

@lyakh You wrote: "This means, that you cannot have the same file used both as a loadable module and built-in...". Where you see use case to have the same code used as loadable and built-in at the same time? I think we do loadable to not have given module built into base FW all the time.
Another think, there are other reasons for having separate .bss section for each module.
One is backward compatibility with reference FW design.
The other even more important is possibility to use in the feature some memory protection features. Mixing up the module .bss with base FW general .bss section will block us from introducing such solution.
The third reason is the debuggability of base FW with presence of external modules. If we mix up the memory spaces, tracking any failures will be more difficult since external modules could corrupt base FW data.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@pjdobrowolski @jxstelter I think there's some confusion here. I'm not proposing to remove .bss or to share .bss between modules or anything special of that kind. I just propose to do what C does: you program

static int module_x;

and it's placed in .bss and it's available there to that file (because it's static). Or you have a global

int global_x;

and it's also in .bss and accessible globally. In all cases there's exactly 1 copy of that object. What I don't understand why loadable modules are linking those objects with module instances. That means, that e.g. if you make volume a loadable module. And you activate 3 pipelines and each of them has a volume component in it so you have 3 instances. So then you give to each instance i.e. to each volume component in each pipeline a separate part of that .bss, i.e. a part of those objects. I understand why it is done, but I don't find this a good idea. It is done to "emulate" a poor-man allocation, so you want to put something like

static struct module_private_data[MAX_MODULE_INSTANCES];

in those modules and then give each instance one of those objects. But I don't find that a good approach. I think it's confusing and misinterpreting the meaning of the ELF .bss section

Copy link
Contributor

Choose a reason for hiding this comment

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

If you would look more carefully in history of commits, you would find out, that connecting .bss with instances was introduce much before idea of "poor-man allocation".

Copy link
Member

Choose a reason for hiding this comment

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

ok, so I think we probably need to make relationship between bss and instances more visible with inline comments in the code here, this way we can avoid any misunderstandings as we continue and add logic for services API and IADK modules.

src/library_manager/lib_manager.c Show resolved Hide resolved
@softwarecki
Copy link
Collaborator Author

I'd have preferred separate commits as there are distinct separate issues you are addressing.

I identified the mentioned issues and simply write a new code from scrach. There were no incremental changes that I could separate.

@lgirdwood
Copy link
Member

@softwarecki fyi some CI failures, there has been a recent west update so you may want to rebase and rerun the CI.

@lyakh lyakh dismissed their stale review December 21, 2023 09:00

I still don't find the .bss handling in loadable modules a good idea, but it seems to be the current convention in IADK

@kv2019i
Copy link
Collaborator

kv2019i commented Jan 9, 2024

@softwarecki This is ready to go, but we'd need a green run for CI, can you check?

@lgirdwood
Copy link
Member

@softwarecki This is ready to go, but we'd need a green run for CI, can you check?

@kv2019i sparse errors ? Do we need a west update to fix them ?

@kv2019i
Copy link
Collaborator

kv2019i commented Jan 9, 2024

@lgirdwood wrote:

@softwarecki This is ready to go, but we'd need a green run for CI, can you check?

@kv2019i sparse errors ? Do we need a west update to fix them ?

"Internal Intel CI System/merge/build — Tests failed " -> https://sof-ci.01.org/sof-pr-viewer/#/build/PR8544/build13245909

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

ok, so we are good to go as soon as CI passes.

@softwarecki
Copy link
Collaborator Author

Im working on it to make CI pass

@softwarecki softwarecki force-pushed the segments branch 2 times, most recently from 34628b3 to bd2059e Compare January 23, 2024 14:36
@lyakh lyakh mentioned this pull request Jan 24, 2024
The previous code have several issues:
* Did not support empty data segment.

* It assumed that certain types of segments would be at fixed indexes,
  without taking into account their flags/types.

* Incorrect handling of mapping error. If the virtual address cannot be
  mapped because is already in use, the error handler will unmap this
  address.

* If there is an error loading one of the modules marked as lib_code,
  previously loaded modules are not unloaded.

This commit fixes the above issues.

Signed-off-by: Adrian Warecki <[email protected]>
A loadable library can contain a several modules marked as lib_code. This
modules contains code shared by a multiple modules.

Signed-off-by: Adrian Warecki <[email protected]>
@softwarecki
Copy link
Collaborator Author

@lgirdwood i think its ready

@lgirdwood
Copy link
Member

Zephr main failures are known and unrelated.

@lgirdwood lgirdwood merged commit fec50da into thesofproject:main Jan 24, 2024
40 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants