It’s the month of December. Do you know what that means? It means it’s time to run my workstation and server with branch tracing enabled! https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/compiler.h#n50
@ljs @rostedt @vbabka You're generally right, but there are a few rare cases where you *WANT* to mispredict.
For example, when waiting for a spinlock, it's more likely to make yet another spin, but I don't care much about the speed of spinning. What I do care about is to leave the spinlock loop ASAP when the lock is finally acquired.
@ljs @rostedt @vbabka Proper performance measurements are hard and extremely time-consuming. And the results are sometimes inconclusive, e.g. variant A runs faster than variant B on hardware X but slower on hardware Y where X and Y are both widely used in practice. Same with different workloads...
I mean, I agree with you; if someone is not able to do all this hard stuff, they'd better stay away from perf stuff. People not realizing diffulty of perf are so pervasive it kills me.
@ljs @ptesarik @rostedt @vbabka i'm not reading it unless you include very random remarks about fish faced people of neptune like this gentleman does https://archive.org/details/the_8088_project_book_grossblatt_robert_1989/mode/2up
@ljs @vbabka This tooling has been around for over a decade. During the month of December, I figure I can run it on my server and workstation as this month is usually slower than other months. But I recently upgraded my server (28 cores / 56 hyperthreaded) and since the profiling updates a single integer (no locking, I’m looking for estimates not real numbers) but the cache line contention is making it impact this server much harder than my older server. It has actually slowed this down much more. I’m thinking of just running it for one week and not three like I use to.
Anyway, the likely/unlikely can be a big performance increase. I sped up the ftrace ring buffer by around 50% by placing strategic likely and unlikely around.
@ptesarik @ljs @vbabka Noted. There’s a lot of bad annotations, and most of them I ignore because they are not obvious that they are indeed wrong. Things like “stats” use to be unlikely (before they were switched over to static_branch
). Because they were runtime switches and the idea is “if you have it disabled, you likely want it to be faster”. So having it enabled would be 100% incorrect. But that was indeed the correct outcome.
Before sending any patch to fix or remove a likely/unlikely() I analyze it to understand the reason it is incorrect. I never blindly send a patch because the tool said so. I send it after I understand the situation. A lot of the fixes I have done were because the likely use to be correct, but a change occurred that made it incorrect. One example of this was a case that a condition was added before the unlikely annotation condition to always be true. The added condition exited the function in 90% of the cases that would have caused the unlikely condition to be unlikely. Now when that condition is hit, it was 90% likely.
Here’s an article I wrote while at VMware. Read it now before they take it down (VMware no longer exists!) I need to copy it too.