On Sat, May 23, 2020 at 6:35 PM Wonsup Yoon <[email protected]> wrote:
> Hi,
>
> I'm trying to use PERCPU macro in application or module.
>
Hi,
The PERCPU macro does not support this. What it does is to add information
about this variable in a special section of the executable (".percpu"),
then arch/x64/loader.ld makes sure all these entries will be together
between "_percpu_start" and "_percpu_end", and finally sched.cc for every
CPU creates (in the cpu::cpu(id) constructor) a copy of this data. So if a
loadable module (share library) contains another per-cpu variable, it never
gets added to the percpu area.
However, I believe we do have a mechanism that will suite you:
*dynamic_percpu<T>*.
You can create (and destroy) such an object of type dynamic_percpu<T> at
any time, and it does the right thing: The variable will be allocated on
all CPUs when the object is created, will be allocated on new cpus if those
happen, and will be freed when the object is destroyed.
In your case you can have a global dynamic_percpu<T> variable in your
loadable module. This object will be created when the module is loaded, and
destroyed when the module is unloaded - which is what you want.
Nadav.
--
You received this message because you are subscribed to the Google Groups "OSv
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/osv-dev/CANEVyjs%2B%2BkfoSgn-Y%3DsT-QWokybDEM93%3DV%2BPrk-G%3Dn%3D0X3Q4XQ%40mail.gmail.com.