hint: sudo perf record -ag might give you interesting info here, including time spent in specific kernel functions, if you have kernel debug symbols installed.
Anyways,
As far as I understand it does not even touches the filesystem.
That's not correct. getcwd as implemented by the linux kernel has to check whether your cwd still exists, whether the file system it's on is still mounted, and iterate up to the root of the file system to check whether the directory is still reachable.
That can have side effects, and be delayed by file systems somehow being in a state where they are blocked.
The most likely culprit here would be the RCU lock being held by very frequent memory reclamation runs in the kernel. That might be a hazardous driver's problem, but also things like very frequent namespace creations etc.