Hacker News new | past | comments | ask | show | jobs | submit login

> Traps (CPU exceptions, such as traditional FPU exceptions like division by zero) usually involve kernel mode context switch.

Could you explain why? I thought that trapping was more like a 'slow branch': slow due to the flush the pipeline but why should the kernel be involved(1)?

1: except if you need to swap in a page, but that's just like any other memory reference.

When we're talking about x86, that's true in ring 0. Otherwise first thing CPU does is to enter privileged, ring 0 mode, save registers, jump through interrupt vector table and process the trap in kernel code. Trap handler will probably need to check usermode program counter and take a look at the instruction that caused the trap. No hard data, but I think we're talking about 1-5 microseconds.

Runtime/language exceptions have different mechanisms that don't require kernel context switches (but might involve slow steps like stack walk).

Applications are open for YC Winter 2020

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact