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

Hardware api 2 #7

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Hardware api 2 #7

wants to merge 8 commits into from

Conversation

alwin-joshy
Copy link
Owner

No description provided.

Beginning to port the hardware debug API to aarch64.
Currently, I have broken the existing code into a
32 bit and 64 bit variant with no overlap between
the two, although they share a decent amount of code.
I intend to make everything functional before pulling
out the common code and structuring it better. At
the moment, the breakpoint_001 test passes.

Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
Watchpoints implemented and passing seL4test. Single stepping
implementation compiles but has not been tested.

Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
@Indanz
Copy link

Indanz commented Jan 23, 2024

Currently the diff is very hard to review because the code moves from e.g. include/arch/arm/arch/machine/debug.h to include/arch/arm/arch/32/mode/machine/debug.h isn't recognised. I would prefer if you would keep the code in include/arch/arm/arch/machine/debug.h with ifdefs for aarch32 and aarch64, so that all changes to the current code are easily reviewed. Same for debug.c.

If you use git mv, it should recognise it, preserve history and reduce the diff, so that's also an option. Preserving history for a file that is split into two is also possible, but a little bit more complicated (you need to do two git mv's in separate branches and merge them, maybe it's easier with newer git).

@alwin-joshy
Copy link
Owner Author

alwin-joshy commented Jan 23, 2024

Currently the diff is very hard to review because the code moves from e.g. include/arch/arm/arch/machine/debug.h to include/arch/arm/arch/32/mode/machine/debug.h isn't recognised. I would prefer if you would keep the code in include/arch/arm/arch/machine/debug.h with ifdefs for aarch32 and aarch64, so that all changes to the current code are easily reviewed. Same for debug.c.

If you use git mv, it should recognise it, preserve history and reduce the diff, so that's also an option. Preserving history for a file that is split into two is also possible, but a little bit more complicated (you need to do two git mv's in separate branches and merge them, maybe it's easier with newer git).

Yeah, it's quite painful. The original code seems to have been written with only ARMv7 in mind, which makes it painful to refactor nicely to include aarch64. I'll see what I can do to make it easier to review but I have a feeling it's going to be kind of ugly no matter what.

Edit: I didn't know about git mv though. Maybe that will make it less horrible.

@Indanz
Copy link

Indanz commented Jan 23, 2024

I'll see what I can do to make it easier to review but I have a feeling it's going to be kind of ugly no matter what.

Edit: I didn't know about git mv though. Maybe that will make it less horrible.

Use git mv for files that will end up being mostly arch specific, and use ifdefs for files that will end up mostly the same.

