xref: /openbmc/linux/drivers/infiniband/core/cgroup.c (revision ee65728e)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2016 Parav Pandit <pandit.parav@gmail.com>
4  */
5 
6 #include "core_priv.h"
7 
8 /**
9  * ib_device_register_rdmacg - register with rdma cgroup.
10  * @device: device to register to participate in resource
11  *          accounting by rdma cgroup.
12  *
13  * Register with the rdma cgroup. Should be called before
14  * exposing rdma device to user space applications to avoid
15  * resource accounting leak.
16  */
17 void ib_device_register_rdmacg(struct ib_device *device)
18 {
19 	device->cg_device.name = device->name;
20 	rdmacg_register_device(&device->cg_device);
21 }
22 
23 /**
24  * ib_device_unregister_rdmacg - unregister with rdma cgroup.
25  * @device: device to unregister.
26  *
27  * Unregister with the rdma cgroup. Should be called after
28  * all the resources are deallocated, and after a stage when any
29  * other resource allocation by user application cannot be done
30  * for this device to avoid any leak in accounting.
31  */
32 void ib_device_unregister_rdmacg(struct ib_device *device)
33 {
34 	rdmacg_unregister_device(&device->cg_device);
35 }
36 
37 int ib_rdmacg_try_charge(struct ib_rdmacg_object *cg_obj,
38 			 struct ib_device *device,
39 			 enum rdmacg_resource_type resource_index)
40 {
41 	return rdmacg_try_charge(&cg_obj->cg, &device->cg_device,
42 				 resource_index);
43 }
44 EXPORT_SYMBOL(ib_rdmacg_try_charge);
45 
46 void ib_rdmacg_uncharge(struct ib_rdmacg_object *cg_obj,
47 			struct ib_device *device,
48 			enum rdmacg_resource_type resource_index)
49 {
50 	rdmacg_uncharge(cg_obj->cg, &device->cg_device,
51 			resource_index);
52 }
53 EXPORT_SYMBOL(ib_rdmacg_uncharge);
54