cgroup/misc: update struct members descriptions
[linux-2.6-block.git] / include / linux / misc_cgroup.h
CommitLineData
a72232ea
VS
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Miscellaneous cgroup controller.
4 *
5 * Copyright 2020 Google LLC
6 * Author: Vipin Sharma <vipinsh@google.com>
7 */
8#ifndef _MISC_CGROUP_H_
9#define _MISC_CGROUP_H_
10
11/**
12 * Types of misc cgroup entries supported by the host.
13 */
14enum misc_res_type {
7aef27f0
VS
15#ifdef CONFIG_KVM_AMD_SEV
16 /* AMD SEV ASIDs resource */
17 MISC_CG_RES_SEV,
18 /* AMD SEV-ES ASIDs resource */
19 MISC_CG_RES_SEV_ES,
20#endif
a72232ea
VS
21 MISC_CG_RES_TYPES
22};
23
24struct misc_cg;
25
26#ifdef CONFIG_CGROUP_MISC
27
28#include <linux/cgroup.h>
29
30/**
31 * struct misc_res: Per cgroup per misc type resource
32 * @max: Maximum limit on the resource.
33 * @usage: Current usage of the resource.
62157e11 34 * @events: Number of times, the resource limit exceeded.
a72232ea
VS
35 */
36struct misc_res {
37 unsigned long max;
38 atomic_long_t usage;
f279294b 39 atomic_long_t events;
a72232ea
VS
40};
41
42/**
43 * struct misc_cg - Miscellaneous controller's cgroup structure.
44 * @css: cgroup subsys state object.
62157e11 45 * @events_file: Handle for the misc resources events file.
a72232ea
VS
46 * @res: Array of misc resources usage in the cgroup.
47 */
48struct misc_cg {
49 struct cgroup_subsys_state css;
f279294b
CX
50
51 /* misc.events */
52 struct cgroup_file events_file;
53
a72232ea
VS
54 struct misc_res res[MISC_CG_RES_TYPES];
55};
56
57unsigned long misc_cg_res_total_usage(enum misc_res_type type);
58int misc_cg_set_capacity(enum misc_res_type type, unsigned long capacity);
59int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
60 unsigned long amount);
61void misc_cg_uncharge(enum misc_res_type type, struct misc_cg *cg,
62 unsigned long amount);
63
64/**
65 * css_misc() - Get misc cgroup from the css.
66 * @css: cgroup subsys state object.
67 *
68 * Context: Any context.
69 * Return:
70 * * %NULL - If @css is null.
71 * * struct misc_cg* - misc cgroup pointer of the passed css.
72 */
73static inline struct misc_cg *css_misc(struct cgroup_subsys_state *css)
74{
75 return css ? container_of(css, struct misc_cg, css) : NULL;
76}
77
78/*
79 * get_current_misc_cg() - Find and get the misc cgroup of the current task.
80 *
81 * Returned cgroup has its ref count increased by 1. Caller must call
82 * put_misc_cg() to return the reference.
83 *
84 * Return: Misc cgroup to which the current task belongs to.
85 */
86static inline struct misc_cg *get_current_misc_cg(void)
87{
88 return css_misc(task_get_css(current, misc_cgrp_id));
89}
90
91/*
92 * put_misc_cg() - Put the misc cgroup and reduce its ref count.
93 * @cg - cgroup to put.
94 */
95static inline void put_misc_cg(struct misc_cg *cg)
96{
97 if (cg)
98 css_put(&cg->css);
99}
100
101#else /* !CONFIG_CGROUP_MISC */
102
dd3f4e49 103static inline unsigned long misc_cg_res_total_usage(enum misc_res_type type)
a72232ea
VS
104{
105 return 0;
106}
107
108static inline int misc_cg_set_capacity(enum misc_res_type type,
109 unsigned long capacity)
110{
111 return 0;
112}
113
114static inline int misc_cg_try_charge(enum misc_res_type type,
115 struct misc_cg *cg,
116 unsigned long amount)
117{
118 return 0;
119}
120
121static inline void misc_cg_uncharge(enum misc_res_type type,
122 struct misc_cg *cg,
123 unsigned long amount)
124{
125}
126
127static inline struct misc_cg *get_current_misc_cg(void)
128{
129 return NULL;
130}
131
132static inline void put_misc_cg(struct misc_cg *cg)
133{
134}
135
136#endif /* CONFIG_CGROUP_MISC */
137#endif /* _MISC_CGROUP_H_ */