0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _MISC_CGROUP_H_
0009 #define _MISC_CGROUP_H_
0010
0011
0012
0013
0014 enum misc_res_type {
0015 #ifdef CONFIG_KVM_AMD_SEV
0016
0017 MISC_CG_RES_SEV,
0018
0019 MISC_CG_RES_SEV_ES,
0020 #endif
0021 MISC_CG_RES_TYPES
0022 };
0023
0024 struct misc_cg;
0025
0026 #ifdef CONFIG_CGROUP_MISC
0027
0028 #include <linux/cgroup.h>
0029
0030
0031
0032
0033
0034
0035
0036 struct misc_res {
0037 unsigned long max;
0038 atomic_long_t usage;
0039 atomic_long_t events;
0040 };
0041
0042
0043
0044
0045
0046
0047 struct misc_cg {
0048 struct cgroup_subsys_state css;
0049
0050
0051 struct cgroup_file events_file;
0052
0053 struct misc_res res[MISC_CG_RES_TYPES];
0054 };
0055
0056 unsigned long misc_cg_res_total_usage(enum misc_res_type type);
0057 int misc_cg_set_capacity(enum misc_res_type type, unsigned long capacity);
0058 int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
0059 unsigned long amount);
0060 void misc_cg_uncharge(enum misc_res_type type, struct misc_cg *cg,
0061 unsigned long amount);
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 static inline struct misc_cg *css_misc(struct cgroup_subsys_state *css)
0073 {
0074 return css ? container_of(css, struct misc_cg, css) : NULL;
0075 }
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 static inline struct misc_cg *get_current_misc_cg(void)
0086 {
0087 return css_misc(task_get_css(current, misc_cgrp_id));
0088 }
0089
0090
0091
0092
0093
0094 static inline void put_misc_cg(struct misc_cg *cg)
0095 {
0096 if (cg)
0097 css_put(&cg->css);
0098 }
0099
0100 #else
0101
0102 static inline unsigned long misc_cg_res_total_usage(enum misc_res_type type)
0103 {
0104 return 0;
0105 }
0106
0107 static inline int misc_cg_set_capacity(enum misc_res_type type,
0108 unsigned long capacity)
0109 {
0110 return 0;
0111 }
0112
0113 static inline int misc_cg_try_charge(enum misc_res_type type,
0114 struct misc_cg *cg,
0115 unsigned long amount)
0116 {
0117 return 0;
0118 }
0119
0120 static inline void misc_cg_uncharge(enum misc_res_type type,
0121 struct misc_cg *cg,
0122 unsigned long amount)
0123 {
0124 }
0125
0126 static inline struct misc_cg *get_current_misc_cg(void)
0127 {
0128 return NULL;
0129 }
0130
0131 static inline void put_misc_cg(struct misc_cg *cg)
0132 {
0133 }
0134
0135 #endif
0136 #endif