Lines Matching full:css
118 * cgroup_offline_wq: use for css offline work
119 * cgroup_release_wq: use for css release work
123 * The cgroup root free work may depend on completion of other css offline
126 * - Free work waits for other css offline work to complete.
127 * - But other css offline work is queued after free work in the same queue.
132 * 3. perf_event CSS A offline enqueues work to same cgroup_destroy_wq (CPUx)
134 * 5. net_prio root destruction blocks waiting for perf_event CSS A offline,
205 * root css so the affected tasks are migrated there before
277 static void kill_css_sync(struct cgroup_subsys_state *css);
278 static void kill_css_finish(struct cgroup_subsys_state *css);
282 static int cgroup_addrm_files(struct cgroup_subsys_state *css,
505 * cgroup_e_css_by_mask - obtain a cgroup's effective css for the specified ss
509 * Similar to cgroup_css() but returns the effective css, which is defined
510 * as the matching css of the nearest ancestor including self which has @ss
512 * function is guaranteed to return non-NULL css.
523 * This function is used while updating css associations and thus
536 * cgroup_e_css - obtain a cgroup's effective css for the specified subsystem
540 * Find and get the effective css of @cgrp for @ss. The effective css is
541 * defined as the matching css of the nearest ancestor including self which
543 * the root css is returned, so this function always returns a valid css.
545 * The returned css is not guaranteed to be online, and therefore it is the
551 struct cgroup_subsys_state *css;
557 css = cgroup_css(cgrp, ss);
559 if (css)
560 return css;
568 * cgroup_get_e_css - get a cgroup's effective css for the specified subsystem
572 * Find and get the effective css of @cgrp for @ss. The effective css is
573 * defined as the matching css of the nearest ancestor including self which
575 * the root css is returned, so this function always returns a valid css.
576 * The returned css must be put using css_put().
581 struct cgroup_subsys_state *css;
589 css = cgroup_css(cgrp, ss);
591 if (css && css_tryget_online(css))
596 css = init_css_set.subsys[ss->id];
597 css_get(css);
600 return css;
665 * files are drained before a css is disassociated with a cgroup,
666 * the matching css from the cgroup's subsys table is guaranteed to
677 * for_each_css - iterate all css's of a cgroup
678 * @css: the iteration cursor
680 * @cgrp: the target cgroup to iterate css's of
684 #define for_each_css(css, ssid, cgrp) \
686 if (!((css) = rcu_dereference_check( \
768 * css_update_populated - update the populated state of a css and ancestors
769 * @css: leaf css whose own populated count is changing
772 * One of the css_sets pinned by @css is getting its first task or losing the
773 * last. Propagate the transition up the parent chain so that a css's
781 static void css_update_populated(struct cgroup_subsys_state *css, bool populated)
790 struct cgroup *cgrp = css_is_self(css) ? css->cgroup : NULL;
791 bool was_populated = css_is_populated(css);
794 WRITE_ONCE(css->nr_populated_csets,
795 css->nr_populated_csets + adj);
797 WRITE_ONCE(css->nr_populated_children,
798 css->nr_populated_children + adj);
809 if (was_populated == css_is_populated(css))
820 * Subtree just emptied below a dying css. Fire deferred kill.
821 * The transition is one-shot for a dying css.
823 if (was_populated && css_is_dying(css)) {
824 css_get(css);
825 WARN_ON_ONCE(!queue_work(cgroup_offline_wq, &css->kill_finish_work));
835 child = css;
836 css = css->parent;
837 } while (css);
847 * subsystem css that @cset pins.
861 struct cgroup_subsys_state *css = cset->subsys[ssid];
863 if (css)
864 css_update_populated(css, populated);
941 static unsigned long css_set_hash(struct cgroup_subsys_state **css)
948 key += (unsigned long)css[i];
967 /* This css_set is dead. Unlink it and release cgroup and css refs */
996 * @template: desired set of css pointers in css_set (pre-calculated)
1030 * share the same effective css, this comparison is always
1075 * find_existing_css_set - init css array and find the matching css_set
1100 * surviving root css so the tasks are migrated there.
1107 * effective css from @cgrp.
1113 * to change the css.
1277 struct cgroup_subsys_state *css = cset->subsys[ssid];
1280 &css->cgroup->e_csets[ssid]);
1281 css_get(css);
1735 struct cgroup_subsys_state *css = cgroup_css(cgrp, cft->ss);
1736 struct cgroup_file *cfile = (void *)css + cft->file_offset;
1750 * @css: target css
1752 static void css_clear_dir(struct cgroup_subsys_state *css)
1754 struct cgroup *cgrp = css->cgroup;
1757 if (!(css->flags & CSS_VISIBLE))
1760 css->flags &= ~CSS_VISIBLE;
1762 if (css_is_self(css)) {
1764 cgroup_addrm_files(css, cgrp,
1767 cgroup_addrm_files(css, cgrp,
1770 cgroup_addrm_files(css, cgrp,
1774 list_for_each_entry(cfts, &css->ss->cfts, node)
1775 cgroup_addrm_files(css, cgrp, cfts, false);
1781 * @css: target css
1785 static int css_populate_dir(struct cgroup_subsys_state *css)
1787 struct cgroup *cgrp = css->cgroup;
1791 if (css->flags & CSS_VISIBLE)
1794 if (css_is_self(css)) {
1796 ret = cgroup_addrm_files(css, cgrp,
1802 ret = cgroup_addrm_files(css, cgrp,
1805 cgroup_addrm_files(css, cgrp,
1811 ret = cgroup_addrm_files(css, cgrp,
1817 list_for_each_entry(cfts, &css->ss->cfts, node) {
1818 ret = cgroup_addrm_files(css, cgrp, cfts, true);
1826 css->flags |= CSS_VISIBLE;
1830 list_for_each_entry(cfts, &css->ss->cfts, node) {
1833 cgroup_addrm_files(css, cgrp, cfts, false);
1876 * migrate their tasks to the root css, so the per-cgroup csses
1891 struct cgroup_subsys_state *css = cgroup_css(scgrp, ss);
1895 WARN_ON(!css || cgroup_css(dcgrp, ss));
1900 * root css first (see cgroup_rebind_ss_mask).
1911 rcu_assign_pointer(dcgrp->subsys[ssid], css);
1915 css->cgroup = dcgrp;
1949 ss->bind(css);
2622 * @dst_cssp: output variable for the destination css
2638 * @dst_cssp: output variable for the destination css
3241 * cgroup_update_dfl_csses - update css assoc of a subtree in default hierarchy
3244 * @cgrp's control masks have changed and its subtree's css associations
3322 * Because css offlining is asynchronous, userland may try to re-enable a
3323 * controller while the previous css is still around. This function grabs
3324 * cgroup_mutex and drains the previous css instances of @cgrp's subtree.
3339 struct cgroup_subsys_state *css = cgroup_css(dsct, ss);
3342 if (!css || !css_is_dying(css))
3420 static bool css_visible(struct cgroup_subsys_state *css)
3422 struct cgroup_subsys *ss = css->ss;
3423 struct cgroup *cgrp = css->cgroup;
3437 * visible. A css is created invisible if it's being implicitly enabled
3438 * through dependency. An invisible css is made visible when the userland
3454 struct cgroup_subsys_state *css = cgroup_css(dsct, ss);
3459 if (!css) {
3460 css = css_create(dsct, ss);
3461 if (IS_ERR(css))
3462 return PTR_ERR(css);
3465 WARN_ON_ONCE(percpu_ref_is_dying(&css->refcnt));
3467 if (css_visible(css)) {
3468 ret = css_populate_dir(css);
3485 * A css is hidden when the userland requests it to be disabled while other
3486 * subsystems are still depending on it. The css must not actively control
3500 struct cgroup_subsys_state *css = cgroup_css(dsct, ss);
3502 if (!css)
3505 WARN_ON_ONCE(percpu_ref_is_dying(&css->refcnt));
3507 if (css->parent &&
3509 kill_css_sync(css);
3510 if (!css_is_populated(css))
3511 kill_css_finish(css);
3512 } else if (!css_visible(css)) {
3513 css_clear_dir(css);
3515 ss->css_reset(css);
3551 * css associations of all tasks in the subtree.
3902 struct cgroup_subsys_state *css;
3922 css = rcu_dereference_raw(cgroup->subsys[ssid]);
3925 css ? (css->nr_descendants + 1) : 0);
3962 * cgroup_tryget_css - try to get a cgroup's css for the specified subsystem
3966 * Find and get @cgrp's css associated with @ss. If the css doesn't exist
3972 struct cgroup_subsys_state *css;
3975 css = cgroup_css(cgrp, ss);
3976 if (css && !css_tryget_online(css))
3977 css = NULL;
3980 return css;
3987 struct cgroup_subsys_state *css;
3993 css = cgroup_tryget_css(cgrp, ss);
3994 if (!css)
3997 ret = ss->css_extra_stat_show(seq, css);
3998 css_put(css);
4006 struct cgroup_subsys_state *css;
4012 css = cgroup_tryget_css(cgrp, ss);
4013 if (!css)
4016 ret = ss->css_local_stat_show(seq, css);
4017 css_put(css);
4309 struct cgroup_subsys_state *css;
4314 cgroup_for_each_live_descendant_pre(dsct, css, cgrp)
4394 struct cgroup_subsys_state *css;
4416 * flight, which means that the matching css is and stays alive and
4421 css = cgroup_css(cgrp, cft->ss);
4428 ret = cft->write_u64(css, cft, v);
4433 ret = cft->write_s64(css, cft, v);
4470 struct cgroup_subsys_state *css = seq_css(m);
4476 seq_printf(m, "%llu\n", cft->read_u64(css, cft));
4478 seq_printf(m, "%lld\n", cft->read_s64(css, cft));
4511 static int cgroup_add_file(struct cgroup_subsys_state *css, struct cgroup *cgrp,
4530 struct cgroup_file *cfile = (void *)css + cft->file_offset;
4542 * @css: the target css
4543 * @cgrp: the target cgroup (usually css->cgroup)
4550 static int cgroup_addrm_files(struct cgroup_subsys_state *css,
4573 ret = cgroup_add_file(css, cgrp, cft);
4592 struct cgroup_subsys_state *css;
4598 css_for_each_descendant_pre(css, cgroup_css(root, ss)) {
4599 struct cgroup *cgrp = css->cgroup;
4601 if (!(css->flags & CSS_VISIBLE))
4604 ret = cgroup_addrm_files(css, cgrp, cfts, is_add);
4839 * css_next_child - find the next child of a given css
4841 * @parent: css whose children to walk
4849 * css which finished ->css_online() is guaranteed to be visible in the
4851 * A css which hasn't finished ->css_online() or already finished
4875 * dereferenced; however, as each css is given a monotonically
4878 * children until the first css with higher serial number than
4905 * @root: css whose descendants to walk
4918 * css which finished ->css_online() is guaranteed to be visible in the
4920 * A css which hasn't finished ->css_online() or already finished
4954 * css_rightmost_descendant - return the rightmost descendant of a css
4955 * @pos: css of interest
5001 * @root: css whose descendants to walk
5014 * css which finished ->css_online() is guaranteed to be visible in the
5016 * A css which hasn't finished ->css_online() or already finished
5046 * css_has_online_children - does a css have online children
5047 * @css: the target css
5049 * Returns %true if @css has any online children; otherwise, %false. This
5053 bool css_has_online_children(struct cgroup_subsys_state *css)
5059 css_for_each_child(child, css) {
5250 * @css: the css to walk tasks of
5254 * Initiate iteration through the tasks of @css. The caller can call
5259 void css_task_iter_start(struct cgroup_subsys_state *css, unsigned int flags,
5268 it->ss = css->ss;
5272 it->cset_pos = &css->cgroup->e_csets[css->ss->id];
5274 it->cset_pos = &css->cgroup->cset_links;
5673 * css destruction is four-stage process.
5679 * and thus css_tryget_online() is guaranteed to fail, the css can be
5687 * 4. After the grace period, the css can be freed. Implemented in
5691 * and thus involve punting to css->destroy_work adding two additional
5696 struct cgroup_subsys_state *css = container_of(to_rcu_work(work),
5698 struct cgroup_subsys *ss = css->ss;
5699 struct cgroup *cgrp = css->cgroup;
5701 percpu_ref_exit(&css->refcnt);
5702 css_rstat_exit(css);
5704 if (!css_is_self(css)) {
5705 /* css free path */
5706 struct cgroup_subsys_state *parent = css->parent;
5707 int id = css->id;
5709 ss->css_free(css);
5747 struct cgroup_subsys_state *css =
5749 struct cgroup_subsys *ss = css->ss;
5750 struct cgroup *cgrp = css->cgroup;
5754 css->flags |= CSS_RELEASED;
5755 list_del_rcu(&css->sibling);
5757 if (!css_is_self(css)) {
5760 css_rstat_flush(css);
5762 cgroup_idr_replace(&ss->css_idr, NULL, css->id);
5764 ss->css_released(css);
5768 * When a css is released and ready to be freed, its
5774 WARN_ON_ONCE(css->nr_descendants);
5808 INIT_RCU_WORK(&css->destroy_rwork, css_free_rwork_fn);
5809 queue_rcu_work(cgroup_free_wq, &css->destroy_rwork);
5814 struct cgroup_subsys_state *css =
5817 INIT_WORK(&css->destroy_work, css_release_work_fn);
5818 queue_work(cgroup_release_wq, &css->destroy_work);
5823 * css's hierarchical populated state drops to zero. Pinned by css_get() at the
5828 struct cgroup_subsys_state *css =
5832 kill_css_finish(css);
5834 css_put(css);
5837 static void init_and_link_css(struct cgroup_subsys_state *css,
5844 memset(css, 0, sizeof(*css));
5845 css->cgroup = cgrp;
5846 css->ss = ss;
5847 css->id = -1;
5848 INIT_LIST_HEAD(&css->sibling);
5849 INIT_LIST_HEAD(&css->children);
5850 INIT_WORK(&css->kill_finish_work, kill_css_finish_work_fn);
5851 css->serial_nr = css_serial_nr_next++;
5852 atomic_set(&css->online_cnt, 0);
5855 css->parent = cgroup_css(cgroup_parent(cgrp), ss);
5856 css_get(css->parent);
5862 /* invoke ->css_online() on a new CSS and mark it online if successful */
5863 static int online_css(struct cgroup_subsys_state *css)
5865 struct cgroup_subsys *ss = css->ss;
5871 ret = ss->css_online(css);
5873 css->flags |= CSS_ONLINE;
5874 rcu_assign_pointer(css->cgroup->subsys[ss->id], css);
5876 atomic_inc(&css->online_cnt);
5877 if (css->parent) {
5878 atomic_inc(&css->parent->online_cnt);
5879 while ((css = css->parent))
5880 css->nr_descendants++;
5886 /* if the CSS is online, invoke ->css_offline() on it and mark it offline */
5887 static void offline_css(struct cgroup_subsys_state *css)
5889 struct cgroup_subsys *ss = css->ss;
5893 if (!css_is_online(css))
5897 ss->css_offline(css);
5899 css->flags &= ~CSS_ONLINE;
5900 RCU_INIT_POINTER(css->cgroup->subsys[ss->id], NULL);
5902 wake_up_all(&css->cgroup->offline_waitq);
5907 * @cgrp: the cgroup new css will be associated with
5908 * @ss: the subsys of new css
5910 * Create a new css associated with @cgrp - @ss pair. On success, the new
5911 * css is online and installed in @cgrp. This function doesn't create the
5919 struct cgroup_subsys_state *css;
5924 css = ss->css_alloc(parent_css);
5925 if (!css)
5926 css = ERR_PTR(-ENOMEM);
5927 if (IS_ERR(css))
5928 return css;
5930 init_and_link_css(css, ss, cgrp);
5932 err = percpu_ref_init(&css->refcnt, css_release, 0, GFP_KERNEL);
5939 css->id = err;
5941 err = css_rstat_init(css);
5945 /* @css is ready to be brought online now, make it visible */
5946 list_add_tail_rcu(&css->sibling, &parent_css->children);
5947 cgroup_idr_replace(&ss->css_idr, css, css->id);
5949 err = online_css(css);
5953 return css;
5956 list_del_rcu(&css->sibling);
5958 INIT_RCU_WORK(&css->destroy_rwork, css_free_rwork_fn);
5959 queue_rcu_work(cgroup_free_wq, &css->destroy_rwork);
6156 /* let's create and online css's */
6170 * This is called when the refcnt of a css is confirmed to be killed.
6172 * initiate destruction and put the css ref from kill_css_finish().
6176 struct cgroup_subsys_state *css;
6178 css = container_of(to_rcu_work(work), struct cgroup_subsys_state, destroy_rwork);
6183 offline_css(css);
6184 css_put(css);
6185 /* @css can't go away while we're holding cgroup_mutex */
6186 css = css->parent;
6187 } while (css && atomic_dec_and_test(&css->online_cnt));
6192 /* css kill confirmation processing requires process context, bounce */
6195 struct cgroup_subsys_state *css =
6198 if (atomic_dec_and_test(&css->online_cnt)) {
6199 INIT_RCU_WORK(&css->destroy_rwork, css_killed_work_fn);
6200 queue_rcu_work(cgroup_offline_wq, &css->destroy_rwork);
6205 * kill_css_sync - synchronous half of css teardown
6206 * @css: css being killed
6210 static void kill_css_sync(struct cgroup_subsys_state *css)
6212 struct cgroup_subsys *ss = css->ss;
6216 if (css->flags & CSS_DYING)
6222 if (css->ss->css_killed)
6223 css->ss->css_killed(css);
6225 css->flags |= CSS_DYING;
6235 * This must happen before css is disassociated with its cgroup.
6238 css_clear_dir(css);
6240 css->cgroup->nr_dying_subsys[ss->id]++;
6242 * Parent css and cgroup cannot be freed until after the freeing
6243 * of child css, see css_free_rwork_fn().
6245 while ((css = css->parent)) {
6246 css->nr_descendants--;
6247 css->cgroup->nr_dying_subsys[ss->id]++;
6252 * kill_css_finish - deferred half of css teardown
6253 * @css: css being killed
6257 static void kill_css_finish(struct cgroup_subsys_state *css)
6262 * Skip on re-entry: cgroup_apply_control_disable() may have killed @css
6266 if (percpu_ref_is_dying(&css->refcnt))
6273 css_get(css);
6277 * no new css reference will be given out via css_tryget_online(). We
6278 * can't simply call percpu_ref_kill() and proceed to offlining css's
6282 * Use percpu_ref_kill_and_confirm() to get notifications as each css is
6285 percpu_ref_kill_and_confirm(&css->refcnt, css_killed_ref_fn);
6307 * on each subsystem css.
6309 * - For each subsys css: fire kill_css_finish() synchronously if the subtree is
6311 * kill_finish_work when the last populated cset under the css empties.
6322 struct cgroup_subsys_state *css;
6357 for_each_css(css, ssid, cgrp)
6358 kill_css_sync(css);
6389 for_each_css(css, ssid, cgrp) {
6390 if (!css_is_populated(css))
6391 kill_css_finish(css);
6423 struct cgroup_subsys_state *css;
6434 css = ss->css_alloc(NULL);
6436 BUG_ON(IS_ERR(css));
6437 init_and_link_css(css, ss, &cgrp_dfl_root.cgrp);
6443 css->flags |= CSS_NO_REF;
6447 css->id = 1;
6449 css->id = cgroup_idr_alloc(&ss->css_idr, css, 1, 2, GFP_KERNEL);
6450 BUG_ON(css->id < 0);
6453 BUG_ON(css_rstat_init(css));
6460 init_css_set.subsys[ss->id] = css;
6472 BUG_ON(online_css(css));
6554 struct cgroup_subsys_state *css =
6557 css->id = cgroup_idr_alloc(&ss->css_idr, css, 1, 2,
6559 BUG_ON(css->id < 0);
6818 struct cgroup_subsys_state *css;
6820 css = css_tryget_online_from_dir(f->f_path.dentry, NULL);
6821 if (IS_ERR(css))
6822 return ERR_CAST(css);
6824 return css->cgroup;
7315 * css_tryget_online_from_dir - get corresponding css from a cgroup dentry
7320 * to get the corresponding css and return it. If such css doesn't exist
7328 struct cgroup_subsys_state *css = NULL;
7345 css = cgroup_css(cgrp, ss);
7347 if (!css || !css_tryget_online(css))
7348 css = ERR_PTR(-ENOENT);
7351 return css;
7355 * css_from_id - lookup css by id
7359 * Returns the css if there's valid one with @id, otherwise returns NULL.