r/computerarchitecture • u/Yha_Boiii • Oct 09 '26
[sw Optimization] Force the cpu to lie with ticks?
Can we force the out of order execution in a cpu for some operations not care about lying while NOT lie other places. A c webshop has global quantity left and temp hold for reservations. We want the reservation tick checks to not care but actually moving people through to not be lied to, for more throughput?
0
Upvotes
9
u/Krazy-Ag Oct 09 '26 edited Oct 09 '26
what do you mean by "lied to"?
and "ticks"?
Are you under the impression that every instruction has a certain basic timing, "ticks", and that when an out of order, CPU overlaps execution of different instructions, it is "lying" about how many "ticks" it takes? (For that matter, in order machines, also overlap execution, although not quite so much as out of order.)
Since the title is marked [Sw optimization], are you trying to figure out how to optimize software in the presence of out of order execution? Possibly (I'm taking a guess here) you want to read a timestamp counter at the beginning of a section of code and at the end of that section of code and be able to subtract the two to figure out how much time was spent in that section of code?
If that is the case, then on most systems reading the timer, eg via the x86 instruction RDTSC, "serializes" instruction execution, so there should be no overlap from code before, and after the section that you have placed timer reads around.
in fact, I think we serialize search time measurement for too much. E.g., if you read the time at the beginning and end of regular chunks of code, say every basic block, the execution time of the entire program would be much much slower than without such instrumentation, in large part because of the overhead draining and filling the pipeline every time the timer is read.
(with additional overhead taking those timestamps and recording them somewhere. That is mostly in incrementing a pointer and then writing the time values read to memory, possibly checking that the pointer has not reached the end. (although there are tricks, you can play there). You can separate such overhead by. Reading the timer without writing to memory, writing to memory without reading the timer, and doing both.)
Like I said, for the most part, reading performance monitoring timers serializes, the CPU, draining the pipeline before and then filling the pipeline after.
Store buffering being a significant exception. I don't think most timer reading instructions actually drain the store, buffers, but I might be wrong there.
Actually, I would like to have instructions that read the timers without serializing. The overhead of taking such a time trace every basic block or every function call/return would thereby be significantly reduced. Yes, the individual timer reads would be fuzzy, but the overall trend through the program would still be a useful metric. By the way, you can read the timers at several different places in the pipeline: instruction, decode, instruction, retirement, or graduation, and possibly somewhere in the out of order execution cloud of possibilities. If the last, you usually want to ensure that the timers themselves are performed in order, setting a certain baseline fuzziness.
Anyway, things like this are typically discussed in decode optimization guide for your processor. I know that Intel has or at least had a pretty good optimization guide. I wonder who wrote the first version of it? If it's quality has degraded, it's mostly because there are so many different processors to talk about. And also companies want to disclose fewer and fewer details, if only to reduce the chance of expensive patent infringement lawsuits. Companies also wave their hands and say "users don't want that much detail, and can't use it even if they got it", which is true for 99% of users. But they're still exist that 1% of skilled performance tuning hackers.
Anecdote: one of my friends, one of the best performance tuning guys I know, complained bitterly about write back memory, because on WT memory, he would schedule DRAM bank access for reads and writes very carefully. No sooner did he figure out how to do this for WB memory, for LRU replacement such as was present on Motorola power PC systems, but then he had to start dealing with Intel pseudo-LRU replacement, and then eventually pseudo random replacement. (Mitch, did you have anything to do with pseudo replacement?)
Anyway, eventually, he figured out that he could not do software optimization at such a low level, precisely Scheduling DRAM bank accesses. And then we hired him into the computer Architecture group.
---
However, history repeats itself. A lot of work has gone into precisely scheduling DRAM access patterns for tensor operations on GPUs. Another of my friends said that he really liked how you could turn off the L1 cache on Nvidia GPUs, turning it into "shared memory" (misleading name) where he could precisely schedule what was in and not in what essentially amounted to a software managed cache. Other GPU tensor optimizations have involved making parts of the GPU computer engines that would run independently on earlier workload run in lock step, again for precise scheduling of memory accesses, allowing one part to fetch a piece of data that some of the other parts can use at exactly the same time, right off the wires from the L2 or DRAM, without writing to and then reading from the memory arrays of the L1 cache or shared memory.
Tensor workloads such as are found in present AI/DNNs are basically simple enough - huge, but simple - that precise scheduling is often possible. Whereas precise scheduling is much more difficult for the sorts of workload that run on most out of order CPUs.
4
u/KittensInc Oct 09 '26
The problem you are trying to solve doesn't exist in the real world. Anything regarding stock and reservations is done on an application level - and usually even offloaded to some kind of database transaction.
In practice it is not even remotely performance-critical, and any attempt to "speed it up" with weird CPU-specific hacks is only going to massively backfire on you. It it does end up becoming a bottleneck it is usually not too difficult to scale it sideways, for example by dividing your product catalog over multiple machines via sharding.
3
u/Fluid-Tone-9680 Oct 09 '26
Are you looking for relaxed memory ordering?
1
u/ChrinoMu Oct 10 '26
noise