Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2332903imu; Fri, 14 Dec 2018 09:18:19 -0800 (PST) X-Google-Smtp-Source: AFSGD/WrzoTwOlML6WykEZXaPSVHzQK2KndlkkcMDm9/9hf7EQd3cAwj6dF3jpjBcUoM9lOODXpB X-Received: by 2002:a17:902:a6:: with SMTP id a35mr3599874pla.201.1544807899825; Fri, 14 Dec 2018 09:18:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544807899; cv=none; d=google.com; s=arc-20160816; b=pEq0hmrtBNwLRwVEqcgh8cbkvG+sA4Hq1Sxf271aPhpnp63QlmxmZpiFqQ0oznKhNW EjBgQA/LMU4AIguG8EXB9yDxYUskUYNYdsSkl71mP2FCGmgLPd0hZxqMR/BdMjRFi9X8 IAUqLlOJM+SYbKs1ag82jI+S39feMNuBDg/dbvyC1abGiW9KISlEiyChmWMjbsi0uWjC 9FwH7momV7EK6ucdPtJSrtXfgsYldte2fuBpn3a10UeKYu4188KhMsD2fu7pX0TLlBQ5 vioT3waxNkKYzFrGJOIoJtSF00/YPlKVZ+QMBM+EQ+lwTNt8zSIfmzAxgQQ6uoavpOkZ zdXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sCRWYoNU0VkVJ/z3jhqejq2doYZrQjVc/bE8fLkqY2M=; b=NDZYB6Hd2MHdc9frWJUmBw1sMe3wUi1mIBMdrQ/QlvgZkLHZjSrgNVMf2AM9gf+vQO cEeG2bXSe9NXJuVZnq9PnSK9g2ejD3abar8CfD7WWUCjLK5mmIfIcYqTGLuqqSJVxKF9 752i91iIyk9Oh/4we2JR/tdoPhYG5lp8Ti/6aSovZC+dF86pb3FFmoLr4uWfuUjHosN/ lqP3ogPDuQkMCrs/zM8EfBKsd/tJJqCxD/V++JARAR5p7UycCtZ75awtBA9utEapQdZo 4wrCn34iYbHOlFk8Ma91XK6MDmmNCNpOgVK2tVsJnSrzxXYjZMyw9RNCsgv4BwaSdxhI G9EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qtqDt0yW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11si4573072pgo.11.2018.12.14.09.18.01; Fri, 14 Dec 2018 09:18:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qtqDt0yW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730369AbeLNRQS (ORCPT + 99 others); Fri, 14 Dec 2018 12:16:18 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:35282 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730359AbeLNRQR (ORCPT ); Fri, 14 Dec 2018 12:16:17 -0500 Received: by mail-pg1-f194.google.com with SMTP id s198so2987756pgs.2 for ; Fri, 14 Dec 2018 09:16:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sCRWYoNU0VkVJ/z3jhqejq2doYZrQjVc/bE8fLkqY2M=; b=qtqDt0yWn90HRTU+TjV+hv+Nm4vyH6Oihs6UoQLIHJzjQGDbObJpGMIW9v+FkBaVLR Uj8Mr9R6Rg0Sz1w7z3mYjuvKfxqj1KpIz5MHIF71R3JSGS6DuFPN+gh6/j1qi+lTThBZ bUtMX2GGllNQNpMM1hWDtA8Jb3e/DqguXh/VMkUbYokl1bHIab0fSzpccYMg5XIsFgtL cwNrvkofLgF/3zHa+CdOYBv8XhaIjPY6MX6VtZTlE9YX5+0piu/xcN/kY9kPUOGsU1hx /NMZB+XqLjN8gHVlZLBzkM9TnJZ0KARCM0+BSoqoytH9MUyVZtILnhGsikxNDrCX2BIa cXWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sCRWYoNU0VkVJ/z3jhqejq2doYZrQjVc/bE8fLkqY2M=; b=byNz5ZegbR9UNEKixEULG2L9cZC1+wm4462AiDJUQawGzLSCehpcPJrXpYYn+rmxJX 1a8ucDfjj+IUPHXnwSnsoRZKenq/uNGrLaeY3x0193OwVJoiXDbGwHZ6KdCEz4i0Nhoz Mbe3k5B6zPkYxey+8ZaGBLUVGlnrLvJd/zCgCdw9ardzGNjf7Vk6zr+OyMg+HPnXloa2 3mrGcVaEnFYlYyhotr72n2d2o1ZRW8Jq+2LaMmLrowlMEulYck2ck5HllpV5KlxGY7HS 1iWpRd0/2dFYMIRKwfZTLhYHXCyOarfi3xvbyPGupKFXdEI9BJkLlzRt82GzhYf5fM6d 6yJA== X-Gm-Message-State: AA+aEWbFybmfnidxZzRR390k3F55BwcpM7zlmk/Q79yhTmV0qmJ6WceY rKMXR716cxXnyz/Q7baU7IBiYA== X-Received: by 2002:a63:b34f:: with SMTP id x15mr3471723pgt.243.1544807776049; Fri, 14 Dec 2018 09:16:16 -0800 (PST) Received: from surenb0.mtv.corp.google.com ([2620:0:1000:1612:3320:4357:47df:276b]) by smtp.googlemail.com with ESMTPSA id g185sm7605761pfc.174.2018.12.14.09.16.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 09:16:14 -0800 (PST) From: Suren Baghdasaryan To: gregkh@linuxfoundation.org Cc: tj@kernel.org, lizefan@huawei.com, hannes@cmpxchg.org, axboe@kernel.dk, dennis@kernel.org, dennisszhou@gmail.com, mingo@redhat.com, peterz@infradead.org, akpm@linux-foundation.org, corbet@lwn.net, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Suren Baghdasaryan Subject: [PATCH 2/6] kernel: cgroup: add poll file operation Date: Fri, 14 Dec 2018 09:15:04 -0800 Message-Id: <20181214171508.7791-3-surenb@google.com> X-Mailer: git-send-email 2.20.0.405.gbc1bbc6f85-goog In-Reply-To: <20181214171508.7791-1-surenb@google.com> References: <20181214171508.7791-1-surenb@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johannes Weiner Cgroup has a standardized poll/notification mechanism for waking all pollers on all fds when a filesystem node changes. To allow polling for custom events, add a .poll callback that can override the default. This is in preparation for pollable cgroup pressure files which have per-fd trigger configurations. Signed-off-by: Johannes Weiner Signed-off-by: Suren Baghdasaryan --- include/linux/cgroup-defs.h | 4 ++++ kernel/cgroup/cgroup.c | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index 5e1694fe035b..6f9ea8601421 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -32,6 +32,7 @@ struct kernfs_node; struct kernfs_ops; struct kernfs_open_file; struct seq_file; +struct poll_table_struct; #define MAX_CGROUP_TYPE_NAMELEN 32 #define MAX_CGROUP_ROOT_NAMELEN 64 @@ -573,6 +574,9 @@ struct cftype { ssize_t (*write)(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off); + __poll_t (*poll)(struct kernfs_open_file *of, + struct poll_table_struct *pt); + #ifdef CONFIG_DEBUG_LOCK_ALLOC struct lock_class_key lockdep_key; #endif diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 6aaf5dd5383b..ffcd7483b8ee 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3499,6 +3499,16 @@ static ssize_t cgroup_file_write(struct kernfs_open_file *of, char *buf, return ret ?: nbytes; } +static __poll_t cgroup_file_poll(struct kernfs_open_file *of, poll_table *pt) +{ + struct cftype *cft = of->kn->priv; + + if (cft->poll) + return cft->poll(of, pt); + + return kernfs_generic_poll(of, pt); +} + static void *cgroup_seqfile_start(struct seq_file *seq, loff_t *ppos) { return seq_cft(seq)->seq_start(seq, ppos); @@ -3537,6 +3547,7 @@ static struct kernfs_ops cgroup_kf_single_ops = { .open = cgroup_file_open, .release = cgroup_file_release, .write = cgroup_file_write, + .poll = cgroup_file_poll, .seq_show = cgroup_seqfile_show, }; @@ -3545,6 +3556,7 @@ static struct kernfs_ops cgroup_kf_ops = { .open = cgroup_file_open, .release = cgroup_file_release, .write = cgroup_file_write, + .poll = cgroup_file_poll, .seq_start = cgroup_seqfile_start, .seq_next = cgroup_seqfile_next, .seq_stop = cgroup_seqfile_stop, -- 2.20.0.405.gbc1bbc6f85-goog