i am trying to solve this ticket Making sure you're not a bot! and currently my ticket is under review and as per the requirements @phoudoin asked me to use X86_NOP because there is no more need for these X86_NOP1,2,3… in the void
arch_altcodepatch_replace(uint16 tag, void* newcodepatch, size_t length) function the problem is i cannot just simply delete all these definitions as other functions in other files may be using it and just simply defining X86_NOP and X86_NOP1 to one hexadecimal code feels odd and adding definitions to these X86_JMP_REL8, X86_JMP_REL32 sort of damages the half pyramid design that was designed before can you guys suggest me a design or way through this??
https://review.haiku-os.org/c/haiku/+/12624/10 this is my patch and currently in .h file i mistakenly removed the definitions for those thinking they are not used anywhere.
Better ask questions like this on the review… there the reviewers can answer you. Not every developer reads this forum
Yes but there is no pictures option to show like this
I quick check using OpenGrok search for X86_NOP1 to X86_NOP9 shows they are only used there, in arch_altcodepatch_replace().
It was named X86_NOP1 to X86_NOP6 not because it’s actual names of X86 instructions, but to represent what each sequence are equivalent to executing how times a single X86 NOP instruction, so 1 up to 9 X86 NOP instructions.
But as your optimization using JMP instructions allows to do any necessary jump in max 5 bytes of X86 instructions code, this “cascading pyramid” or sequences is not needed, as now its replaced by
- to skip 1 byte of code => 0x90 (aka x86 “NOP” instruction)
- to skip between 2 and 129 bytes of code => 0xEB (aka x86 “JMP_REL8” instruction) + one byte with the [-128 .. 127] length of the jump
- beyond 129 bytes of code to skip => 0xE9 (aka x86 “JMP_REL32” instruction) + 4 bytes with the [-2147483648 .. 2147483647] length of the jump.
You don’t need anymore the previous cascading pyramid of instructions sequence down to a single NOP, as with just a condition check and without needing to loop, you now have max 5 bytes needed to jump from just one single byte of code to up to 2147483652 (forward only, as only need forward jump).
Your optimization is making the pyramid which was designed before deprecated and far less performant.
And as it was used nowhere else, enjoy remove it!
Frankly speaking, I don’t think this ticket is a good start for a new contributor with a lack of x86 assembly knowledge, and x86 cpu arch concepts, like instruction fetching, decoding, branching and branch predictions, pipelining etc. And even with all that knowledge, one would need to carefully benchmark the performance on real hardware before and after the change.
I’d suggest OP to leave the current code as it is and pick some other kernel code that doesn’t require deep CPU arch knowledge.
In any case, I have added my performance concerns both to the review and the ticket.
that explanation provides very thoughtful insights and thanks for taking time to explain me the architecture sure i will remove it but there are some points raised by @VoloDroid that replacing the NOP with JMP causes a halt in performance, as a beginner i cannot understand the exact reason why
thanks for the advice , i can understand that it is out of my scope but i tried solving the issue by reading some intel developer manuals ![]()
https://review.haiku-os.org/c/haiku/+/12624 this is the final patchset corrected by things you mentioned but whether this improves the performance or downgrades it have to be decided by you guys as i don’t have deeper understanding on the cpu architectures
How do you think people learn about such things, if not by experimenting with it?
To me it seems like a good start if you’re interested about such things, and the lesson learnt is that you should not trust all the tickets with optimization ideas, and when working on such things, you should always prepare a way to measure the performance impact of your changes.
When I started contributing I was not capable of solving any ticket on my own. I think it is perfectly fine to attempt stuff in your area of interest, as long as you are willing to learn and be helped along the way. Which seems certainly the case here ![]()
thanks for the support ![]()
I guess my previous comment was not clear enough. The ticket #20101 OP was working on was labeled as (easy) in Trac, which I assume is the way to let new contributors know which are the good first tickets to address (pls, correct me if I’m wrong here). My point is, the ticket is not easy at all, and it’s not a good start for a new contributor, unless they already have quite specific x86 knowledge, or they are actively looking into learning and improving the knowledge of the x86 architecture. I don’t think that was the case here, as OP in their initial post on the forum said they don’t know where to start and asked for a direction:
The problem is i just don’t know where and how to start with things it would really help me if you give me any kind of direction
So yeah, @Sathwik-88 my suggestion for you would be: don’t dive into arch specifics or assembly language until you feel confident with more high-level Haiku stuff. Otherwise, you risk becoming disappointed and losing motivation when you won’t see quick successful results.
And btw, I’m not checking the forum everyday these days, so I’ve just seen you sent me a DM. I’d be happy to help. I’ll write you back today with a few ideas.
That’s the goal of the “easy” tag, but it turns out identifying such easy tickets is not… easy. I think the idea is to mark the ones where we already have a good description of what needs to be done, and just waiting for someone to write the code. In other cases there is some level of investigation needed first, to understand the problem.
This means we can provide guidance and help, and there shouldn’t be a situation where a newcomer asks a question and it turns out no one has the answer.
There’s also the problem that actually very easy tasks tend to get solved quickly by the existing developers, as that’s usually easier than writing a ticket (there’s no need to “proxy” the development work to someone else).
okayy i will select tickets more wisely and thanks for noticing my DM
understood the point you are trying to make and thanks for the explanation
