Page MenuHomeFreeBSD

LinuxKPI: implement devres() framework parts and two examples
ClosedPublic

Authored by bz on Jan 15 2021, 11:58 PM.

Details

Summary

LinuxKPI: implement devres() framework parts and two examples

This code implements a version of the devres framework found
working for various iwlwifi use cases and also providing functions
for ttm_page_alloc_dma.c from DRM.

Part of the framework replicates the consumed KPI, while others
are internal helper functions (currently listed in devices.h but
we may wonder if in the future we might have "private" header files
in src/ as well?) or the "release" functions.

In addition the simple devm_k*malloc() consumers were implemented
and kvasprintf() was enhanced to work also for the devm_kasprintf()
case.
Addmittingly lkpi_devm_kmalloc_release() could be avoided but for
the overall understanding of the code and possible memory tracing
it may still be helpful.

Further devsres consumer are implemented for iwlwifi but will follow
later as the main reason for this change is to sort out overlap with
DRM.

Sponsored-by: The FreeBSD Foundation

Test Plan
DRM code stil compiles with this implementation.
Iwlwifi (with the extra devres consumers) leaks a lot less memory.

Diff Detail

Repository
R10 FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

bz requested review of this revision.Jan 15 2021, 11:58 PM
sys/compat/linuxkpi/common/src/linux_compat.c
259

Could you put this new functions in an own .c file?

Else your changes look good.

sys/compat/linuxkpi/common/src/linux_compat.c
259

I can. two questions:

(1) Should we name new files linuxkpi_ or lkpi_ instead of linux_ ?
(2) Can we have header files in common/src/ next to the implementations to put "internal" function declarations etc. in there which don't have to be publicly visible to the "Linux KPI consumers"?

I can. two questions:

(1) Should we name new files linuxkpi_ or lkpi_ instead of linux_ ?

linux_devm.c is the style for now. Maybe later, if it is needed we can rename all .c files in there.
Don't forget to update sys/conf/files and sys/modules/linuxkpi/Makefile .

(2) Can we have header files in common/src/ next to the implementations to put "internal" function declarations etc. in there which don't have to be publicly visible to the "Linux KPI consumers"?

Yes, you can, or just in the .c -file if it is very internal.

--HPS

Moved devres framework and k*alloc release function into its own implementation
file as requested. For now leave headers as they are; may reconsider when
bringing in more devres consumers.

bz marked an inline comment as done.Jan 16 2021, 9:49 PM
This revision is now accepted and ready to land.Jan 18 2021, 8:30 AM

LGTM.
Can you provide a merge request on freebsd/drm-kmod before commiting please ?
I'll adapt the __FreeBSD_version change, if any.