News for hackers. Stuff that matters.
Re:Why isn't memset() async-signal-safe? by spc476 on Tuesday January 03, 2017 @05:54PM (#13314021)
The more state you save, the larger the latency in handling the interrupt. And the amount of state in modern CPUs can be quite large indeed.
Re:Why isn't memset() async-signal-safe? by wfunction on Tuesday January 03, 2017 @06:04PM (#13314101)
Any idea how much it is? (just as a guess, I'd guess like maybe 8 KiB?)
Re:Why isn't memset() async-signal-safe? by haimez on Tuesday January 03, 2017 @08:27PM (#13314927)
Show your work.
Re:Why isn't memset() async-signal-safe? by wfunction on Tuesday January 03, 2017 @08:37PM (#13314976)
I don't remember how many there were for AVX, but let's say there are 8 512-bit registers (4 KiB)? and then equivalent in other kinds of registers, so 8 KiB. Just an order-of-magnitude estimate, nothing I expect to be too accurate.
Re:Why isn't memset() async-signal-safe? by haimez on Tuesday January 03, 2017 @09:45PM (#13315258)
I'm also not an expert, but I think the bigger cost here is memory latency. Size correlates to, but scales differently than the switching cost of registers because it's zero sum. A register saved is a register waited on, twice. There's also the cost of decoding and executing the instructions to store / restore the register values on both ends.
Re:Why isn't memset() async-signal-safe? by wfunction on Tuesday January 03, 2017 @09:54PM (#13315303)
I don't get it, you have to save and restore all the state on context switches either way. The only question is whether you're doing it with a generic instruction or through some other more specialized instructions. It's not a question of whether they should be saved and restored at all.

That said, I'm confused why you replied to my comment above, since it's totally off-topic. This thread chain was asking how much state exists; maybe you were trying to reply to another thread?

Re:Why isn't memset() async-signal-safe? by pwg on Wednesday January 04, 2017 @06:20AM (#13317296)
> I don't get it, you have to save and restore all the state on context switches either way.

Actually, no, you don't, at least not on _all_ context switches. What you have to save is what the switched-to routine will overwrite. For something like an interrupt handler (where latency often matters very much), if you know it will only modify, for example, eflags and EAX, then you only need save on entry and restore on exit from the handler eflags and EAX. The registers that are not modified remain identical from entry to exit and time is saved by not pushing/popping them needlessly.

Re:Why isn't memset() async-signal-safe? by zAy0LfpBZLC8mAC on Wednesday January 04, 2017 @04:05AM (#13316771)
> I don't get it, you have to save and restore all the state on context switches either way.

Actually, you don't. I'm not up to date as to what's done in this direction by current kernels, but a while back, a patch was merged that disabled floating point and MMX operations by default for a process, and enabled it for a while only when some FP or MMX instruction lead to an exception, which then allowed the kernel to avoid saving and restoring FP state on processes that weren't actually doing any FP/MMX operations.