From patchwork Wed Mar 21 23:23:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 10300663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 818A760349 for ; Wed, 21 Mar 2018 23:25:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 731C5290D7 for ; Wed, 21 Mar 2018 23:25:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6797E2990D; Wed, 21 Mar 2018 23:25:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 38E1F290D7 for ; Wed, 21 Mar 2018 23:25:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3FED46EB35; Wed, 21 Mar 2018 23:25:07 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0D6626EB2F; Wed, 21 Mar 2018 23:25:05 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Mar 2018 16:25:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,341,1517904000"; d="scan'208";a="210273045" Received: from mdroper-desk.fm.intel.com ([10.1.134.220]) by orsmga005.jf.intel.com with ESMTP; 21 Mar 2018 16:25:04 -0700 From: Matt Roper To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, cgroups@vger.kernel.org Subject: [PATCH v4.5 2/8] cgroup: Introduce task_get_dfl_cgroup() (v2) Date: Wed, 21 Mar 2018 16:23:38 -0700 Message-Id: <20180321232344.20727-3-matthew.d.roper@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180321232344.20727-1-matthew.d.roper@intel.com> References: <20180321232344.20727-1-matthew.d.roper@intel.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tejun Heo MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Wraps task_dfl_cgroup() to also take a reference to the cgroup. v2: - Eliminate cgroup_mutex and make lighter-weight (Tejun) Cc: Tejun Heo Cc: cgroups@vger.kernel.org Signed-off-by: Matt Roper --- include/linux/cgroup.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 63d22dfa00bd..74b435f913c1 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -527,6 +527,35 @@ static inline struct cgroup *task_dfl_cgroup(struct task_struct *task) return task_css_set(task)->dfl_cgrp; } +/** + * task_get_dfl_cgroup() - find and get the cgroup for a task + * @task: the target task + * + * Find the cgroup in the v2 hierarchy that a task belongs to, increment its + * reference count, and return it. + * + * Returns: + * The appropriate cgroup from the default hierarchy. + */ +static inline struct cgroup * +task_get_dfl_cgroup(struct task_struct *task) +{ + struct cgroup *cgrp; + + rcu_read_lock(); + while (true) { + cgrp = task_dfl_cgroup(task); + + if (likely(cgroup_tryget(cgrp))) + break; + + cpu_relax(); + } + rcu_read_unlock(); + + return cgrp; +} + static inline struct cgroup *cgroup_parent(struct cgroup *cgrp) { struct cgroup_subsys_state *parent_css = cgrp->self.parent;