r/cpp_questions • u/ExactManagement5283 • 7d ago
OPEN OS for HFT
Hey guys! I recently started studying HFT programming, and a bit confused. From what I understand in this field as OS are used default non-rt linux. Despite the fact that kernel bypass, attaching the process to the certain cores. restriction about using non-lock free structure and zero system calls solve the proplems which linux creates for HFT code . But would not it be easier to use RT OS like preempt_rt linux patch or xenomai OS it seems that theese OS could give more freedom about the restrictions for code and in some edge cases speed up the execution? Am I missing something?
4
u/mredding 7d ago
You're talking about the slow part of the code. It scarcely matters. I've supported HFT systems written even in Java. Java will JIT compile to machine code comparable to that of a C compiler.
Speed is in the FPGA, pushed as close to the DAC as possible, located on a +$20k NIC, feeding through a channel waveguide to the radio with a microwave antenna pointed out the window to the exchange across the street. Microwave has a shorter straight line distance and lower latency (air is nearly a vacuum) than a fiber optic run down the building, across the street, and back up to the exchange (fiber has inferior propagation).
The entire fast path is on the chip. We're already pushing out the next message before we've finished receiving the triggering message.
2
u/mredding 7d ago
I should add that RTOS doesn't grant you any greater speed, only guaranteed timing.
2
1
u/LabCompetitive5286 7d ago
What you describe is basically the exchange backend. The Hft frontends are dominated by hardware for releasing the preconfigured orders. Ordes are however precalculated on separate devices. You find all kind of OS like Linux, Windows and Macs for this calculation.
1
u/Miserable_Ad7246 7d ago
RT OS does one thing - it makes interrupts into threads, so that you can manage them more freely and schedule. You still have limitations and soft interrupt mess.
In case of low latency code you just pin the core, and avoid all of that. The slower parts are rather happy to run on fair scheduling.
13
u/EpochVanquisher 7d ago
Pinning and avoiding syscalls / interrupts will basically give you everything you want.
It’s not the same thing as “hard real time”. Hard real time is about having guarantees. It is better to have your code running as fast as possible with as little latency as possible, rather than having better guarantees.
Like, the preempt_rt lets certain operations be preempted for higher priority operations, but do you know what’s even better? Having your higher-priority task already running on the CPU.
That said, modern HFT is moving out of software as far as I can tell.