Hacker News new | ask | show | jobs
by st_goliath 871 days ago
> ... can change during the lifetime of a process, ...

Fun fact: this is already an issue for the vdso.

gettimeofday(2) can use the CPU builtin cycle counters, but it needs information from the kernel to convert cycles to an actual timestamp (start and scale). This information too can change during the runtime.

To not have userspace trampled over by the kernel, the vdso contains an open-coded spinlock that is used when accessing this information.

I learnt about this while debugging a fun issue with a real-time co-kernel where the userspace thread occasionally ended up deadlocking inside gettimeofday and triggering the watchdog :-)

1 comments

Does avoiding userspace being trampled by the kernel mean avoiding a context switch? Does the kernel write to userspace-accessible memory that the spinlock guards?

Unrelated, but what does "open-coded" mean? I never seem to find an obvious answer online.

> Unrelated, but what does "open-coded" mean? I never seem to find an obvious answer online.

In my understanding, open-coded means something akin to "manually inlined". Or: written inline while an acceptable alternative exists as a function.