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

Adapt GPU label support to debugfs DRM entry changes #802

Merged
merged 1 commit into from
Dec 17, 2021

Conversation

eero-t
Copy link
Contributor

@eero-t eero-t commented Dec 10, 2021

"gen" number is in latest kernels capabilities files replaced with separate display, graphics, and media versions.

For compatibility with newer kernels, provide "gen" based on the new labels (but without decimals), and for older kernel compatibility, new labels based on "gen".

Optimize capabilities file parsing by using prefix check instead of scanf.

@codecov-commenter
Copy link

codecov-commenter commented Dec 10, 2021

Codecov Report

Merging #802 (449be9f) into main (26f1a0e) will increase coverage by 0.23%.
The diff coverage is 89.74%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #802      +/-   ##
==========================================
+ Coverage   53.70%   53.94%   +0.23%     
==========================================
  Files          39       39              
  Lines        3545     3572      +27     
==========================================
+ Hits         1904     1927      +23     
- Misses       1531     1533       +2     
- Partials      110      112       +2     
Impacted Files Coverage Δ
cmd/gpu_nfdhook/labeler.go 79.71% <89.74%> (+1.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 26f1a0e...449be9f. Read the comment docs.

Copy link
Contributor

@mythi mythi left a comment

Choose a reason for hiding this comment

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

lgtm

uniemimu
uniemimu previously approved these changes Dec 14, 2021
Copy link
Contributor

@uniemimu uniemimu left a comment

Choose a reason for hiding this comment

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

lgtm

Comment on lines 202 to 219
for prefix, action := range searchStringActionMap {
line := scanner.Text()
if !strings.HasPrefix(line, prefix) {
continue
}
fields := strings.Split(line, ": ")
if len(fields) == 2 {
action(fields[1])
} else {
klog.Warningf("invalid '%s' line format: '%s'", file.Name(), line)
}
delete(searchStringActionMap, prefix)
if len(searchStringActionMap) == 0 {
return
}
break
}
Copy link
Contributor

@rojkov rojkov Dec 16, 2021

Choose a reason for hiding this comment

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

Do I understand it right that we take a first entry in searchStringActionMap (which can be any) and look for it in the first line. If not found we take another entry and look for it in the second line (but not in the first line). If we are lucky and the second entry of the unordered map coincided with the second line then we either stop iterating or return from the function at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Admittedly the code is a bit convoluted, partly because the original was also, before Eero touched it. My folt.

The code does indeed take the first entry in the searchStringActionMap and looks for the prefix from THE line. If the prefix is NOT found, another string from the map is attempted (the continue -path) with the same line from the scanner. The scanner does not progress forward with a call to Text(). Perhaps one could take the "line := scanner.Text()" out of the loop? Probably.

If the string IS found, well eventually either the whole function returns in case there are no more strings left in the map, or we proceed with the break-path which means the for loop exits, and another line is read from the scanner. That means, another line from the capability file gets investigated with the same reducing search map.

@eero-t
Copy link
Contributor Author

eero-t commented Dec 16, 2021

I wondered why tests did not catch the bug that I had retained "return" [1] for the case when "searchStringActionMap" goes empty, until I realized that it does not get empty any more. There is either "gen" or *_version strings in the capability file, but not both i.e. with new kernels the whole capability file will be scanned (even without this PR), until we can remove check for "gen"...

(And "gen" support can be dropped only when even LTS kernels have upgraded from "gen" to *_version fields.)

[1] Check should break from both loops using name break (or goto), or by being moved one level up (i.e. would be done for every line). Any preferences?

Comment on lines +215 to 217
if len(searchStringActionMap) == 0 {
break scanning
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess now this check can be moved right after the loop. Then there would be no need for the loop label.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then it would be run for every capabilities line, instead of only when one of the prefixes matches. With drm-tip on DG1:

# wc -l /sys/kernel/debug/dri/*/i915_capabilities 
104 /sys/kernel/debug/dri/0/i915_capabilities

i.e. 104 instead of 2-3 times.

Copy link
Contributor

Choose a reason for hiding this comment

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

The internal loop breaks right after the check unconditionally. I don't expect it to keep iterating.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It keeps iterating because it never becomes empty with current kernels, and while both "gen" and *_version fields are supported. All the kernel capability files I have seen, have either "gen" or *_version fields, not both.

Copy link
Contributor

Choose a reason for hiding this comment

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

I missed something. What never becomes empty? searchStringActionMap?

If one of the prefixes matches then the internal loop breaks and doesn't iterate regardless of the map's emptiness.

Copy link
Contributor Author

@eero-t eero-t Dec 16, 2021

Choose a reason for hiding this comment

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

Yes, currently searchStringActionMap never becomes empty for the reason I stated, therefore all lines in the capability file will be parsed (even before this PR, in case of newer kernels). Along with the number of map keys increasing, that's why this PR optimizes the map key comparisons.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Now I see what you mean. Thanks! Let's keep it this way too.

cmd/gpu_nfdhook/labeler.go Show resolved Hide resolved
rojkov
rojkov previously approved these changes Dec 16, 2021
Comment on lines +215 to 217
if len(searchStringActionMap) == 0 {
break scanning
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Now I see what you mean. Thanks! Let's keep it this way too.

uniemimu
uniemimu previously approved these changes Dec 16, 2021
@mythi
Copy link
Contributor

mythi commented Dec 16, 2021

@eero-t can you squash the commits still, thanks!

GPU generation "gen" number is replaced in the capability files of
latest kernels with separate display, graphics, and media versions.

For compatibility with newer kernels, provide "gen" based on the new
labels (but without decimals), and for older kernel compatibility, new
labels based on the "gen".

Because different kernels match different items from the action map,
whole capability file will get parsed. Capability file parsing is
optimized by using prefix check instead of scanf.

"platform_gen" label is deprecated, and can be dropped whenever it
becomes inconvenient (lint complains about line count etc).
@eero-t
Copy link
Contributor Author

eero-t commented Dec 16, 2021

Rebased to latest main, squashed to single commit, and updated the commit description.

@mythi mythi merged commit 8058d3c into intel:main Dec 17, 2021
@eero-t eero-t deleted the nfd-gen-label branch December 28, 2021 09:49
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.

None yet

5 participants