Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1762030ybh; Tue, 14 Jul 2020 06:45:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4zXAWIUXCOhOKkCObkYwOxMBglWeK4cEIGnWkhjw1opAs0C/Wl/76RjwzzrnAKinS7trD X-Received: by 2002:a17:906:a84d:: with SMTP id dx13mr4355229ejb.246.1594734316088; Tue, 14 Jul 2020 06:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594734316; cv=none; d=google.com; s=arc-20160816; b=TRu03CQxooIh6RrDIxsVD/vPHtKpPuiPU/GqEcpzQ7DrmELnCNqDapKqbTU0VbjquR 1ky+BcIR3CzOm9r/ZFCDAIZbQGXdYQG81dILbQZogXnI/hrPBwS0TNXheErYZ0/R+WE1 2hYIL2gi+FKqrd4rPoen6ULpSZqDBUcxFNGdnKxcQv0VQXveXPSBXBrnLD1EIoeu1G1w R3GG9BS40hYfgxkKynGJbAlg1HDG9MDWR9qTNA98mwdKLoo/dAdTH5pYIdpVmpLUjozB 4SG/4V5r4LIlhuH/4MtMW3kuNmVm1Zi/iejTH8bVX8hZkA53yuESiOy54NIbEBZyoI2n Ci9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from :dkim-signature:dkim-signature:date; bh=tUdCMtCp1Gj3QLfmNOfgEwGCdQpToQuLKLSiq+Be9z0=; b=TqQ67yFEJv6ixzUIgBqYhPp+LQ4ELNZR2fHsID3YffV8/OOhH9vgP7i40D0jQXcR+j dlBNYyNctWlbVCQclP0RkHo2tIrucWChIs+N5lsFKkDjkaoCuxVsD8GmlLqJWp4P1EO5 U4UPu0bnPz07r1XR6QXYZBvyqqASSFm0QSC/zvnBbI5KMo5RD6piFg4SD2bI7hXjhIWY 6xKtrvKHLWlgeu7mTykQsmQwDArpxJAafVRmieuLpSqTshIWiwretyvmAba7ROq02m5C H7ndIY79RouN7TjSYB+bLxULnniY5+Vz1cnV9b/Ug+gYM2g/8A2Hb9v6nEbvgx+SwHzQ iuxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=evFcMbPv; dkim=neutral (no key) header.i=@vger.kernel.org; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g8si10854983ejs.512.2020.07.14.06.44.50; Tue, 14 Jul 2020 06:45:16 -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=@linutronix.de header.s=2020 header.b=evFcMbPv; dkim=neutral (no key) header.i=@vger.kernel.org; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726793AbgGNNoP (ORCPT + 99 others); Tue, 14 Jul 2020 09:44:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725981AbgGNNoO (ORCPT ); Tue, 14 Jul 2020 09:44:14 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74CC5C061755; Tue, 14 Jul 2020 06:44:14 -0700 (PDT) Date: Tue, 14 Jul 2020 15:44:10 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1594734252; 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: in-reply-to:in-reply-to:references:references; bh=tUdCMtCp1Gj3QLfmNOfgEwGCdQpToQuLKLSiq+Be9z0=; b=evFcMbPvdfhG2mR+vp7Rf2lOWv3E2tWYqPH7GibmsRf68V8QGi5qE+toNq3obNDbY4DTCQ tlijGD47H6v1a8CzwV4gE7bovFyu2fJZ2qVoPAouZOawUalMy5B/Chi1vvI6e0ywJFaBHl aPbD+oDWuGq9ftrgZ4YLJZfmZi1rrYkYevzK53pJsbvO1g8jpIGge+hEqNyDqenDvAOgwg 3xkdXfrrtAr37SYzttkmcQoBf4/XbrnvF0bPbZAXrwlsIrS9QMmn8VgYm+golg3iPZBt+A Qzzv6DMSjrH7BO91TEON+SmZysR1SjWHSd699TUnuRpFsx1uhP29G3FliTiXfg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1594734252; 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: in-reply-to:in-reply-to:references:references; bh=tUdCMtCp1Gj3QLfmNOfgEwGCdQpToQuLKLSiq+Be9z0=; b=n49Wsx7DyIEJ8wLPjvnuyiy4ej330Y3xqfY/rkav27T70w6CDVTkJdFL8CKjrE1juqKjQh H7zTNtiSoTvPceDg== From: Sebastian Andrzej Siewior To: Zhang Rui , Robert Moore , Erik Kaneda , "Rafael J. Wysocki" , Len Brown Cc: Thomas Gleixner , Peter Zijlstra , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Stephen Berman , devel@acpica.org Subject: Re: power-off delay/hang due to commit 6d25be57 (mainline) Message-ID: <20200714134410.3odqfvjq6rndjjf6@linutronix.de> References: <20200615145130.bcdidqkp6w23xb6c@linutronix.de> <87tuzbh482.fsf@gmx.net> <20200616073827.vysntufld3ves666@linutronix.de> <87o8pjh1i0.fsf@gmx.net> <20200616155501.psduxnisltitodme@linutronix.de> <871rmesqkk.fsf@gmx.net> <20200617142734.mxwfoblufmo6li5e@linutronix.de> <87ftatqu07.fsf@gmx.net> <20200624201156.xu6hel3drnhno6c3@linutronix.de> <87ftak2kxr.fsf@rub.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <87ftak2kxr.fsf@rub.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-06-24 23:49:52 [+0200], Stephen Berman wrote: Let me summarize the thread here: On Stephen's system, ACPI informs the thermal zone driver to poll the temperature every second and the driver does so. The driver queries the temperature by invoking acpi_evaluate_integer() which invokes (at some point) acpi_ev_queue_notify_request(). This then invokes acpi_os_execute_deferred() via queue_work_on(, kacpi_notify_wq, ) acpi_os_execute_deferred() invokes acpi_ev_notify_dispatch() and this is no longer synchronised with the initial acpi_evaluate_integer() request. Before commit 6d25be5782e48 ("sched/core, workqueues: Distangle worker accounting from rq lock") that function took on average 1.023993 seconds to complete. The interval when the thermal driver invokes acpi_evaluate_integer() isn't exactly 1 second but almost (it is not an absolute timer so). Still it looks that one function slowly overtakes the other. After 5 Minutes uptime there is: | kworker/0:1-12 [000] 312.315565: acpi_ev_queue_notify_request: Dispatching Notify on [TZ10] (Thermal) Value 0x81 (Information Change) Node ffff9935ab20f7a8 | kworker/0:1-12 [000] 312.315567: acpi_os_execute: Adding acpi_ev_notify_dispatch+0x0/0x5a ffff9935a6c64050 Enqueue worker with job ffff9935a7eb5e00 | kworker/0:1-12 [000] 312.315596: acpi_os_execute_deferred_notify: End ffff9935a7eb5c80 acpi_ev_notify_dispatch+0x0/0x5a(ffff9935a6c64c80) | kworker/0:1-12 [000] 312.315607: acpi_os_execute_deferred_notify: Start ffff9935a7eb5d80 acpi_ev_notify_dispatch+0x0/0x5a(ffff9935a6c64dc0) previous worker completed, another (already enqueued) started. | kworker/0:1-12 [000] 313.339564: acpi_ev_queue_notify_request: Dispatching Notify on [TZ10] (Thermal) Value 0x81 (Information Change) Node ffff9935ab20f7a8 | kworker/0:1-12 [000] 313.339566: acpi_os_execute: Adding acpi_ev_notify_dispatch+0x0/0x5a ffff9935a6c64f00 another one enqueued. | kworker/0:1-12 [000] 313.339595: acpi_os_execute_deferred_notify: End ffff9935a7eb5d80 acpi_ev_notify_dispatch+0x0/0x5a(ffff9935a6c64dc0) | kworker/0:1-12 [000] 313.339597: acpi_os_execute_deferred_notify: Start ffff9935a7eb5e00 acpi_ev_notify_dispatch+0x0/0x5a(ffff9935a6c64050) finally, job ffff9935a7eb5e00 started (one second after enqueue). | kworker/0:1-12 [000] 314.363571: acpi_ev_queue_notify_request: Dispatching Notify on [TZ10] (Thermal) Value 0x81 (Information Change) Node ffff9935ab20f7a8 | kworker/0:1-12 [000] 314.363574: acpi_os_execute: Adding acpi_ev_notify_dispatch+0x0/0x5a ffff9935a6c646e0 | kworker/0:1-12 [000] 314.363608: acpi_os_execute_deferred_notify: End ffff9935a7eb5e00 acpi_ev_notify_dispatch+0x0/0x5a(ffff9935a6c64050) and ended, two seconds after enqueue. Before it ended, the system enqueued two more jobs. And this just within 5 Minutes of uptime. The worker pile slowly up. According to Stephen, after previously mentioned commit the situation gets worse. According to tracing the execution time of acpi_ev_notify_dispatch() varies between 1.023990 (like before) and 2.048005 seconds. While I don't have an explanation for the changed behaviour (or see anything wrong the commit in question), the pile up of worker increased. Stephen noticed this because system shutdown flushes kacpi_notify_wq and this takes quite some time (with that amount of worker pending). I tried a few test cases to reproduce that behaviour but failed. However, even before that commit in question the situation is far from perfect: - There is the lack of synchronisation between thermal driver's requests and its tail (that acpi_ev_notify_dispatch() part). - Do we have to respect ACPI interval of one seconds. Is the hardware really so accurate that it can change noticeable in one second. - The requests are already back to back which keeps the CPU busy (maybe sched-switch will reveal that the CPU is idle most of the time). So... Is there a simple way to synchronize the ACPI part? The obvious thing would be flush_workqueue(kacpi_notify_wq); or acpi_os_wait_events_complete() in thermal_get_temp(). Would it make sense to ensure that the polling interval is no less than 10 seconds? > Steve Berman Sebastian