Set control registers on all cores
I need to enable cr4 bit 8 (PCE) on all kernels of a given system. I currently have a working module that sets this bit on the kernel it runs on when the module is loaded. I got stuck here and didn't find much documentation on how to parallelize this to work on all cores:
1) It looks like the unloading doesn't always happen in the kernel where the boot happened, so I can't clean up properly
2) I can't figure out how to get the module initialization to be done on a specific kernel. If I could, I could just have a module that can be called on a per-kernel basis to install all kernels. There seems to be no equivalent for modules to sched_setaffinity.
Is there a way to get this module to work on all cores, either by parallelizing or iterating over all cores? I can't change the kernel itself or load a module at boot, so I can't just change what the register was originally set from.
Thanks for any hints, I'm going crazy trying to figure this out!
source to share
Found it out - smp_call_function () calls a function on all cores of the system. It's very difficult to get a search result that brings this (little / no documentation): - /
This works great and you can check that each core runs the code by printing smp_processor_id () in the called function.
EDIT: This function only calls other kernels, so you still have to call the function separately to get the kernel that the given module is running on!
source to share