Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1555037rbb; Mon, 26 Feb 2024 13:12:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUHMfqaMOkuO5VvupmegRK0DprgOt5fX/95mGUWA202C98oQysLovG0rqoLyKaAzNI0/OQH6Emhxcje9u+U8PNX/ANi0HrIsxL1mNOfiw== X-Google-Smtp-Source: AGHT+IFDWEFfnbCHPfDNPTUyb+u4QMLBQpi9AYpzDBkOrhkyk2WfyvsQiLXwsra/qgbzHfCGKw0O X-Received: by 2002:a17:906:f0c5:b0:a43:9e1f:240e with SMTP id dk5-20020a170906f0c500b00a439e1f240emr259086ejb.60.1708981972451; Mon, 26 Feb 2024 13:12:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708981972; cv=pass; d=google.com; s=arc-20160816; b=qyQ6IKJb+/n0TnIrGQxICm3WVMzutRG06s8j5qbLZCzW+3xR8pfT2DHlQunQna8kw4 CwZS388QWrvgp66me0E/f+7tyOMlUk6hECC6TFvyfnC5w+IsMW5C23cUqFb41rPo1YGl SqKP9IaHp6T/rkBjr3LIhpRfg+b9Z0omD4Nl9BeJiSsOn0xvHMPRHbmfUIuLkyU7BGnl c+B7/Z1EniPth/R6dVfsuFw/4VKSq2dc8e74ceBF7xwsJdNh3AbFsHXMzuS/OBy3ocpR VjpX4aqEJ2g6dB9FP/BNOFnK6w63lOs7PqE7n9xTIVPU1wQHkbSe8Y49fBf6KvOUaGwa LeKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=3x3BD2GkxMZMqd/1VnWeb2aZg9kXrVU17QnxzRPyDP4=; fh=KRxQ74lBjI6rXy1IqfQR654Eet6NH9msJ1QOOr4kDXc=; b=zQfL0nv0kR1ITgUULm/hS68cp90BQYcboN+aROxB5QVHsfOzfjGcLqQOZIq6/O3f1t DMrfp6rij1e5cFSMQCP70551fpv3M5aa1oAeLyx8FVf6J6JJyyMT1yKMy3grTgBnM6Kl d+s8D2h2Qh4HQh8uW4VpREo9sOIsTuPnN+9QvpF0BrdpBYdC/2EGidztp5W5qIBINzER 3TRAIVSgQlwm9MnlWkc+0Ze4x5h4rq2qOpqTyEwOGq736jTi5QvVzIRMeuiTMnHOpzbd fS5lSN6IchS0f+UIQAcsP3+epHeXlYfVlnYRjRmKrS2HISZtKezpza4olTiXXv4DtSjz BL8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VAogCIzq; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-82325-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82325-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u16-20020a170906655000b00a3fc3454a34si92082ejn.540.2024.02.26.13.12.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:12:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82325-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VAogCIzq; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-82325-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82325-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 36C231F2275E for ; Mon, 26 Feb 2024 21:12:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B713613172B; Mon, 26 Feb 2024 21:12:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VAogCIzq" Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 5B249405CE for ; Mon, 26 Feb 2024 21:12:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708981963; cv=none; b=YaPqQzOJkN5DSExlMnMpVfLZqy+YgMR3KW6rRbg07capW5OIc0X0biCuvqAZ+jDYGKJlLm0mhyuOOGBL9mfwHm2UXUU/eAFonHlF2ODuQXLnG5NBCw4aLxuDqgR91CYzQBMLaBHo7HivTcXnNEtYYYvoBrkrSrrq5SkrXbZeU0A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708981963; c=relaxed/simple; bh=GdPy4GkFXCLovNiPIxd6I6JUjafJipYvTlGkL2o8yIk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=rsrUfT/nKd8EqN54s7G6QWRt4+R2tSALVRd70cNjGDR8+ynqw5uHOPq7fTD4EVQK87unt+Xc7m8/NJzqRl6EVNlgyDDhLX5Ox3WDYJ7W/BOLOB1k7ph6+jPf2jOHnJJYpcwsE52707kqXOoLaFW+vB1AMsg5t9r//4Xsa5TCiec= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VAogCIzq; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-412a5b63c11so8889715e9.2 for ; Mon, 26 Feb 2024 13:12:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708981960; x=1709586760; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3x3BD2GkxMZMqd/1VnWeb2aZg9kXrVU17QnxzRPyDP4=; b=VAogCIzqKBgfwtzs+GAfkGxXrO3DNLL+/W4NTHLXiupKs/faJxC9OeLeVWOs7lKDdR v/HXkvEwc6sW4k/QrIYpDtW71ZrVnPm7FGveAZcwW6du3zEL4GQaGyhc44amDJBuYm92 IpPjfc4w0fJoivzMuXMY8TNf0i0aU0HPkxDLv7RxOvJsDzVOHN6MuaEZXOXfY+Y5/I2e 9+Ed3MLG2R1q0o3ypkVk5lcYfWUl0qOUUHdOioe0TuFjMcXGUGt2Fcr47okFbDtsdAAY YUpcBeeUFDgne5UkvaBpscvlkwUY1/s/rmUUw9mid8G/MxktyHPlBnVmrGClx5xSQugN gSxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708981961; x=1709586761; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3x3BD2GkxMZMqd/1VnWeb2aZg9kXrVU17QnxzRPyDP4=; b=rtAQAHCWTQsN99/cSSgwvxcchzJw8QZzmWlyOrRZn+n2eXrLoHs1x8MRU1d78PfThV W/wAu6htS/25XJMYd0285uyJGwt5WBvQ3QY6OwDjLucTfbskIMDTwAEn2fbl7q/ODCr8 eevYVvZM/elIKmxZXwt0wnRkTu278iOk3MSkdYUaaBLdMjdMsf4IwsFIGodpvS6rE8eM 0gM9XO+AcPm87kEstMlPV90kV2CTJFnLsZ11iAmJEzdVQAjd2i9OQSbtVRqU7Nqxch60 BW9+0jq5lNq7+JojjTNvxFbrbtxwpn1ELnNbNfhY3iawISHUe2C6xwmUAvuKwiTJhgXM oqAA== X-Gm-Message-State: AOJu0Ywq9drKvbnjfRliec05YxRu5fYqpDoLSjwMynMKcjpk3q+WXfam s/Ue4ExLYKuzHbC7/ylgZ4rL3pecoCTvlqnlv05KoAPybNCwAWOC X-Received: by 2002:a05:600c:45cd:b0:412:7b4d:b256 with SMTP id s13-20020a05600c45cd00b004127b4db256mr5815822wmo.18.1708981960416; Mon, 26 Feb 2024 13:12:40 -0800 (PST) Received: from localhost.localdomain (host86-133-224-40.range86-133.btcentralplus.com. [86.133.224.40]) by smtp.gmail.com with ESMTPSA id bv15-20020a0560001f0f00b0033d47c6073esm9373109wrb.12.2024.02.26.13.12.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 26 Feb 2024 13:12:40 -0800 (PST) From: Levi Yun To: hannes@cmpxchg.org, surenb@google.com, peterz@infradead.org, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com Cc: linux-kernel@vger.kernel.org, Levi Yun Subject: [PATCH v2] psi: Fix avg trigger being fired unexpectedly. Date: Mon, 26 Feb 2024 21:12:37 +0000 Message-ID: <20240226211237.48415-1-ppbuk5246@gmail.com> X-Mailer: git-send-email 2.41.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit commit 915a087e4c473("psi: Fix trigger being fired unexpectedly at initial") fixes unexpected event fired when group->total accumulated for PSI_POLL. But, for PSI_AVGS, win->value should be initialized with group->total[PSI_AVGS]. Moreover, to get exact initial value for win->value, it should be set under each trigger lock to avoid concurrent changes to group->total[]. Signed-off-by: Levi Yun Acked-by: Suren Baghdasaryan --- v2: Fix commit message. --- kernel/sched/psi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 7b4aa5809c0f..e7f66ab2ad3e 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -1323,9 +1323,6 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf, t->state = state; t->threshold = threshold_us * NSEC_PER_USEC; t->win.size = window_us * NSEC_PER_USEC; - window_reset(&t->win, sched_clock(), - group->total[PSI_POLL][t->state], 0); - t->event = 0; t->last_event_time = 0; t->of = of; @@ -1336,6 +1333,8 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf, if (privileged) { mutex_lock(&group->rtpoll_trigger_lock); + window_reset(&t->win, sched_clock(), + group->total[PSI_POLL][t->state], 0); if (!rcu_access_pointer(group->rtpoll_task)) { struct task_struct *task; @@ -1361,6 +1360,9 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf, } else { mutex_lock(&group->avgs_lock); + window_reset(&t->win, sched_clock(), + group->total[PSI_AVGS][t->state], 0); + list_add(&t->node, &group->avg_triggers); group->avg_nr_triggers[t->state]++; -- 2.39.2