From patchwork Tue Jan 30 01:00:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras Soares Passos X-Patchwork-Id: 193762 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp925710dyb; Mon, 29 Jan 2024 17:01:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSB2ROgpwqcwcT80D9xHBDx97EPh57hH/H+/HwziWSs2tss11Hp5Iy2B00fJXssuaD75Z+ X-Received: by 2002:a05:6358:6f0e:b0:176:c391:3899 with SMTP id r14-20020a0563586f0e00b00176c3913899mr5792623rwn.11.1706576498619; Mon, 29 Jan 2024 17:01:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706576498; cv=pass; d=google.com; s=arc-20160816; b=bJONA9MPmBC2eaOytgTaL9748HmAiKq4ZrtstwWl1ylCpqAZNWxT0QMxKN7fU5bsFe kfw8QZm6H/DqH/1ZQe2DtC2FIMK0nHi0IgZXDb3Ef0f+TcINdoWN32oGorColf9IG6YX s2LIiC92i3eoSfE3gKZei7ju2tbTcukHQjb0D2rkcbnZCyoRNNMUwfkQ0Rj98XLVv56u /HRZeWdMJz2NRrdl+lyRtkK3m4ZgE7UKEy/V9EYDRo7B3qx/tDaIJ7D+BXi3NLWFUrkT a4M24IDKDpCk2f2LpwudSBiwYvmAJTaGgCV8QgNyPvbmnBaVi9yvX/5p7Z1jOkkJpVeg mUTw== 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=bDV0d2K1/adHDmTgUutNz6jKT+pZG4kv9THTh/fStTM=; fh=0cyWcoyIfEBtUTvryZt2nFJU1A7WekVMJYn+KBZLpcA=; b=rj8R5dmppkND6YWJGgWrTkU57xOtKbuTR7fTx+EZ59vzfnile3gsV6mPmy+5ZHd4Sr 4TGR9PEkmtxabz/OgYnVBwfat29zhh+An5x12yXgONmTPzoyfll6jiNyttpVwaDj0NKa emWP2zEaPLrtawIwvv+tAQnfF7Vzfi4gwsljihJuqdHY89nlCbZHkS6wnvYpH80VW6F2 jqoFoySNZlN+/p9Lx2c0aIr1xpuFi2AVdjU+ln6Cwt8zIYHDEESCLBSaNL4Ko2Tp+a6H kl1Nsi/OrRZqJ5lGDkky1UhbN8tn/a09zrVS7pS/mZm8fOOa9uRRTwuHJn3Wf0jdL9++ EBOw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Kx6ru7LU; 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-43703-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43703-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id a10-20020aa78e8a000000b006dde3ecae1bsi6542449pfr.292.2024.01.29.17.01.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 17:01:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-43703-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Kx6ru7LU; 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-43703-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43703-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D76F82844CE for ; Tue, 30 Jan 2024 01:01:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BAF16360AE; Tue, 30 Jan 2024 01:01:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Kx6ru7LU" 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 B77E12E403 for ; Tue, 30 Jan 2024 01:01:16 +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=1706576482; cv=none; b=pAgNX12W/kDiSsaRfdTSZSCVssWFjRA+sS1DpK5Aju4u2xh62FtCGRRXOC+YiEk7fA0YsfMFPbnv2Gow8pZ95XvGPqpE9sY5oByCsSbTbdNjNEJFZqfnv00a10yNf/vha8qhgn+u+1c+c47RiHBpFdN+42FFhrh4pDwBOuv5fBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706576482; c=relaxed/simple; bh=1LGEO7I1BqruecxFtj7rpE8e2oy/VyosnmAQNqB7h+U=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=OFjA1qGUZrvt1vrV2IbQvvka+NHQ5R3mRYVA8qqlLxlkAVC/5UTBQDQMNnyUtjnBI41/Dd1vlxVy53j1yBQExzXrL4yNG9cOx7yNRGZAOjnsmn8rOKUaM8LmWmLtYxkE+cGRdTJPP8LERMPO0EE0/ordmj50gpmzAGIchzjhvvE= 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=Kx6ru7LU; 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=1706576475; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=bDV0d2K1/adHDmTgUutNz6jKT+pZG4kv9THTh/fStTM=; b=Kx6ru7LUk2PFUHm53qbaG/hjM9uzv8TkPyiGsGTSw8xORw694ingSQwf4nawaXvpsM9FOn 5ItngeBINrMq97AJe78uY0Wa4fkSgqv0kWaNkroIu5+sf9iGqd8pxLsfrlaqUtJNgc+lwk NElUA220mGRrKetx8reLsfeUHKOLqnQ= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-534-RmblI2dLMKyOF7ec2BlkCA-1; Mon, 29 Jan 2024 20:01:13 -0500 X-MC-Unique: RmblI2dLMKyOF7ec2BlkCA-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-783fb71911bso289925885a.2 for ; Mon, 29 Jan 2024 17:01:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706576473; x=1707181273; 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=bDV0d2K1/adHDmTgUutNz6jKT+pZG4kv9THTh/fStTM=; b=Sny2613CTSA3LRWiAANu+mqnGI5QHt6QtSohgWVhRk5USLU5ylIm2R6KVzcNyRvIv9 1JiBbxV/XFGqWVB3y4yIdjX1TEiglLwR6qUblYD5iCTXoXoVleKe7ifLK6WwVs6wZHCX aIZA08J9wjLqYKMgRKVp44F5VNFMnjN7YbGQ3OugWbzxYt1cvYSeOxUmTSDRfNeHV83/ 3BishQQoWtpqpsCCo8sAObY+AHqDXnxM18om5kPP36LqYM3bpxFucL4zgvUdxGdOp4lX PXk6NUJksdEeIoeVF0DCkaZg4R9AIle2YQ7q8MGEC3GsdbDXH24VZIqiFI8fw5miUlFT 290g== X-Gm-Message-State: AOJu0YxNiJcqHmpiVBWj+6PnSCNC8gfrAIAEvDipQTGEIyLjGYNOdfx+ 8sOVJibcJ4I961+H2GIGcpGy2rdWUTdQiaD0+xq9M6vPZzvS/Wbnf7ololWLBAsmnx7leXEcEzY TuZLwMYRWMxTnekuBnbBEyzDgmY5y7A+6X1E49/7K2ZyGOE5ozYx+SwyrRZpjGg== X-Received: by 2002:ad4:5b87:0:b0:68c:5573:2280 with SMTP id 7-20020ad45b87000000b0068c55732280mr1931014qvp.127.1706576473121; Mon, 29 Jan 2024 17:01:13 -0800 (PST) X-Received: by 2002:ad4:5b87:0:b0:68c:5573:2280 with SMTP id 7-20020ad45b87000000b0068c55732280mr1931003qvp.127.1706576472903; Mon, 29 Jan 2024 17:01:12 -0800 (PST) Received: from LeoBras.redhat.com ([2804:1b3:a803:e70d:8905:313f:9514:fada]) by smtp.gmail.com with ESMTPSA id mb6-20020a056214550600b0068c5e3d86bdsm205718qvb.48.2024.01.29.17.01.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 17:01:12 -0800 (PST) From: Leonardo Bras To: Tejun Heo , Lai Jiangshan Cc: Leonardo Bras , linux-kernel@vger.kernel.org, Junyao Zhao Subject: [PATCH v2 1/1] wq: Avoid using isolated cpus' timers on queue_delayed_work Date: Mon, 29 Jan 2024 22:00:46 -0300 Message-ID: <20240130010046.2730139-2-leobras@redhat.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789475158163244541 X-GMAIL-MSGID: 1789475158163244541 When __queue_delayed_work() is called, it chooses a cpu for handling the timer interrupt. As of today, it will pick either the cpu passed as parameter or the last cpu used for this. This is not good if a system does use CPU isolation, because it can take away some valuable cpu time to: 1 - deal with the timer interrupt, 2 - schedule-out the desired task, 3 - queue work on a random workqueue, and 4 - schedule the desired task back to the cpu. So to fix this, during __queue_delayed_work(), if cpu isolation is in place, pick a random non-isolated cpu to handle the timer interrupt. As an optimization, if the current cpu is not isolated, use it instead of looking for another candidate. Signed-off-by: Leonardo Bras --- Changes since v1: - Make sure the CPU is isolated for any value of "cpu" Changes since RFC: - Do not use the same cpu from the timer for queueing the work. - If the current cpu is not isolated, use it's timer instead of looking for another candidate. kernel/workqueue.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 76e60faed8923..8dd7c01b326a4 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1958,10 +1958,18 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq, dwork->cpu = cpu; timer->expires = jiffies + delay; - if (unlikely(cpu != WORK_CPU_UNBOUND)) + if (housekeeping_enabled(HK_TYPE_TIMER)) { + /* If the current cpu is a housekeeping cpu, use it. */ + cpu = smp_processor_id(); + if (!housekeeping_test_cpu(cpu, HK_TYPE_TIMER)) + cpu = housekeeping_any_cpu(HK_TYPE_TIMER); add_timer_on(timer, cpu); - else - add_timer(timer); + } else { + if (likely(cpu == WORK_CPU_UNBOUND)) + add_timer(timer); + else + add_timer_on(timer, cpu); + } } /**