Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp271495lqb; Tue, 4 Jun 2024 10:47:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW3skj3+ht/YsKs+1NrsllBagSe/EvnAZvJK5SCFAINH4DDZF6FlV1TbFFr+AeRgsBS8a1vc/ArBFbSkKQQnWJooqBY0jrw1ouo1c837Q== X-Google-Smtp-Source: AGHT+IEQQmDf5eyYopHgmAE8aUIACwbX/D91pt+h/2/FfHuZt4UuO7QTXH9uHQLdgloqNH9NfyFY X-Received: by 2002:a05:6a00:b4b:b0:702:39e9:e51b with SMTP id d2e1a72fcca58-703e597ade5mr210524b3a.17.1717523254198; Tue, 04 Jun 2024 10:47:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717523254; cv=pass; d=google.com; s=arc-20160816; b=v/stSBNMuq0UG1+aBv/HzRv3mcHyeek89hLzurvqby9GgatUseiI4uA0EeImllv9ot 7RgodGUVy5GrS3e04K5z+AfB2+4q9QXfLlBt2oDu1YLkdkiGfadeM2rOXkaNIDEgWD0Q sC9lFIj+rToFCeLQxS8gSdM1yE1opFuEmoU9wwhcbpUQN5cXa/BbbIr1wYX1gWhYtFON 53PgC5SBclKSCHhYBa+WO+GxZURx47QujooDALiBUgOLmTbiTKG2fbZ123BnpxQVCjb+ 8b8rZB8G0LpP0DAzJTSoMQa1FfECp8n5qZVcjWctu6EZnHkpP4ZzmH0gzTF6E5pPMgm7 jkuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=jjwPD4TVq3EAmy5AS/FS3mLLstD1BC2BCaYeSVtKmJY=; fh=y77Z0KWVpNhPH9qJ4vAYjEKHTasKT+F1kZ+PJTZqHvk=; b=ihO2//+e+wne+KNtCyS4ZRsXHM7Ng9a37eT50unwyNVHQIVKUU40rhIm03jCj2a+3I RIAtomnbPUksGSKz+xZEw46PlbAHmiSTU7Kz9FqENzPwbgJYHZm1HfSZyvyjzn8vV+Qe 9pVD40tdcbKDipO39UHFjHuoOF3TzD40axCyp+ev9jnytrsFOKMlybyHVKxsP+MHv4vT GJNztpwX4Rw0jIO5gAXWDSjaoDh3HMnMjM/KNmViC1JY48VfZd46EH0laRmAlztMeycp aU6hlGKM4ZVE9MV2MYTAPCIzB5NCEB5OOa0A2wem5Pm2Nuc1GIDKmgmkAHhrhJGF/4Sf +1Og==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="B8k/+m3H"; arc=pass (i=1 spf=pass spfdomain=flex--isaacmanjarres.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-201173-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201173-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d2e1a72fcca58-70242c293e0si2524891b3a.288.2024.06.04.10.47.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 10:47:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201173-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="B8k/+m3H"; arc=pass (i=1 spf=pass spfdomain=flex--isaacmanjarres.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-201173-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201173-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 71EE928ACCA for ; Tue, 4 Jun 2024 17:37:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF28E14A600; Tue, 4 Jun 2024 17:36:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B8k/+m3H" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8456414A0B8 for ; Tue, 4 Jun 2024 17:36:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717522573; cv=none; b=Dj5aLSkM3gIonieujMWUKZdiYMFkUATcIul1KlvgrqpLHjv1tlLShPvqY4HCm9ZNQ+m/Ma69A/AFFnXpTN7QA4Wu4moSC1rypDEGGY2bO/uCJSZhgPPArtQ3oJPDmu+Ol6nlmMj3et8rMFHkVOSx4p4jntx4f3FouGPTbXL0g4M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717522573; c=relaxed/simple; bh=r5L86LKo0SdTsCjI9YO8qd+i5Ww1vAx2jexZe2Csz04=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=CjfwULq3CxTYM4hBl3qibLpD7cdUMOFV6fL+McvvsT/1B+L6Dh9pRAZzPd2EFOqY+WwxAfsALzthvlEjV6iuwqJX+2CWsv4bGgli7KQSEJNu71I7SGxXnARr9qsB4jqfdufeLq24DgSvXvKc+8J76ECvGS+dpqET9vKSa1Gl8rE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--isaacmanjarres.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=B8k/+m3H; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--isaacmanjarres.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dfa74682897so6909644276.2 for ; Tue, 04 Jun 2024 10:36:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717522570; x=1718127370; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=jjwPD4TVq3EAmy5AS/FS3mLLstD1BC2BCaYeSVtKmJY=; b=B8k/+m3HrZONejieKsZWQTIvuiA2GYX0OiSCQOdEWy5er/+3ecDJgfvofr4v9L+m76 vjLADnDX01cPND/IGcTWtlZIJ01gZHHWKEStekRWe75o8mCGmc5H4pRnSAQ6iXuFBU3f SGe4qSL/t5ey1G7K7j1mC5z/4yeF0UZcMuwoOVyUqKA88s6sm48nG8PQaBb2RR2w43cJ LSUB2H8PYHnPn+3YNGxNDJtnAsxmNmgXld0gsJASd+ZdcayG7+EgXLa3als8UWXKa403 Xf3b5qrSREweyW8NF0DeZL24FNBjgthXiBze1amoEnAEYOPTFYN2Hnc+LuU7Whpt8TfF sFaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717522570; x=1718127370; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jjwPD4TVq3EAmy5AS/FS3mLLstD1BC2BCaYeSVtKmJY=; b=Q3B6szogR4ZRiUoal3thtxeqMmPds9SKyR+adyiKGM0JF3xSwMtVj/ngJCi+JVfnTX C0q+u4cJeVnvZwKIfmYsqKPIhbgISJc9T/6FrMUUa5A7XARePixO2Wd0+9n2Lr5zlQ4w opLY+MvuaoCcIbrcPKWzMrZGslN27of2MFjU7oNSKsv12+/uI4GYvHVlcCnH5GtIav2U xw6iY/jstN90PDSVkqeAbAqrpEBysTa04Fit7lOd/kyBlpKoF1+pIXQ9Rw6gOmXqTZBl qN0jL5ojAwWiCAkAIvZ3XKcRvtefYrFICc8/YOq2LWDP5KCJeTCq5kf49t7iv3cDiC42 RZFQ== X-Forwarded-Encrypted: i=1; AJvYcCXlEP4vGKiBQjaRdyWVFHl2ZNYZpZaRJrfSy90R0CfOOA2B6DSYFfrt+174/5SY1O/YrjmNJ4tMbc57a8teiqzKR3s01wiK9nJaSrW2 X-Gm-Message-State: AOJu0YxkKREUS2EhSMevJPLxDzWqYk9v4Utg8VmS9vxmrXpu2zdB3CVK xLHBhT2d8BBm1oG6Isp6ERhc2WKi3GP4d7FwyHRSrFzJfC1a0diYHVSyG/3+jIqq5Fnuoj4vLX/ NOzdBJTF8kWj0Cv3G9cb9U/A2JgoY22KV1A== X-Received: from isaacmanjarres.irv.corp.google.com ([2620:15c:2d:3:b345:5eb0:8af2:5eb0]) (user=isaacmanjarres job=sendgmr) by 2002:a05:6902:1101:b0:dfa:48f9:186a with SMTP id 3f1490d57ef6-dfacab1eaf7mr472276.3.1717522570543; Tue, 04 Jun 2024 10:36:10 -0700 (PDT) Date: Tue, 4 Jun 2024 10:36:05 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240604173606.998721-1-isaacmanjarres@google.com> Subject: [PATCH v4] fs: Improve eventpoll logging to stop indicting timerfd From: "Isaac J. Manjarres" To: tglx@linutronix.de, "Rafael J. Wysocki" , Pavel Machek , Len Brown , Greg Kroah-Hartman , Alexander Viro , Christian Brauner , Jan Kara Cc: saravanak@google.com, Manish Varma , Kelly Rossmoyer , "Isaac J . Manjarres" , kernel-team@android.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" From: Manish Varma timerfd doesn't create any wakelocks, but eventpoll can. When it does, it names them after the underlying file descriptor, and since all timerfd file descriptors are named "[timerfd]" (which saves memory on systems like desktops with potentially many timerfd instances), all wakesources created as a result of using the eventpoll-on-timerfd idiom are called... "[timerfd]". However, it becomes impossible to tell which "[timerfd]" wakesource is affliated with which process and hence troubleshooting is difficult. This change addresses this problem by changing the way eventpoll wakesources are named: 1) the top-level per-process eventpoll wakesource is now named "epollN:P" (instead of just "eventpoll"), where N is a unique ID token, and P is the PID of the creating process. 2) individual per-underlying-file descriptor eventpoll wakesources are now named "epollitemN:P.F", where N is a unique ID token and P is PID of the creating process and F is the name of the underlying file descriptor. Co-developed-by: Kelly Rossmoyer Signed-off-by: Kelly Rossmoyer Signed-off-by: Manish Varma Co-developed-by: Isaac J. Manjarres Signed-off-by: Isaac J. Manjarres --- drivers/base/power/wakeup.c | 10 ++++++++-- fs/eventpoll.c | 11 +++++++++-- include/linux/pm_wakeup.h | 4 ++-- 3 files changed, 19 insertions(+), 6 deletions(-) v1 -> v2: - Renamed instance count to wakesource_create_id to better describe its purpose. - Changed the wakeup source naming convention for wakeup sources created by eventpoll to avoid changing the timerfd names. - Used the PID of the process instead of the process name for the sake of uniqueness when creating wakeup sources. v2 -> v3: - Changed wakeup_source_register() to take in a format string and arguments to avoid duplicating code to construct wakeup source names. - Moved the definition of wakesource_create_id so that it is always defined to fix an compilation error. v3 -> v4: - Changed the naming convention for the top-level epoll wakeup sources to include an ID for uniqueness. This is needed in cases where a process is using two epoll fds. - Edited commit log to reflect new changes and add new tags. diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index 752b417e8129..86276f904be8 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c @@ -209,13 +209,19 @@ EXPORT_SYMBOL_GPL(wakeup_source_remove); /** * wakeup_source_register - Create wakeup source and add it to the list. * @dev: Device this wakeup source is associated with (or NULL if virtual). - * @name: Name of the wakeup source to register. + * @fmt: format string for the wakeup source name */ struct wakeup_source *wakeup_source_register(struct device *dev, - const char *name) + const char *fmt, ...) { struct wakeup_source *ws; int ret; + char name[128]; + va_list args; + + va_start(args, fmt); + vsnprintf(name, sizeof(name), fmt, args); + va_end(args); ws = wakeup_source_create(name); if (ws) { diff --git a/fs/eventpoll.c b/fs/eventpoll.c index f53ca4f7fced..941df15208a4 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -338,6 +338,7 @@ static void __init epoll_sysctls_init(void) #define epoll_sysctls_init() do { } while (0) #endif /* CONFIG_SYSCTL */ +static atomic_t wakesource_create_id = ATOMIC_INIT(0); static const struct file_operations eventpoll_fops; static inline int is_file_epoll(struct file *f) @@ -1545,15 +1546,21 @@ static int ep_create_wakeup_source(struct epitem *epi) { struct name_snapshot n; struct wakeup_source *ws; + pid_t task_pid; + int id; + + task_pid = task_pid_nr(current); if (!epi->ep->ws) { - epi->ep->ws = wakeup_source_register(NULL, "eventpoll"); + id = atomic_inc_return(&wakesource_create_id); + epi->ep->ws = wakeup_source_register(NULL, "epoll:%d:%d", id, task_pid); if (!epi->ep->ws) return -ENOMEM; } + id = atomic_inc_return(&wakesource_create_id); take_dentry_name_snapshot(&n, epi->ffd.file->f_path.dentry); - ws = wakeup_source_register(NULL, n.name.name); + ws = wakeup_source_register(NULL, "epollitem%d:%d.%s", id, task_pid, n.name.name); release_dentry_name_snapshot(&n); if (!ws) diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h index 76cd1f9f1365..40972ca262cc 100644 --- a/include/linux/pm_wakeup.h +++ b/include/linux/pm_wakeup.h @@ -100,7 +100,7 @@ extern void wakeup_source_destroy(struct wakeup_source *ws); extern void wakeup_source_add(struct wakeup_source *ws); extern void wakeup_source_remove(struct wakeup_source *ws); extern struct wakeup_source *wakeup_source_register(struct device *dev, - const char *name); + const char *fmt, ...); extern void wakeup_source_unregister(struct wakeup_source *ws); extern int wakeup_sources_read_lock(void); extern void wakeup_sources_read_unlock(int idx); @@ -141,7 +141,7 @@ static inline void wakeup_source_add(struct wakeup_source *ws) {} static inline void wakeup_source_remove(struct wakeup_source *ws) {} static inline struct wakeup_source *wakeup_source_register(struct device *dev, - const char *name) + const char *fmt, ...) { return NULL; } -- 2.45.1.288.g0e0cd299f1-goog