techpack: camera: use kmem_cache pool for struct sync_user_payload
These get allocated and freed millions of times on this kernel tree. Use a dedicated kmem_cache pool and avoid costly dynamic memory allocations. Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com> [@0ctobot: Adapted for 4.19] Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
This commit is contained in:
parent
4c374f8565
commit
737ee0e2bf
@ -17,6 +17,7 @@
|
||||
#include <synx_api.h>
|
||||
#endif
|
||||
struct sync_device *sync_dev;
|
||||
static struct kmem_cache *kmem_payload_pool;
|
||||
|
||||
/*
|
||||
* Flag to determine whether to enqueue cb of a
|
||||
@ -598,7 +599,7 @@ static int cam_sync_handle_register_user_payload(
|
||||
if (sync_obj >= CAM_SYNC_MAX_OBJS || sync_obj <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
user_payload_kernel = kzalloc(sizeof(*user_payload_kernel), GFP_KERNEL);
|
||||
user_payload_kernel = kmem_cache_zalloc(kmem_payload_pool, GFP_KERNEL);
|
||||
if (!user_payload_kernel)
|
||||
return -ENOMEM;
|
||||
|
||||
@ -614,7 +615,7 @@ static int cam_sync_handle_register_user_payload(
|
||||
"Error: accessing an uninitialized sync obj = %d",
|
||||
sync_obj);
|
||||
spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
|
||||
kfree(user_payload_kernel);
|
||||
kmem_cache_free(kmem_payload_pool, user_payload_kernel);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -628,7 +629,7 @@ static int cam_sync_handle_register_user_payload(
|
||||
CAM_SYNC_USER_PAYLOAD_SIZE * sizeof(__u64));
|
||||
|
||||
spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
|
||||
kfree(user_payload_kernel);
|
||||
kmem_cache_free(kmem_payload_pool, user_payload_kernel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -642,7 +643,7 @@ static int cam_sync_handle_register_user_payload(
|
||||
user_payload_kernel->payload_data[1]) {
|
||||
|
||||
spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
|
||||
kfree(user_payload_kernel);
|
||||
kmem_cache_free(kmem_payload_pool, user_payload_kernel);
|
||||
return -EALREADY;
|
||||
}
|
||||
}
|
||||
@ -697,7 +698,7 @@ static int cam_sync_handle_deregister_user_payload(
|
||||
user_payload_kernel->payload_data[1] ==
|
||||
userpayload_info.payload[1]) {
|
||||
list_del_init(&user_payload_kernel->list);
|
||||
kfree(user_payload_kernel);
|
||||
kmem_cache_free(kmem_payload_pool, user_payload_kernel);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1132,6 +1133,8 @@ static int __init cam_sync_init(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
kmem_payload_pool = KMEM_CACHE(sync_user_payload, SLAB_HWCACHE_ALIGN | SLAB_PANIC);
|
||||
|
||||
rc = platform_device_register(&cam_sync_device);
|
||||
if (rc)
|
||||
return -ENODEV;
|
||||
@ -1148,6 +1151,8 @@ static void __exit cam_sync_exit(void)
|
||||
platform_driver_unregister(&cam_sync_driver);
|
||||
platform_device_unregister(&cam_sync_device);
|
||||
kfree(sync_dev);
|
||||
|
||||
kmem_cache_destroy(kmem_payload_pool);
|
||||
}
|
||||
|
||||
module_init(cam_sync_init);
|
||||
|
Loading…
Reference in New Issue
Block a user