-
Notifications
You must be signed in to change notification settings - Fork 393
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
Fix PerfBuffer shutdown #638
Fix PerfBuffer shutdown #638
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @eyakubovich!
LGTM
only two small comments
libbpfgo/selftest/perfbuffers/run.sh
Outdated
MINOR_VERSION_LIMIT=$(echo $VERSION_LIMIT | cut -d '.' -f2) | ||
MINOR_CURRENT_VERSION=$(echo $CURRENT_VERSION | cut -d '.' -f2) | ||
if (( $(echo "$MINOR_CURRENT_VERSION < $MINOR_VERSION_LIMIT") |bc -l)); then | ||
echo -e "${RED}[*] OUTDATED MINOR KERNEL VERSION${NC}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
$MAJOR_CURRENT_VERSION > $MAJOR_VERSION_LIMIT -
there is no reason to check for minor, otherwise, version like 6.0 will not pass this test, right?
libbpfgo/selftest/perfbuffers/run.sh
Outdated
MINOR_CURRENT_VERSION=$(echo $CURRENT_VERSION | cut -d '.' -f2) | ||
if (( $(echo "$MINOR_CURRENT_VERSION < $MINOR_VERSION_LIMIT") |bc -l)); then | ||
echo -e "${RED}[*] OUTDATED MINOR KERNEL VERSION${NC}" | ||
exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we want to exit with a value different from 0? If we do want to use exit 0 here, why not for the above major test as well?
@yanivagman the minor/major checks look like they're just copied from the script I have for running the ringbuffer selftest so I can answer for them. For your first comment on checking minor version after major, you're absolutely right. I'm going to have to fix this. The reason we exit 0 is for the sake of the github action not failing. I picture having multiple environments where the github actions run, including older kernels. We should just not run the test if we don't expect the kernel to support it. I suppose we can return a particular exit code and have the test runner make exceptions for this scenario but we're not there yet. |
libbpfgo/libbpfgo.go
Outdated
// result in a deadlock: the channel will fill up and the poll | ||
// goroutine will block in the callback. | ||
go func() { | ||
for _ = range eventsChan { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for _ = range eventsChan { | |
for range eventsChan { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice! I didn't know about this variant of for
.
libbpfgo/libbpfgo.go
Outdated
} | ||
|
||
if lostChan != nil { | ||
for _ = range lostChan { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for _ = range lostChan { | |
for range lostChan { |
libbpfgo/selftest/perfbuffers/run.sh
Outdated
MINOR_VERSION_LIMIT=$(echo $VERSION_LIMIT | cut -d '.' -f2) | ||
MINOR_CURRENT_VERSION=$(echo $CURRENT_VERSION | cut -d '.' -f2) | ||
if (( $(echo "$MINOR_CURRENT_VERSION < $MINOR_VERSION_LIMIT") |bc -l)); then | ||
echo -e "${RED}[*] OUTDATED MINOR KERNEL VERSION${NC}" | ||
exit 0 | ||
else | ||
echo -e "${GREEN}[*] SUFFICIENT KERNEL VERSION${NC}" | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MINOR_VERSION_LIMIT=$(echo $VERSION_LIMIT | cut -d '.' -f2) | |
MINOR_CURRENT_VERSION=$(echo $CURRENT_VERSION | cut -d '.' -f2) | |
if (( $(echo "$MINOR_CURRENT_VERSION < $MINOR_VERSION_LIMIT") |bc -l)); then | |
echo -e "${RED}[*] OUTDATED MINOR KERNEL VERSION${NC}" | |
exit 0 | |
else | |
echo -e "${GREEN}[*] SUFFICIENT KERNEL VERSION${NC}" | |
fi | |
# Check minor version, only if MAJOR_CURRENT_VERSION is same as MAJOR_VERSION_LIMIT | |
MINOR_VERSION_LIMIT=$(echo $VERSION_LIMIT | cut -d '.' -f2) | |
MINOR_CURRENT_VERSION=$(echo $CURRENT_VERSION | cut -d '.' -f2) | |
if (( $(echo "$MAJOR_CURRENT_VERSION == $MAJOR_VERSION_LIMIT") |bc -l)); then | |
if (( $(echo "$MINOR_CURRENT_VERSION < $MINOR_VERSION_LIMIT") |bc -l)); then | |
echo -e "${RED}[*] OUTDATED MINOR KERNEL VERSION${NC}" | |
exit 1 | |
else | |
echo -e "${GREEN}[*] SUFFICIENT KERNEL VERSION${NC}" | |
fi | |
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this look? We only need to check minor version if the major version is equal to the major version limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I copied the whole file (as well as most of the files in the directory) as is from the ringbuffer test and didn't look too much into it. Since we're relying on bc
anyway, you can just compare both major and minor in one shot:
if [ $(echo "$CURRENT_VERSION < $VERSION_LIMIT" | bc) -eq "1" ]; then
echo -e "${RED}[*] OUTDATED KERNEL VERSION${NC}"
exit 1
fi
Also perf buffer was added in 4.3 so I need to adjust the VERSION_LIMIT
value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure bc is good for version comparison:
❯ echo "1.30 < 1.3" | bc
0
I'd recommend sort -v
for version aware comparisons
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, that works too, once you push that change i'll go ahead and approve!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@itaysk you're right, of course, can't compare them as decimals. How do I do it with sort? All I can come up with is:
min=$(sort -V <<EOF | head -n 1
$CURRENT_VERSION
$VERSION_LIMIT
EOF
)
if [ "$min" -ne "$VERSION_LIMIT" ]; then
echo "too low"
fi
Is there anything cleaner?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe something like
test $(echo "$CURRENT_VERSION\n$VERSION_LIMIT" | sort -V | head -n1) = "$VERSION_LIMIT"
(feel free to use Grant's solution as well)
6c83c5e
to
076fa9c
Compare
This is anlogous to 09b2b47 (which fixed RingBuffer). It does a clean PerfBuffer stop by waiting for the polling goroutine to finish its work.
076fa9c
to
77cf435
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks so much @eyakubovich, much appreciated!
This is anlogous to 09b2b47 (which fixed RingBuffer).
It does a clean PerfBuffer stop by waiting for the
polling goroutine to finish its work.
Fixes #640