[PATCH ath-next] wifi: ath12k: avoid dynamic alloc when parsing wmi tb
Baochen Qiang
baochen.qiang at oss.qualcomm.com
Tue Mar 10 22:46:06 PDT 2026
On 3/10/2026 6:31 PM, Nicolas Escande wrote:
> On Tue Mar 10, 2026 at 3:05 AM CET, Baochen Qiang wrote:
> [...]
>>> diff --git a/drivers/net/wireless/ath/ath12k/core.h b/drivers/net/wireless/ath/ath12k/core.h
>>> index 59c193b24764..ebe7b94fd712 100644
>>> --- a/drivers/net/wireless/ath/ath12k/core.h
>>> +++ b/drivers/net/wireless/ath/ath12k/core.h
>>> @@ -19,6 +19,7 @@
>>> #include <linux/average.h>
>>> #include <linux/of.h>
>>> #include <linux/rhashtable.h>
>>> +#include <linux/percpu.h>
>>> #include "qmi.h"
>>> #include "htc.h"
>>> #include "wmi.h"
>>> @@ -937,6 +938,7 @@ struct ath12k_base {
>>> struct device *dev;
>>> struct ath12k_qmi qmi;
>>> struct ath12k_wmi_base wmi_ab;
>>> + void __percpu *wmi_tb;
>>
>> any reason why my v1 suggestion is not considered?
>>
>
> I considered it but I for sure did not write enough about it in the changelog.
> Sorry about that, see my thoughts bellow.
>
>> instead of allocating it per device, how about making it global and define/allocate once
>> when loading driver. This way we may save some memory in case where more than one devices
>> get probed?
>
> So what I did try first is to use DEFINE_PER_CPU() directly in wmi.c to have
> this as a static array, directly in the compilation unit where it is used.
> But this failled at runtime as the allocated size it too big and it would have
hmm, I didn't expect that.
> needed modifying the max alloc size that the module loader would allow.
Let's not do this.
>
> My second option was to add something in the module_init so ath12k_wifi7_init().
> But as there is no ath12k 'global' struct, it meant adding a global variable to
> hold the per cpu array, that would be alloced in wifi7/core.c and used in wmi.c.
> And that felt weird too, the wifi version specific part of it at least.
Agree.
>
> So I stayed with the per ath12k_base, which as relatively low overhead for a
> clean consistant interface.
>
> But if you guys don't want it that way, I can rework it. Just tell me in more
> details what you think is the right way and I can modify it.
then how about adding module init path to ath12k module and do percpu allocation there:
in ath12k/core.c
+void __percpu *wmi_tb;
+
+static int ath12k_core_module_init(void)
+{
+ wmi_tb = __alloc_percpu(WMI_TAG_MAX * sizeof(void *),
+ __alignof__(void *));
+ if (!wmi_tb)
+ return -ENOMEM;
+
+ return 0;
+}
+
+static void ath12k_core_module_exit(void)
+{
+ free_percpu(wmi_tb);
+}
+
+module_init(ath12k_core_module_init);
+module_exit(ath12k_core_module_exit);
>
> Thanks
More information about the ath12k
mailing list