Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2478753rdb; Wed, 4 Oct 2023 02:24:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH4QFkjV05uYk0jOPfZIbwYs8gR/A/io0PxXee2mJH5yPjwRkSTuE9px7MIIaUtM1BpATxp X-Received: by 2002:a05:6a20:3d02:b0:13d:1d14:6693 with SMTP id y2-20020a056a203d0200b0013d1d146693mr1905916pzi.45.1696411440160; Wed, 04 Oct 2023 02:24:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696411440; cv=none; d=google.com; s=arc-20160816; b=cVve7M55uKqvd6qrMjbTU7LIYofxCZ+CVXUD2bMf3vS3Q0x/w45L+WI7SfeuZFy/Nb ThI836v1YX5CHXQBDkq6Uu1ZSEjYw9zR1cYDZYzOLC++h5y9obegpkXEvpJx9Qt0xm9V a3SsWVjkOnM45zPn+iaRo+9T+cVMQCiJrC15evk4+8OGORfv1c+r9XFO0xlEkoXF5c+x fvaSy7TKmAsUXU9PPIrf4joDpF6S/+8L2wgdQNf0W8xrLkJvmiy+/xdyuCifIwc0BUcz MaO1O7ry79O2Hs7GZDcqCI1wrdjxD15w8+hg2KTQSCPiSx2DGpkoiIVeCY0aA66F0Bu/ yVgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=uGJycS1XitgkoppU454BOwvs+F7fdIZ3djwExAyv22A=; fh=cR1L2r4AhLXEpdJDMrlTY+QupFjfHxmHGxloCziTM90=; b=zTL15O/PIhOJCxcXdHMMr9Ae4CM8tkyWEc6o7HT495Q4w+OYzBOXSMjOJ3e++wR9nh Ol1RKY4Jc6PF7yvKNWbxwqZNMiGBDPc7e2kV08vaf0ysMcPvC4jQh9xhoZGbEynslnR9 QI/AAOl3Ot71FlHBmeAa5tL/t1I95SwXprPzr21t9TM5Et5I+cMKZ+sN1p9ITPx//fst YnF2T0xGuAxgH5dBjzqhrYG8r2aWggLcZvNZMGCJr3OKNV/sQ9mzMJIiZrjJH5rsa3LB YvxDm/oGXQotL7NUxXU2PEkHgGklUUGwpNmTUs7SBAntlX9hGF2iTotVaoQBvDA0igDY UJpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NicWSEgs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id c128-20020a633586000000b005780f049ffesi3336315pga.347.2023.10.04.02.23.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 02:24:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NicWSEgs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id C36068073DD2; Wed, 4 Oct 2023 02:23:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232854AbjJDJXv (ORCPT + 99 others); Wed, 4 Oct 2023 05:23:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232774AbjJDJXv (ORCPT ); Wed, 4 Oct 2023 05:23:51 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7FDB9E for ; Wed, 4 Oct 2023 02:23:46 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-9b281a2aa94so337919066b.2 for ; Wed, 04 Oct 2023 02:23:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696411425; x=1697016225; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=uGJycS1XitgkoppU454BOwvs+F7fdIZ3djwExAyv22A=; b=NicWSEgsb8N7Fii/+5WNdoOWidBEz0RvaMAi/sqLmZQfmxtUsprz11U9gK38Lk127m TeNgKovQPTi4EIh1PbN5xMKk/killsXLvweWTLqsPDDpUGlWa2n2QBDVW7uhqZBPqlhP yv2oMoSN+00V+wRHXFILOZYjh7L8/OaQiG+ooYZEsRuim+SpcZSSimWW+krnhs39uZQF 7qkO4t7cd4pnqZGjdOd5B6R0Kc7tr8pJRPgQ1mxUFc7bFaoMdFoeuUCpGFH3j1I3gGJg mM8mV0UzEfesIurZcBIKPDw+ZbYK0wppNGHBwkf8YMXuyrj2g5e5h+vNDPQiNjb9ZoHk IWfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696411425; x=1697016225; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uGJycS1XitgkoppU454BOwvs+F7fdIZ3djwExAyv22A=; b=jbC1hqxKrJSvghzA4BW771+zqMxkGYtmm4Uu1MjnaboWXlrGqPrxAXo2w4bYyPUk1h cRhm3sWylDGRbz2hEx1n2Sby5oEHp2VgQSMO8TZpD+zwPVNb5419hTBKVhJuaj79lg1M 0FuJPv6qh0FN07AVbrJai4qGRELw5f9ipX5jztFCKfvrN78Jcz9UYqfdiujBXGaomhmN tuzU3ufebfmDIQCNIjDtp9sOX03lKR+rPRgMoz84m0ySM3XW2chAUPxNqqpfq0XrwExn PYlajIbeYJGq1RjM1FfKF1LMTafHL3i7ztXb/FjKmFHOphzrzoKDi54Z1B8XUI37t53j ZWqQ== X-Gm-Message-State: AOJu0YxMcAsZdRpFkAdNfDkeafGOAHYRRnW1zsc8bn+P3hONqH1c3Nvg ejeabnH4RUdrZePZPXN0E8s= X-Received: by 2002:a17:906:2253:b0:9b2:6db8:e108 with SMTP id 19-20020a170906225300b009b26db8e108mr1331086ejr.13.1696411425025; Wed, 04 Oct 2023 02:23:45 -0700 (PDT) Received: from gmail.com (1F2EF530.nat.pool.telekom.hu. [31.46.245.48]) by smtp.gmail.com with ESMTPSA id fu31-20020a170907b01f00b009b947aacb4bsm24077ejc.191.2023.10.04.02.23.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 02:23:43 -0700 (PDT) Sender: Ingo Molnar Date: Wed, 4 Oct 2023 11:23:41 +0200 From: Ingo Molnar To: Peter Zijlstra Cc: Waiman Long , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org, Phil Auld , Brent Rowsell , Peter Hunt , Florian Weimer Subject: Re: [PATCH v4] sched/core: Use zero length to reset cpumasks in sched_setaffinity() Message-ID: References: <20231003205735.2921964-1-longman@redhat.com> <20231004083648.GI27267@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231004083648.GI27267@noisy.programming.kicks-ass.net> X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 04 Oct 2023 02:23:57 -0700 (PDT) * Peter Zijlstra wrote: > On Tue, Oct 03, 2023 at 04:57:35PM -0400, Waiman Long wrote: > > Since commit 8f9ea86fdf99 ("sched: Always preserve the user requested > > cpumask"), user provided CPU affinity via sched_setaffinity(2) is > > perserved even if the task is being moved to a different cpuset. However, > > that affinity is also being inherited by any subsequently created child > > processes which may not want or be aware of that affinity. > > > > One way to solve this problem is to provide a way to back off from that > > user provided CPU affinity. This patch implements such a scheme by > > using an input cpumask length of 0 to signal a reset of the cpumasks > > to the default as allowed by the current cpuset. A non-NULL cpumask > > should still be provided to avoid problem with older kernel. > > > > If sched_setaffinity(2) has been called previously to set a user > > supplied cpumask, a value of 0 will be returned to indicate success. > > Otherwise, an error value of -EINVAL will be returned. > > > > We may have to update the sched_setaffinity(2) manpage to document > > this new side effect of passing in an input length of 0. > > Bah.. so while this is less horrible than some of the previous hacks, > but I still think an all set mask is the sanest option. > > Adding FreeBSD's CPU_FILL() to glibc() isn't the hardest thing ever, but > even without that, it's a single memset() away. > > > Would not the below two patches, one kernel, one glibc, be all it takes? I'd much prefer this ABI variant, it's a pretty natural extension of the existing ABI and principles: > if (user_mask) { > - cpumask_copy(user_mask, in_mask); > + /* > + * All-set user cpumask resets affinity and drops the explicit > + * user mask. > + */ > + cpumask_and(user_mask, in_mask, cpu_possible_mask); > + if (cpumask_equal(user_mask, cpu_possible_mask)) { > + kfree(user_mask); > + user_mask = NULL; > + } Question: is there any observable behavioral difference between current (old) all-set cpumask calls and the patched (new) one? Thanks, Ingo