Received: by 10.213.65.68 with SMTP id h4csp458321imn; Fri, 23 Mar 2018 08:13:28 -0700 (PDT) X-Google-Smtp-Source: AG47ELsk1cxHFozKbRk7cKIS+5vyl00ANGEUIHlSYYGCDiNxzJr1RHMMLAdguCrTliYwjAv1j62Y X-Received: by 10.98.162.26 with SMTP id m26mr24311694pff.217.1521818008033; Fri, 23 Mar 2018 08:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521818008; cv=none; d=google.com; s=arc-20160816; b=UPNTeKJ8pTYvsrYsifRYHurOj3MqqA1DGCiVOTgLy06+yhYnDs6Mlc1FrTqYfulr4Y hHTqrIrNcCEMn4QrpFsVPHXgzJGIHAQ3D5bYE1ic2yE8MAaDy8SHJuYq4dlLfjXxgdqC SzRnp5+Q/Jyy3CNGs9KKT/Lh2WrnmbUtwkqOcxMXkVyh12WGYgPJA2TD5oXa5WQoHn3a RF61G59pvF8re4LJ6uSQQ6ZsGVWvJPrqvVmusPz/qlREpJVW6bOlA9lKBI9wK7Zn+XDr lgkeX1a+d5I0/LMfR0FmxSgF/H3eFKpwM5E84+bslx6G4bzmFsPcWOcgXtNXnLpE733g AMNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:user-agent:content-disposition:mime-version :reply-to:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=nahReU4Jdsz0bSrIydCDRhgjAQsuvGn8I8FzWTu0w9o=; b=iE24RmEmDx05yUBYom5n2cwYKa+QXLrXa2hmMP4GdTBzPQY1zyB/nWmmZUf0Ced4Gv UuyXAdBuwXW+4cIFziO84do1+yqFFb3gRPO7wDEbnrMqt3taOeR1wOU0rk+Jn+dkPdhO nlZtQtQ2JmZAjpQ4Y9pVaHcC6Km+MVMvrwiLU2AhL0Vc0VG0gU87OrLJQAMDg01Xi85y E8BPJVs2AvsIMTe7w8jyO5Ftpa2AeunX/3GeDoSnquRMza++h43NGyyn/vpY8nXo7rex 9noiSFX9W/KLMfGkby/tdVjqVfD9UdQdDVAIuFxrzKt6NNOxzsHKa4UKj5u+ZtD8r38Q j9ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@concurrentrt.onmicrosoft.com header.s=selector1-concurrentrt-com02e header.b=lKkfS7Bt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si6299775pgq.11.2018.03.23.08.12.58; Fri, 23 Mar 2018 08:13:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@concurrentrt.onmicrosoft.com header.s=selector1-concurrentrt-com02e header.b=lKkfS7Bt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752014AbeCWPKJ (ORCPT + 99 others); Fri, 23 Mar 2018 11:10:09 -0400 Received: from mail-sn1nam02on0093.outbound.protection.outlook.com ([104.47.36.93]:44696 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751825AbeCWPKG (ORCPT ); Fri, 23 Mar 2018 11:10:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=concurrentrt.onmicrosoft.com; s=selector1-concurrentrt-com02e; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=nahReU4Jdsz0bSrIydCDRhgjAQsuvGn8I8FzWTu0w9o=; b=lKkfS7BtyZLAG6mGXDK3XjUkrmF/q9S9QsnxV1/HZmfJM4JM92RM1/0bKSp3LdxGvuwBxOV8nRXXNUxfOrsGMapLnvN5uFgrQKrNtc1xbk8JEHxoIJlF0Kwk2ADuAugOH17MWCE0VjD2rPG0fhhbgpRqSovmJsD1wjBjz5l15V4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Joe.Korty@concurrent-rt.com; Received: from zipoli.concurrent-rt.com (12.220.59.2) by DM6PR11MB2571.namprd11.prod.outlook.com (2603:10b6:5:c6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.567.14; Fri, 23 Mar 2018 15:10:03 +0000 Date: Fri, 23 Mar 2018 11:09:59 -0400 From: joe.korty@concurrent-rt.com To: bigeasy@linutronix.de Cc: mingo@redhat.com, tglx@linutronix.de, rostedt@goodmis.org, linux-rt-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RT] Defer migrate_enable migration while task state != TASK_RUNNING Message-ID: <20180323150959.GA16131@zipoli.concurrent-rt.com> Reply-To: "Joe Korty" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.8.3 (2017-05-23) X-Originating-IP: [12.220.59.2] X-ClientProxiedBy: BN6PR11CA0002.namprd11.prod.outlook.com (2603:10b6:405:2::12) To DM6PR11MB2571.namprd11.prod.outlook.com (2603:10b6:5:c6::13) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9a4325c7-aab4-421e-4efd-08d590d027c7 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:DM6PR11MB2571; X-Microsoft-Exchange-Diagnostics: 1;DM6PR11MB2571;3:bbxzUqdJiDal6JMt6f80EVrj+qI7ETnGD7qd5JRK6IITTSs3YO7aVY9C5Shhmn8gZbCxqWMln5Td+SbgJczUL/pf2B9ju0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yikd52IaNmSTLaMJ+GHV71OJOsqEVtmHuvfNETk85sP6hR7uWL0D3D66k+VSvgkmEg==;4:mjvEWI4e5ePaH9y/Ock2ibq2Vls1OXRpCSzqDo0AmDEEaN+SoVRMtribKPFR0zAgVOFxmF1XapxPv2Qv7mKh1Cbrjr7+UlGeNoe+oPwU3LAFsVJVvX9Sztk7mbJ/loyXOBrPy6q5uOkVDZq5IP3Vfr/PcAWVxmw9mgWcb0svFHnWvLVfsFZTH8DlSLC9IUAG5OwLdKIql9v8Knv0i+a6RWXegZo5xD96slYHxD4qTmd1iQ2uuO1XSW2riHqP5tDLm2HIIt0wXEHD/8ziD0YT4A== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(3231221)(944501327)(52105095)(3002001)(10201501046)(93006095)(93001095)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011);SRVR:DM6PR11MB2571;BCL:0;PCL:0;RULEID:;SRVR:DM6PR11MB2571; X-Forefront-PRVS: 0620CADDF3 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(39840400004)(396003)(39380400002)(376002)(366004)(346002)(199004)(189003)(86362001)(72206003)(4326008)(26005)(55016002)(9686003)(3846002)(6116002)(23726003)(69596002)(8676002)(2361001)(81166006)(186003)(33656002)(81156014)(25786009)(2351001)(316002)(97736004)(16526019)(106356001)(8936002)(6666003)(6916009)(66066001)(105586002)(68736007)(47776003)(386003)(53936002)(58126008)(85782001)(1076002)(5660300001)(59450400001)(7696005)(7736002)(16586007)(50466002)(43066004)(305945005)(2906002)(478600001)(52116002)(53416004)(18370500001)(85772001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM6PR11MB2571;H:zipoli.concurrent-rt.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; Received-SPF: None (protection.outlook.com: concurrent-rt.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM6PR11MB2571;23:HhVEdKfDMNtfZOv+IlD7mcDx+kvrRGlhHM82kY06v?= =?us-ascii?Q?ar0r78wixwL+DdDWHgwITDfq06LvqSa1tJ01Xo/lOw7kh6SLBx5SOP16/rg3?= =?us-ascii?Q?/AGXaAXr1mCw3AWFw5fcDuroyh8uyqJfThOf+1ltF0gQeJsBM1K6ITU42tea?= =?us-ascii?Q?P133L5PQihIXsPAcOzyZ897GGBgEoNakNbbUbyKVOM3AohYbJfFa5S4PRt+A?= =?us-ascii?Q?4YHcwuhuFB5+REzHK3M/bPUe2c/SQAq42QAvsNST3fm2RcXCbKZs1JzPkr6w?= =?us-ascii?Q?Nz8XOET9Madf0CFX6rwsRQrHR0bEPnPSZqi+AK4qbXeMBqFuIlwWelus517b?= =?us-ascii?Q?lAkszwzMkX448Y3ZD3KNI1E3f+y7ykYPp9fQ5fNmx5qzvD85W5jr0yRuDQGJ?= =?us-ascii?Q?/LWmTnmcvKb3ZINWSkkJUwfWyBwo5C2H5a0k/3v9+NBbfuU253IYPU3GVgt4?= =?us-ascii?Q?g0tmdOSZRx+IDV5jiaF6Nry3iO/lCzXcAirT5k69GLbeFiY5AqZkoATdCUCf?= =?us-ascii?Q?TVDFwDjgWhau2pZ9SCTjMH3XQZPnDZyWPKgEonKpcCxOrde1CRsV5yb382XT?= =?us-ascii?Q?wiL6R8UfBLFgdn2yJbfM3VuT7CyiG4h+4a2RKePnAva06eoSZxwgdi6fhI//?= =?us-ascii?Q?j14ddbKTuLq8hiUz5PwT0cnig7ZjTbB0Pog2OalXuRpj5q4jb8nizHKsFQpp?= =?us-ascii?Q?fHawkb8072R6XCCdd27Ll6z6VSp+jS7l1Ea6Y3ampOvpx07O5SH4ST1kC5w7?= =?us-ascii?Q?NjiqYVvnGA8NEKZH/ylkYw7GhALfd8yuWPXVYbC/CRTtLRX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DJWb0vdWdP0HYTG0XdKaC52voLZw74LVIAehFYmL7okRHdRW51hO2MO8J/jC29PURKwFr5TT4hUNffWp1rOKrALFy88VFC0uAEdP8KrIYV9IRgsigCQQbVhNUJthI=;5:yD3vAW6PIyn9XBMfLY+bPuYfJaHCJkBc7eetxemrwEhEU9RTAbnoFtG33PV8eXytJxhCBTSlBCPpsTb++7bXO8mZHdwcXIy5gktNsploVgTSCxhfAIt44+BW8C6LCnAinA+ytbqQHpzKZzE/yhxB6Ve8ZLKZhPhkokFqVMJ40Vs=;24:L9PWgat5OHCJWDImdQUbPElZobKUxX5a37VI+hZAUXYS17El/nTkn/+iokrHUuUFixUlSWScEfv2XLdxmvY6O57F2LcefG+ZZelBO9ryWhE=;7:ZD7MqN4uSX4h8jlJvAzlP1MgkDJpyfr3oWPRxETpZTsQiwqh+iY3nRRR4vZdNZLgmRpUavAl/R1FJEJoMcRz+tnTY94z43sFXBWt4LDq9t1xhplZkIkTtjgXLZmofLTIggZHRpiez7MHFb8HK5YwkRWH3oy5sji8imytlULzSp7Gktlvbe/kd8KmNQ47HndfKzlfRQkWsvKkWQBL4DjrRiwxezW7hxeKCUPrpT4a81TfOYIPLgVdx8w/XuiD3aCQ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: concurrent-rt.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2018 15:10:03.1982 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9a4325c7-aab4-421e-4efd-08d590d027c7 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 38747689-e6b0-4933-86c0-1116ee3ef93e X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB2571 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I see the below kernel splat in 4.9-rt when I run a test program that continually changes the affinity of some set of running pids: do not call blocking ops when !TASK_RUNNING; state=2 set at ... ... stop_one_cpu+0x60/0x80 migrate_enable+0x21f/0x3e0 rt_spin_unlock+0x2f/0x40 prepare_to_wait+0x5c/0x80 ... The reason is that spin_unlock, write_unlock, and read_unlock call migrate_enable, and since 4.4-rt, migrate_enable will sleep if it discovers that a migration is in order. But sleeping in the unlock services is not expected by most kernel developers, and where that counts most is in code sequences like the following: set_current_state(TASK_UNINTERRUPIBLE); spin_unlock(&s); schedule(); Rather than try to fix up such expectations, this patch merely restores the non-sleeping nature of unlocking by the simple expediate of deferring, to a future migrate_enable, and actual migration-with-sleep operation, for as long as migrate_enable sees task state != TASK_RUNNING. This works well as the kernel is littered with lock/unlock sequences, so if the current unlock cannot migrate, another unlock will come along shortly and it will do the deferred migration for us. With this patch and a debug harness applied to 4.9.84-rt62, I get the following results when a set of stress(1) threads have their affinities randomly changes as fast as possible: [ 111.331805] 6229(stress): migrate_enable() deferred. [ 111.332112] 6229(stress): migrate_enable() deferral APPLIED. [ 111.977399] 6231(stress): migrate_enable() deferred. [ 111.977833] 6231(stress): migrate_enable() deferral APPLIED. [ 135.240704] 6231(stress): migrate_enable() deferred. [ 135.241164] 6231(stress): migrate_enable() deferral APPLIED. [ 139.734616] 6229(stress): migrate_enable() deferred. [ 139.736553] 6229(stress): migrate_enable() deferral APPLIED. [ 156.441660] 6229(stress): migrate_enable() deferred. [ 156.441709] 6229(stress): migrate_enable() deferral APPLIED. [ 163.600191] 6231(stress): migrate_enable() deferred. [ 163.600561] 6231(stress): migrate_enable() deferral APPLIED. [ 181.593035] 6231(stress): migrate_enable() deferred. [ 181.593136] 6231(stress): migrate_enable() deferral APPLIED. [ 198.376387] 6229(stress): migrate_enable() deferred. [ 198.376591] 6229(stress): migrate_enable() deferral APPLIED. [ 202.355940] 6231(stress): migrate_enable() deferred. [ 202.356939] 6231(stress): migrate_enable() deferral APPLIED. [ 203.773164] 6229(stress): migrate_enable() deferred. [ 203.773243] 6229(stress): migrate_enable() deferral APPLIED. ... The test sequence used: stress --cpu 8 --io 1 --vm 2 & ./rotate $(ps -eLotid,comm | fgrep stress | awk '{print $1}') The test program used: cat <rotate.c /* * rotate.c * Randomly and rapidly change the affinity of some set of processes. * Does not return. * Limitations: Hard coded to use cpus 0-7. May not work on systems * with more than 64 cpus. * * Usage: rotate pid pid ... * * Algorithm: In a loop, for each pid given, randomly select 2 of * the 8 cpus 37.5% of the time; otherwise, randomly select a * single cpu from that same set. */ #define _GNU_SOURCE #include #include #include #include #include int pids[100000]; int npids; int ncpus = 8; int main(int argc, char **argv) { int pid, cpu, status; unsigned long mask = 0; int i; setbuf(stdout, NULL); argc--,argv++; npids = argc; for(i=0; imigrate_enable_deferred) { 18 XXXXXXXX+ p->migrate_enable_deferred = 0; 19 XXXXXXXX+ pr_info("%d(%s): migrate_enable() deferral APPLIED.\n", 20 XXXXXXXX+ p->pid, p->comm); 21 XXXXXXXX+ } 22 XXXXXXXX+ 23 XXXXXXXX rq = task_rq_lock(p, &rf); 24 XXXXXXXX update_rq_clock(rq); 25 XXXXXXXX 26 XXXXXXXX@@ -3499,6 +3505,15 @@ void migrate_enable(void) 27 XXXXXXXX tlb_migrate_finish(p->mm); 28 XXXXXXXX return; 29 XXXXXXXX } 30 XXXXXXXX+ } else if (p->migrate_disable_update && p->state != TASK_RUNNING) { 31 XXXXXXXX+ if (p->migrate_enable_deferred) 32 XXXXXXXX+ pr_info("%d(%s): migrate_enable() deferred (again).\n", 33 XXXXXXXX+ p->pid, p->comm); 34 XXXXXXXX+ else { 35 XXXXXXXX+ pr_info("%d(%s): migrate_enable() deferred.\n", 36 XXXXXXXX+ p->pid, p->comm); 37 XXXXXXXX+ p->migrate_enable_deferred = 1; 38 XXXXXXXX+ } 39 XXXXXXXX } 40 XXXXXXXX 41 XXXXXXXX unpin_current_cpu(); EOF The rt patch sched-migrate-disable-handle-updated-task-mask-mg-di.patch appears to have introduced this issue, around the 4.4-rt timeframe. Signed-off-by: Joe Korty Index: b/kernel/sched/core.c =================================================================== --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3457,7 +3457,14 @@ void migrate_enable(void) */ p->migrate_disable = 0; - if (p->migrate_disable_update) { + /* + * Do not apply affinity update on this migrate_enable if task + * is preparing to go to sleep for some other reason (eg, task + * state == TASK_INTERRUPTIBLE). Instead defer update to a + * future migate_enable that is called when task state is again + * == TASK_RUNNING. + */ + if (p->migrate_disable_update && p->state == TASK_RUNNING) { struct rq *rq; struct rq_flags rf;