If you want to split a file, you need to do something complicated (see e.g. here, but make sure you do all this on a temporary branch so you won't accidentally mess up everything).

But if we end up with some kind of ugly, I'd prefer ifdefs with at least correct history and easier to review diffs. We can do the proper file moves and splitting at the very end.

@alwin-joshy
Copy link
Owner Author

@Indanz Do you think it would be good to break it up into two PRs for clarity?

One that restructures the existing hardware debug API (like #8) and another pull request that adds support for aarch64.

@Indanz
Copy link

Indanz commented Feb 14, 2024

Looking at the size of the diff, that might be a good idea.

But whether it's one or two PRs doesn't matter much, it's how easy it is to check for correctness that counts. The main way to achieve that is to separate big moves that touch a lot of lines, but don't change content, from actual changes in content.

The advantage of one PR is that you see why things are done (well, theoretically).

What you have in #8 is already much better, but instead of copying src/arch/arm/32/machine/debug.c back into src/arch/arm/machine/debug.c, make a branch that does the initial move and merge that branch back later on.

After that you want a commit that removes duplicate lines, with no other changes in the moved files (it's okay to move declarations from one header to another, for instance, and do anything else to make it compile). It's a lot easier to convince git to keep both files if you do the duplicate line removal in two separate commits, one in your main branch and on in the mv branch, as it will notice a conflict and you can resolve it by keeping src/arch/arm/machine/debug.c as-is.

At this point you should have split the file in two and everything should still work, without any code content changes anywhere. You can delete your temporary branch now.

And then you want to commit any actual changes in code, like removing static from function declarations and whatever else you want to do. Like moving DEBUG_GENERATE_READ_FN from debug.c file to debug.h, but please make it a static inline if you do.

And lastly, you could add aarch64 support, but if that's a lot it can be done in a separate PR too.

@alwin-joshy
Copy link
Owner Author

Okay thanks, I'll give that a go

@alwin-joshy
Copy link
Owner Author

alwin-joshy commented Feb 14, 2024

@Indanz One thing I don't really get in the remove duplication step is, what about static functions that are used by both arm/machine/debug.c and arm/32/machine/debug.c? Should I just leave a copy of the function in both files in this step to get it compiling and clean it up by making it non-static and adding it to the header file in the next commit?

@Indanz
Copy link

Indanz commented Feb 14, 2024

I would only keep the version you want to keep after the merge. Don't try to make it compile pre-merge. I forgot about static functions, those you could make non-static when removing the unused code, or do it in the merge itself, or in a separate commit. It doesn't matter much because the change is local and self-contained, unlike the refactoring.

@alwin-joshy
Copy link
Owner Author

alwin-joshy commented Feb 15, 2024

@Indanz I tried something like what you said in seL4#1198. Normal merging didn't really work, so I ended up doing the octopus merge solution from https://devblogs.microsoft.com/oldnewthing/20190917-00/?p=102894.

@alwin-joshy
Copy link
Owner Author

@Indanz Not sure if the mention worked last time because I edited it in, but I've now got this more or less done with the aarch64 port in the same PR #10. Is this more like what you wanted?

@Indanz
Copy link

Indanz commented Feb 16, 2024

Review-wise, that looks exactly like I meant, very good. However, I think history gets lost for the new file (git blame shows you as author for moved files, for instance). I'll try something tomorrow to see if I can convince git to do what I want.

@alwin-joshy
Copy link
Owner Author

That's weird, I swear it was right at some point. Something might have messed up when I cherry-picked the aarch64 changes from another branch.

@Indanz
Copy link

Indanz commented Feb 18, 2024

Okay, I think I got the history right at least, please check I didn't mess anything up, see my refactor_hw_debug_aarch32_attempt_iz branch.

I did:

  • Do the git mv and remove lines that aren't supposed to end up in the new file. This was done in branch refactor_hw_debug_aarch32_attempt_iz_split.
  • Start fresh and cherry picked your commit 268e3bf, but without the addition of the new file. This removes the lines that were moved to the arch32 file.
  • Merged refactor_hw_debug_aarch32_attempt_iz_split. Now we have both files with correct history and hopefully no duplicate code at any point. (Here git was a bit fuzzy and I used src/arch/arm/32/machine/debug.c from the split branch to resolve the conflict.)
  • Then I cherry picked your compilation fix and aarch64 commits.

@alwin-joshy
Copy link
Owner Author

alwin-joshy commented Feb 19, 2024

@Indanz Looks good, there are a couple of TODOs Ieft in there that I should fix, but if you're happy with the git aspect, we can move on to a submitting an actual PR after I fix those.

EDIT: Done, you can find the extra stuff here: seL4/seL4@master...alwin-joshy:refactor_hw_debug_aarch32_attempt_iz. I'll probably squash this one with the last one if you're okay with the changes.

@Indanz
Copy link

Indanz commented Feb 19, 2024

I'd do an interactive rebase and add the 32-bit fixes to "change files to allow compilation" and squash the 64-bit fixes with the last commit.

So, other than the horrible DEBUG_GENERATE_*_FN macro, what I don't like are the unexplained changes to the current 32-bit code. Those should be done in a separate commits with explanations I think.

Same for cosmetic changes like renaming all fields: Either don't do that at all, or at least do it in a separate commit.

@alwin-joshy
Copy link
Owner Author

@Indanz Okay, I think I've done that. Not too sure which changes to aarch32 code you mean, I think the only real changes I've made to aarch32 are the names of the fields, which I've now put into a seperate commit, and the Arch_setupBcr/Wcr functions, which I changed because there would have been duplicated code in the aarch32 and aarch64 implementations.

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.

2 participants