xref: /openbmc/linux/drivers/infiniband/core/cgroup.c (revision d2574c33)
1 /*
2  * Copyright (C) 2016 Parav Pandit <pandit.parav@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms and conditions of the GNU General Public License,
6  * version 2, as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  */
13 
14 #include "core_priv.h"
15 
16 /**
17  * ib_device_register_rdmacg - register with rdma cgroup.
18  * @device: device to register to participate in resource
19  *          accounting by rdma cgroup.
20  *
21  * Register with the rdma cgroup. Should be called before
22  * exposing rdma device to user space applications to avoid
23  * resource accounting leak.
24  */
25 void ib_device_register_rdmacg(struct ib_device *device)
26 {
27 	device->cg_device.name = device->name;
28 	rdmacg_register_device(&device->cg_device);
29 }
30 
31 /**
32  * ib_device_unregister_rdmacg - unregister with rdma cgroup.
33  * @device: device to unregister.
34  *
35  * Unregister with the rdma cgroup. Should be called after
36  * all the resources are deallocated, and after a stage when any
37  * other resource allocation by user application cannot be done
38  * for this device to avoid any leak in accounting.
39  */
40 void ib_device_unregister_rdmacg(struct ib_device *device)
41 {
42 	rdmacg_unregister_device(&device->cg_device);
43 }
44 
45 int ib_rdmacg_try_charge(struct ib_rdmacg_object *cg_obj,
46 			 struct ib_device *device,
47 			 enum rdmacg_resource_type resource_index)
48 {
49 	return rdmacg_try_charge(&cg_obj->cg, &device->cg_device,
50 				 resource_index);
51 }
52 EXPORT_SYMBOL(ib_rdmacg_try_charge);
53 
54 void ib_rdmacg_uncharge(struct ib_rdmacg_object *cg_obj,
55 			struct ib_device *device,
56 			enum rdmacg_resource_type resource_index)
57 {
58 	rdmacg_uncharge(cg_obj->cg, &device->cg_device,
59 			resource_index);
60 }
61 EXPORT_SYMBOL(ib_rdmacg_uncharge);
62