Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4958082ybb; Tue, 24 Mar 2020 08:22:27 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuFO+65u7oC2T3qYbM94QlwOB1QMdS5q0+nZUowMIip6akT0xyO1eaFBB8czQLb+So1vLQs X-Received: by 2002:aca:c78d:: with SMTP id x135mr3610695oif.51.1585063347000; Tue, 24 Mar 2020 08:22:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585063346; cv=none; d=google.com; s=arc-20160816; b=tfxVIklj5iCj+ieJdb+uJOcdNoGzcZwGPL22thtOsw31ELubk9hXUPAxHmdlYRuZ+O 1Fw1/C1xLhGroHADabfXw6dRgmwdfAn+eV9uIAbz5C89QpJelfWdPwdpC00VsOnJ9fXU jxjzfzAGQjtBDKF24GGfnLzJfu1RhvBXjctuYjkB90CL3CZFRW4TK5GlUOA/cM0KGPO8 X8kVJxJkvTdAKbIqIRF/VBQcfI69/mGomH36eHc8cMtMAwrdDocp6tgIMj4LbFPKNj8n tpwBT23nuK0yfUwrfteP7wZd00Zv95hkBNDuRnotLL6moC1CiXu1OA2Q+nUyvc3uJMhr hYsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=BPqV8YQEnUqCh5JitavMy788HT8uf23i2uO5Wlz2Xqs=; b=cqIYc9nW5jSKDRkAUYWGS1vcRtGRzkXbtwRBoWBf1aRKOBcinHVR3UCrsjz1mp7HWG xARfdnvcO8byuI8JBFuufjIrm77r58OMVApyM5t+hnIPmw0EbW9gKkuwuTr5ha+qcoXq L5qTOl0Sfq5m3J0IGtUZuJiCijLk6JAZ5vRdIf2y93+L2FGhMs6obxWADl9C410dWrM3 jffiqGkJyPwRRl1SYNQTWpfjhLteDdgIo+bduZIZr5fAGgpw+vwqiTnyogSvCxAzx189 WE28Dh0mLeZbh2VzyrvQQ1gEMth91zIkCkJs7OzXI1Q+Qkc209CWbK6Bq+NEA+wyEejr yQlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P122EjaD; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3si6141551otr.93.2020.03.24.08.22.13; Tue, 24 Mar 2020 08:22:26 -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=@redhat.com header.s=mimecast20190719 header.b=P122EjaD; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728338AbgCXPUv (ORCPT + 99 others); Tue, 24 Mar 2020 11:20:51 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:45369 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727547AbgCXPUu (ORCPT ); Tue, 24 Mar 2020 11:20:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585063249; 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=BPqV8YQEnUqCh5JitavMy788HT8uf23i2uO5Wlz2Xqs=; b=P122EjaDfTK2gy0heAIRn0SFv4TTx9veIjwLBsuC+C9isGrAezy8jE9L3bUDn520x83GcB hHovkr4Oe6HVcNLxaXw4gAEK/r4boHAq3S9QOMRmLl096RFaaPmtdZghkF/nrqjksNHnr/ SRSmCu6USy38IErZqxnNdngWEXJX7rE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-416-SHSxYeuyMk2ejESIAuIkig-1; Tue, 24 Mar 2020 11:20:43 -0400 X-MC-Unique: SHSxYeuyMk2ejESIAuIkig-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 523F51005516; Tue, 24 Mar 2020 15:20:42 +0000 (UTC) Received: from fuller.cnet (ovpn-116-9.gru2.redhat.com [10.97.116.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 113F294B4B; Tue, 24 Mar 2020 15:20:42 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id 2CEB64198B39; Tue, 24 Mar 2020 12:07:07 -0300 (-03) Date: Tue, 24 Mar 2020 12:07:07 -0300 From: Marcelo Tosatti To: Chris Friesen Cc: linux-kernel@vger.kernel.org, Christoph Lameter , Vu Tran , Jim Somerville , Andrew Morton Subject: Re: [PATCH] affine kernel threads to specified cpumask Message-ID: <20200324150707.GB24352@fuller.cnet> References: <20200323135414.GA28634@fuller.cnet> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Chris, On Mon, Mar 23, 2020 at 09:29:23AM -0600, Chris Friesen wrote: > On 3/23/2020 7:54 AM, Marcelo Tosatti wrote: > > > > This is a kernel enhancement to configure the cpu affinity of kernel > > threads via kernel boot option kthread_cpus=. > > > > With kthread_cpus specified, the cpumask is immediately applied upon > > thread launch. This does not affect kernel threads that specify cpu > > and node. > > > > This allows CPU isolation (that is not allowing certain threads > > to execute on certain CPUs) without using the isolcpus= parameter, > > making it possible to enable load balancing on such CPUs > > during runtime. > > > > Note-1: this is based off on MontaVista's patch at > > https://github.com/starlingx-staging/stx-integ/blob/master/kernel/kernel-std/centos/patches/affine-compute-kernel-threads.patch > > It's Wind River, not MontaVista. :) Doh. > > Difference being that this patch is limited to modifying > > kernel thread cpumask: Behaviour of other threads can > > be controlled via cgroups or sched_setaffinity. > > What cgroup would the usermode helpers called by the kernel end up in? > Same as init? > > Assuming that's covered, I'm good with this patch. > > * Runs a user-space application. The application is started * asynchronously if wait is not set, and runs as a child of system workqueues. * (ie. it runs with full root capabilities and optimized affinity). */ int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait) { ... queue_work(system_unbound_wq, &sub_info->work); And unbound workqueue workers cpumask are controllable: static void worker_attach_to_pool(struct worker *worker, struct worker_pool *pool) { mutex_lock(&wq_pool_attach_mutex); /* * set_cpus_allowed_ptr() will fail if the cpumask doesn't have any * online CPUs. It'll be re-applied when any of the CPUs come up. */ set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); > > > +static struct cpumask user_cpu_kthread_mask __read_mostly; > > +static int user_cpu_kthread_mask_valid __read_mostly; > > Would it be cleaner to get rid of user_cpu_kthread_mask_valid and just > move the "if (!cpumask_empty" check into init_kthread_cpumask()? I'm > not really opinionated, just thinking out loud. Will get rid of this with Thomas's isolcpus= suggestion. > > +int __init init_kthread_cpumask(void) > > +{ > > + if (user_cpu_kthread_mask_valid == 1) > > + cpumask_copy(&__cpu_kthread_mask, &user_cpu_kthread_mask); > > + else > > + cpumask_copy(&__cpu_kthread_mask, cpu_all_mask); > > + > > + return 0; > > +} > > + > > +static int __init kthread_setup(char *str) > > +{ > > + cpulist_parse(str, &user_cpu_kthread_mask); > > + if (!cpumask_empty(&user_cpu_kthread_mask)) > > + user_cpu_kthread_mask_valid = 1; > > + > > + return 1; > > +}