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

Add and remove CPU from epoch computation on active and idle #3920

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Alan-Jowett
Copy link
Member

@Alan-Jowett Alan-Jowett commented Oct 8, 2024

Description

Restore the changes reverted by 205802b and fix a bug that was causing use after free (the for loop for computing oldest epoch was malformed resulting in a no-op).

Note: This is intentionally three or more commits:

  1. Restore the reverted code (including the bug).
  2. Fix the bug.
  3. PR feedback and addition of new tests.

Testing

CI/CD + 24 hour run of api_test.exe (previously failing after 2 hours).

Documentation

Yes, in the files.

Installation

No.

@Alan-Jowett
Copy link
Member Author

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

CodiumAI-Agent commented Oct 8, 2024

PR Reviewer Guide 🔍

(Review updated until commit af048fb)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Thread Safety
The code modifies shared state without sufficient synchronization mechanisms in several places, which could lead to race conditions or data corruption in a multi-threaded environment.

Resource Leak
The new implementation introduces potential resource leaks where allocated resources on error paths are not always properly freed or handled.

Error Handling
Error paths may not correctly restore previous states, potentially leaving the system in an inconsistent state after an error.

libs/runtime/ebpf_epoch.c Outdated Show resolved Hide resolved
libs/runtime/ebpf_epoch.c Outdated Show resolved Hide resolved
@Alan-Jowett Alan-Jowett force-pushed the cpu_activation branch 6 times, most recently from 7b60ca4 to 6dfd02b Compare October 9, 2024 18:24
Copy link
Collaborator

@hawkinsw hawkinsw left a comment

Choose a reason for hiding this comment

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

I hope that what I wrote isn't too annoying.

libs/runtime/unit/platform_unit_test.cpp Outdated Show resolved Hide resolved
@Alan-Jowett
Copy link
Member Author

I hope that what I wrote isn't too annoying.

No, I loved it. I dislike that en-gb and en-us differ like this :-P

@CodiumAI-Agent
Copy link

Persistent review updated to latest commit af048fb

libs/runtime/unit/platform_unit_test.cpp Outdated Show resolved Hide resolved
libs/runtime/ebpf_epoch.c Outdated Show resolved Hide resolved
@Alan-Jowett Alan-Jowett force-pushed the cpu_activation branch 2 times, most recently from 1b357e6 to 0bb37d0 Compare October 10, 2024 18:53
@Alan-Jowett Alan-Jowett marked this pull request as draft October 16, 2024 22:14
@Alan-Jowett
Copy link
Member Author

Converting to draft until usersim bug is fixed.

@Alan-Jowett Alan-Jowett force-pushed the cpu_activation branch 2 times, most recently from 88d6e89 to 98263a7 Compare November 3, 2024 23:00
@Alan-Jowett Alan-Jowett force-pushed the cpu_activation branch 2 times, most recently from d4a4a2b to 9ed7807 Compare November 21, 2024 23:39
@Alan-Jowett Alan-Jowett marked this pull request as ready for review November 21, 2024 23:39

while (entry != &cpu_entry->epoch_state_list) {
// Walk over each thread_entry in the epoch_state_list and compute the minimum epoch.
for (ebpf_list_entry_t* entry = cpu_entry->epoch_state_list.Flink; entry != &cpu_entry->epoch_state_list;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we were activating, do we still need to iterate over the state list? Won't the current epoch of everything on this CPU still be EBPF_EPOCH_UNKNOWN (even though we've updated the freed epoch).

Also, should the current epoch (as well as freed_epoch) for each state entry be updated to current_epoch in the above loop?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, I think it would be current_epoch-1 for the start epoch of the threads that started while we were activating, since this is the first propose since we started activation.

@Alan-Jowett
Copy link
Member Author

Alan-Jowett commented Dec 3, 2024

Switching to draft until usersim is fixed microsoft/usersim#224

@Alan-Jowett Alan-Jowett marked this pull request as draft December 3, 2024 17:16
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.

5 participants