Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp833240lqe; Sun, 7 Apr 2024 06:11:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWAGF9HXnvCg9QRcFlV0tqjYPbhwo1aeTkiSLlvyHUqjSqw2v5Es8Ci5iUAg4k2kmAaltPPuHqcZOV0y9RBp+T1B9NaJhbXhOfINb40KA== X-Google-Smtp-Source: AGHT+IGCUGOYfWWpmf3DxlDjp1Vc7Kx7W1yUHo8AEFA2WbhlAumuV5ucjpckNqv9vvOh0nY2wLcv X-Received: by 2002:a17:906:f20d:b0:a4e:df0:e9e with SMTP id gt13-20020a170906f20d00b00a4e0df00e9emr5521971ejb.24.1712495464579; Sun, 07 Apr 2024 06:11:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712495464; cv=pass; d=google.com; s=arc-20160816; b=yK1lIU09W5QSdIeBbcC2WsBHSuh+9CJLXxSLJfFolaocpylnYrnJQyrWM12K11i4hS ScWX85BLj0M40i+3sz/utwu/PJ6EC1z8pcyDyiNOmcaqNmsjZoXsi/TXrCnoXqv7oroX uRscJMuiHwnN3T1cIDX8r9mWgZ2L6Ceb9f+cfXmEV3QLhHzwx5e6stLnq3Bj7Z4uwyXv PMvF/Lta6NIKbeiK25tcdyEa4fh5MFN46cWlqpvz6HzwM0cCXswJ7z7vDb2fPZD7dUSh k2LUdCfbtwSBW0qtxO9F5Gm3VdrpKHCqpF3P4YQW7MMTJmd3XxmCpimy83syx3v7r2es Misw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:references:message-id:subject:cc:to:from:date :dkim-signature; bh=a6vxxG5xgzXX9R/YtKyD3zzQDfQBIezrwLJQElkxb28=; fh=2InlgaUf6YM4x7N5en8bF5Ts9/p78k4HiB3/TZmHd4c=; b=CVDnIGCTrl0OXa+3msxZcHFuWbeqdBj9ec+nUUQuwdOc73SAWRoA6O2GTYpcWAnoai 8bRMrXiroynEaWsg2zIil07GU/j11XJU2H+c3eMDxnte/7zuOFEFImYwEfthSBh2OqsI EIdROZlh53oowzYyiLkp9NjQyJ1dKsKtwRxrPBhYIJWj2vGCSUFjNnF7B4+rz4DY+tRN eW63EArkDS+XH2FXsCuRTULVZ/qjUW1+WpgX8oDygfIZlaRzedr0vnIF+T0QBvGanG4c khEPPe5fR5xC4hBq4FTjuXZ9K1CjZAn1CEV6BztVsRIDlCIFIyfX7MWVt4NlkCOAR65D W9+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XgT6VCuh; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-134396-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134396-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 ov1-20020a170906fc0100b00a46e9f5a524si2643454ejb.957.2024.04.07.06.11.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 06:11:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134396-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=@redhat.com header.s=mimecast20190719 header.b=XgT6VCuh; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-134396-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134396-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 EFB791F217B1 for ; Sun, 7 Apr 2024 13:11:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DEF0F376EC; Sun, 7 Apr 2024 13:10:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XgT6VCuh" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 482302BAE8 for ; Sun, 7 Apr 2024 13:10:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712495456; cv=none; b=GfoS/kFxsv14yKNqmtIVwR4fFt8rvy2IOOwAzl0yFKB6z/fM2akjyVYxPdUNT0wK8+vrqTn7aqoTw1pTHT6vJFyt965RJI7ZMnsnbxzufw5T1bLbX82DFc4+POzlmaNtxPQqtLhDTIsYYwFdtFnIIQKXBNBNq670xQzHOUdhitw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712495456; c=relaxed/simple; bh=9PXGMNAgOACqNin9bgdIyvcpskUTE+lFjxIcvvOoZeA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PCuIIePoByLcCgBkr6e/zK8bEVyAi3WRCuOrNlLSOowif+mZgnnkjwknvSyz4+Lnzee7vXuSGR4+GjqbYgHmblVYZaoxFQMvCONND7Fmj3N8Jc5IiZsVwJcMU/HBAUAXpkHz4PPVjDSWGAJcrFJp8FyqRP9Fo/Ifje/hF3NNrkQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XgT6VCuh; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712495453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a6vxxG5xgzXX9R/YtKyD3zzQDfQBIezrwLJQElkxb28=; b=XgT6VCuhMZ2oKkG81sb9IwUe33R5O9iwnDqJYCqNSZMri/aTA0qyRQOR++RQky/xR31bn1 nOpT4258yYm9S8MVIgMZYp15qTpvuO1fzY23MYymUrMkQJvO8GArfI/cNHjSMKNlAdpQZh 4wTdYHJjYbxAmjjEGjHDbqyz6Q+1I6U= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-288-n62oceUmPRWuQNZU-k7Xmw-1; Sun, 07 Apr 2024 09:10:48 -0400 X-MC-Unique: n62oceUmPRWuQNZU-k7Xmw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9CEA629AB3F7; Sun, 7 Apr 2024 13:10:47 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.79]) by smtp.corp.redhat.com (Postfix) with SMTP id BB260200B3C6; Sun, 7 Apr 2024 13:10:44 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sun, 7 Apr 2024 15:09:22 +0200 (CEST) Date: Sun, 7 Apr 2024 15:09:14 +0200 From: Oleg Nesterov To: Frederic Weisbecker Cc: Nick Piggin , Tejun Heo , Leonardo Bras , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Lai Jiangshan , linux-kernel@vger.kernel.org, Junyao Zhao , Chris von Recklinghausen Subject: Re: Nohz_full on boot CPU is broken (was: Re: [PATCH v2 1/1] wq: Avoid using isolated cpus' timers on queue_delayed_work) Message-ID: <20240407130914.GA10796@redhat.com> References: <20240130010046.2730139-2-leobras@redhat.com> <20240402105847.GA24832@redhat.com> <20240403203814.GD31764@redhat.com> <20240405140449.GB22839@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 On 04/05, Frederic Weisbecker wrote: > > +Cc Nick > > Le Fri, Apr 05, 2024 at 04:04:49PM +0200, Oleg Nesterov a ?crit : > > On 04/03, Oleg Nesterov wrote: > > > > > > > > OTOH, Documentation/timers/no_hz.rst says > > > > > > > > > > Therefore, the > > > > > boot CPU is prohibited from entering adaptive-ticks mode. Specifying a > > > > > "nohz_full=" mask that includes the boot CPU will result in a boot-time > > > > > error message, and the boot CPU will be removed from the mask. > > > > > > > > > > and this doesn't match the reality. > > > > > > > > Don't some archs allow the boot CPU to go down too tho? If so, this doesn't > > > > really solve the problem, right? > > > > > > I do not know. But I thought about this too. > > > > > > In the context of this discussion we do not care if the boot CPU goes down. > > > But we need at least one housekeeping CPU after cpu_down(). The comment in > > > cpu_down_maps_locked() says > > > > > > Also keep at least one housekeeping cpu onlined > > > > > > but it checks HK_TYPE_DOMAIN, and I do not know (and it is too late for me > > > to try to read the code ;) if housekeeping.cpumasks[HK_TYPE_TIMER] can get > > > empty or not. > > > > This nearly killed me, but I managed to convince myself we shouldn't worry > > about cpu_down(). > > > > HK_FLAG_TIMER implies HK_FLAG_TICK. > > > > HK_FLAG_TICK implies tick_nohz_full_setup() which sets > > tick_nohz_full_mask = non_housekeeping_mask. > > > > When tick_setup_device() is called on a housekeeping CPU it does > > > > else if (tick_do_timer_boot_cpu != -1 && > > !tick_nohz_full_cpu(cpu)) { > > tick_take_do_timer_from_boot(); > > tick_do_timer_boot_cpu = -1; > > > > > > and this sets tick_do_timer_cpu = first-housekeeping-cpu. > > > > cpu_down(tick_do_timer_cpu) will fail, tick_nohz_cpu_down() will nack it. > > > > So cpu_down() can't make housekeeping.cpumasks[HK_FLAG_TIMER] empty and I > > still think that the change below is the right approach. > > > > But probably WARN_ON() in housekeeping_any_cpu() makes sense anyway. > > > > What do you think? > > Good analysis on this nasty housekeeping VS tick code. I promised so many > times to cleanup this mess but things keep piling up. > > It is indeed possible for the boot CPU to be a nohz_full CPU and as > you can see, it's only half-working. This is so ever since: > > 08ae95f4fd3b (nohz_full: Allow the boot CPU to be nohz_full) Thanks... So this is intentional. I was confused by Therefore, the boot CPU is prohibited from entering adaptive-ticks mode. Specifying a "nohz_full=" mask that includes the boot CPU will result in a boot-time error message, and the boot CPU will be removed from the mask. from Documentation/timers/no_hz.rst > I would love > to revert that now but I don't know if anyone uses this and have it working > by chance somewhere... Should we continue to support a broken feature? Can we > break user ABI if it's already half-broken? Well, the changelog says nohz_full has been trialed at a large supercomputer site and found to significantly reduce jitter. In order to deploy it in production, they need CPU0 to be nohz_full so I guess this feature has users. But after the commit aae17ebb53cd3da ("workqueue: Avoid using isolated cpus' timers on queue_delayed_work") the kernel will crash at boot time if the boot CPU is nohz_full. So we need a workaround at least. I am starting to think I will send a trivial patch which changes __queue_delayed_work() to validate the cpu returned by housekeeping_any_cpu(HK_TYPE_TIMER). But perhaps something like below makes more sense as a (stupid) workaround? Oleg. --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -46,7 +46,15 @@ int housekeeping_any_cpu(enum hk_type type) if (cpu < nr_cpu_ids) return cpu; - return cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask); + cpu = cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask); + if (cpu < nr_cpu_ids) + return cpu; + + cpu = READ_ONCE(tick_do_timer_boot_cpu); + if (cpu >= 0) + return cpu; + + WARN_ON_ONCE(1); } } return smp_processor_id();