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

depmod: Use shared/ more often #193

Closed
wants to merge 3 commits into from

Conversation

stoeckmann
Copy link
Contributor

The dependency output code basically contained its own version of shared/array and shared/strbuf.

Use these implementations for easier code, smaller binary size and slightly faster runtime due to reusage of memory.

@stoeckmann stoeckmann marked this pull request as draft October 18, 2024 15:34
@evelikov
Copy link
Collaborator

Btw if you want to de-duplicate depmod, here's another similar task #62

@stoeckmann stoeckmann marked this pull request as ready for review October 18, 2024 16:16
Copy link
Collaborator

@evelikov evelikov left a comment

Choose a reason for hiding this comment

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

Couple of minor suggestions, but looking great overall.

tools/depmod.c Outdated
continue;
} else if (err < 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: there is no need for an else after continue/return/break

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merged into one, since an error here is the unlikely code path.

tools/depmod.c Outdated
@@ -2071,39 +2037,42 @@ static inline const char *mod_get_compressed_path(const struct mod *mod)
static int output_deps(struct depmod *depmod, FILE *out)
{
size_t i;
struct array array;

array_init(&array, 8);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Quick grep on a couple kernels shows we peak at 30, so let's bump this to 32 or even 64 if we want to splash out :-P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted with 64

tools/depmod.c Outdated
@@ -2112,28 +2081,28 @@ static int output_deps_bin(struct depmod *depmod, FILE *out)
if (idx == NULL)
return -ENOMEM;

array_init(&array, 8);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted with 64

tools/depmod.c Outdated
}
line[linepos] = '\0';
line = sbuf.used > 0 ? strbuf_str(&sbuf) : "";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Let's drop the strbuf.used check here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted, forgot that it's safe now.

tools/depmod.c Outdated
for (idx = 0; idx < depmod->modules.count; idx++) {
struct mod *m = depmod->modules.array[idx];
m->idx = idx;
if (depmod->modules.count > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be > 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted

tools/depmod.c Outdated Show resolved Hide resolved
Copy link
Contributor

@lucasdemarchi lucasdemarchi left a comment

Choose a reason for hiding this comment

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

a few nits, but LGTM

tools/depmod.c Outdated Show resolved Hide resolved
tools/depmod.c Outdated Show resolved Hide resolved
tools/depmod.c Outdated Show resolved Hide resolved
tools/depmod.c Show resolved Hide resolved
The shared/array implementation is already used within depmod, but not
for dependency output. Adding it here reduces the amount of custom code
in depmod, simplifies auditing, reduces binary size, and has the nice
benefit of slightly faster runtime due to memory reusage.

Signed-off-by: Tobias Stoeckmann <[email protected]>
Use shared/strbuf instead of manually re-implementing its features.
Reduces the amount of custom code in depmod, simplifies auditing,
reduces binary size, and has the nice benefit of slightly faster
runtime due to memory reusage.

Signed-off-by: Tobias Stoeckmann <[email protected]>
Calling qsort with NULL argument is invalid, although size 0 would
prevent anything bad from happening. Make sure that UBSAN is not
triggered.

Signed-off-by: Tobias Stoeckmann <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 22, 2024
The shared/array implementation is already used within depmod, but not
for dependency output. Adding it here reduces the amount of custom code
in depmod, simplifies auditing, reduces binary size, and has the nice
benefit of slightly faster runtime due to memory reusage.

Signed-off-by: Tobias Stoeckmann <[email protected]>
Reviewed-by: Emil Velikov <[email protected]>
Link: #193
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 22, 2024
Use shared/strbuf instead of manually re-implementing its features.
Reduces the amount of custom code in depmod, simplifies auditing,
reduces binary size, and has the nice benefit of slightly faster
runtime due to memory reusage.

Signed-off-by: Tobias Stoeckmann <[email protected]>
Reviewed-by: Emil Velikov <[email protected]>
Link: #193
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 22, 2024
Calling qsort with NULL argument is invalid, although size 0 would
prevent anything bad from happening. Make sure that UBSAN is not
triggered.

Signed-off-by: Tobias Stoeckmann <[email protected]>
Reviewed-by: Emil Velikov <[email protected]>
Link: #193
Signed-off-by: Lucas De Marchi <[email protected]>
@lucasdemarchi
Copy link
Contributor

Applied, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants