Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp817149pxf; Thu, 25 Mar 2021 14:55:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsstXOxoa3NxJE51ll0dRiGcbAie6giH82qEzIiQT5ANcuE6U30tSKK/0BIZKt63cJCI8P X-Received: by 2002:a17:906:2551:: with SMTP id j17mr11864672ejb.441.1616709326164; Thu, 25 Mar 2021 14:55:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616709326; cv=none; d=google.com; s=arc-20160816; b=zjedmJpvQ2aCaCsutQUFnVsvll27idsN2CCCxgRGOf89uv/wUlx5t/8lDA2vuY9oLx nk/G+korCFHMv3aRmeRhDR574HSHPvwrTgUXEhEXzi2esPhb/nNOzUExN9u3L3UiCVFe 2O3xdWPvD2du/Y4JOfWgozsHJ7tEAqterZf/5AYjJy0mx2QPHQ5EzJAjH0BreBr4kq/Q NGrs0XjLWP2jxyR4EqRcdrRxi2l0qYCfgB0+swAgSwSKekXD7ebjZEynQK3DzLIWV4+R gTlppN9lcMUiw2kjectT+Ix5suN78DorQEs7AESWqdlCBE64FmiH3wDpfGQdo56TaUG8 6bYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xPDX5Uvos2ib1btitjeT/DSWvnYPpsVpIIBrEV7n3/w=; b=vVJGu1rGG4RgqAPyLz+5LN3YILdsvCs6bqZ3BYChYonf4uXS4T5cu7MWIXje4xehth 4ayLeHPscFWpoktN5t88kBVCa5oN2GLisZiXGn/XeX1ZzODVnjN/e/CKwL0RrWAagZfp ciflLHg9uF4uo86Nlboo0hjCyDNU6Mh9ME009uu9XNJms6vxDTAEogBAGFoXweQzvEXO jwuVoH9IAKQXRjuhzgUE5IRFt9IeHDMOcWC9WYM91fD8tmRLqDCYZfPAUiXfuPmsn03J Yb4p1Cukry/emdrGZXZudfA3QvZUMj1sv9vVZ0Cj6zwEhInAzzDF2PXiPG1V0L/fW8cQ eVQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=PzOKsYkv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id o21si5392729ejc.724.2021.03.25.14.55.03; Thu, 25 Mar 2021 14:55:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=PzOKsYkv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231144AbhCYVvQ (ORCPT + 99 others); Thu, 25 Mar 2021 17:51:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231184AbhCYVuo (ORCPT ); Thu, 25 Mar 2021 17:50:44 -0400 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D29DC06175F for ; Thu, 25 Mar 2021 14:50:44 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id i9so3398806qka.2 for ; Thu, 25 Mar 2021 14:50:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xPDX5Uvos2ib1btitjeT/DSWvnYPpsVpIIBrEV7n3/w=; b=PzOKsYkvSBTrup8k68oKcP/7M5mr/IMYCggyr9Hm87+hGOn4uL95lVBiZBBTMOkXHT HvoPF6CNNcatwoKgem1fPZrwSAsRyOsgln2qBQzGjFFMdIt3pHGOP2OsBg/6EfWlN6Ja d9OUfAkVRzSkl7ABsAtFHIoonu2udIrkVOYeBO2zijSc5TjfkJLYcjoMuOv82TG7UVia CKdnKHs46LcMt2keeeFQeqvWcgvbk8nQhFOgqHAXMOV31h5j5LBjzvfNALECOOwnl8PF jk9myShHlWo3z4p3nwHUXt3yPfILtuSDw20e4sW3DtGoHOp12hw50vVRugbvXCdvU3kb VN0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xPDX5Uvos2ib1btitjeT/DSWvnYPpsVpIIBrEV7n3/w=; b=tUmQjgsI0gVhtzRORm8bdwiBRUxfRggTxP6cmOHq2erH+Ju4b45wnNT/MOoCKv9vVw A+y3RlLj0+j50+ZbHnVnhioCro6et5e6xXgjWNJRuh6rIZ1GZL2KzeSYXMCUgMwH2lD8 wCa9rAGNhS54+GUFM4dEaMxiiwVxFJa2plAMdIO4uxr5flaKBAXTfjAVNI0qqe0SXnAv m2qtM1opijf5p+sSe7PcqWoBJeHaNLao0v5EszUy+CdXMGM59Lrx+Qb2j4EVpPBuj5iR fxo9fs+k1iVJJaMLCdFN+QEQe9kihXTNL4zwDvn4Xp+4hPGq11hNYYZXqoe6JdzShMal 55VA== X-Gm-Message-State: AOAM532AkeIR9l7pGVP/VUlv/t/syhDtbGhrzGLkfABgP+17OWrfwdOe ohxkK9oBtNH/u3LaoZLQBMWpujVA10OcbG8sQRI+yAsqoLE= X-Received: by 2002:a37:a643:: with SMTP id p64mr9830973qke.276.1616709043374; Thu, 25 Mar 2021 14:50:43 -0700 (PDT) MIME-Version: 1.0 References: <20210323035706.572953-1-joshdon@google.com> <20210324112739.GO15768@suse.de> In-Reply-To: <20210324112739.GO15768@suse.de> From: Josh Don Date: Thu, 25 Mar 2021 14:50:32 -0700 Message-ID: Subject: Re: [PATCH v2] sched: Warn on long periods of pending need_resched To: Mel Gorman Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Daniel Bristot de Oliveira , Luis Chamberlain , Kees Cook , Iurii Zaikin , linux-kernel , linux-fsdevel@vger.kernel.org, David Rientjes , Oleg Rombakh , linux-doc@vger.kernel.org, Paul Turner Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 24, 2021 at 4:27 AM Mel Gorman wrote: > > I'm not a fan of the name. I know other sysctls have _enabled in the > name but it's redundant. If you say the name out loud, it sounds weird. > I would suggest an alternative but see below. Now using the version rebased by Peter; this control has gone away and we have simply a scheduling feature "LATENCY WARN" > I suggest semantics and naming similar to hung_task_warnings > because it's sortof similar. resched_latency_warnings would combine > resched_latency_warn_enabled and resched_latency_warn_once. 0 would mean > "never warn", -1 would mean always warn and any positive value means > "warn X number of times". See above. I'm happy with the enabled bit being toggled separately by a sched feature; the warn_once behavior is not overloaded with the enabling/disabling. Also, I don't see value in "warn X number of times", given the warning is rate limited anyway. > > +int sysctl_resched_latency_warn_ms = 100; > > +int sysctl_resched_latency_warn_once = 1; > > Use __read_mostly Good point, done. > > +#ifdef CONFIG_SCHED_DEBUG > > +static u64 resched_latency_check(struct rq *rq) > > +{ > > + int latency_warn_ms = READ_ONCE(sysctl_resched_latency_warn_ms); > > + u64 need_resched_latency, now = rq_clock(rq); > > + static bool warned_once; > > + > > + if (sysctl_resched_latency_warn_once && warned_once) > > + return 0; > > + > > That is a global variable that can be modified in parallel and I do not > think it's properly locked (scheduler_tick is holding rq lock which does > not protect this). > > Consider making resched_latency_warnings atomic and use > atomic_dec_if_positive. If it drops to zero in this path, disable the > static branch. > > That said, it may be overkill. hung_task_warnings does not appear to have > special protection that prevents it going to -1 or lower values by accident > either. Maybe it can afford to be a bit more relaxed because a system that > is spamming hung task warnings is probably dead or might as well be dead. There's no real issue if we race over modification to that sysctl. This is intentionally not more strongly synchronized for that reason. > > + if (!need_resched() || WARN_ON_ONCE(latency_warn_ms < 2)) > > + return 0; > > + > > Why is 1ms special? Regardless of the answer, if the sysctl should not > be 1 then the user should not be able to set it to 1. Yea let me change that to !latency_warn_ms so it isn't HZ specific. > > > + /* Disable this warning for the first few mins after boot */ > > + if (now < resched_boot_quiet_sec * NSEC_PER_SEC) > > + return 0; > > + > > Check system_state == SYSTEM_BOOTING instead? Yea, that might be better; let me test that. > > + if (!rq->last_seen_need_resched_ns) { > > + rq->last_seen_need_resched_ns = now; > > + rq->ticks_without_resched = 0; > > + return 0; > > + } > > + > > + rq->ticks_without_resched++; > > + need_resched_latency = now - rq->last_seen_need_resched_ns; > > + if (need_resched_latency <= latency_warn_ms * NSEC_PER_MSEC) > > + return 0; > > + > > The naming need_resched_latency implies it's a boolean but it's not. > Maybe just resched_latency? > > Similarly, resched_latency_check implies it returns a boolean but it > returns an excessive latency value. At this point I've been reading the > patch for a long time so I've ran out of naming suggestions :) The "need_" part does confuse it a bit; I reworded these to hopefully make it more clear. > > + warned_once = true; > > + > > + return need_resched_latency; > > +} > > + > > I note that you split when a warning is needed and printing the warning > but it's not clear why. Sure you are under the RQ lock but there are other > places that warn under the RQ lock. I suppose for consistency it could > use SCHED_WARN_ON even though all this code is under SCHED_DEBUG already. We had seen a circular lock dependency warning (console_sem, pi lock, rq lock), since printing might need to wake a waiter. However, I do see plenty of warns under rq->lock, so maybe I missed a patch to address this?