]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/cgroup.h
core: refactor cpu shares/blockio weight cgroup logic
[thirdparty/systemd.git] / src / core / cgroup.h
CommitLineData
03467c88 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
8e274523 2
c2f1db8f 3#pragma once
8e274523
LP
4
5/***
6 This file is part of systemd.
7
4ad49000 8 Copyright 2013 Lennart Poettering
8e274523
LP
9
10 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
8e274523
LP
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 18 Lesser General Public License for more details.
8e274523 19
5430f7f2 20 You should have received a copy of the GNU Lesser General Public License
8e274523
LP
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22***/
23
c1ff5570
TA
24#include <stdbool.h>
25
4ad49000 26#include "list.h"
c1ff5570 27#include "time-util.h"
8e274523 28
4ad49000
LP
29typedef struct CGroupContext CGroupContext;
30typedef struct CGroupDeviceAllow CGroupDeviceAllow;
31typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight;
32typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth;
8e274523 33
4ad49000 34typedef enum CGroupDevicePolicy {
8e274523 35
4ad49000
LP
36 /* When devices listed, will allow those, plus built-in ones,
37 if none are listed will allow everything. */
38 CGROUP_AUTO,
8e274523 39
4ad49000
LP
40 /* Everything forbidden, except built-in ones and listed ones. */
41 CGROUP_CLOSED,
9d58f1db 42
4ad49000
LP
43 /* Everythings forbidden, except for the listed devices */
44 CGROUP_STRICT,
9d58f1db 45
4ad49000
LP
46 _CGROUP_DEVICE_POLICY_MAX,
47 _CGROUP_DEVICE_POLICY_INVALID = -1
48} CGroupDevicePolicy;
8e274523 49
4ad49000
LP
50struct CGroupDeviceAllow {
51 LIST_FIELDS(CGroupDeviceAllow, device_allow);
52 char *path;
53 bool r:1;
54 bool w:1;
55 bool m:1;
56};
8c6db833 57
4ad49000
LP
58struct CGroupBlockIODeviceWeight {
59 LIST_FIELDS(CGroupBlockIODeviceWeight, device_weights);
60 char *path;
d53d9474 61 uint64_t weight;
8e274523
LP
62};
63
4ad49000
LP
64struct CGroupBlockIODeviceBandwidth {
65 LIST_FIELDS(CGroupBlockIODeviceBandwidth, device_bandwidths);
66 char *path;
67 uint64_t bandwidth;
68 bool read;
69};
8e274523 70
4ad49000
LP
71struct CGroupContext {
72 bool cpu_accounting;
73 bool blockio_accounting;
74 bool memory_accounting;
03a7b521 75 bool tasks_accounting;
8e274523 76
d53d9474
LP
77 uint64_t cpu_shares;
78 uint64_t startup_cpu_shares;
b2f8b02e 79 usec_t cpu_quota_per_sec_usec;
8e274523 80
d53d9474
LP
81 uint64_t blockio_weight;
82 uint64_t startup_blockio_weight;
4ad49000
LP
83 LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights);
84 LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths);
246aa6dd 85
4ad49000 86 uint64_t memory_limit;
64747e2d 87
4ad49000
LP
88 CGroupDevicePolicy device_policy;
89 LIST_HEAD(CGroupDeviceAllow, device_allow);
a931ad47 90
03a7b521 91 uint64_t tasks_max;
d53d9474
LP
92
93 bool delegate;
4ad49000 94};
64747e2d 95
4ad49000 96#include "unit.h"
4ad49000 97#include "cgroup-util.h"
8e274523 98
4ad49000
LP
99void cgroup_context_init(CGroupContext *c);
100void cgroup_context_done(CGroupContext *c);
101void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix);
efdb0237 102void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, ManagerState state);
bc432dc7 103
efdb0237 104CGroupMask cgroup_context_get_mask(CGroupContext *c);
fb385181 105
4ad49000
LP
106void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a);
107void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w);
108void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b);
8e274523 109
efdb0237
LP
110CGroupMask unit_get_own_mask(Unit *u);
111CGroupMask unit_get_siblings_mask(Unit *u);
112CGroupMask unit_get_members_mask(Unit *u);
113CGroupMask unit_get_subtree_mask(Unit *u);
114
115CGroupMask unit_get_target_mask(Unit *u);
116CGroupMask unit_get_enable_mask(Unit *u);
bc432dc7
LP
117
118void unit_update_cgroup_members_masks(Unit *u);
efdb0237
LP
119
120char *unit_default_cgroup_path(Unit *u);
121int unit_set_cgroup_path(Unit *u, const char *path);
122
0a1eb06d 123int unit_realize_cgroup(Unit *u);
efdb0237
LP
124void unit_release_cgroup(Unit *u);
125void unit_prune_cgroup(Unit *u);
126int unit_watch_cgroup(Unit *u);
127
7b3fd631 128int unit_attach_pids_to_cgroup(Unit *u);
8e274523 129
4ad49000
LP
130int manager_setup_cgroup(Manager *m);
131void manager_shutdown_cgroup(Manager *m, bool delete);
6dde1f33 132
4ad49000 133unsigned manager_dispatch_cgroup_queue(Manager *m);
4fbf50b3 134
4ad49000 135Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup);
b3ac818b 136Unit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid);
4ad49000 137Unit* manager_get_unit_by_pid(Manager *m, pid_t pid);
8e274523 138
efdb0237
LP
139int unit_search_main_pid(Unit *u, pid_t *ret);
140int unit_watch_all_pids(Unit *u);
8e274523 141
5ad096b3 142int unit_get_memory_current(Unit *u, uint64_t *ret);
03a7b521 143int unit_get_tasks_current(Unit *u, uint64_t *ret);
5ad096b3
LP
144int unit_get_cpu_usage(Unit *u, nsec_t *ret);
145int unit_reset_cpu_usage(Unit *u);
146
e9db43d5
LP
147bool unit_cgroup_delegate(Unit *u);
148
efdb0237
LP
149int unit_notify_cgroup_empty(Unit *u);
150int manager_notify_cgroup_empty(Manager *m, const char *group);
151
4ad49000
LP
152const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
153CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;